Skip to content

@phiggins /output
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Bad error message using rspec's #=~ on hashes
pete@balloon:~/projects/rspec-expectations$ rspec rspec_test.rb
FF
Failures:
1) Hash #=~ displays confusing error message when hashes are equal
Failure/Error: actual.should =~ actual
expected: {:foo=>"bar"}
got: {:foo=>"bar"} (using =~)
Diff:{:foo=>"bar"}.==({:foo=>"bar"}) returned false even though the diff between {:foo=>"bar"} and {:foo=>"bar"} is empty. Check the implementation of {:foo=>"bar"}.==.
# ./lib/rspec/expectations/fail_with.rb:33:in `fail_with'
# ./lib/rspec/matchers/operator_matcher.rb:47:in `fail_with_message'
# ./lib/rspec/matchers/operator_matcher.rb:69:in `__delegate_operator'
# ./lib/rspec/matchers/operator_matcher.rb:59:in `eval_match'
# ./lib/rspec/matchers/operator_matcher.rb:28:in `block in use_custom_matcher_or_delegate'
# ./rspec_test.rb:5:in `block (2 levels) in <top (required)>'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/example.rb:114:in `instance_eval'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/example.rb:114:in `block in run'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/example.rb:254:in `with_around_each_hooks'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/example.rb:111:in `run'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/example_group.rb:388:in `block in run_examples'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/example_group.rb:384:in `map'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/example_group.rb:384:in `run_examples'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/example_group.rb:369:in `run'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/command_line.rb:28:in `map'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/command_line.rb:28:in `block in run'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/reporter.rb:34:in `report'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/command_line.rb:25:in `run'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/runner.rb:80:in `run'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/runner.rb:17:in `block in autorun'
2) Hash #=~ displays correct error message when hashes differ
Failure/Error: actual.should =~ expected
expected: {:bar=>"baz"}
got: {:foo=>"bar"} (using =~)
Diff:
@@ -1,2 +1,2 @@
-:bar => "baz"
+:foo => "bar"
# ./lib/rspec/expectations/fail_with.rb:33:in `fail_with'
# ./lib/rspec/matchers/operator_matcher.rb:47:in `fail_with_message'
# ./lib/rspec/matchers/operator_matcher.rb:69:in `__delegate_operator'
# ./lib/rspec/matchers/operator_matcher.rb:59:in `eval_match'
# ./lib/rspec/matchers/operator_matcher.rb:28:in `block in use_custom_matcher_or_delegate'
# ./rspec_test.rb:12:in `block (2 levels) in <top (required)>'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/example.rb:114:in `instance_eval'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/example.rb:114:in `block in run'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/example.rb:254:in `with_around_each_hooks'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/example.rb:111:in `run'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/example_group.rb:388:in `block in run_examples'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/example_group.rb:384:in `map'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/example_group.rb:384:in `run_examples'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/example_group.rb:369:in `run'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/command_line.rb:28:in `map'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/command_line.rb:28:in `block in run'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/reporter.rb:34:in `report'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/command_line.rb:25:in `run'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/runner.rb:80:in `run'
# /home/pete/.rvm/gems/ruby-1.9.3-p327@rspec-expectations/bundler/gems/rspec-core-e227bb4bf288/lib/rspec/core/runner.rb:17:in `block in autorun'
Finished in 0.00081 seconds
2 examples, 2 failures
Failed examples:
rspec ./rspec_test.rb:2 # Hash #=~ displays confusing error message when hashes are equal
rspec ./rspec_test.rb:8 # Hash #=~ displays correct error message when hashes differ
describe Hash do
it "#=~_match displays confusing error message when hashes are equal" do
actual = {:foo => 'bar'}
actual.should =~ actual
end
it "#=~ displays correct error message when hashes differ" do
actual = {:foo => 'bar'}
expected = {:bar => 'baz'}
actual.should =~ expected
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.