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

Errors on ranges not handled correctly #938

Closed
joevandyk opened this issue Apr 30, 2015 · 3 comments
Closed

Errors on ranges not handled correctly #938

joevandyk opened this issue Apr 30, 2015 · 3 comments

Comments

@joevandyk
Copy link

it 'accepts a time range' do
  range = Time.new...Time.new
  expect(a_double).to receive(:random_call).with(range: range)
  a_double.random_call(range: 1)
end

fails with not what I'd expect.

  1) argument matchers matching ranges accepts a time range
     Failure/Error: a_double.random_call(range: 1)
     TypeError:
       can't iterate from Time
     # /usr/local/tanga/ruby_2.2.0-gh-201503006-1/lib/ruby/gems/2.2.0/bundler/gems/rspec-support-afdba844f4a5/lib/rspec/support/fuzzy_matcher.rb:18:in `each'
     # /usr/local/tanga/ruby_2.2.0-gh-201503006-1/lib/ruby/gems/2.2.0/bundler/gems/rspec-support-afdba844f4a5/lib/rspec/support/fuzzy_matcher.rb:18:in `include?'
     # /usr/local/tanga/ruby_2.2.0-gh-201503006-1/lib/ruby/gems/2.2.0/bundler/gems/rspec-support-afdba844f4a5/lib/rspec/support/fuzzy_matcher.rb:18:in `include?'
     # /usr/local/tanga/ruby_2.2.0-gh-201503006-1/lib/ruby/gems/2.2.0/bundler/gems/rspec-support-afdba844f4a5/lib/rspec/support/fuzzy_matcher.rb:18:in `==='
     # /usr/local/tanga/ruby_2.2.0-gh-201503006-1/lib/ruby/gems/2.2.0/bundler/gems/rspec-support-afdba844f4a5/lib/rspec/support/fuzzy_matcher.rb:18:in `values_match?'
     # /usr/local/tanga/ruby_2.2.0-gh-201503006-1/lib/ruby/gems/2.2.0/bundler/gems/rspec-support-afdba844f4a5/lib/rspec/support/fuzzy_matcher.rb:41:in `block in hashes_match?'
     # /usr/local/tanga/ruby_2.2.0-gh-201503006-1/lib/ruby/gems/2.2.0/bundler/gems/rspec-support-afdba844f4a5/lib/rspec/support/fuzzy_matcher.rb:39:in `each'
     # /usr/local/tanga/ruby_2.2.0-gh-201503006-1/lib/ruby/gems/2.2.0/bundler/gems/rspec-support-afdba844f4a5/lib/rspec/support/fuzzy_matcher.rb:39:in `all?'
     # /usr/local/tanga/ruby_2.2.0-gh-201503006-1/lib/ruby/gems/2.2.0/bundler/gems/rspec-support-afdba844f4a5/lib/rspec/support/fuzzy_matcher.rb:39:in `hashes_match?'
     # /usr/local/tanga/ruby_2.2.0-gh-201503006-1/lib/ruby/gems/2.2.0/bundler/gems/rspec-support-afdba844f4a5/lib/rspec/support/fuzzy_matcher.rb:10:in `values_match?'
     # /usr/local/tanga/ruby_2.2.0-gh-201503006-1/lib/ruby/gems/2.2.0/bundler/gems/rspec-support-afdba844f4a5/lib/rspec/support/fuzzy_matcher.rb:31:in `block in arrays_match?'
     # /usr/local/tanga/ruby_2.2.0-gh-201503006-1/lib/ruby/gems/2.2.0/bundler/gems/rspec-support-afdba844f4a5/lib/rspec/support/fuzzy_matcher.rb:30:in `each'
     # /usr/local/tanga/ruby_2.2.0-gh-201503006-1/lib/ruby/gems/2.2.0/bundler/gems/rspec-support-afdba844f4a5/lib/rspec/support/fuzzy_matcher.rb:30:in `all?'
     # /usr/local/tanga/ruby_2.2.0-gh-201503006-1/lib/ruby/gems/2.2.0/bundler/gems/rspec-support-afdba844f4a5/lib/rspec/support/fuzzy_matcher.rb:30:in `arrays_match?'
     # /usr/local/tanga/ruby_2.2.0-gh-201503006-1/lib/ruby/gems/2.2.0/bundler/gems/rspec-support-afdba844f4a5/lib/rspec/support/fuzzy_matcher.rb:12:in `values_match?'
@myronmarston
Copy link
Member

Thanks for reporting this, @joevandyk. I believe this is a bug in time range objects --- === just flat out doesn't work on them, but did in 1.8.7. I opened an issue with the ruby core team:

https://bugs.ruby-lang.org/issues/11113

I'd rather not put special-case handling in RSpec for time range objects to avoid calling === but we may have to. I want to wait to hear what the ruby core team says about the bug, though.

@myronmarston
Copy link
Member

As a temporary work around, you can wrap your range object in the eq matcher (or an alias), as that will only call == on the range:

it 'accepts a time range' do
  range = Time.new...Time.new
  expect(a_double).to receive(:random_call).with(range: an_object_eq_to(range))
  a_double.random_call(range: 1)
end

Not great, but it works.

@myronmarston
Copy link
Member

So it looks like the ruby core team has promptly fixed this:

ruby/ruby@b061634

Given that it's a ruby bug that has already been fixed and there's a reasonable work around shown above, I don't think it makes sense for us to put special case code in rspec to work around this. I'm going to close this. Thanks again for reporting it, @joevandyk.

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

2 participants