我最近回到了rails并且我记得它,一旦你设置了数据库DEV并测试了每次迁移,你就可以调用bundle exec rspec了。
但现在,当我这样做时,我不断收到此错误:
/Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/formatters/base_formatter.rb:1:in `<top (required)>': undefined method `require_rspec_core' for RSpec::Support:Module (NoMethodError)
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-extra-formatters-1.0.0/lib/rspec-extra-formatters/junit_formatter.rb:30:in `<top (required)>'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-extra-formatters-1.0.0/lib/rspec-extra-formatters.rb:1:in `<top (required)>'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/runtime.rb:76:in `require'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/runtime.rb:72:in `each'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/runtime.rb:72:in `block in require'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/runtime.rb:61:in `each'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/runtime.rb:61:in `require'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler.rb:134:in `require'
from /Users/kgan/Git/level_up_exercises/cyoa/the_honey_hour/config/application.rb:7:in `<top (required)>'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/spring-1.3.2/lib/spring/application.rb:82:in `require'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/spring-1.3.2/lib/spring/application.rb:82:in `preload'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/spring-1.3.2/lib/spring/application.rb:143:in `serve'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/spring-1.3.2/lib/spring/application.rb:131:in `block in run'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/spring-1.3.2/lib/spring/application.rb:125:in `loop'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/spring-1.3.2/lib/spring/application.rb:125:in `run'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/spring-1.3.2/lib/spring/application/boot.rb:18:in `<top (required)>'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
Coverage report generated for RSpec to /Users/kgan/Git/level_up_exercises/cyoa/the_honey_hour/coverage. 6 / 10 LOC (60.0%) covered.
/Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:393:in `check_pending!': (ActiveRecord::PendingMigrationError)
Migrations are pending. To resolve this issue, run:
bin/rake db:migrate RAILS_ENV=test
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:406:in `load_schema_if_pending!'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:412:in `block in maintain_test_schema!'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:640:in `suppress_messages'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:417:in `method_missing'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:412:in `maintain_test_schema!'
from /Users/kgan/Git/level_up_exercises/cyoa/the_honey_hour/spec/rails_helper.rb:18:in `<top (required)>'
from /Users/kgan/Git/level_up_exercises/cyoa/the_honey_hour/spec/models/user_spec.rb:1:in `require'
from /Users/kgan/Git/level_up_exercises/cyoa/the_honey_hour/spec/models/user_spec.rb:1:in `<top (required)>'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `load'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `block in load_spec_files'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `each'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `load_spec_files'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:96:in `setup'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:84:in `run'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:69:in `run'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:37:in `invoke'
from /Users/kgan/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/exe/rspec:4:in `<top (required)>'
from /Users/kgan/.rbenv/versions/2.1.5/bin/rspec:23:in `load'
from /Users/kgan/.rbenv/versions/2.1.5/bin/rspec:23:in `<main>'
但是在运行db:test:prepare之后,它就变好了。任何想法或这是测试环境中Rails的新默认行为?
答案 0 :(得分:1)
不一定,只需在每次更新架构或运行新迁移文件时运行它。它基本上处理数据库的克隆,因此您不必在测试数据库上运行迁移。