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

Change rails_helper.rb template to friendly error log #1924

Merged
merged 1 commit into from
Dec 8, 2017

Conversation

koic
Copy link
Contributor

@koic koic commented Dec 7, 2017

This commit will change rails_helper.rb template to the following pending migration error log.

Before

% bin/rspec spec/models/foo_spec.rb
/Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/bundler/gems/rails-0f8568f58d36/activerecord/lib/active_record/migration.rb:578:in
 `check_pending!':  (ActiveRecord::PendingMigrationError)

Migrations are pending. To resolve this issue, run:

        bin/rails db:migrate RAILS_ENV=test

        from /Users/koic/src/ (snip) /spec/spec_helper.rb:27:in `<top (required)>'
        from /Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/configuration.rb:1455:in `require'
        from /Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/configuration.rb:1455:in
        `block in requires='
        from /Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/configuration.rb:1455:in `each'
        from /Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/configuration.rb:1455:in `requires='
        from /Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/configuration_options.rb:112:in
        `block in process_options_into'
        from /Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/configuration_options.rb:111:in `each'
        from
        /Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/configuration_options.rb:111:in
        `process_options_into'
        from
        /Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/configuration_options.rb:21:in
        `configure'
        from /Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/runner.rb:99:in `setup'
        from /Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/runner.rb:86:in `run'
        from /Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/runner.rb:71:in `run'
        from /Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/runner.rb:45:in `invoke'
        from /Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/exe/rspec:4:in `<top (required)>'
        from bin/rspec:9:in `load'
        from bin/rspec:9:in `<main>'

After

% bin/rspec spec/models/foo_spec.rb
Migrations are pending. To resolve this issue, run:

        bin/rails db:migrate RAILS_ENV=test

This PR got an idea from rails/rails#28939.

@koic koic force-pushed the friendly_pending_migration_error_log branch from 008e07b to b202560 Compare December 7, 2017 08:59
@fables-tales
Copy link
Member

👍

@fables-tales
Copy link
Member

@koic this looks good to me, I'll write a changelog entry and get it in to the master branch when I get some time. I think this is good to put out in the next minor version of RSpec.

# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!

# If you are not using ActiveRecord, you can remove this lines.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider: "these lines" or "this block"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated it. Thanks!

@koic koic force-pushed the friendly_pending_migration_error_log branch from b202560 to 88e89be Compare December 7, 2017 14:29
This commit will change `rails_helper.rb` template to
the following pending migration error log.

## Before

```console
% bin/rspec spec/models/foo_spec.rb
/Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/bundler/gems/rails-0f8568f58d36/activerecord/lib/active_record/migration.rb:578:in
 `check_pending!':  (ActiveRecord::PendingMigrationError)

Migrations are pending. To resolve this issue, run:

        bin/rails db:migrate RAILS_ENV=test

        from /Users/koic/src/ (snip) /spec/spec_helper.rb:27:in `<top (required)>'
        from /Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/configuration.rb:1455:in `require'
        from /Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/configuration.rb:1455:in
        `block in requires='
        from /Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/configuration.rb:1455:in `each'
        from /Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/configuration.rb:1455:in `requires='
        from /Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/configuration_options.rb:112:in
        `block in process_options_into'
        from /Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/configuration_options.rb:111:in `each'
        from
        /Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/configuration_options.rb:111:in
        `process_options_into'
        from
        /Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/configuration_options.rb:21:in
        `configure'
        from /Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/runner.rb:99:in `setup'
        from /Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/runner.rb:86:in `run'
        from /Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/runner.rb:71:in `run'
        from /Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/runner.rb:45:in `invoke'
        from /Users/koic/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/exe/rspec:4:in `<top (required)>'
        from bin/rspec:9:in `load'
        from bin/rspec:9:in `<main>'
```

## After

```console
% bin/rspec spec/models/foo_spec.rb
Migrations are pending. To resolve this issue, run:

        bin/rails db:migrate RAILS_ENV=test
```

This PR got an idea from rails/rails#28939.
@koic koic force-pushed the friendly_pending_migration_error_log branch from 88e89be to 372477c Compare December 7, 2017 21:42
@JonRowe JonRowe merged commit 46779c7 into rspec:master Dec 8, 2017
@JonRowe
Copy link
Member

JonRowe commented Dec 8, 2017

Thanks ❤️

@koic koic deleted the friendly_pending_migration_error_log branch December 8, 2017 05:50
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

Successfully merging this pull request may close these issues.

None yet

4 participants