rspec-expectations 2.6.0.rc2 → 2.6.0.rc4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -3
- data/features/.nav +1 -0
- data/features/Changelog.md +5 -1
- data/features/README.markdown +18 -11
- data/features/built_in_matchers/README.md +67 -0
- data/features/built_in_matchers/be_within.feature +7 -7
- data/features/built_in_matchers/equality.feature +11 -8
- data/features/built_in_matchers/exist.feature +8 -14
- data/features/built_in_matchers/predicates.feature +13 -13
- data/lib/rspec/expectations/version.rb +1 -1
- metadata +11 -9
data/Gemfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
3
|
### rspec libs
|
4
|
-
%w[rspec-core rspec-expectations rspec-mocks].each do |lib|
|
4
|
+
%w[rspec rspec-core rspec-expectations rspec-mocks].each do |lib|
|
5
5
|
library_path = File.expand_path("../../#{lib}", __FILE__)
|
6
6
|
if File.exist?(library_path)
|
7
7
|
gem lib, :path => library_path
|
@@ -12,8 +12,8 @@ end
|
|
12
12
|
|
13
13
|
### dev dependencies
|
14
14
|
gem "rake", "0.8.7"
|
15
|
-
|
16
|
-
|
15
|
+
gem "cucumber", "~> 0.10.2"
|
16
|
+
gem "aruba", "~> 0.3.6"
|
17
17
|
gem "rcov", "0.9.9", :platforms => :mri
|
18
18
|
gem "relish", "0.2.0"
|
19
19
|
gem "guard-rspec", "0.1.9"
|
data/features/.nav
CHANGED
data/features/Changelog.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
+
### 2.6.0.rc4 / 2011-05-01
|
2
|
+
|
3
|
+
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.6.0.rc2...v2.6.0.rc4)
|
4
|
+
|
1
5
|
### 2.6.0.rc2 / 2011-04-18
|
2
6
|
|
3
|
-
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.5.0...v2.6.
|
7
|
+
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.5.0...v2.6.0.rc2)
|
4
8
|
|
5
9
|
* Enhancments
|
6
10
|
* `change` matcher accepts Regexps (Robert Davis)
|
data/features/README.markdown
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
rspec-expectations is used to
|
1
|
+
rspec-expectations is used to define expected outcomes.
|
2
2
|
|
3
3
|
describe Account do
|
4
4
|
it "has a balance of zero when first created" do
|
@@ -6,14 +6,23 @@ rspec-expectations is used to set expectations in executable examples.
|
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
-
##
|
9
|
+
## Basic structure
|
10
10
|
|
11
|
-
|
12
|
-
these can accept a matcher and, in most cases, an optional custom failure
|
13
|
-
message (see [customized
|
14
|
-
message](/rspec/rspec-expectations/v/2-3/customized-message)).
|
11
|
+
The basic structure of an rspec expectation is:
|
15
12
|
|
16
|
-
|
13
|
+
actual.should matcher(expected)
|
14
|
+
actual.should_not matcher(expected)
|
15
|
+
|
16
|
+
## `should` and `should_not`
|
17
|
+
|
18
|
+
`rspec-expectations` adds `should` and `should_not` to every object in
|
19
|
+
the system. These methods each accept a matcher as an argument. This allows
|
20
|
+
each matcher to work in a positive or negative mode:
|
21
|
+
|
22
|
+
5.should eq(5)
|
23
|
+
5.should_not eq(4)
|
24
|
+
|
25
|
+
## What is a matcher?
|
17
26
|
|
18
27
|
A Matcher is any object that responds to the following methods:
|
19
28
|
|
@@ -26,10 +35,8 @@ These methods are also part of the matcher protocol, but are optional:
|
|
26
35
|
failure_message_for_should_not
|
27
36
|
description
|
28
37
|
|
29
|
-
RSpec ships with a number of
|
30
|
-
matchers
|
31
|
-
writing your own [custom
|
32
|
-
matchers](/rspec/rspec-expectations/v/2-3/dir/custom-matchers).
|
38
|
+
RSpec ships with a number of built-in matchers and a DSL for writing custom
|
39
|
+
matchers.
|
33
40
|
|
34
41
|
## Issues
|
35
42
|
|
@@ -0,0 +1,67 @@
|
|
1
|
+
## Object identity
|
2
|
+
|
3
|
+
actual.should equal(expected) # passes if actual.equal?(expected)
|
4
|
+
|
5
|
+
## Object equivalence
|
6
|
+
|
7
|
+
actual.should == expected # passes if actual == expected
|
8
|
+
actual.should eql(expected) # passes if actual.eql?(expected)
|
9
|
+
|
10
|
+
## Optional APIs for identity/equivalence
|
11
|
+
|
12
|
+
actual.should eq(expected) # passes if actual == expected
|
13
|
+
actual.should be(expected) # passes if actual.equal?(expected)
|
14
|
+
|
15
|
+
## Comparisons
|
16
|
+
|
17
|
+
actual.should be > expected
|
18
|
+
actual.should be >= expected
|
19
|
+
actual.should be <= expected
|
20
|
+
actual.should be < expected
|
21
|
+
actual.should =~ /expression/
|
22
|
+
actual.should match(/expression/)
|
23
|
+
actual.should be_within(delta).of(expected)
|
24
|
+
|
25
|
+
## Types/classes
|
26
|
+
|
27
|
+
actual.should be_instance_of(expected)
|
28
|
+
actual.should be_kind_of(expected)
|
29
|
+
|
30
|
+
## Truthiness and existentialism
|
31
|
+
|
32
|
+
actual.should be_true # passes if actual is anything but nil or false
|
33
|
+
actual.should be_false # passes if actual is nil or false
|
34
|
+
actual.should be_nil # passes if actual is nil
|
35
|
+
actual.should be # passes if actual is not nil
|
36
|
+
|
37
|
+
## Expecting errors
|
38
|
+
|
39
|
+
expect { ... }.to raise_error
|
40
|
+
expect { ... }.to raise_error(ErrorClass)
|
41
|
+
expect { ... }.to raise_error("message")
|
42
|
+
expect { ... }.to raise_error(ErrorClass, "message")
|
43
|
+
|
44
|
+
## Expecting throws
|
45
|
+
|
46
|
+
expect { ... }.to throw_symbol
|
47
|
+
expect { ... }.to throw_symbol(:symbol)
|
48
|
+
expect { ... }.to throw_symbol(:symbol, 'value')
|
49
|
+
|
50
|
+
## Predicate matchers
|
51
|
+
|
52
|
+
actual.should be_xxx # passes if actual.xxx?
|
53
|
+
|
54
|
+
### Example
|
55
|
+
|
56
|
+
[].should be_empty # passes because [].empty? returns true
|
57
|
+
|
58
|
+
## Collection membership
|
59
|
+
|
60
|
+
actual.should include(expected)
|
61
|
+
|
62
|
+
### Examples
|
63
|
+
|
64
|
+
[1,2,3].should include(1)
|
65
|
+
[1,2,3].should include(1, 2)
|
66
|
+
{:a => 'b'}.should include(:a => 'b')
|
67
|
+
"this string".should include("is str")
|
@@ -3,17 +3,17 @@ Feature: be_within matcher
|
|
3
3
|
Normal equality expectations do not work well for floating point values.
|
4
4
|
Consider this irb session:
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
> radius = 3
|
7
|
+
=> 3
|
8
|
+
> area_of_circle = radius * radius * Math::PI
|
9
|
+
=> 28.2743338823081
|
10
|
+
> area_of_circle == 28.2743338823081
|
11
|
+
=> false
|
12
12
|
|
13
13
|
Instead, you should use the be_within matcher to check that the value
|
14
14
|
is within a delta of your expected value:
|
15
15
|
|
16
|
-
|
16
|
+
area_of_circle.should be_within(0.1).of(28.3)
|
17
17
|
|
18
18
|
Note that the difference between the actual and expected values must be
|
19
19
|
smaller than your delta; if it is equal, the matcher will fail.
|
@@ -2,9 +2,9 @@ Feature: equality matchers
|
|
2
2
|
|
3
3
|
Ruby exposes several different methods for handling equality:
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
a.equal?(b) # object identity - a and b refer to the same object
|
6
|
+
a.eql?(b) # object equivalence - a and b have the same value
|
7
|
+
a == b # object equivalence - a and b have the same value with type conversions
|
8
8
|
|
9
9
|
Note that these descriptions are guidelines but are not forced by the
|
10
10
|
language. Any object can implement any of these methods with its own
|
@@ -12,14 +12,17 @@ Feature: equality matchers
|
|
12
12
|
|
13
13
|
rspec-expectations ships with matchers that align with each of these methods:
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
a.should equal(b) # passes if a.equal?(b)
|
16
|
+
a.should eql(b) # passes if a.eql?(b)
|
17
|
+
a.should == b # passes if a == b
|
18
18
|
|
19
19
|
It also ships with two matchers that have more of a DSL feel to them:
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
a.should be(b) # passes if a.equal?(b)
|
22
|
+
a.should eq(b) # passes if a == b
|
23
|
+
|
24
|
+
These are a useful pair if you wish to avoid the warning that Ruby emits on
|
25
|
+
`a.should == b`
|
23
26
|
|
24
27
|
Scenario: compare using eq (==)
|
25
28
|
Given a file named "compare_using_eq.rb" with:
|
@@ -5,7 +5,7 @@ Feature: exist matcher
|
|
5
5
|
|
6
6
|
obj.should exist # passes if obj.exist? or obj.exists?
|
7
7
|
|
8
|
-
Scenario
|
8
|
+
Scenario: basic usage
|
9
9
|
Given a file named "exist_matcher_spec.rb" with:
|
10
10
|
"""
|
11
11
|
class Planet
|
@@ -19,21 +19,21 @@ Feature: exist matcher
|
|
19
19
|
"<Planet: #{name}>"
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def exist? # also works with exists?
|
23
23
|
%w[Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune].include?(name)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
describe "Earth" do
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
let(:earth) { Planet.new("Earth") }
|
29
|
+
specify { earth.should exist }
|
30
|
+
specify { earth.should_not exist } # deliberate failure
|
31
31
|
end
|
32
32
|
|
33
33
|
describe "Tatooine" do
|
34
|
-
|
35
|
-
it {
|
36
|
-
it {
|
34
|
+
let(:tatooine) { Planet.new("Tatooine") }
|
35
|
+
it { tatooine.should exist } # deliberate failure
|
36
|
+
it { tatooine.should_not exist }
|
37
37
|
end
|
38
38
|
"""
|
39
39
|
When I run `rspec exist_matcher_spec.rb`
|
@@ -41,9 +41,3 @@ Feature: exist matcher
|
|
41
41
|
| 4 examples, 2 failures |
|
42
42
|
| expected <Planet: Earth> not to exist |
|
43
43
|
| expected <Planet: Tatooine> to exist |
|
44
|
-
|
45
|
-
Examples:
|
46
|
-
| predicate_method |
|
47
|
-
| exist? |
|
48
|
-
| exists? |
|
49
|
-
|
@@ -2,16 +2,16 @@ Feature: predicate matchers
|
|
2
2
|
|
3
3
|
Ruby objects commonly provide predicate methods:
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
7.zero? # => false
|
6
|
+
0.zero? # => true
|
7
|
+
[1].empty? # => false
|
8
|
+
[].empty? # => true
|
9
|
+
{ :a => 5 }.has_key?(:b) # => false
|
10
|
+
{ :b => 5 }.has_key?(:b) # => true
|
11
11
|
|
12
12
|
You could use a basic equality matcher to set expectations on these:
|
13
13
|
|
14
|
-
|
14
|
+
7.zero?.should == true # fails with "expected true, got false (using ==)"
|
15
15
|
|
16
16
|
...but RSpec provides dynamic predicate matchers that are more readable and
|
17
17
|
provide better failure output.
|
@@ -19,19 +19,19 @@ Feature: predicate matchers
|
|
19
19
|
For any predicate method, RSpec gives you a corresponding matcher. Simply
|
20
20
|
prefix the method with "be_" and remove the question mark. Examples:
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
7.should_not be_zero # calls 7.zero?
|
23
|
+
[].should be_empty # calls [].empty?
|
24
|
+
x.should be_multiple_of(3) # calls x.multiple_of?(3)
|
25
25
|
|
26
26
|
Alternately, for a predicate method that begins with "has_" like Hash#has_key?,
|
27
27
|
RSpec allows you to use an alternate form since "be_has_key" makes no sense.
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
hash.should have_key(:foo) # calls hash.has_key?(:foo)
|
30
|
+
array.should_not have_odd_values # calls array.has_odd_values?
|
31
31
|
|
32
32
|
In either case, RSpec provides nice, clear error messages, such as:
|
33
33
|
|
34
|
-
|
34
|
+
expected zero? to return true, got false
|
35
35
|
|
36
36
|
Any arguments passed to the matcher will be passed on to the predicate method.
|
37
37
|
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-expectations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15424061
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 6
|
9
9
|
- 0
|
10
10
|
- rc
|
11
|
-
-
|
12
|
-
version: 2.6.0.
|
11
|
+
- 4
|
12
|
+
version: 2.6.0.rc4
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- David Chelimsky
|
@@ -18,13 +18,10 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2011-
|
21
|
+
date: 2011-05-01 00:00:00 -04:00
|
22
22
|
default_executable:
|
23
23
|
dependencies:
|
24
24
|
- !ruby/object:Gem::Dependency
|
25
|
-
prerelease: false
|
26
|
-
type: :runtime
|
27
|
-
name: diff-lcs
|
28
25
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
29
26
|
none: false
|
30
27
|
requirements:
|
@@ -36,7 +33,10 @@ dependencies:
|
|
36
33
|
- 1
|
37
34
|
- 2
|
38
35
|
version: 1.1.2
|
36
|
+
prerelease: false
|
37
|
+
type: :runtime
|
39
38
|
requirement: *id001
|
39
|
+
name: diff-lcs
|
40
40
|
description: rspec expectations (should[_not] and matchers)
|
41
41
|
email: dchelimsky@gmail.com;chad.humphries@gmail.com
|
42
42
|
executables: []
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- features/Changelog.md
|
60
60
|
- features/README.markdown
|
61
61
|
- features/Upgrade.md
|
62
|
+
- features/built_in_matchers/README.md
|
62
63
|
- features/built_in_matchers/be.feature
|
63
64
|
- features/built_in_matchers/be_within.feature
|
64
65
|
- features/built_in_matchers/equality.feature
|
@@ -195,14 +196,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
195
196
|
requirements: []
|
196
197
|
|
197
198
|
rubyforge_project: rspec
|
198
|
-
rubygems_version: 1.
|
199
|
+
rubygems_version: 1.6.2
|
199
200
|
signing_key:
|
200
201
|
specification_version: 3
|
201
|
-
summary: rspec-expectations-2.6.0.
|
202
|
+
summary: rspec-expectations-2.6.0.rc4
|
202
203
|
test_files:
|
203
204
|
- features/Changelog.md
|
204
205
|
- features/README.markdown
|
205
206
|
- features/Upgrade.md
|
207
|
+
- features/built_in_matchers/README.md
|
206
208
|
- features/built_in_matchers/be.feature
|
207
209
|
- features/built_in_matchers/be_within.feature
|
208
210
|
- features/built_in_matchers/equality.feature
|