Ruby version: 2.6.6
Rails version: 6.1.0-rc2
RSpec version: 4.1.0.pre (branch 6-1-dev)
Running rspec raises an error:
NoMethodError:
undefined method `assert_nothing_raised' for #<RSpec::ExampleGroups::Test "fails" (./spec/test_spec.rb:5)>
No "undefined method" error should be raised; it worked up until Rails 6.0.3.4.
Make a new app and add this to the Gemfile:
%w[rspec rspec-core rspec-expectations rspec-mocks rspec-support].each do |lib|
gem lib, git: "https://github.com/rspec/#{lib}.git", branch: "main"
end
git "https://github.com/rspec/rspec-rails", branch: "rails-6-1-dev" do
gem "rspec-rails"
end
Install:
bundle install
rails generate rspec:install
Add a test:
# rspec/test_spec.rb
# frozen_string_literal: true
require "rails_helper"
RSpec.describe "test" do
it "fails" do
assert_nothing_raised()
end
end
Run the tests:
bundle exec rspec spec/test_spec.rb
Any reason not to use https://relishapp.com/rspec/rspec-expectations/v/3-9/docs/built-in-matchers/raise-error-matcher?
expect { raise "oops" }.to raise_error
I have the same problem, because using the ActiveJob::TestHelpers
uses that method underneath:
RSpec.describe do
include ActiveJob::TestHelper
it 'works' do
perform_enqueued_jobs do
SomeService.doSomething
end
end
end
NoMethodError:
undefined method `assert_nothing_raised' for #<RSpec::ExampleGroups::xxxx:0x0000559e7b2a3018>
Did you mean? assert_raises
# .../gems/rspec-expectations-3.10.0/lib/rspec/matchers.rb:965:in `method_missing'
# .../gems/rspec-core-3.10.0/lib/rspec/core/example_group.rb:764:in `method_missing'
# .../gems/activejob-6.1.0.rc2/lib/active_job/test_helper.rb:591:in `perform_enqueued_jobs'
what's the best method to replicate that functionality?
EDIT
Workaround for now:
RSpec.configure do |config|
def assert_nothing_raised(&block)
expect(&block).to_not raise_error
end
end
It sounds like the module it is defined in has moved, there are a bunch of assertion modules we bring in to support various helpers.
Method definition is located in ActiveSupport::Testing::Assertions.
So you can also work around it by:
RSpec.configure do |config|
config.include ActiveSupport::Testing::Assertions
end
@benoittgt Do you think we can fix this for 6.1?
Most helpful comment
Method definition is located in ActiveSupport::Testing::Assertions.
So you can also work around it by: