I'm testing the new Rails version 5.0.0.alpha
and RSpec 3.1.7
but I'm receiving the error:
undefined method `use_transactional_tests=' for #<RSpec::Core::Configuration:0x007fccf515e338> (NoMethodError)
In rails_helper.rb
I usually use this and all works fine:
config.use_transactional_fixtures = true
But I received this warning:
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)
So, I changed my rails_helper.rb
to use the new way:
config.use_transactional_tests = true
And now I received this error:
/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>'
Any ideas? Thank you.
The deprecation warning and suggestion you are getting is from Rails, not RSpec or the rspec-rails gem. The rspec-rails gem implements use_transactional_fixtures=
and turns around and calls the same method in Rails. It does not implement use_transactional_tests=
, so you're getting that error message when you made that change.
Unless the rspec-rails gem is upgraded to support the new Rails 5 features, you'll need to set the Rails configuration directly - and as of rspec-rails 3.8 it does not.
You need to keep using config.use_transactional_fixtures = true in rspec configure for rails 5 beta (at least till the official release, not sure what are the rspec team plans on supporting this). The fix is already on master branch, here is the line fixing it.
Set the rspec gems on master branch:
%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
I updated my rspec version, so I didn't have the need to change my use_transactional_fixtures
line. In the meantime there's just a beta version:
gem 'rspec', '~> 3.5.0.beta4'
gem 'rspec-rails', '~> 3.5.0.beta4'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With