Skip to content
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

rspec spec/unit fails with ruby 3.3.0dev #1578

Closed
mtasaka opened this issue Nov 5, 2023 · 0 comments · Fixed by #1579
Closed

rspec spec/unit fails with ruby 3.3.0dev #1578

mtasaka opened this issue Nov 5, 2023 · 0 comments · Fixed by #1579

Comments

@mtasaka
Copy link
Contributor

mtasaka commented Nov 5, 2023

With ruby3.3.0dev (I tried: ruby/ruby@6e38076 ), shoulda-matcher (strictly speaking of Fedora: rubygem-shoulda-matchers-5.1.0-3.fc39 : https://src.fedoraproject.org/rpms/rubygem-shoulda-matchers/c/385e2e375340c40880ef1182320753e1b3c7f982) rspec spec/unit fails like:

Failures:

  1) Shoulda::Matchers::Independent::DelegateMethodMatcher qualified with #allow_nil when delegating manually when the delegating method does not account for the delegate object being nil rejects with the correct failure message
     Failure/Error: country.hello

     NoMethodError:
       undefined method `hello' for nil
     # ./spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb:635:in `hello'
     # ./lib/shoulda/matchers/independent/delegate_method_matcher.rb:423:in `public_send'
     # ./lib/shoulda/matchers/independent/delegate_method_matcher.rb:423:in `block in call_delegating_method_with_delegate_method_returning'
     # ./lib/shoulda/matchers/doublespeak/world.rb:29:in `with_doubles_activated'
     # ./lib/shoulda/matchers/independent/delegate_method_matcher.rb:422:in `call_delegating_method_with_delegate_method_returning'
     # ./lib/shoulda/matchers/independent/delegate_method_matcher.rb:397:in `subject_handles_nil_delegate_object?'
     # ./lib/shoulda/matchers/independent/delegate_method_matcher.rb:205:in `matches?'
     # ./spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb:650:in `block (6 levels) in <top (required)>'
     # /builddir/build/BUILD/spec/support/unit/matchers/fail_with_message_matcher.rb:21:in `block (2 levels) in <module:Matchers>'
     # ./spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb:653:in `block (5 levels) in <top (required)>'
     # /usr/share/gems/gems/bundler-2.5.0.dev/libexec/bundle:37:in `block in <top (required)>'
     # /usr/share/gems/gems/bundler-2.5.0.dev/libexec/bundle:29:in `<top (required)>'

  2) Shoulda::Matchers::Independent::DelegateMethodMatcher qualified with #allow_nil when using Forwardable when the delegate object is nil rejects with the correct failure message
     Failure/Error: subject.public_send(delegating_method, *delegated_arguments)

     NoMethodError:
       undefined method `hello' for nil
     # ./lib/shoulda/matchers/independent/delegate_method_matcher.rb:423:in `public_send'
     # ./lib/shoulda/matchers/independent/delegate_method_matcher.rb:423:in `block in call_delegating_method_with_delegate_method_returning'
     # ./lib/shoulda/matchers/doublespeak/world.rb:29:in `with_doubles_activated'
     # ./lib/shoulda/matchers/independent/delegate_method_matcher.rb:422:in `call_delegating_method_with_delegate_method_returning'
     # ./lib/shoulda/matchers/independent/delegate_method_matcher.rb:397:in `subject_handles_nil_delegate_object?'
     # ./lib/shoulda/matchers/independent/delegate_method_matcher.rb:205:in `matches?'
     # ./spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb:599:in `block (7 levels) in <top (required)>'
     # /usr/share/gems/gems/activesupport-7.0.8/lib/active_support/core_ext/kernel/reporting.rb:28:in `with_warnings'
     # /usr/share/gems/gems/activesupport-7.0.8/lib/active_support/core_ext/kernel/reporting.rb:15:in `silence_warnings'
     # ./spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb:598:in `block (6 levels) in <top (required)>'
     # /builddir/build/BUILD/spec/support/unit/matchers/fail_with_message_matcher.rb:21:in `block (2 levels) in <module:Matchers>'
     # ./spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb:603:in `block (5 levels) in <top (required)>'
     # /usr/share/gems/gems/bundler-2.5.0.dev/libexec/bundle:37:in `block in <top (required)>'
     # /usr/share/gems/gems/bundler-2.5.0.dev/libexec/bundle:29:in `<top (required)>'

Finished in 5 minutes 29 seconds (files took 8.26 seconds to load)
2485 examples, 2 failures

(Line number may differ from vanilla shoulda-matchers 5.1.0)

This is due to the following change:
ruby/ruby#6950
https://bugs.ruby-lang.org/issues/18285

NoMethodError messages will change on ruby 3.3.
With ruby 3.2.2:

$ ruby --disable-gems  -e "foo = nil ; foo.bar"
-e:1:in `<main>': undefined method `bar' for nil:NilClass (NoMethodError)

With ruby3.3.0dev:

$ ruby --disable-gems  -e "foo = nil ; foo.bar"
-e:1:in `<main>': undefined method `bar' for nil (NoMethodError)
mtasaka added a commit to mtasaka/shoulda-matchers that referenced this issue Nov 5, 2023
ruby3.3.0dev changes the error messages on NoMethodError with the following
commit / issue:

ruby/ruby#6950
https://bugs.ruby-lang.org/issues/18285

So to catch this new NoMethodError message, modify regex accordingly.

Fixes thoughtbot#1578 .
matsales28 pushed a commit that referenced this issue Dec 1, 2023
ruby3.3.0dev changes the error messages on NoMethodError with the following
commit / issue:

ruby/ruby#6950
https://bugs.ruby-lang.org/issues/18285

So to catch this new NoMethodError message, modify regex accordingly.

Fixes #1578 .
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

Successfully merging a pull request may close this issue.

1 participant