未定义的方法`use_transactional_tests =&#39; for#<rspec :: core :: configuration:0x007fccf515e338>(NoMethodError)

时间:2015-08-07 14:37:46

标签: rspec ruby-on-rails-5

我正在测试新的Rails版本3.1.7和RSpec undefined method `use_transactional_tests=' for #<RSpec::Core::Configuration:0x007fccf515e338> (NoMethodError) ,但我收到了错误:

rails_helper.rb

config.use_transactional_fixtures = true 我经常使用这个,一切正常:

DEPRECATION WARNING: use_transactional_fixtures= is deprecated and will be removed from Rails 5.0 (use use_transactional_tests= instead). (called from block in <module:FixtureSupport> at /Users/monteirobrena/.rvm/gems/ruby-2.2.2@global/gems/rspec-rails-3.1.0/lib/rspec/rails/fixture_support.rb:25)

但是我收到了这个警告:

rails_helper.rb

所以,我改变了我的config.use_transactional_tests = true 以使用新的方式:

/Users/monteirobrena/project/spec/rails_helper.rb:34:in `block in <top (required)>': undefined method `use_transactional_tests=' for #<RSpec::Core::Configuration:0x007fccf515e338> (NoMethodError)
from /Users/monteirobrena/.rvm/gems/ruby-2.2.2@global/gems/rspec-core-3.1.7/lib/rspec/core.rb:81:in `configure'
from /Users/monteirobrena/project/spec/rails_helper.rb:27:in `<top (required)>'
from /Users/monteirobrena/project/spec/controllers/messages_controller_spec.rb:1:in `require'
from /Users/monteirobrena/project/spec/controllers/messages_controller_spec.rb:1:in `<top (required)>'
from /Users/monteirobrena/.rvm/rubies/ruby-2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `load'
from /Users/monteirobrena/.rvm/rubies/ruby-2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `block in load_spec_files'
from /Users/monteirobrena/.rvm/rubies/ruby-2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `each'
from /Users/monteirobrena/.rvm/rubies/ruby-2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `load_spec_files'
from /Users/monteirobrena/.rvm/rubies/ruby-2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:96:in `setup'
from /Users/monteirobrena/.rvm/rubies/ruby-2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:84:in `run'
from /Users/monteirobrena/.rvm/rubies/ruby-2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:69:in `run'
from /Users/monteirobrena/.rvm/rubies/ruby-2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:37:in `invoke'
from /Users/monteirobrena/.rvm/gems/ruby-2.2.2@global/gems/rspec-core-3.1.7/exe/rspec:4:in `<top (required)>'
from /Users/monteirobrena/.rvm/rubies/ruby-2.2.2/bin/rspec:23:in `load'
from /Users/monteirobrena/.rvm/rubies/ruby-2.2.2/bin/rspec:23:in `<main>'
from /Users/monteirobrena/.rvm/gems/ruby-2.2.2@global/bin/ruby_executable_hooks:15:in `eval'
from /Users/monteirobrena/.rvm/gems/ruby-2.2.2@global/bin/ruby_executable_hooks:15:in `<main>'

现在我收到了这个错误:

return Nobody$.MODULE$;

有什么想法吗?谢谢。

3 个答案:

答案 0 :(得分:6)

您获得的弃用警告和建议来自Rails,而不是RSpec或rspec-rails gem。 rspec-rails gem实现use_transactional_fixtures=并转换并在每个https://github.com/rspec/rspec-rails/blob/3-3-maintenance/lib/rspec/rails/fixture_support.rb的Rails中调用相同的方法。它没有实现use_transactional_tests=,因此您在进行更改时会收到该错误消息。

在升级rspec-rails gem以支持新的Rails 5功能之前,您需要直接设置Rails配置。

答案 1 :(得分:1)

你需要继续在rspec配置 rails 5 beta 中使用 config.use_transactional_fixtures = true (至少在官方发布之前,不确定rspec团队的计划是什么支持这个)。 修复程序已在主分支here is the line fixing it.

在master分支上设置rspec gems:

%w[rspec-core rspec-expectations rspec-mocks rspec-rails rspec-support].each do |lib|
    gem lib, git: "https://github.com/rspec/#{lib}.git", branch: 'master'
end

答案 2 :(得分:0)

我更新了我的rspec版本,因此我无需更改use_transactional_fixtures行。与此同时,只有测试版:

gem 'rspec', '~> 3.5.0.beta4'
gem 'rspec-rails', '~> 3.5.0.beta4'