forked from rspec/rspec-expectations
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8dc9c2c
commit 14475f0
Showing
2 changed files
with
90 additions
and
8 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
## Object identity | ||
|
||
actual.should equal(expected) # passes if actual.equal?(expected) | ||
|
||
## Object equivalence | ||
|
||
actual.should == expected # passes if actual == expected | ||
actual.should eql(expected) # passes if actual.eql?(expected) | ||
|
||
## Optional APIs for identity/equivalence | ||
|
||
actual.should eq(expected) # passes if actual == expected | ||
actual.should be(expected) # passes if actual.equal?(expected) | ||
|
||
## Near-equality (for floats) | ||
|
||
actual.should be_within(delta).of(expected) | ||
|
||
## Regular expressions | ||
|
||
actual.should =~ /expression/ | ||
actual.should match(/expression/) | ||
|
||
## Types/classes | ||
|
||
actual.should be_instance_of(expected) | ||
actual.should be_kind_of(expected) | ||
|
||
## Truthiness and existentialism | ||
|
||
actual.should be_true # passes if actual is anything but nil or false | ||
actual.should be_false # passes if actual is nil or false | ||
actual.should be_nil # passes if actual is nil | ||
actual.should be # passes if actual is not nil | ||
|
||
## Expecting errors | ||
|
||
expect { ... }.to raise_error | ||
expect { ... }.to raise_error(ErrorClass) | ||
expect { ... }.to raise_error("message") | ||
expect { ... }.to raise_error(ErrorClass, "message") | ||
|
||
## Expecting throws | ||
|
||
expect { ... }.to throw_symbol | ||
expect { ... }.to throw_symbol(:symbol) | ||
expect { ... }.to throw_symbol(:symbol, 'value') | ||
|
||
## Operator matchers | ||
|
||
actual.should be > expected | ||
actual.should be >= expected | ||
actual.should be <= expected | ||
actual.should be < expected | ||
|
||
## Predicate matchers | ||
|
||
actual.should be_xxx # passes if actual.xxx? | ||
|
||
### Example | ||
|
||
[].should be_empty # passes because [].empty? returns true | ||
|
||
## Collection membership | ||
|
||
actual.should include(expected) | ||
|
||
### Examples | ||
|
||
[1,2,3].should include(1) | ||
[1,2,3].should include(1, 2) | ||
{:a => 'b'}.should include(:a => 'b') | ||
"this string".should include("is str") |