Last active
May 3, 2017 23:16
-
-
Save gaygenius/2c8b42cfe1a50b2259eb45db2d929aa3 to your computer and use it in GitHub Desktop.
Correct use of rspec matching
This file contains hidden or 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
describe 'Expectations' do | |
it 'fails with the wrong expectations' do | |
my_hash = { 'created_at' => Time.now } | |
expect(my_hash['created_at']).to be_a_kind_of(Time) | |
# expect(my_hash) | |
# .to eql({ 'created_at' => a_kind_of(Time) }) | |
# expect(my_hash) | |
# .to eq({ 'created_at' => a_kind_of(Time) }) | |
array_of_hashes = [ my_hash ] | |
# expect(array_of_hashes) | |
# .to eql([ { 'created_at' => a_kind_of(Time) } ]) | |
# expect(array_of_hashes) | |
# .to eq([ { 'created_at' => a_kind_of(Time) } ]) | |
end | |
it 'works with the right expectations' do | |
my_hash = { 'created_at' => Time.now } | |
expect(my_hash['created_at']).to be_a_kind_of(Time) | |
expect(my_hash) | |
.to match({ 'created_at' => a_kind_of(Time) }) | |
array_of_hashes = [ my_hash ] | |
expect(array_of_hashes) | |
.to contain_exactly({ 'created_at' => a_kind_of(Time) }) | |
expect(array_of_hashes) | |
.to match_array([ { 'created_at' => a_kind_of(Time) } ]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment