rspec-expectations 2.13.0 → 2.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. data/Changelog.md +46 -0
  2. data/README.md +43 -87
  3. data/features/README.md +8 -9
  4. data/features/built_in_matchers/README.md +41 -41
  5. data/features/built_in_matchers/be_within.feature +3 -3
  6. data/features/built_in_matchers/expect_change.feature +6 -6
  7. data/features/built_in_matchers/expect_error.feature +2 -2
  8. data/features/built_in_matchers/start_with.feature +1 -1
  9. data/features/built_in_matchers/throw_symbol.feature +11 -11
  10. data/features/built_in_matchers/yield.feature +18 -3
  11. data/features/custom_matchers/define_diffable_matcher.feature +1 -1
  12. data/features/custom_matchers/define_matcher_outside_rspec.feature +6 -6
  13. data/features/custom_matchers/define_matcher_with_fluent_interface.feature +1 -1
  14. data/features/customized_message.feature +1 -1
  15. data/features/support/env.rb +10 -1
  16. data/features/syntax_configuration.feature +3 -0
  17. data/features/test_frameworks/test_unit.feature +15 -17
  18. data/lib/rspec/expectations/deprecation.rb +12 -33
  19. data/lib/rspec/expectations/differ.rb +25 -7
  20. data/lib/rspec/expectations/expectation_target.rb +7 -8
  21. data/lib/rspec/expectations/extensions/object.rb +2 -12
  22. data/lib/rspec/expectations/fail_with.rb +11 -1
  23. data/lib/rspec/expectations/handler.rb +11 -6
  24. data/lib/rspec/expectations/syntax.rb +2 -2
  25. data/lib/rspec/expectations/version.rb +1 -1
  26. data/lib/rspec/expectations.rb +1 -1
  27. data/lib/rspec/matchers/be_close.rb +1 -1
  28. data/lib/rspec/matchers/built_in/be.rb +2 -0
  29. data/lib/rspec/matchers/built_in/be_within.rb +1 -1
  30. data/lib/rspec/matchers/built_in/change.rb +9 -1
  31. data/lib/rspec/matchers/built_in/have.rb +20 -4
  32. data/lib/rspec/matchers/built_in/include.rb +2 -10
  33. data/lib/rspec/matchers/built_in/raise_error.rb +23 -7
  34. data/lib/rspec/matchers/built_in/yield.rb +78 -3
  35. data/lib/rspec/matchers/operator_matcher.rb +1 -1
  36. data/lib/rspec/matchers/pretty.rb +7 -1
  37. data/lib/rspec/matchers/test_unit_integration.rb +11 -0
  38. data/lib/rspec/matchers.rb +141 -143
  39. data/spec/rspec/expectations/differ_spec.rb +27 -5
  40. data/spec/rspec/expectations/expectation_target_spec.rb +10 -3
  41. data/spec/rspec/expectations/extensions/kernel_spec.rb +5 -5
  42. data/spec/rspec/expectations/fail_with_spec.rb +19 -0
  43. data/spec/rspec/expectations/handler_spec.rb +42 -21
  44. data/spec/rspec/expectations/syntax_spec.rb +45 -3
  45. data/spec/rspec/matchers/be_close_spec.rb +6 -6
  46. data/spec/rspec/matchers/be_spec.rb +36 -36
  47. data/spec/rspec/matchers/be_within_spec.rb +8 -0
  48. data/spec/rspec/matchers/change_spec.rb +17 -6
  49. data/spec/rspec/matchers/configuration_spec.rb +57 -89
  50. data/spec/rspec/matchers/description_generation_spec.rb +16 -2
  51. data/spec/rspec/matchers/exist_spec.rb +9 -9
  52. data/spec/rspec/matchers/has_spec.rb +1 -1
  53. data/spec/rspec/matchers/have_spec.rb +12 -2
  54. data/spec/rspec/matchers/include_matcher_integration_spec.rb +2 -2
  55. data/spec/rspec/matchers/include_spec.rb +4 -4
  56. data/spec/rspec/matchers/match_array_spec.rb +1 -1
  57. data/spec/rspec/matchers/match_spec.rb +1 -1
  58. data/spec/rspec/matchers/raise_error_spec.rb +189 -99
  59. data/spec/rspec/matchers/respond_to_spec.rb +4 -4
  60. data/spec/rspec/matchers/satisfy_spec.rb +1 -1
  61. data/spec/rspec/matchers/start_with_end_with_spec.rb +2 -2
  62. data/spec/rspec/matchers/yield_spec.rb +81 -4
  63. data/spec/spec_helper.rb +1 -1
  64. metadata +8 -7
data/Changelog.md CHANGED
@@ -1,3 +1,49 @@
1
+ ### 2.14.0 / 2013-07-06
2
+ [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.0.rc1...v2.14.0)
3
+
4
+ Bug fixes
5
+
6
+ * Values that are not matchers use `#inspect`, rather than `#description` for
7
+ documentation output (Andy Lindeman, Sam Phippen).
8
+ * Make `expect(a).to be_within(x).percent_of(y)` work with negative y
9
+ (Katsuhiko Nishimra).
10
+ * Make the `be_predicate` matcher work as expected used with `expect{...}.to
11
+ change...` (Sam Phippen).
12
+
13
+ ### 2.14.0.rc1 / 2013-05-27
14
+ [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.13.0...v2.14.0.rc1)
15
+
16
+ Enhancements
17
+
18
+ * Enhance `yield_control` so that you can specify an exact or relative
19
+ number of times: `expect { }.to yield_control.exactly(3).times`,
20
+ `expect { }.to yield_control.at_least(2).times`, etc (Bartek
21
+ Borkowski).
22
+ * Make the differ that is used when an expectation fails better handle arrays
23
+ by splitting each element of the array onto its own line. (Sam Phippen)
24
+ * Accept duck-typed strings that respond to `:to_str` as expectation messages.
25
+ (Toby Ovod-Everett)
26
+
27
+ Bug fixes
28
+
29
+ * Fix differ to not raise errors when dealing with differently-encoded
30
+ strings (Jon Rowe).
31
+ * Fix `expect(something).to be_within(x).percent_of(y)` where x and y are both
32
+ integers (Sam Phippen).
33
+ * Fix `have` matcher to handle the fact that on ruby 2.0,
34
+ `Enumerator#size` may return nil (Kenta Murata).
35
+ * Fix `expect { raise s }.to raise_error(s)` where s is an error instance
36
+ on ruby 2.0 (Sam Phippen).
37
+ * Fix `expect(object).to raise_error` passing. This now warns the user and
38
+ fails the spec (tomykaira).
39
+
40
+ Deprecations
41
+
42
+ * Deprecate `expect { }.not_to raise_error(SpecificErrorClass)` or
43
+ `expect { }.not_to raise_error("some specific message")`. Using
44
+ these was prone to hiding failures as they would allow _any other
45
+ error_ to pass. (Sam Phippen and David Chelimsky)
46
+
1
47
  ### 2.13.0 / 2013-02-23
2
48
  [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.12.1...v2.13.0)
3
49
 
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  RSpec::Expectations lets you express expected outcomes on an object in an
4
4
  example.
5
5
 
6
- account.balance.should eq(Money.new(37.42, :USD))
6
+ expect(account.balance).to eq(Money.new(37.42, :USD))
7
7
 
8
8
  ## Install
9
9
 
@@ -38,8 +38,7 @@ describe Order do
38
38
  end
39
39
  ```
40
40
 
41
- The `describe` and `it` methods come from rspec-core. The `Order`, `LineItem`,
42
- and `Item` classes would be from _your_ code. The last line of the example
41
+ The `describe` and `it` methods come from rspec-core. The `Order`, `LineItem`, `Item` and `Money` classes would be from _your_ code. The last line of the example
43
42
  expresses an expected outcome. If `order.total == Money.new(5.55, :USD)`, then
44
43
  the example passes. If not, it fails with a message like:
45
44
 
@@ -51,52 +50,50 @@ the example passes. If not, it fails with a message like:
51
50
  ### Equivalence
52
51
 
53
52
  ```ruby
54
- actual.should eq(expected) # passes if actual == expected
55
- actual.should == expected # passes if actual == expected
56
- actual.should eql(expected) # passes if actual.eql?(expected)
53
+ expect(actual).to eq(expected) # passes if actual == expected
54
+ expect(actual).to eql(expected) # passes if actual.eql?(expected)
57
55
  ```
58
56
 
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.
57
+ Note: The new `expect` syntax no longer supports `==` matcher.
62
58
 
63
59
  ### Identity
64
60
 
65
61
  ```ruby
66
- actual.should be(expected) # passes if actual.equal?(expected)
67
- actual.should equal(expected) # passes if actual.equal?(expected)
62
+ expect(actual).to be(expected) # passes if actual.equal?(expected)
63
+ expect(actual).to equal(expected) # passes if actual.equal?(expected)
68
64
  ```
69
65
 
70
66
  ### Comparisons
71
67
 
72
68
  ```ruby
73
- actual.should be > expected
74
- actual.should be >= expected
75
- actual.should be <= expected
76
- actual.should be < expected
77
- actual.should be_within(delta).of(expected)
69
+ expect(actual).to be > expected
70
+ expect(actual).to be >= expected
71
+ expect(actual).to be <= expected
72
+ expect(actual).to be < expected
73
+ expect(actual).to be_within(delta).of(expected)
78
74
  ```
79
75
 
80
76
  ### Regular expressions
81
77
 
82
78
  ```ruby
83
- actual.should match(/expression/)
84
- actual.should =~ /expression/
79
+ expect(actual).to match(/expression/)
85
80
  ```
86
81
 
82
+ Note: The new `expect` syntax no longer supports `=~` matcher.
83
+
87
84
  ### Types/classes
88
85
 
89
86
  ```ruby
90
- actual.should be_an_instance_of(expected)
91
- actual.should be_a_kind_of(expected)
87
+ expect(actual).to be_an_instance_of(expected)
88
+ expect(actual).to be_a_kind_of(expected)
92
89
  ```
93
90
 
94
91
  ### Truthiness
95
92
 
96
93
  ```ruby
97
- actual.should be_true # passes if actual is truthy (not nil or false)
98
- actual.should be_false # passes if actual is falsy (nil or false)
99
- actual.should be_nil # passes if actual is nil
94
+ expect(actual).to be_true # passes if actual is truthy (not nil or false)
95
+ expect(actual).to be_false # passes if actual is falsy (nil or false)
96
+ expect(actual).to be_nil # passes if actual is nil
100
97
  ```
101
98
 
102
99
  ### Expecting errors
@@ -134,92 +131,51 @@ expect { |b| { :a => 1, :b => 2 }.each(&b) }.to yield_successive_args([:a, 1], [
134
131
  ### Predicate matchers
135
132
 
136
133
  ```ruby
137
- actual.should be_xxx # passes if actual.xxx?
138
- actual.should have_xxx(:arg) # passes if actual.has_xxx?(:arg)
134
+ expect(actual).to be_xxx # passes if actual.xxx?
135
+ expect(actual).to have_xxx(:arg) # passes if actual.has_xxx?(:arg)
139
136
  ```
140
137
 
141
138
  ### Ranges (Ruby >= 1.9 only)
142
139
 
143
140
  ```ruby
144
- (1..10).should cover(3)
141
+ expect(1..10).to cover(3)
145
142
  ```
146
143
 
147
144
  ### Collection membership
148
145
 
149
146
  ```ruby
150
- actual.should include(expected)
151
- actual.should start_with(expected)
152
- actual.should end_with(expected)
147
+ expect(actual).to include(expected)
148
+ expect(actual).to start_with(expected)
149
+ expect(actual).to end_with(expected)
153
150
  ```
154
151
 
155
152
  #### Examples
156
153
 
157
154
  ```ruby
158
- [1,2,3].should include(1)
159
- [1,2,3].should include(1, 2)
160
- [1,2,3].should start_with(1)
161
- [1,2,3].should start_with(1,2)
162
- [1,2,3].should end_with(3)
163
- [1,2,3].should end_with(2,3)
164
- {:a => 'b'}.should include(:a => 'b')
165
- "this string".should include("is str")
166
- "this string".should start_with("this")
167
- "this string".should end_with("ring")
155
+ expect([1,2,3]).to include(1)
156
+ expect([1,2,3]).to include(1, 2)
157
+ expect([1,2,3]).to start_with(1)
158
+ expect([1,2,3]).to start_with(1,2)
159
+ expect([1,2,3]).to end_with(3)
160
+ expect([1,2,3]).to end_with(2,3)
161
+ expect({:a => 'b'}).to include(:a => 'b')
162
+ expect("this string").to include("is str")
163
+ expect("this string").to start_with("this")
164
+ expect("this string").to end_with("ring")
168
165
  ```
169
166
 
170
- ## `expect` syntax
171
-
172
- In addition to the `should` syntax, rspec-expectations supports
173
- a new `expect` syntax as of version 2.11.0:
174
-
175
- ```ruby
176
- expect(actual).to eq expected
177
- expect(actual).to be > 3
178
- expect([1, 2, 3]).to_not include 4
179
- ```
167
+ ## `should` syntax
180
168
 
181
- If you want your project to only use one of these syntaxes, you can
182
- configure it:
169
+ In addition to the `expect` syntax, rspec-expectations continues to support the
170
+ `should` syntax:
183
171
 
184
172
  ```ruby
185
- RSpec.configure do |config|
186
- config.expect_with :rspec do |c|
187
- c.syntax = :expect
188
- # or
189
- c.syntax = :should
190
- # or
191
- c.syntax = [:should, :expect]
192
- end
193
- end
173
+ actual.should eq expected
174
+ actual.should be > 3
175
+ [1, 2, 3].should_not include 4
194
176
  ```
195
177
 
196
- See
197
- [RSpec::Expectations::Syntax#expect](http://rubydoc.info/gems/rspec-expectations/RSpec/Expectations/Syntax:expect)
198
- for more information.
199
-
200
- ### Motivation for `expect`
201
-
202
- We added the `expect` syntax to resolve some edge case issues, most notably
203
- that objects whose definitions wipe out all but a few methods were throwing
204
- `should` and `should_not` away. `expect` solves that by not monkey patching
205
- those methods onto `Kernel` (or any global object).
206
-
207
- See
208
- [http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax](http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax)
209
- for a detailed explanation.
210
-
211
- ### One-liners
212
-
213
- The one-liner syntax supported by
214
- [rspec-core](http://rubydoc.info/gems/rspec-core) uses `should` even when
215
- `config.syntax = :expect`. It reads better than the alternative, and does not
216
- require a global monkey patch:
217
-
218
- ```ruby
219
- describe User do
220
- it { should validate_presence_of :email }
221
- end
222
- ```
178
+ See [detailed information on the `should` syntax and its usage.](https://github.com/rspec/rspec-expectations/blob/master/Should.md)
223
179
 
224
180
  ## Also see
225
181
 
data/features/README.md CHANGED
@@ -2,7 +2,7 @@ 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
5
- Account.new.balance.should eq(Money.new(0))
5
+ expect(Account.new.balance).to eq(Money.new(0))
6
6
  end
7
7
  end
8
8
 
@@ -10,17 +10,16 @@ rspec-expectations is used to define expected outcomes.
10
10
 
11
11
  The basic structure of an rspec expectation is:
12
12
 
13
- actual.should matcher(expected)
14
- actual.should_not matcher(expected)
13
+ expect(actual).to matcher(expected)
14
+ expect(actual).not_to matcher(expected)
15
15
 
16
- ## `should` and `should_not`
16
+ Note: You can also use `expect(..).to_not` instead of `expect(..).not_to`.
17
+ One is an alias to the other, so you can use whichever reads better to you.
17
18
 
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:
19
+ #### Examples
21
20
 
22
- 5.should eq(5)
23
- 5.should_not eq(4)
21
+ expect(5).to eq(5)
22
+ expect(5).not_to eq(4)
24
23
 
25
24
  ## What is a matcher?
26
25
 
@@ -1,55 +1,55 @@
1
1
  # Built-in Matchers
2
2
 
3
- Here is a list of matchers that ship with rspec-expectations. Each matcher
4
- can be used with `should` or `should_not` e.g.
3
+ rspec-expectations ships with a number of built-in matchers.
4
+ Each matcher can be used with `expect(..).to` or `expect(..).not_to` to define
5
+ positive and negative expectations respectively on an object. Most matchers can
6
+ also be accessed using the `(...).should` and `(...).should_not` syntax, see
7
+ [using should syntax](https://github.com/rspec/rspec-expectations/blob/master/Should.md)
8
+ for why we recommend using `expect`.
5
9
 
6
- result.should eq(3)
7
- list.should_not be_empty
10
+ e.g.
11
+
12
+ expect(result).to eq(3)
13
+ expect(list).not_to be_empty
14
+ pi.should be > 3
8
15
 
9
16
  ## Object identity
10
17
 
11
- actual.should be(expected) # passes if actual.equal?(expected)
12
-
18
+ expect(actual).to be(expected) # passes if actual.equal?(expected)
19
+
13
20
  ## Object equivalence
14
21
 
15
- actual.should eq(expected) # passes if actual == expected
22
+ expect(actual).to eq(expected) # passes if actual == expected
16
23
 
17
24
  ## Optional APIs for identity/equivalence
18
25
 
19
- actual.should == expected # passes if actual == expected
20
- actual.should eql(expected) # passes if actual.eql?(expected)
21
- actual.should equal(expected) # passes if actual.equal?(expected)
26
+ expect(actual).to eql(expected) # passes if actual.eql?(expected)
27
+ expect(actual).to equal(expected) # passes if actual.equal?(expected)
22
28
 
23
- # NOTE: this can't work in Ruby 1.8, so we don't support it at all:
24
- # actual.should != expected
25
- # The reason is that Ruby 1.8 parses it as:
26
- # !(actual.should.==(expected)),
27
- # so by the time RSpec sees it it has no way to know that it's
28
- # been negated. Use either of these instead:
29
- # actual.should_not eq(expected)
30
- # actual.should_not == expected
29
+ # NOTE: `expect` does not support `==` matcher.
31
30
 
32
31
  ## Comparisons
33
32
 
34
- actual.should be > expected
35
- actual.should be >= expected
36
- actual.should be <= expected
37
- actual.should be < expected
38
- actual.should =~ /expression/
39
- actual.should match(/expression/)
40
- actual.should be_within(delta).of(expected)
33
+ expect(actual).to be > expected
34
+ expect(actual).to be >= expected
35
+ expect(actual).to be <= expected
36
+ expect(actual).to be < expected
37
+ expect(actual).to match(/expression/)
38
+ expect(actual).to be_within(delta).of(expected)
39
+
40
+ # NOTE: `expect` does not support `=~` matcher.
41
41
 
42
42
  ## Types/classes
43
43
 
44
- actual.should be_instance_of(expected)
45
- actual.should be_kind_of(expected)
44
+ expect(actual).to be_instance_of(expected)
45
+ expect(actual).to be_kind_of(expected)
46
46
 
47
47
  ## Truthiness and existentialism
48
48
 
49
- actual.should be_true # passes if actual is truthy (not nil or false)
50
- actual.should be_false # passes if actual is falsy (nil or false)
51
- actual.should be_nil # passes if actual is nil
52
- actual.should be # passes if actual is truthy (not nil or false)
49
+ expect(actual).to be_true # passes if actual is truthy (not nil or false)
50
+ expect(actual).to be_false # passes if actual is falsy (nil or false)
51
+ expect(actual).to be_nil # passes if actual is nil
52
+ expect(actual).to be # passes if actual is truthy (not nil or false)
53
53
 
54
54
  ## Expecting errors
55
55
 
@@ -66,25 +66,25 @@ can be used with `should` or `should_not` e.g.
66
66
 
67
67
  ## Predicate matchers
68
68
 
69
- actual.should be_xxx # passes if actual.xxx?
70
- actual.should have_xxx(:arg) # passes if actual.has_xxx?(:arg)
69
+ expect(actual).to be_xxx # passes if actual.xxx?
70
+ expect(actual).to have_xxx(:arg) # passes if actual.has_xxx?(:arg)
71
71
 
72
72
  ### Examples
73
73
 
74
- [].should be_empty # passes because [].empty? returns true
75
- { :a => 1 }.should have_key(:a) # passes because the hash has the key :a
74
+ expect([]).to be_empty
75
+ expect(:a => 1).to have_key(:a)
76
76
 
77
77
  ## Collection membership
78
78
 
79
- actual.should include(expected)
79
+ expect(actual).to include(expected)
80
80
 
81
81
  ### Examples
82
82
 
83
- [1,2,3].should include(1)
84
- [1,2,3].should include(1, 2)
85
- {:a => 'b'}.should include(:a => 'b')
86
- "this string".should include("is str")
83
+ expect([1,2,3]).to include(1)
84
+ expect([1,2,3]).to include(1, 2)
85
+ expect(:a => 'b').to include(:a => 'b')
86
+ expect("this string").to include("is str")
87
87
 
88
88
  ## Ranges (1.9 only)
89
89
 
90
- (1..10).should cover(3)
90
+ expect(1..10).to cover(3)
@@ -4,11 +4,11 @@ Feature: be_within matcher
4
4
  Consider this irb session:
5
5
 
6
6
  > radius = 3
7
- => 3
7
+ => 3
8
8
  > area_of_circle = radius * radius * Math::PI
9
- => 28.2743338823081
9
+ => 28.2743338823081
10
10
  > area_of_circle == 28.2743338823081
11
- => false
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:
@@ -11,14 +11,14 @@ Feature: expect change
11
11
  @count ||= 0
12
12
  @count += 1
13
13
  end
14
-
14
+
15
15
  def count
16
16
  @count ||= 0
17
17
  end
18
18
  end
19
19
  end
20
20
  """
21
-
21
+
22
22
  Scenario: expect change
23
23
  Given a file named "spec/example_spec.rb" with:
24
24
  """ruby
@@ -45,13 +45,13 @@ Feature: expect change
45
45
  require "counter"
46
46
 
47
47
  describe Counter, "#increment" do
48
- it "should not increment the count by 1 (using to_not)" do
49
- expect { Counter.increment }.to_not change{Counter.count}
50
- end
51
-
52
48
  it "should not increment the count by 1 (using not_to)" do
53
49
  expect { Counter.increment }.not_to change{Counter.count}
54
50
  end
51
+
52
+ it "should not increment the count by 1 (using to_not)" do
53
+ expect { Counter.increment }.to_not change{Counter.count}
54
+ end
55
55
  end
56
56
  """
57
57
  When I run `rspec spec/example_spec.rb`
@@ -124,7 +124,7 @@ Feature: raise_error matcher
124
124
  describe Object, "#public_instance_methods" do
125
125
  it "does not raise" do
126
126
  expect { Object.public_instance_methods }.
127
- to_not raise_error(NameError)
127
+ not_to raise_error(NameError)
128
128
  end
129
129
  end
130
130
  """
@@ -136,7 +136,7 @@ Feature: raise_error matcher
136
136
  """
137
137
  describe "#to_s" do
138
138
  it "does not raise" do
139
- expect { Object.new.to_s }.to_not raise_error
139
+ expect { Object.new.to_s }.not_to raise_error
140
140
  end
141
141
  end
142
142
  """
@@ -1,6 +1,6 @@
1
1
  Feature: start_with matcher
2
2
 
3
- Use the `start_with` matcher to specify that a string or array starts with
3
+ Use the `start_with` matcher to specify that a string or array starts with
4
4
  the expected characters or elements.
5
5
 
6
6
  ```ruby
@@ -26,11 +26,11 @@ Feature: throw_symbol matcher
26
26
  describe "throw" do
27
27
  specify { expect { throw :foo }.to throw_symbol }
28
28
  specify { expect { throw :bar, 7 }.to throw_symbol }
29
- specify { expect { 5 + 5 }.to_not throw_symbol }
29
+ specify { expect { 5 + 5 }.not_to throw_symbol }
30
30
 
31
31
  # deliberate failures
32
- specify { expect { throw :foo }.to_not throw_symbol }
33
- specify { expect { throw :bar, 7 }.to_not throw_symbol }
32
+ specify { expect { throw :foo }.not_to throw_symbol }
33
+ specify { expect { throw :bar, 7 }.not_to throw_symbol }
34
34
  specify { expect { 5 + 5 }.to throw_symbol }
35
35
  end
36
36
  """
@@ -47,12 +47,12 @@ Feature: throw_symbol matcher
47
47
  describe "throw symbol" do
48
48
  specify { expect { throw :foo }.to throw_symbol(:foo) }
49
49
  specify { expect { throw :foo, 7 }.to throw_symbol(:foo) }
50
- specify { expect { 5 + 5 }.to_not throw_symbol(:foo) }
51
- specify { expect { throw :bar }.to_not throw_symbol(:foo) }
50
+ specify { expect { 5 + 5 }.not_to throw_symbol(:foo) }
51
+ specify { expect { throw :bar }.not_to throw_symbol(:foo) }
52
52
 
53
53
  # deliberate failures
54
- specify { expect { throw :foo }.to_not throw_symbol(:foo) }
55
- specify { expect { throw :foo, 7 }.to_not throw_symbol(:foo) }
54
+ specify { expect { throw :foo }.not_to throw_symbol(:foo) }
55
+ specify { expect { throw :foo, 7 }.not_to throw_symbol(:foo) }
56
56
  specify { expect { 5 + 5 }.to throw_symbol(:foo) }
57
57
  specify { expect { throw :bar }.to throw_symbol(:foo) }
58
58
  end
@@ -70,12 +70,12 @@ Feature: throw_symbol matcher
70
70
  """ruby
71
71
  describe "throw symbol with argument" do
72
72
  specify { expect { throw :foo, 7 }.to throw_symbol(:foo, 7) }
73
- specify { expect { throw :foo, 8 }.to_not throw_symbol(:foo, 7) }
74
- specify { expect { throw :bar, 7 }.to_not throw_symbol(:foo, 7) }
75
- specify { expect { throw :foo }.to_not throw_symbol(:foo, 7) }
73
+ specify { expect { throw :foo, 8 }.not_to throw_symbol(:foo, 7) }
74
+ specify { expect { throw :bar, 7 }.not_to throw_symbol(:foo, 7) }
75
+ specify { expect { throw :foo }.not_to throw_symbol(:foo, 7) }
76
76
 
77
77
  # deliberate failures
78
- specify { expect { throw :foo, 7 }.to_not throw_symbol(:foo, 7) }
78
+ specify { expect { throw :foo, 7 }.not_to throw_symbol(:foo, 7) }
79
79
  specify { expect { throw :foo, 8 }.to throw_symbol(:foo, 7) }
80
80
  specify { expect { throw :bar, 7 }.to throw_symbol(:foo, 7) }
81
81
  specify { expect { throw :foo }.to throw_symbol(:foo, 7) }
@@ -30,6 +30,10 @@ Feature: yield matchers
30
30
  yield *args
31
31
  end
32
32
 
33
+ def self.yield_twice_with(*args)
34
+ 2.times { yield *args }
35
+ end
36
+
33
37
  def self.raw_yield
34
38
  yield
35
39
  end
@@ -47,17 +51,28 @@ Feature: yield matchers
47
51
  describe "yield_control matcher" do
48
52
  specify { expect { |b| MyClass.yield_once_with(1, &b) }.to yield_control }
49
53
  specify { expect { |b| MyClass.dont_yield(&b) }.not_to yield_control }
54
+ specify { expect { |b| MyClass.yield_twice_with(1, &b) }.to yield_control.twice }
55
+ specify { expect { |b| MyClass.yield_twice_with(1, &b) }.to yield_control.exactly(2).times }
56
+ specify { expect { |b| MyClass.yield_twice_with(1, &b) }.to yield_control.at_least(1) }
57
+ specify { expect { |b| MyClass.yield_twice_with(1, &b) }.to yield_control.at_most(3).times }
50
58
 
51
59
  # deliberate failures
52
60
  specify { expect { |b| MyClass.yield_once_with(1, &b) }.not_to yield_control }
53
61
  specify { expect { |b| MyClass.dont_yield(&b) }.to yield_control }
62
+ specify { expect { |b| MyClass.yield_once_with(1, &b) }.to yield_control.at_least(2).times }
63
+ specify { expect { |b| MyClass.yield_twice_with(1, &b) }.not_to yield_control.twice }
64
+ specify { expect { |b| MyClass.yield_twice_with(1, &b) }.not_to yield_control.at_least(2).times }
65
+ specify { expect { |b| MyClass.yield_twice_with(1, &b) }.not_to yield_control.at_least(1) }
66
+ specify { expect { |b| MyClass.yield_twice_with(1, &b) }.not_to yield_control.at_most(3).times }
54
67
  end
55
68
  """
56
69
  When I run `rspec yield_control_spec.rb`
57
70
  Then the output should contain all of these:
58
- | 4 examples, 2 failures |
59
- | expected given block to yield control |
60
- | expected given block not to yield control |
71
+ | 13 examples, 7 failures |
72
+ | expected given block to yield control |
73
+ | expected given block not to yield control |
74
+ | expected given block not to yield control at least twice |
75
+ | expected given block not to yield control at most 3 times |
61
76
 
62
77
  Scenario: yield_with_args matcher
63
78
  Given a file named "yield_with_args_spec.rb" with:
@@ -12,7 +12,7 @@ Feature: define diffable matcher
12
12
  match do |actual|
13
13
  actual == expected
14
14
  end
15
-
15
+
16
16
  diffable
17
17
  end
18
18
 
@@ -9,19 +9,19 @@ Feature: define matcher outside rspec
9
9
  """ruby
10
10
  require "rspec/expectations"
11
11
  require "test/unit"
12
-
12
+
13
13
  RSpec::Matchers.define :be_a_multiple_of do |expected|
14
14
  match do |actual|
15
15
  actual % expected == 0
16
16
  end
17
17
  end
18
-
18
+
19
19
  class Test::Unit::TestCase
20
20
  include RSpec::Matchers
21
21
  end
22
-
22
+
23
23
  class TestMultiples < Test::Unit::TestCase
24
-
24
+
25
25
  def test_9_should_be_a_multiple_of_3
26
26
  9.should be_a_multiple_of(3)
27
27
  end
@@ -29,10 +29,10 @@ Feature: define matcher outside rspec
29
29
  def test_9_should_be_a_multiple_of_4
30
30
  9.should be_a_multiple_of(4)
31
31
  end
32
-
32
+
33
33
  end
34
34
  """
35
35
  When I run `ruby test_multiples.rb`
36
- Then the exit status should not be 0
36
+ Then the exit status should not be 0
37
37
  And the output should contain "expected 9 to be a multiple of 4"
38
38
  And the output should contain "2 tests, 0 assertions, 0 failures, 1 errors"
@@ -1,7 +1,7 @@
1
1
  Feature: define matcher with fluent interface
2
2
 
3
3
  Use the chain() method to define matchers with a fluent interface.
4
-
4
+
5
5
  Scenario: chained method with argumetn
6
6
  Given a file named "between_spec.rb" with:
7
7
  """ruby
@@ -3,7 +3,7 @@ Feature: customized message
3
3
  RSpec tries to provide useful failure messages, but for cases in which you
4
4
  want more specific information, you can define your own message right in the
5
5
  example. This works for any matcher _other than the operator matchers_.
6
-
6
+
7
7
  Scenario: customize failure message
8
8
  Given a file named "example_spec.rb" with:
9
9
  """ruby