Skip to content

Undefined method "assert_nothing_raised" with Rails 6.1.0-rc2 #2410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jenskutilek opened this issue Dec 7, 2020 · 9 comments
Closed

Undefined method "assert_nothing_raised" with Rails 6.1.0-rc2 #2410

jenskutilek opened this issue Dec 7, 2020 · 9 comments
Milestone

Comments

@jenskutilek
Copy link

What Ruby, Rails and RSpec versions are you using?

Ruby version: 2.6.6
Rails version: 6.1.0-rc2
RSpec version: 4.1.0.pre (branch 6-1-dev)

Observed behaviour

Running rspec raises an error:

NoMethodError:
       undefined method `assert_nothing_raised' for #<RSpec::ExampleGroups::Test "fails" (./spec/test_spec.rb:5)>

Expected behaviour

No "undefined method" error should be raised; it worked up until Rails 6.0.3.4.

Can you provide an example app?

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
@pirj
Copy link
Member

pirj commented Dec 7, 2020

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

@zealot128
Copy link

zealot128 commented Dec 8, 2020

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

@JonRowe
Copy link
Member

JonRowe commented Dec 8, 2020

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.

@benoittgt benoittgt mentioned this issue Dec 9, 2020
3 tasks
@doits
Copy link
Contributor

doits commented Dec 10, 2020

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

@pirj
Copy link
Member

pirj commented Dec 10, 2020

@benoittgt Do you think we can fix this for 6.1?

@doits
Copy link
Contributor

doits commented Jan 19, 2021

This is fixed in Rails 6.1.1. rails/rails#40780, nothing to do here 🎉

@pirj
Copy link
Member

pirj commented Jan 19, 2021

@doits, thanks for the heads-up. It is known to be resolved in Rails (see #2398 (comment)).
Since Rails 6.1.1 is out, we can actually close this and if someone reports, we could recommend updating their Rails version. WDYT, @benoittgt ?

@JonRowe
Copy link
Member

JonRowe commented Jan 19, 2021

I think we should add the test from #2412 as a regression check, and if it passes with 6.1.1 close this.

@pirj
Copy link
Member

pirj commented Feb 2, 2021

Regression test added in #2455

@pirj pirj closed this as completed Feb 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants