7

我正在测试新的 Rails 版本5.0.0.alpha和 RSpec 3.1.7,但收到错误消息:

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>'

有任何想法吗?谢谢你。

4

3 回答 3

7

您收到的弃用警告和建议来自 Rails,而不是 RSpec 或 rspec-rails gem。rspec-rails gemuse_transactional_fixtures= 在 Rails 中实现和调用相同的方法。它没有实现use_transactional_tests=,因此在进行更改时会收到该错误消息。

除非升级 rspec-rails gem 以支持新的 Rails 5 功能,否则您需要直接设置 Rails 配置 - 从 rspec-rails 3.8 开始不需要。

于 2015-08-07T20:22:14.433 回答
3

您需要在 rspec configure 中继续使用config.use_transactional_fixtures = true来为rails 5 beta配置(至少在正式发布之前,不确定 rspec 团队计划支持这一点)。修复已经在 master 分支上,这里是修复它的行。

在 master 分支上设置 rspec gem:

%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
于 2016-03-17T15:26:36.550 回答
1

我更新了我的 rspec 版本,所以我不需要更改我的use_transactional_fixtures线路。与此同时,只有一个测试版:

gem 'rspec', '~> 3.5.0.beta4'
gem 'rspec-rails', '~> 3.5.0.beta4'
于 2016-06-14T21:38:08.047 回答