Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding list of existing files to failure message #44

Open
danascheider opened this issue Sep 9, 2018 · 3 comments
Open

Adding list of existing files to failure message #44

danascheider opened this issue Sep 9, 2018 · 3 comments

Comments

@danascheider
Copy link

Hi there! I had an idea for a feature that would be useful and wanted to ask if it's something you'd accept a PR for.

I'm running some generator specs and getting failures. I'm noticing it would be really useful to have a message like, "Expected file ___ to exist, but does not. Existing files in this location were..." and a list.

My use case is that I have a Rails 5 app that connects to two databases, so I have a separate migration generator for the second DB. Like the regular Rails migration generator, these migrations have timestamps in the filename, making it hard to use assert_file since I don't exactly know what the timestamp will be. Not seeing a list of files in the location makes it hard to know if no file was created or if it just had a different filename from the expected one.

To give you an idea, this is what my tests looked like:

RSpec.describe UserMigrationGenerator, type: :generator do
  destination File.expand_path("../../../tmp", __FILE__)
  arguments %w(add_foobar_to_users)
  let!(:timestamp) { Time.now.gsub(/\W/, "")[0..-5] }

  before(:all) do
    prepare_destination
    run_generator
  end

  it "creates a migration" do
    assert_file "tmp/db_users/migrate/#{timestamp}_add_foobar_to_users.rb"
  end
end

Is this a feature you'd be interested in adding? If so, I can work on it and submit a PR.

@stevehodgkiss
Copy link
Owner

Hey @danascheider. Yeah, sounds good. I'd be happy to accept a PR for that.

@danascheider
Copy link
Author

Cool, I'll work on it! Thanks!

@danascheider
Copy link
Author

I started working on this and realized it'd be easier to submit a PR to Rails instead since Rails code defines the matcher. If they're willing to accept the PR, I'll do that.

The only issue with that is, it'd only change the behavior of this gem for people using the next release of Rails. If you think this would be useful to others, I can still make it work in generator_spec so it'd be there for everyone but wanted to get your thoughts on this as it might involve some monkey patching, which we'd obviously rather avoid if possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants