rspec-expectations 2.11.3 → 2.12.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +25 -2
- data/README.md +5 -1
- data/features/built_in_matchers/be.feature +4 -4
- data/features/built_in_matchers/be_within.feature +1 -1
- data/features/built_in_matchers/cover.feature +1 -1
- data/features/built_in_matchers/end_with.feature +2 -2
- data/features/built_in_matchers/equality.feature +5 -5
- data/features/built_in_matchers/exist.feature +1 -1
- data/features/built_in_matchers/expect_change.feature +3 -3
- data/features/built_in_matchers/expect_error.feature +4 -4
- data/features/built_in_matchers/have.feature +2 -2
- data/features/built_in_matchers/include.feature +3 -3
- data/features/built_in_matchers/match.feature +2 -2
- data/features/built_in_matchers/operators.feature +3 -3
- data/features/built_in_matchers/predicates.feature +9 -8
- data/features/built_in_matchers/respond_to.feature +2 -2
- data/features/built_in_matchers/satisfy.feature +1 -1
- data/features/built_in_matchers/start_with.feature +2 -2
- data/features/built_in_matchers/throw_symbol.feature +3 -3
- data/features/built_in_matchers/types.feature +2 -2
- data/features/built_in_matchers/yield.feature +5 -5
- data/features/custom_matchers/access_running_example.feature +3 -3
- data/features/custom_matchers/define_diffable_matcher.feature +1 -1
- data/features/custom_matchers/define_matcher.feature +12 -12
- data/features/custom_matchers/define_matcher_outside_rspec.feature +1 -1
- data/features/custom_matchers/define_matcher_with_fluent_interface.feature +1 -1
- data/features/customized_message.feature +1 -1
- data/features/diffing.feature +4 -4
- data/features/implicit_docstrings.feature +2 -2
- data/features/test_frameworks/test_unit.feature +1 -1
- data/lib/rspec/expectations/differ.rb +35 -1
- data/lib/rspec/expectations/handler.rb +21 -6
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/matchers/built_in/be_instance_of.rb +4 -0
- data/lib/rspec/matchers/built_in/include.rb +3 -1
- data/lib/rspec/matchers/built_in/match_array.rb +12 -6
- data/lib/rspec/matchers/built_in/raise_error.rb +17 -7
- data/lib/rspec/matchers/built_in/yield.rb +5 -5
- data/lib/rspec/matchers/configuration.rb +42 -0
- data/lib/rspec/matchers/generated_descriptions.rb +2 -3
- data/spec/rspec/expectations/differ_spec.rb +24 -0
- data/spec/rspec/expectations/handler_spec.rb +40 -40
- data/spec/rspec/expectations/syntax_spec.rb +35 -0
- data/spec/rspec/matchers/be_instance_of_spec.rb +19 -2
- data/spec/rspec/matchers/be_spec.rb +10 -10
- data/spec/rspec/matchers/configuration_spec.rb +155 -123
- data/spec/rspec/matchers/dsl_spec.rb +8 -8
- data/spec/rspec/matchers/have_spec.rb +8 -38
- data/spec/rspec/matchers/include_spec.rb +6 -0
- data/spec/rspec/matchers/match_array_spec.rb +14 -0
- data/spec/rspec/matchers/raise_error_spec.rb +89 -38
- data/spec/rspec/matchers/start_with_end_with_spec.rb +1 -1
- data/spec/rspec/matchers/yield_spec.rb +35 -0
- metadata +70 -78
data/Changelog.md
CHANGED
@@ -1,5 +1,28 @@
|
|
1
|
+
### 2.12.0 / 2012-11-12
|
2
|
+
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.11.3...2.12.0)
|
3
|
+
|
4
|
+
Enhancements
|
5
|
+
|
6
|
+
* Colorize diffs if the `--color` option is configured. (Alex Coplan)
|
7
|
+
* Include backtraces in unexpected errors handled by `raise_error`
|
8
|
+
matcher (Myron Marston)
|
9
|
+
* Print a warning when users accidentally pass a non-string argument
|
10
|
+
as an expectation message (Sam Phippen)
|
11
|
+
* `=~` and `match_array` matchers output a more useful error message when
|
12
|
+
the actual value is not an array (or an object that responds to `#to_ary`)
|
13
|
+
(Sam Phippen)
|
14
|
+
|
15
|
+
Bug fixes
|
16
|
+
|
17
|
+
* Fix `include` matcher so that `expect({}).to include(:a => nil)`
|
18
|
+
fails as it should (Sam Phippen).
|
19
|
+
* Fix `be_an_instance_of` matcher so that `Class#to_s` is used in the
|
20
|
+
description rather than `Class#inspect`, since some classes (like
|
21
|
+
`ActiveRecord::Base`) define a long, verbose `#inspect`.
|
22
|
+
(Tom Stuart)
|
23
|
+
|
1
24
|
### 2.11.3 / 2012-09-04
|
2
|
-
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.11.2...
|
25
|
+
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.11.2...v2.11.3)
|
3
26
|
|
4
27
|
Bug fixes
|
5
28
|
|
@@ -7,7 +30,7 @@ Bug fixes
|
|
7
30
|
though it was never a documented or intended syntax. It worked as a
|
8
31
|
consequence of the implementation of `expect` in RSpec 2.10 and
|
9
32
|
earlier. (Myron Marston)
|
10
|
-
* Ensure #== is defined on
|
33
|
+
* Ensure #== is defined on built in matchers so that they can be composed.
|
11
34
|
For example:
|
12
35
|
|
13
36
|
expect {
|
data/README.md
CHANGED
@@ -56,6 +56,10 @@ actual.should == expected # passes if actual == expected
|
|
56
56
|
actual.should eql(expected) # passes if actual.eql?(expected)
|
57
57
|
```
|
58
58
|
|
59
|
+
Note: we recommend the `eq` matcher over `==` to avoid Ruby's "== in a
|
60
|
+
useless context" warning when the `==` matcher is used anywhere but the
|
61
|
+
last statement of an example.
|
62
|
+
|
59
63
|
### Identity
|
60
64
|
|
61
65
|
```ruby
|
@@ -76,8 +80,8 @@ actual.should be_within(delta).of(expected)
|
|
76
80
|
### Regular expressions
|
77
81
|
|
78
82
|
```ruby
|
79
|
-
actual.should =~ /expression/
|
80
83
|
actual.should match(/expression/)
|
84
|
+
actual.should =~ /expression/
|
81
85
|
```
|
82
86
|
|
83
87
|
### Types/classes
|
@@ -9,7 +9,7 @@ Feature: "be" matchers
|
|
9
9
|
|
10
10
|
Scenario: be_true matcher
|
11
11
|
Given a file named "be_true_spec.rb" with:
|
12
|
-
"""
|
12
|
+
"""ruby
|
13
13
|
describe "be_true matcher" do
|
14
14
|
specify { true.should be_true }
|
15
15
|
specify { 7.should be_true }
|
@@ -55,7 +55,7 @@ Feature: "be" matchers
|
|
55
55
|
|
56
56
|
Scenario: be_false matcher
|
57
57
|
Given a file named "be_false_spec.rb" with:
|
58
|
-
"""
|
58
|
+
"""ruby
|
59
59
|
describe "be_false matcher" do
|
60
60
|
specify { nil.should be_false }
|
61
61
|
specify { false.should be_false }
|
@@ -101,7 +101,7 @@ Feature: "be" matchers
|
|
101
101
|
|
102
102
|
Scenario: be_nil matcher
|
103
103
|
Given a file named "be_nil_spec.rb" with:
|
104
|
-
"""
|
104
|
+
"""ruby
|
105
105
|
describe "be_nil matcher" do
|
106
106
|
specify { nil.should be_nil }
|
107
107
|
specify { false.should_not be_nil }
|
@@ -147,7 +147,7 @@ Feature: "be" matchers
|
|
147
147
|
|
148
148
|
Scenario: be matcher
|
149
149
|
Given a file named "be_spec.rb" with:
|
150
|
-
"""
|
150
|
+
"""ruby
|
151
151
|
describe "be_matcher" do
|
152
152
|
specify { true.should be }
|
153
153
|
specify { 7.should be }
|
@@ -9,7 +9,7 @@ Feature: end_with matcher
|
|
9
9
|
|
10
10
|
Scenario: string usage
|
11
11
|
Given a file named "example_spec.rb" with:
|
12
|
-
"""
|
12
|
+
"""ruby
|
13
13
|
describe "this string" do
|
14
14
|
it { should end_with "string" }
|
15
15
|
it { should_not end_with "stringy" }
|
@@ -27,7 +27,7 @@ Feature: end_with matcher
|
|
27
27
|
|
28
28
|
Scenario: array usage
|
29
29
|
Given a file named "example_spec.rb" with:
|
30
|
-
"""
|
30
|
+
"""ruby
|
31
31
|
describe [0, 1, 2, 3, 4] do
|
32
32
|
it { should end_with 4 }
|
33
33
|
it { should end_with 3, 4 }
|
@@ -26,7 +26,7 @@ Feature: equality matchers
|
|
26
26
|
|
27
27
|
Scenario: compare using eq (==)
|
28
28
|
Given a file named "compare_using_eq.rb" with:
|
29
|
-
"""
|
29
|
+
"""ruby
|
30
30
|
require 'spec_helper'
|
31
31
|
|
32
32
|
describe "a string" do
|
@@ -50,7 +50,7 @@ Feature: equality matchers
|
|
50
50
|
|
51
51
|
Scenario: compare using ==
|
52
52
|
Given a file named "compare_using_==.rb" with:
|
53
|
-
"""
|
53
|
+
"""ruby
|
54
54
|
require 'spec_helper'
|
55
55
|
|
56
56
|
describe "a string" do
|
@@ -74,7 +74,7 @@ Feature: equality matchers
|
|
74
74
|
|
75
75
|
Scenario: compare using eql (eql?)
|
76
76
|
Given a file named "compare_using_eql.rb" with:
|
77
|
-
"""
|
77
|
+
"""ruby
|
78
78
|
require 'spec_helper'
|
79
79
|
|
80
80
|
describe "an integer" do
|
@@ -97,7 +97,7 @@ Feature: equality matchers
|
|
97
97
|
|
98
98
|
Scenario: compare using equal (equal?)
|
99
99
|
Given a file named "compare_using_equal.rb" with:
|
100
|
-
"""
|
100
|
+
"""ruby
|
101
101
|
require 'spec_helper'
|
102
102
|
|
103
103
|
describe "a string" do
|
@@ -121,7 +121,7 @@ Feature: equality matchers
|
|
121
121
|
|
122
122
|
Scenario: compare using be (equal?)
|
123
123
|
Given a file named "compare_using_be.rb" with:
|
124
|
-
"""
|
124
|
+
"""ruby
|
125
125
|
require 'spec_helper'
|
126
126
|
|
127
127
|
describe "a string" do
|
@@ -4,7 +4,7 @@ Feature: expect change
|
|
4
4
|
|
5
5
|
Background:
|
6
6
|
Given a file named "lib/counter.rb" with:
|
7
|
-
"""
|
7
|
+
"""ruby
|
8
8
|
class Counter
|
9
9
|
class << self
|
10
10
|
def increment
|
@@ -21,7 +21,7 @@ Feature: expect change
|
|
21
21
|
|
22
22
|
Scenario: expect change
|
23
23
|
Given a file named "spec/example_spec.rb" with:
|
24
|
-
"""
|
24
|
+
"""ruby
|
25
25
|
require "counter"
|
26
26
|
|
27
27
|
describe Counter, "#increment" do
|
@@ -41,7 +41,7 @@ Feature: expect change
|
|
41
41
|
|
42
42
|
Scenario: expect no change
|
43
43
|
Given a file named "spec/example_spec.rb" with:
|
44
|
-
"""
|
44
|
+
"""ruby
|
45
45
|
require "counter"
|
46
46
|
|
47
47
|
describe Counter, "#increment" do
|
@@ -48,7 +48,7 @@ Feature: raise_error matcher
|
|
48
48
|
|
49
49
|
Scenario: match message with a string
|
50
50
|
Given a file named "example_spec.rb" with:
|
51
|
-
"""
|
51
|
+
"""ruby
|
52
52
|
describe "matching error message with string" do
|
53
53
|
it "matches the error message" do
|
54
54
|
expect { raise StandardError, 'this message exactly'}.
|
@@ -61,7 +61,7 @@ Feature: raise_error matcher
|
|
61
61
|
|
62
62
|
Scenario: match message with a regexp
|
63
63
|
Given a file named "example_spec.rb" with:
|
64
|
-
"""
|
64
|
+
"""ruby
|
65
65
|
describe "matching error message with regex" do
|
66
66
|
it "matches the error message" do
|
67
67
|
expect { raise StandardError, "my message" }.
|
@@ -74,7 +74,7 @@ Feature: raise_error matcher
|
|
74
74
|
|
75
75
|
Scenario: match type + message with string
|
76
76
|
Given a file named "example_spec.rb" with:
|
77
|
-
"""
|
77
|
+
"""ruby
|
78
78
|
describe "matching error message with string" do
|
79
79
|
it "matches the error message" do
|
80
80
|
expect { raise StandardError, 'this message exactly'}.
|
@@ -87,7 +87,7 @@ Feature: raise_error matcher
|
|
87
87
|
|
88
88
|
Scenario: match type + message with regexp
|
89
89
|
Given a file named "example_spec.rb" with:
|
90
|
-
"""
|
90
|
+
"""ruby
|
91
91
|
describe "matching error message with regex" do
|
92
92
|
it "matches the error message" do
|
93
93
|
expect { raise StandardError, "my message" }.
|
@@ -25,7 +25,7 @@ Feature: have(n).items matcher
|
|
25
25
|
|
26
26
|
Scenario: have(x).items on a collection
|
27
27
|
Given a file named "have_items_spec.rb" with:
|
28
|
-
"""
|
28
|
+
"""ruby
|
29
29
|
describe [1, 2, 3] do
|
30
30
|
it { should have(3).items }
|
31
31
|
it { should_not have(2).items }
|
@@ -61,7 +61,7 @@ Feature: have(n).items matcher
|
|
61
61
|
|
62
62
|
Scenario: have(x).words on a String when String#words is defined
|
63
63
|
Given a file named "have_words_spec.rb" with:
|
64
|
-
"""
|
64
|
+
"""ruby
|
65
65
|
class String
|
66
66
|
def words
|
67
67
|
split(' ')
|
@@ -25,7 +25,7 @@ Feature: include matcher
|
|
25
25
|
|
26
26
|
Scenario: array usage
|
27
27
|
Given a file named "array_include_matcher_spec.rb" with:
|
28
|
-
"""
|
28
|
+
"""ruby
|
29
29
|
describe [1, 3, 7] do
|
30
30
|
it { should include(1) }
|
31
31
|
it { should include(3) }
|
@@ -60,7 +60,7 @@ Feature: include matcher
|
|
60
60
|
|
61
61
|
Scenario: string usage
|
62
62
|
Given a file named "string_include_matcher_spec.rb" with:
|
63
|
-
"""
|
63
|
+
"""ruby
|
64
64
|
describe "a string" do
|
65
65
|
it { should include("str") }
|
66
66
|
it { should include("a", "str", "ng") }
|
@@ -84,7 +84,7 @@ Feature: include matcher
|
|
84
84
|
|
85
85
|
Scenario: hash usage
|
86
86
|
Given a file named "hash_include_matcher_spec.rb" with:
|
87
|
-
"""
|
87
|
+
"""ruby
|
88
88
|
describe Hash do
|
89
89
|
subject { { :a => 7, :b => 5 } }
|
90
90
|
|
@@ -14,7 +14,7 @@ Feature: match matcher
|
|
14
14
|
|
15
15
|
Scenario: string usage
|
16
16
|
Given a file named "string_match_spec.rb" with:
|
17
|
-
"""
|
17
|
+
"""ruby
|
18
18
|
describe "a string" do
|
19
19
|
it { should match(/str/) }
|
20
20
|
it { should_not match(/foo/) }
|
@@ -32,7 +32,7 @@ Feature: match matcher
|
|
32
32
|
|
33
33
|
Scenario: regular expression usage
|
34
34
|
Given a file named "regexp_match_spec.rb" with:
|
35
|
-
"""
|
35
|
+
"""ruby
|
36
36
|
describe /foo/ do
|
37
37
|
it { should match("food") }
|
38
38
|
it { should_not match("drinks") }
|
@@ -26,7 +26,7 @@ Feature: operator matchers
|
|
26
26
|
|
27
27
|
Scenario: numeric operator matchers
|
28
28
|
Given a file named "numeric_operator_matchers_spec.rb" with:
|
29
|
-
"""
|
29
|
+
"""ruby
|
30
30
|
describe 18 do
|
31
31
|
it { should == 18 }
|
32
32
|
it { should be < 20 }
|
@@ -87,7 +87,7 @@ Feature: operator matchers
|
|
87
87
|
|
88
88
|
Scenario: string operator matchers
|
89
89
|
Given a file named "string_operator_matchers_spec.rb" with:
|
90
|
-
"""
|
90
|
+
"""ruby
|
91
91
|
describe "Strawberry" do
|
92
92
|
it { should == "Strawberry" }
|
93
93
|
it { should be < "Tomato" }
|
@@ -178,7 +178,7 @@ Feature: operator matchers
|
|
178
178
|
|
179
179
|
Scenario: array operator matchers
|
180
180
|
Given a file named "array_operator_matchers_spec.rb" with:
|
181
|
-
"""
|
181
|
+
"""ruby
|
182
182
|
describe [1, 2, 3] do
|
183
183
|
it { should == [1, 2, 3] }
|
184
184
|
it { should_not == [1, 3, 2] }
|
@@ -17,14 +17,15 @@ Feature: predicate matchers
|
|
17
17
|
provide better failure output.
|
18
18
|
|
19
19
|
For any predicate method, RSpec gives you a corresponding matcher. Simply
|
20
|
-
prefix the method with
|
20
|
+
prefix the method with `be_` and remove the question mark. Examples:
|
21
21
|
|
22
22
|
7.should_not be_zero # calls 7.zero?
|
23
23
|
[].should be_empty # calls [].empty?
|
24
24
|
x.should be_multiple_of(3) # calls x.multiple_of?(3)
|
25
25
|
|
26
|
-
Alternately, for a predicate method that begins with
|
27
|
-
RSpec allows you to use an alternate form since
|
26
|
+
Alternately, for a predicate method that begins with `has_` like
|
27
|
+
`Hash#has_key?`, RSpec allows you to use an alternate form since `be_has_key`
|
28
|
+
makes no sense.
|
28
29
|
|
29
30
|
hash.should have_key(:foo) # calls hash.has_key?(:foo)
|
30
31
|
array.should_not have_odd_values # calls array.has_odd_values?
|
@@ -37,7 +38,7 @@ Feature: predicate matchers
|
|
37
38
|
|
38
39
|
Scenario: should be_zero (based on Fixnum#zero?)
|
39
40
|
Given a file named "should_be_zero_spec.rb" with:
|
40
|
-
"""
|
41
|
+
"""ruby
|
41
42
|
describe 0 do
|
42
43
|
it { should be_zero }
|
43
44
|
end
|
@@ -52,7 +53,7 @@ Feature: predicate matchers
|
|
52
53
|
|
53
54
|
Scenario: should_not be_empty (based on Array#empty?)
|
54
55
|
Given a file named "should_not_be_empty_spec.rb" with:
|
55
|
-
"""
|
56
|
+
"""ruby
|
56
57
|
describe [1, 2, 3] do
|
57
58
|
it { should_not be_empty }
|
58
59
|
end
|
@@ -67,7 +68,7 @@ Feature: predicate matchers
|
|
67
68
|
|
68
69
|
Scenario: should have_key (based on Hash#has_key?)
|
69
70
|
Given a file named "should_have_key_spec.rb" with:
|
70
|
-
"""
|
71
|
+
"""ruby
|
71
72
|
describe Hash do
|
72
73
|
subject { { :foo => 7 } }
|
73
74
|
it { should have_key(:foo) }
|
@@ -80,7 +81,7 @@ Feature: predicate matchers
|
|
80
81
|
|
81
82
|
Scenario: should_not have_all_string_keys (based on custom #has_all_string_keys? method)
|
82
83
|
Given a file named "should_not_have_all_string_keys_spec.rb" with:
|
83
|
-
"""
|
84
|
+
"""ruby
|
84
85
|
class Hash
|
85
86
|
def has_all_string_keys?
|
86
87
|
keys.all? { |k| String === k }
|
@@ -105,7 +106,7 @@ Feature: predicate matchers
|
|
105
106
|
|
106
107
|
Scenario: matcher arguments are passed on to the predicate method
|
107
108
|
Given a file named "predicate_matcher_argument_spec.rb" with:
|
108
|
-
"""
|
109
|
+
"""ruby
|
109
110
|
class Fixnum
|
110
111
|
def multiple_of?(x)
|
111
112
|
(self % x).zero?
|
@@ -22,7 +22,7 @@ Feature: respond_to matcher
|
|
22
22
|
|
23
23
|
Scenario: basic usage
|
24
24
|
Given a file named "respond_to_matcher_spec.rb" with:
|
25
|
-
"""
|
25
|
+
"""ruby
|
26
26
|
describe "a string" do
|
27
27
|
it { should respond_to(:length) }
|
28
28
|
it { should respond_to(:hash, :class, :to_s) }
|
@@ -53,7 +53,7 @@ Feature: respond_to matcher
|
|
53
53
|
|
54
54
|
Scenario: specify arguments
|
55
55
|
Given a file named "respond_to_matcher_argument_checking_spec.rb" with:
|
56
|
-
"""
|
56
|
+
"""ruby
|
57
57
|
describe 7 do
|
58
58
|
it { should respond_to(:zero?).with(0).arguments }
|
59
59
|
it { should_not respond_to(:zero?).with(1).argument }
|
@@ -9,7 +9,7 @@ Feature: start_with matcher
|
|
9
9
|
|
10
10
|
Scenario: with a string
|
11
11
|
Given a file named "example_spec.rb" with:
|
12
|
-
"""
|
12
|
+
"""ruby
|
13
13
|
describe "this string" do
|
14
14
|
it { should start_with "this" }
|
15
15
|
it { should_not start_with "that" }
|
@@ -27,7 +27,7 @@ Feature: start_with matcher
|
|
27
27
|
|
28
28
|
Scenario: with an array
|
29
29
|
Given a file named "example_spec.rb" with:
|
30
|
-
"""
|
30
|
+
"""ruby
|
31
31
|
describe [0, 1, 2, 3, 4] do
|
32
32
|
it { should start_with 0 }
|
33
33
|
it { should start_with(0, 1)}
|