thoughtbot / shoulda-matchers

Simple one-liner tests for common Rails functionality
https://matchers.shoulda.io
MIT License
3.51k stars 912 forks source link

rspec spec/unit fails with ruby 3.3.0dev #1578

Closed mtasaka closed 10 months ago

mtasaka commented 11 months ago

With ruby3.3.0dev (I tried: https://github.com/ruby/ruby/commit/6e38076b1689af98ab1164af9119b9304e54829a ), 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: https://github.com/ruby/ruby/pull/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)