Skip to content

Instantly share code, notes, and snippets.

@blaisethomas
Created March 3, 2015 19:38
Show Gist options
  • Save blaisethomas/d6e0884f6380a0fe353c to your computer and use it in GitHub Desktop.
Save blaisethomas/d6e0884f6380a0fe353c to your computer and use it in GitHub Desktop.
expect matchers
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