Created
June 13, 2014 04:27
-
-
Save znz/cd75b4033638de679f22 to your computer and use it in GitHub Desktop.
rspec で be(false) と eq(false) の違い
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% cat spec/falsey_spec.rb | |
describe do | |
it do | |
expect(true).to be(false) | |
end | |
it do | |
expect(true).to eq(false) | |
end | |
end | |
% bundle exec rspec -v | |
2.99.0 | |
% bundle exec rspec spec/falsey_spec.rb | |
FF | |
Failures: | |
1) should equal false | |
Failure/Error: expect(true).to be(false) | |
expected #<FalseClass:0> => false | |
got #<TrueClass:20> => true | |
Compared using equal?, which compares object identity, | |
but expected and actual are not the same object. Use | |
`expect(actual).to eq(expected)` if you don't care about | |
object identity in this example. | |
# ./spec/falsey_spec.rb:3:in `block (2 levels) in <top (required)>' | |
2) should eq false | |
Failure/Error: expect(true).to eq(false) | |
expected: false | |
got: true | |
(compared using ==) | |
# ./spec/falsey_spec.rb:6:in `block (2 levels) in <top (required)>' | |
Finished in 0.00116 seconds | |
2 examples, 2 failures | |
Failed examples: | |
rspec ./spec/falsey_spec.rb:2 # should equal false | |
rspec ./spec/falsey_spec.rb:5 # should eq false | |
zsh: exit 1 bundle exec rspec spec/falsey_spec.rb | |
% rspec -v | |
3.0.1 | |
% rspec spec/falsey_spec.rb | |
FF | |
Failures: | |
1) should equal false | |
Failure/Error: expect(true).to be(false) | |
expected false | |
got true | |
# ./spec/falsey_spec.rb:3:in `block (2 levels) in <top (required)>' | |
2) should eq false | |
Failure/Error: expect(true).to eq(false) | |
expected: false | |
got: true | |
(compared using ==) | |
# ./spec/falsey_spec.rb:6:in `block (2 levels) in <top (required)>' | |
Finished in 0.00151 seconds (files took 0.12108 seconds to load) | |
2 examples, 2 failures | |
Failed examples: | |
rspec ./spec/falsey_spec.rb:2 # should equal false | |
rspec ./spec/falsey_spec.rb:5 # should eq false | |
zsh: exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment