Created
March 3, 2015 19:38
-
-
Save blaisethomas/d6e0884f6380a0fe353c to your computer and use it in GitHub Desktop.
expect matchers
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
Object identity | |
expect(actual).to be(expected) # passes if actual.equal?(expected) | |
Object equivalence | |
expect(actual).to eq(expected) # passes if actual == expected | |
Comparisons | |
expect(actual).to be > expected | |
expect(actual).to be >= expected | |
Types/classes/response | |
expect(actual).to be_instance_of(expected) | |
expect(actual).to be_kind_of(expected) | |
expect(actual).to respond_to(expected) | |
Truthiness and existentialism | |
expect(actual).to be_truthy # passes if actual is truthy (not nil or false) | |
expect(actual).to be true # passes if actual == true | |
expect(actual).to be_nil # passes if actual is nil | |
expect(actual).to exist # passes if actual.exist? and/or actual.exists? | |
Collection membership #like yesterday's quiz (include?) | |
expect(actual).to include(expected) | |
expect(array).to match_array(expected_array)# ...which is the same as: | |
Change observation | |
expect { object.action }.to change(object, :value).from(old).to(new) | |
expect { object.action }.to change(object, :value).by(delta) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment