rspec-expectations 2.14.0 → 3.13.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 (155) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/.document +1 -1
  4. data/.yardopts +1 -1
  5. data/Changelog.md +976 -25
  6. data/{License.txt → LICENSE.md} +5 -3
  7. data/README.md +162 -26
  8. data/lib/rspec/expectations/block_snippet_extractor.rb +253 -0
  9. data/lib/rspec/expectations/configuration.rb +230 -0
  10. data/lib/rspec/expectations/expectation_target.rb +127 -51
  11. data/lib/rspec/expectations/fail_with.rb +17 -57
  12. data/lib/rspec/expectations/failure_aggregator.rb +229 -0
  13. data/lib/rspec/expectations/handler.rb +146 -32
  14. data/lib/rspec/expectations/minitest_integration.rb +58 -0
  15. data/lib/rspec/expectations/syntax.rb +68 -100
  16. data/lib/rspec/expectations/version.rb +1 -1
  17. data/lib/rspec/expectations.rb +58 -23
  18. data/lib/rspec/matchers/aliased_matcher.rb +116 -0
  19. data/lib/rspec/matchers/built_in/all.rb +86 -0
  20. data/lib/rspec/matchers/built_in/base_matcher.rb +191 -20
  21. data/lib/rspec/matchers/built_in/be.rb +114 -114
  22. data/lib/rspec/matchers/built_in/be_between.rb +77 -0
  23. data/lib/rspec/matchers/built_in/be_instance_of.rb +15 -4
  24. data/lib/rspec/matchers/built_in/be_kind_of.rb +10 -1
  25. data/lib/rspec/matchers/built_in/be_within.rb +35 -18
  26. data/lib/rspec/matchers/built_in/change.rb +389 -80
  27. data/lib/rspec/matchers/built_in/compound.rb +290 -0
  28. data/lib/rspec/matchers/built_in/contain_exactly.rb +310 -0
  29. data/lib/rspec/matchers/built_in/count_expectation.rb +169 -0
  30. data/lib/rspec/matchers/built_in/cover.rb +3 -0
  31. data/lib/rspec/matchers/built_in/eq.rb +30 -8
  32. data/lib/rspec/matchers/built_in/eql.rb +23 -8
  33. data/lib/rspec/matchers/built_in/equal.rb +55 -22
  34. data/lib/rspec/matchers/built_in/exist.rb +74 -10
  35. data/lib/rspec/matchers/built_in/has.rb +141 -22
  36. data/lib/rspec/matchers/built_in/have_attributes.rb +114 -0
  37. data/lib/rspec/matchers/built_in/include.rb +184 -32
  38. data/lib/rspec/matchers/built_in/match.rb +95 -1
  39. data/lib/rspec/matchers/built_in/operators.rb +128 -0
  40. data/lib/rspec/matchers/built_in/output.rb +207 -0
  41. data/lib/rspec/matchers/built_in/raise_error.rb +192 -44
  42. data/lib/rspec/matchers/built_in/respond_to.rb +154 -28
  43. data/lib/rspec/matchers/built_in/satisfy.rb +39 -9
  44. data/lib/rspec/matchers/built_in/start_or_end_with.rb +94 -0
  45. data/lib/rspec/matchers/built_in/throw_symbol.rb +58 -14
  46. data/lib/rspec/matchers/built_in/yield.rb +240 -161
  47. data/lib/rspec/matchers/built_in.rb +47 -33
  48. data/lib/rspec/matchers/composable.rb +171 -0
  49. data/lib/rspec/matchers/dsl.rb +531 -10
  50. data/lib/rspec/matchers/english_phrasing.rb +58 -0
  51. data/lib/rspec/matchers/fail_matchers.rb +42 -0
  52. data/lib/rspec/matchers/generated_descriptions.rb +14 -8
  53. data/lib/rspec/matchers/matcher_delegator.rb +61 -0
  54. data/lib/rspec/matchers/matcher_protocol.rb +105 -0
  55. data/lib/rspec/matchers/multi_matcher_diff.rb +82 -0
  56. data/lib/rspec/matchers.rb +520 -173
  57. data.tar.gz.sig +0 -0
  58. metadata +141 -242
  59. metadata.gz.sig +2 -0
  60. data/features/README.md +0 -48
  61. data/features/Upgrade.md +0 -53
  62. data/features/built_in_matchers/README.md +0 -90
  63. data/features/built_in_matchers/be.feature +0 -175
  64. data/features/built_in_matchers/be_within.feature +0 -48
  65. data/features/built_in_matchers/cover.feature +0 -47
  66. data/features/built_in_matchers/end_with.feature +0 -48
  67. data/features/built_in_matchers/equality.feature +0 -139
  68. data/features/built_in_matchers/exist.feature +0 -45
  69. data/features/built_in_matchers/expect_change.feature +0 -59
  70. data/features/built_in_matchers/expect_error.feature +0 -144
  71. data/features/built_in_matchers/have.feature +0 -109
  72. data/features/built_in_matchers/include.feature +0 -174
  73. data/features/built_in_matchers/match.feature +0 -52
  74. data/features/built_in_matchers/operators.feature +0 -227
  75. data/features/built_in_matchers/predicates.feature +0 -137
  76. data/features/built_in_matchers/respond_to.feature +0 -84
  77. data/features/built_in_matchers/satisfy.feature +0 -33
  78. data/features/built_in_matchers/start_with.feature +0 -48
  79. data/features/built_in_matchers/throw_symbol.feature +0 -91
  80. data/features/built_in_matchers/types.feature +0 -116
  81. data/features/built_in_matchers/yield.feature +0 -161
  82. data/features/custom_matchers/access_running_example.feature +0 -53
  83. data/features/custom_matchers/define_diffable_matcher.feature +0 -27
  84. data/features/custom_matchers/define_matcher.feature +0 -368
  85. data/features/custom_matchers/define_matcher_outside_rspec.feature +0 -38
  86. data/features/custom_matchers/define_matcher_with_fluent_interface.feature +0 -24
  87. data/features/customized_message.feature +0 -22
  88. data/features/diffing.feature +0 -85
  89. data/features/implicit_docstrings.feature +0 -52
  90. data/features/step_definitions/additional_cli_steps.rb +0 -22
  91. data/features/support/env.rb +0 -14
  92. data/features/syntax_configuration.feature +0 -71
  93. data/features/test_frameworks/test_unit.feature +0 -44
  94. data/lib/rspec/expectations/deprecation.rb +0 -17
  95. data/lib/rspec/expectations/differ.rb +0 -133
  96. data/lib/rspec/expectations/errors.rb +0 -9
  97. data/lib/rspec/expectations/extensions/array.rb +0 -9
  98. data/lib/rspec/expectations/extensions/object.rb +0 -29
  99. data/lib/rspec/expectations/extensions.rb +0 -2
  100. data/lib/rspec/matchers/be_close.rb +0 -9
  101. data/lib/rspec/matchers/built_in/have.rb +0 -124
  102. data/lib/rspec/matchers/built_in/match_array.rb +0 -51
  103. data/lib/rspec/matchers/built_in/start_and_end_with.rb +0 -48
  104. data/lib/rspec/matchers/compatibility.rb +0 -14
  105. data/lib/rspec/matchers/configuration.rb +0 -108
  106. data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +0 -39
  107. data/lib/rspec/matchers/matcher.rb +0 -300
  108. data/lib/rspec/matchers/method_missing.rb +0 -12
  109. data/lib/rspec/matchers/operator_matcher.rb +0 -109
  110. data/lib/rspec/matchers/pretty.rb +0 -70
  111. data/lib/rspec/matchers/test_unit_integration.rb +0 -11
  112. data/lib/rspec-expectations.rb +0 -1
  113. data/spec/rspec/expectations/differ_spec.rb +0 -192
  114. data/spec/rspec/expectations/expectation_target_spec.rb +0 -82
  115. data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
  116. data/spec/rspec/expectations/fail_with_spec.rb +0 -114
  117. data/spec/rspec/expectations/handler_spec.rb +0 -227
  118. data/spec/rspec/expectations/syntax_spec.rb +0 -139
  119. data/spec/rspec/matchers/base_matcher_spec.rb +0 -62
  120. data/spec/rspec/matchers/be_close_spec.rb +0 -22
  121. data/spec/rspec/matchers/be_instance_of_spec.rb +0 -63
  122. data/spec/rspec/matchers/be_kind_of_spec.rb +0 -41
  123. data/spec/rspec/matchers/be_spec.rb +0 -516
  124. data/spec/rspec/matchers/be_within_spec.rb +0 -137
  125. data/spec/rspec/matchers/change_spec.rb +0 -553
  126. data/spec/rspec/matchers/configuration_spec.rb +0 -206
  127. data/spec/rspec/matchers/cover_spec.rb +0 -69
  128. data/spec/rspec/matchers/description_generation_spec.rb +0 -190
  129. data/spec/rspec/matchers/dsl_spec.rb +0 -57
  130. data/spec/rspec/matchers/eq_spec.rb +0 -60
  131. data/spec/rspec/matchers/eql_spec.rb +0 -41
  132. data/spec/rspec/matchers/equal_spec.rb +0 -78
  133. data/spec/rspec/matchers/exist_spec.rb +0 -124
  134. data/spec/rspec/matchers/has_spec.rb +0 -122
  135. data/spec/rspec/matchers/have_spec.rb +0 -455
  136. data/spec/rspec/matchers/include_matcher_integration_spec.rb +0 -30
  137. data/spec/rspec/matchers/include_spec.rb +0 -531
  138. data/spec/rspec/matchers/match_array_spec.rb +0 -194
  139. data/spec/rspec/matchers/match_spec.rb +0 -61
  140. data/spec/rspec/matchers/matcher_spec.rb +0 -471
  141. data/spec/rspec/matchers/matchers_spec.rb +0 -37
  142. data/spec/rspec/matchers/method_missing_spec.rb +0 -28
  143. data/spec/rspec/matchers/operator_matcher_spec.rb +0 -223
  144. data/spec/rspec/matchers/raise_error_spec.rb +0 -485
  145. data/spec/rspec/matchers/respond_to_spec.rb +0 -292
  146. data/spec/rspec/matchers/satisfy_spec.rb +0 -44
  147. data/spec/rspec/matchers/start_with_end_with_spec.rb +0 -186
  148. data/spec/rspec/matchers/throw_symbol_spec.rb +0 -116
  149. data/spec/rspec/matchers/yield_spec.rb +0 -514
  150. data/spec/spec_helper.rb +0 -54
  151. data/spec/support/classes.rb +0 -56
  152. data/spec/support/in_sub_process.rb +0 -38
  153. data/spec/support/matchers.rb +0 -22
  154. data/spec/support/ruby_version.rb +0 -10
  155. data/spec/support/shared_examples.rb +0 -13
@@ -1,227 +0,0 @@
1
- Feature: operator matchers
2
-
3
- RSpec provides a number of matchers that are based on Ruby's built-in
4
- operators. These pretty much work like you expect. For example, each of these
5
- pass:
6
-
7
- ```ruby
8
- 7.should == 7
9
- [1, 2, 3].should == [1, 2, 3]
10
- "this is a string".should =~ /^this/
11
- "this is a string".should_not =~ /^that/
12
- String.should === "this is a string"
13
- ```
14
-
15
- You can also use comparison operators combined with the "be" matcher like
16
- this:
17
-
18
- ```ruby
19
- 37.should be < 100
20
- 37.should be <= 38
21
- 37.should be >= 2
22
- 37.should be > 7
23
- ```
24
-
25
- RSpec also provides a `=~` matcher for arrays that disregards differences in
26
- the ording between the actual and expected array. For example:
27
-
28
- ```ruby
29
- [1, 2, 3].should =~ [2, 3, 1] # pass
30
- [:a, :c, :b].should =~ [:a, :c] # fail
31
- ```
32
-
33
- Scenario: numeric operator matchers
34
- Given a file named "numeric_operator_matchers_spec.rb" with:
35
- """ruby
36
- describe 18 do
37
- it { should == 18 }
38
- it { should be < 20 }
39
- it { should be > 15 }
40
- it { should be <= 19 }
41
- it { should be >= 17 }
42
-
43
- it { should_not == 28 }
44
-
45
- # deliberate failures
46
- it { should == 28 }
47
- it { should be < 15 }
48
- it { should be > 20 }
49
- it { should be <= 17 }
50
- it { should be >= 19 }
51
-
52
- it { should_not == 18 }
53
- end
54
- """
55
- When I run `rspec numeric_operator_matchers_spec.rb`
56
- Then the output should contain "12 examples, 6 failures"
57
- And the output should contain:
58
- """
59
- Failure/Error: it { should == 28 }
60
- expected: 28
61
- got: 18 (using ==)
62
- """
63
- And the output should contain:
64
- """
65
- Failure/Error: it { should be < 15 }
66
- expected: < 15
67
- got: 18
68
- """
69
- And the output should contain:
70
- """
71
- Failure/Error: it { should be > 20 }
72
- expected: > 20
73
- got: 18
74
- """
75
- And the output should contain:
76
- """
77
- Failure/Error: it { should be <= 17 }
78
- expected: <= 17
79
- got: 18
80
- """
81
- And the output should contain:
82
- """
83
- Failure/Error: it { should be >= 19 }
84
- expected: >= 19
85
- got: 18
86
- """
87
- And the output should contain:
88
- """
89
- Failure/Error: it { should_not == 18 }
90
- expected not: == 18
91
- got: 18
92
- """
93
-
94
- Scenario: string operator matchers
95
- Given a file named "string_operator_matchers_spec.rb" with:
96
- """ruby
97
- describe "Strawberry" do
98
- it { should == "Strawberry" }
99
- it { should be < "Tomato" }
100
- it { should be > "Apple" }
101
- it { should be <= "Turnip" }
102
- it { should be >= "Banana" }
103
- it { should =~ /berry/ }
104
-
105
- it { should_not == "Peach" }
106
- it { should_not =~ /apple/ }
107
-
108
- it "reports that it is a string using ===" do
109
- String.should === subject
110
- end
111
-
112
- # deliberate failures
113
- it { should == "Peach" }
114
- it { should be < "Cranberry" }
115
- it { should be > "Zuchini" }
116
- it { should be <= "Potato" }
117
- it { should be >= "Tomato" }
118
- it { should =~ /apple/ }
119
-
120
- it { should_not == "Strawberry" }
121
- it { should_not =~ /berry/ }
122
-
123
- it "fails a spec asserting that it is a symbol" do
124
- Symbol.should === subject
125
- end
126
- end
127
- """
128
- When I run `rspec string_operator_matchers_spec.rb`
129
- Then the output should contain "18 examples, 9 failures"
130
- And the output should contain:
131
- """
132
- Failure/Error: it { should == "Peach" }
133
- expected: "Peach"
134
- got: "Strawberry" (using ==)
135
- """
136
- And the output should contain:
137
- """
138
- Failure/Error: it { should be < "Cranberry" }
139
- expected: < "Cranberry"
140
- got: "Strawberry"
141
- """
142
- And the output should contain:
143
- """
144
- Failure/Error: it { should be > "Zuchini" }
145
- expected: > "Zuchini"
146
- got: "Strawberry"
147
- """
148
- And the output should contain:
149
- """
150
- Failure/Error: it { should be <= "Potato" }
151
- expected: <= "Potato"
152
- got: "Strawberry"
153
- """
154
- And the output should contain:
155
- """
156
- Failure/Error: it { should be >= "Tomato" }
157
- expected: >= "Tomato"
158
- got: "Strawberry"
159
- """
160
- And the output should contain:
161
- """
162
- Failure/Error: it { should =~ /apple/ }
163
- expected: /apple/
164
- got: "Strawberry" (using =~)
165
- """
166
- And the output should contain:
167
- """
168
- Failure/Error: it { should_not == "Strawberry" }
169
- expected not: == "Strawberry"
170
- got: "Strawberry"
171
- """
172
- And the output should contain:
173
- """
174
- Failure/Error: it { should_not =~ /berry/ }
175
- expected not: =~ /berry/
176
- got: "Strawberry"
177
- """
178
- And the output should contain:
179
- """
180
- Failure/Error: Symbol.should === subject
181
- expected: "Strawberry"
182
- got: Symbol (using ===)
183
- """
184
-
185
- Scenario: array operator matchers
186
- Given a file named "array_operator_matchers_spec.rb" with:
187
- """ruby
188
- describe [1, 2, 3] do
189
- it { should == [1, 2, 3] }
190
- it { should_not == [1, 3, 2] }
191
-
192
- it { should =~ [1, 2, 3] }
193
- it { should =~ [1, 3, 2] }
194
- it { should =~ [2, 1, 3] }
195
- it { should =~ [2, 3, 1] }
196
- it { should =~ [3, 1, 2] }
197
- it { should =~ [3, 2, 1] }
198
-
199
- # deliberate failures
200
- it { should_not == [1, 2, 3] }
201
- it { should == [1, 3, 2] }
202
- it { should =~ [1, 2, 1] }
203
- end
204
- """
205
- When I run `rspec array_operator_matchers_spec.rb`
206
- Then the output should contain "11 examples, 3 failures"
207
- And the output should contain:
208
- """
209
- Failure/Error: it { should_not == [1, 2, 3] }
210
- expected not: == [1, 2, 3]
211
- got: [1, 2, 3]
212
- """
213
- And the output should contain:
214
- """
215
- Failure/Error: it { should == [1, 3, 2] }
216
- expected: [1, 3, 2]
217
- got: [1, 2, 3] (using ==)
218
- """
219
- And the output should contain:
220
- """
221
- Failure/Error: it { should =~ [1, 2, 1] }
222
- expected collection contained: [1, 1, 2]
223
- actual collection contained: [1, 2, 3]
224
- the missing elements were: [1]
225
- the extra elements were: [3]
226
- """
227
-
@@ -1,137 +0,0 @@
1
- Feature: predicate matchers
2
-
3
- Ruby objects commonly provide predicate methods:
4
-
5
- ```ruby
6
- 7.zero? # => false
7
- 0.zero? # => true
8
- [1].empty? # => false
9
- [].empty? # => true
10
- { :a => 5 }.has_key?(:b) # => false
11
- { :b => 5 }.has_key?(:b) # => true
12
- ```
13
-
14
- You could use a basic equality matcher to set expectations on these:
15
-
16
- ```ruby
17
- 7.zero?.should == true # fails with "expected true, got false (using ==)"
18
- ```
19
-
20
- ...but RSpec provides dynamic predicate matchers that are more readable and
21
- provide better failure output.
22
-
23
- For any predicate method, RSpec gives you a corresponding matcher. Simply
24
- prefix the method with `be_` and remove the question mark. Examples:
25
-
26
- ```ruby
27
- 7.should_not be_zero # calls 7.zero?
28
- [].should be_empty # calls [].empty?
29
- x.should be_multiple_of(3) # calls x.multiple_of?(3)
30
- ```
31
-
32
- Alternately, for a predicate method that begins with `has_` like
33
- `Hash#has_key?`, RSpec allows you to use an alternate form since `be_has_key`
34
- makes no sense.
35
-
36
- ```ruby
37
- hash.should have_key(:foo) # calls hash.has_key?(:foo)
38
- array.should_not have_odd_values # calls array.has_odd_values?
39
- ```
40
-
41
- In either case, RSpec provides nice, clear error messages, such as:
42
-
43
- `expected zero? to return true, got false`
44
-
45
- Any arguments passed to the matcher will be passed on to the predicate method.
46
-
47
- Scenario: should be_zero (based on Fixnum#zero?)
48
- Given a file named "should_be_zero_spec.rb" with:
49
- """ruby
50
- describe 0 do
51
- it { should be_zero }
52
- end
53
-
54
- describe 7 do
55
- it { should be_zero } # deliberate failure
56
- end
57
- """
58
- When I run `rspec should_be_zero_spec.rb`
59
- Then the output should contain "2 examples, 1 failure"
60
- And the output should contain "expected zero? to return true, got false"
61
-
62
- Scenario: should_not be_empty (based on Array#empty?)
63
- Given a file named "should_not_be_empty_spec.rb" with:
64
- """ruby
65
- describe [1, 2, 3] do
66
- it { should_not be_empty }
67
- end
68
-
69
- describe [] do
70
- it { should_not be_empty } # deliberate failure
71
- end
72
- """
73
- When I run `rspec should_not_be_empty_spec.rb`
74
- Then the output should contain "2 examples, 1 failure"
75
- And the output should contain "expected empty? to return false, got true"
76
-
77
- Scenario: should have_key (based on Hash#has_key?)
78
- Given a file named "should_have_key_spec.rb" with:
79
- """ruby
80
- describe Hash do
81
- subject { { :foo => 7 } }
82
- it { should have_key(:foo) }
83
- it { should have_key(:bar) } # deliberate failure
84
- end
85
- """
86
- When I run `rspec should_have_key_spec.rb`
87
- Then the output should contain "2 examples, 1 failure"
88
- And the output should contain "expected #has_key?(:bar) to return true, got false"
89
-
90
- Scenario: should_not have_all_string_keys (based on custom #has_all_string_keys? method)
91
- Given a file named "should_not_have_all_string_keys_spec.rb" with:
92
- """ruby
93
- class Hash
94
- def has_all_string_keys?
95
- keys.all? { |k| String === k }
96
- end
97
- end
98
-
99
- describe Hash do
100
- context 'with symbol keys' do
101
- subject { { :foo => 7, :bar => 5 } }
102
- it { should_not have_all_string_keys }
103
- end
104
-
105
- context 'with string keys' do
106
- subject { { 'foo' => 7, 'bar' => 5 } }
107
- it { should_not have_all_string_keys } # deliberate failure
108
- end
109
- end
110
- """
111
- When I run `rspec should_not_have_all_string_keys_spec.rb`
112
- Then the output should contain "2 examples, 1 failure"
113
- And the output should contain "expected #has_all_string_keys? to return false, got true"
114
-
115
- Scenario: matcher arguments are passed on to the predicate method
116
- Given a file named "predicate_matcher_argument_spec.rb" with:
117
- """ruby
118
- class Fixnum
119
- def multiple_of?(x)
120
- (self % x).zero?
121
- end
122
- end
123
-
124
- describe 12 do
125
- it { should be_multiple_of(3) }
126
- it { should_not be_multiple_of(7) }
127
-
128
- # deliberate failures
129
- it { should_not be_multiple_of(4) }
130
- it { should be_multiple_of(5) }
131
- end
132
- """
133
- When I run `rspec predicate_matcher_argument_spec.rb`
134
- Then the output should contain "4 examples, 2 failures"
135
- And the output should contain "expected multiple_of?(4) to return false, got true"
136
- And the output should contain "expected multiple_of?(5) to return true, got false"
137
-
@@ -1,84 +0,0 @@
1
- Feature: respond_to matcher
2
-
3
- Use the respond_to matcher to specify details of an object's interface. In
4
- its most basic form:
5
-
6
- ```ruby
7
- obj.should respond_to(:foo) # pass if obj.respond_to?(:foo)
8
- ```
9
-
10
- You can specify that an object responds to multiple messages in a single
11
- statement with multiple arguments passed to the matcher:
12
-
13
- ```ruby
14
- obj.should respond_to(:foo, :bar) # passes if obj.respond_to?(:foo) && obj.respond_to?(:bar)
15
- ```
16
-
17
- If the number of arguments accepted by the method is important to you,
18
- you can specify that as well:
19
-
20
- ```ruby
21
- obj.should respond_to(:foo).with(1).argument
22
- obj.should respond_to(:bar).with(2).arguments
23
- ```
24
-
25
- Note that this matcher relies entirely upon #respond_to?. If an object
26
- dynamically responds to a message via #method_missing, but does not indicate
27
- this via #respond_to?, then this matcher will give you false results.
28
-
29
- Scenario: basic usage
30
- Given a file named "respond_to_matcher_spec.rb" with:
31
- """ruby
32
- describe "a string" do
33
- it { should respond_to(:length) }
34
- it { should respond_to(:hash, :class, :to_s) }
35
- it { should_not respond_to(:to_model) }
36
- it { should_not respond_to(:compact, :flatten) }
37
-
38
- # deliberate failures
39
- it { should respond_to(:to_model) }
40
- it { should respond_to(:compact, :flatten) }
41
- it { should_not respond_to(:length) }
42
- it { should_not respond_to(:hash, :class, :to_s) }
43
-
44
- # mixed examples--String responds to :length but not :flatten
45
- # both specs should fail
46
- it { should respond_to(:length, :flatten) }
47
- it { should_not respond_to(:length, :flatten) }
48
- end
49
- """
50
- When I run `rspec respond_to_matcher_spec.rb`
51
- Then the output should contain all of these:
52
- | 10 examples, 6 failures |
53
- | expected "a string" to respond to :to_model |
54
- | expected "a string" to respond to :compact, :flatten |
55
- | expected "a string" not to respond to :length |
56
- | expected "a string" not to respond to :hash, :class, :to_s |
57
- | expected "a string" to respond to :flatten |
58
- | expected "a string" not to respond to :length |
59
-
60
- Scenario: specify arguments
61
- Given a file named "respond_to_matcher_argument_checking_spec.rb" with:
62
- """ruby
63
- describe 7 do
64
- it { should respond_to(:zero?).with(0).arguments }
65
- it { should_not respond_to(:zero?).with(1).argument }
66
-
67
- it { should respond_to(:between?).with(2).arguments }
68
- it { should_not respond_to(:between?).with(7).arguments }
69
-
70
- # deliberate failures
71
- it { should respond_to(:zero?).with(1).argument }
72
- it { should_not respond_to(:zero?).with(0).arguments }
73
-
74
- it { should respond_to(:between?).with(7).arguments }
75
- it { should_not respond_to(:between?).with(2).arguments }
76
- end
77
- """
78
- When I run `rspec respond_to_matcher_argument_checking_spec.rb`
79
- Then the output should contain all of these:
80
- | 8 examples, 4 failures |
81
- | expected 7 to respond to :zero? with 1 argument |
82
- | expected 7 not to respond to :zero? with 0 arguments |
83
- | expected 7 to respond to :between? with 7 arguments |
84
- | expected 7 not to respond to :between? with 2 arguments |
@@ -1,33 +0,0 @@
1
- Feature: satisfy matcher
2
-
3
- The satisfy matcher is extremely flexible and can handle almost anything
4
- you want to specify. It passes if the block you provide returns true:
5
-
6
- ```ruby
7
- 10.should satisfy { |v| v % 5 == 0 }
8
- 7.should_not satisfy { |v| v % 5 == 0 }
9
- ```
10
-
11
- This flexibility comes at a cost, however: the failure message
12
- ("expected [actual] to satisfy block") is not very descriptive
13
- or helpful. You will usually be better served by using one of
14
- the other built-in matchers, or writing a custom matcher.
15
-
16
- Scenario: basic usage
17
- Given a file named "satisfy_matcher_spec.rb" with:
18
- """ruby
19
- describe 10 do
20
- it { should satisfy { |v| v > 5 } }
21
- it { should_not satisfy { |v| v > 15 } }
22
-
23
- # deliberate failures
24
- it { should_not satisfy { |v| v > 5 } }
25
- it { should satisfy { |v| v > 15 } }
26
- end
27
- """
28
- When I run `rspec satisfy_matcher_spec.rb`
29
- Then the output should contain all of these:
30
- | 4 examples, 2 failures |
31
- | expected 10 not to satisfy block |
32
- | expected 10 to satisfy block |
33
-
@@ -1,48 +0,0 @@
1
- Feature: start_with matcher
2
-
3
- Use the `start_with` matcher to specify that a string or array starts with
4
- the expected characters or elements.
5
-
6
- ```ruby
7
- "this string".should start_with("this")
8
- "this string".should_not start_with("that")
9
- [0,1,2].should start_with(0, 1)
10
- ```
11
-
12
- Scenario: with a string
13
- Given a file named "example_spec.rb" with:
14
- """ruby
15
- describe "this string" do
16
- it { should start_with "this" }
17
- it { should_not start_with "that" }
18
-
19
- # deliberate failures
20
- it { should_not start_with "this" }
21
- it { should start_with "that" }
22
- end
23
- """
24
- When I run `rspec example_spec.rb`
25
- Then the output should contain all of these:
26
- | 4 examples, 2 failures |
27
- | expected "this string" not to start with "this" |
28
- | expected "this string" to start with "that" |
29
-
30
- Scenario: with an array
31
- Given a file named "example_spec.rb" with:
32
- """ruby
33
- describe [0, 1, 2, 3, 4] do
34
- it { should start_with 0 }
35
- it { should start_with(0, 1)}
36
- it { should_not start_with(2) }
37
- it { should_not start_with(0, 1, 2, 3, 4, 5) }
38
-
39
- # deliberate failures
40
- it { should_not start_with 0 }
41
- it { should start_with 3 }
42
- end
43
- """
44
- When I run `rspec example_spec.rb`
45
- Then the output should contain all of these:
46
- | 6 examples, 2 failures |
47
- | expected [0, 1, 2, 3, 4] not to start with 0 |
48
- | expected [0, 1, 2, 3, 4] to start with 3 |
@@ -1,91 +0,0 @@
1
- Feature: throw_symbol matcher
2
-
3
- The throw_symbol matcher is used to specify that a block of code
4
- throws a symbol. The most basic form passes if any symbol is thrown:
5
-
6
- ```ruby
7
- expect { throw :foo }.to throw_symbol
8
- ```
9
-
10
- You'll often want to specify that a particular symbol is thrown:
11
-
12
- ```ruby
13
- expect { throw :foo }.to throw_symbol(:foo)
14
- ```
15
-
16
- If you care about the additional argument given to throw, you can
17
- specify that as well:
18
-
19
- ```ruby
20
- expect { throw :foo, 7 }.to throw_symbol(:foo, 7)
21
- ```
22
-
23
- Scenario: basic usage
24
- Given a file named "throw_symbol_matcher_spec.rb" with:
25
- """ruby
26
- describe "throw" do
27
- specify { expect { throw :foo }.to throw_symbol }
28
- specify { expect { throw :bar, 7 }.to throw_symbol }
29
- specify { expect { 5 + 5 }.not_to throw_symbol }
30
-
31
- # deliberate failures
32
- specify { expect { throw :foo }.not_to throw_symbol }
33
- specify { expect { throw :bar, 7 }.not_to throw_symbol }
34
- specify { expect { 5 + 5 }.to throw_symbol }
35
- end
36
- """
37
- When I run `rspec throw_symbol_matcher_spec.rb`
38
- Then the output should contain all of these:
39
- | 6 examples, 3 failures |
40
- | expected no Symbol to be thrown, got :foo |
41
- | expected no Symbol to be thrown, got :bar |
42
- | expected a Symbol to be thrown, got nothing |
43
-
44
- Scenario: specify thrown symbol
45
- Given a file named "throw_symbol_matcher_spec.rb" with:
46
- """ruby
47
- describe "throw symbol" do
48
- specify { expect { throw :foo }.to throw_symbol(:foo) }
49
- specify { expect { throw :foo, 7 }.to throw_symbol(:foo) }
50
- specify { expect { 5 + 5 }.not_to throw_symbol(:foo) }
51
- specify { expect { throw :bar }.not_to throw_symbol(:foo) }
52
-
53
- # deliberate failures
54
- specify { expect { throw :foo }.not_to throw_symbol(:foo) }
55
- specify { expect { throw :foo, 7 }.not_to throw_symbol(:foo) }
56
- specify { expect { 5 + 5 }.to throw_symbol(:foo) }
57
- specify { expect { throw :bar }.to throw_symbol(:foo) }
58
- end
59
- """
60
- When I run `rspec throw_symbol_matcher_spec.rb`
61
- Then the output should contain all of these:
62
- | 8 examples, 4 failures |
63
- | expected :foo not to be thrown, got :foo |
64
- | expected :foo not to be thrown, got :foo with 7 |
65
- | expected :foo to be thrown, got nothing |
66
- | expected :foo to be thrown, got :bar |
67
-
68
- Scenario: specify thrown symbol and argument
69
- Given a file named "throw_symbol_argument_matcher_spec.rb" with:
70
- """ruby
71
- describe "throw symbol with argument" do
72
- specify { expect { throw :foo, 7 }.to 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
-
77
- # deliberate failures
78
- specify { expect { throw :foo, 7 }.not_to throw_symbol(:foo, 7) }
79
- specify { expect { throw :foo, 8 }.to throw_symbol(:foo, 7) }
80
- specify { expect { throw :bar, 7 }.to throw_symbol(:foo, 7) }
81
- specify { expect { throw :foo }.to throw_symbol(:foo, 7) }
82
- end
83
- """
84
- When I run `rspec throw_symbol_argument_matcher_spec.rb`
85
- Then the output should contain all of these:
86
- | 8 examples, 4 failures |
87
- | expected :foo with 7 not to be thrown, got :foo with 7 |
88
- | expected :foo with 7 to be thrown, got :foo with 8 |
89
- | expected :foo with 7 to be thrown, got :bar |
90
- | expected :foo with 7 to be thrown, got :foo with no argument |
91
-