rspec-expectations 2.11.3 → 3.11.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 (152) 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 +1026 -21
  6. data/{License.txt → LICENSE.md} +5 -3
  7. data/README.md +174 -78
  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 +130 -55
  11. data/lib/rspec/expectations/fail_with.rb +17 -33
  12. data/lib/rspec/expectations/failure_aggregator.rb +212 -0
  13. data/lib/rspec/expectations/handler.rb +163 -29
  14. data/lib/rspec/expectations/minitest_integration.rb +58 -0
  15. data/lib/rspec/expectations/syntax.rb +68 -54
  16. data/lib/rspec/expectations/version.rb +1 -1
  17. data/lib/rspec/expectations.rb +59 -24
  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 +150 -20
  21. data/lib/rspec/matchers/built_in/be.rb +115 -109
  22. data/lib/rspec/matchers/built_in/be_between.rb +77 -0
  23. data/lib/rspec/matchers/built_in/be_instance_of.rb +16 -1
  24. data/lib/rspec/matchers/built_in/be_kind_of.rb +10 -1
  25. data/lib/rspec/matchers/built_in/be_within.rb +43 -17
  26. data/lib/rspec/matchers/built_in/change.rb +392 -75
  27. data/lib/rspec/matchers/built_in/compound.rb +290 -0
  28. data/lib/rspec/matchers/built_in/contain_exactly.rb +302 -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 +26 -8
  32. data/lib/rspec/matchers/built_in/eql.rb +19 -8
  33. data/lib/rspec/matchers/built_in/equal.rb +56 -19
  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 +175 -20
  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 +212 -38
  42. data/lib/rspec/matchers/built_in/respond_to.rb +155 -29
  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 +252 -98
  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 +530 -10
  50. data/lib/rspec/matchers/english_phrasing.rb +58 -0
  51. data/lib/rspec/matchers/expecteds_for_multiple_diffs.rb +82 -0
  52. data/lib/rspec/matchers/fail_matchers.rb +42 -0
  53. data/lib/rspec/matchers/generated_descriptions.rb +15 -10
  54. data/lib/rspec/matchers/matcher_delegator.rb +35 -0
  55. data/lib/rspec/matchers/matcher_protocol.rb +105 -0
  56. data/lib/rspec/matchers.rb +604 -252
  57. data.tar.gz.sig +0 -0
  58. metadata +178 -278
  59. metadata.gz.sig +0 -0
  60. data/features/README.md +0 -49
  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 -173
  64. data/features/built_in_matchers/be_within.feature +0 -46
  65. data/features/built_in_matchers/cover.feature +0 -45
  66. data/features/built_in_matchers/end_with.feature +0 -46
  67. data/features/built_in_matchers/equality.feature +0 -145
  68. data/features/built_in_matchers/exist.feature +0 -43
  69. data/features/built_in_matchers/expect_change.feature +0 -59
  70. data/features/built_in_matchers/expect_error.feature +0 -138
  71. data/features/built_in_matchers/have.feature +0 -103
  72. data/features/built_in_matchers/include.feature +0 -121
  73. data/features/built_in_matchers/match.feature +0 -50
  74. data/features/built_in_matchers/operators.feature +0 -221
  75. data/features/built_in_matchers/predicates.feature +0 -128
  76. data/features/built_in_matchers/respond_to.feature +0 -78
  77. data/features/built_in_matchers/satisfy.feature +0 -31
  78. data/features/built_in_matchers/start_with.feature +0 -46
  79. data/features/built_in_matchers/throw_symbol.feature +0 -85
  80. data/features/built_in_matchers/types.feature +0 -114
  81. data/features/built_in_matchers/yield.feature +0 -146
  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 -340
  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 -5
  92. data/features/syntax_configuration.feature +0 -68
  93. data/features/test_frameworks/test_unit.feature +0 -46
  94. data/lib/rspec/expectations/deprecation.rb +0 -38
  95. data/lib/rspec/expectations/differ.rb +0 -81
  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 -39
  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 -108
  102. data/lib/rspec/matchers/built_in/match_array.rb +0 -45
  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 -66
  106. data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +0 -39
  107. data/lib/rspec/matchers/matcher.rb +0 -299
  108. data/lib/rspec/matchers/method_missing.rb +0 -12
  109. data/lib/rspec/matchers/operator_matcher.rb +0 -84
  110. data/lib/rspec/matchers/pretty.rb +0 -60
  111. data/lib/rspec-expectations.rb +0 -1
  112. data/spec/rspec/expectations/differ_spec.rb +0 -153
  113. data/spec/rspec/expectations/expectation_target_spec.rb +0 -65
  114. data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
  115. data/spec/rspec/expectations/fail_with_spec.rb +0 -70
  116. data/spec/rspec/expectations/handler_spec.rb +0 -206
  117. data/spec/rspec/matchers/base_matcher_spec.rb +0 -60
  118. data/spec/rspec/matchers/be_close_spec.rb +0 -22
  119. data/spec/rspec/matchers/be_instance_of_spec.rb +0 -40
  120. data/spec/rspec/matchers/be_kind_of_spec.rb +0 -37
  121. data/spec/rspec/matchers/be_spec.rb +0 -452
  122. data/spec/rspec/matchers/be_within_spec.rb +0 -80
  123. data/spec/rspec/matchers/change_spec.rb +0 -528
  124. data/spec/rspec/matchers/configuration_spec.rb +0 -202
  125. data/spec/rspec/matchers/cover_spec.rb +0 -69
  126. data/spec/rspec/matchers/description_generation_spec.rb +0 -176
  127. data/spec/rspec/matchers/dsl_spec.rb +0 -57
  128. data/spec/rspec/matchers/eq_spec.rb +0 -54
  129. data/spec/rspec/matchers/eql_spec.rb +0 -41
  130. data/spec/rspec/matchers/equal_spec.rb +0 -60
  131. data/spec/rspec/matchers/exist_spec.rb +0 -110
  132. data/spec/rspec/matchers/has_spec.rb +0 -118
  133. data/spec/rspec/matchers/have_spec.rb +0 -461
  134. data/spec/rspec/matchers/include_spec.rb +0 -367
  135. data/spec/rspec/matchers/match_array_spec.rb +0 -124
  136. data/spec/rspec/matchers/match_spec.rb +0 -61
  137. data/spec/rspec/matchers/matcher_spec.rb +0 -434
  138. data/spec/rspec/matchers/matchers_spec.rb +0 -31
  139. data/spec/rspec/matchers/method_missing_spec.rb +0 -24
  140. data/spec/rspec/matchers/operator_matcher_spec.rb +0 -221
  141. data/spec/rspec/matchers/raise_error_spec.rb +0 -344
  142. data/spec/rspec/matchers/respond_to_spec.rb +0 -295
  143. data/spec/rspec/matchers/satisfy_spec.rb +0 -44
  144. data/spec/rspec/matchers/start_with_end_with_spec.rb +0 -182
  145. data/spec/rspec/matchers/throw_symbol_spec.rb +0 -116
  146. data/spec/rspec/matchers/yield_spec.rb +0 -402
  147. data/spec/spec_helper.rb +0 -27
  148. data/spec/support/classes.rb +0 -56
  149. data/spec/support/in_sub_process.rb +0 -31
  150. data/spec/support/matchers.rb +0 -22
  151. data/spec/support/ruby_version.rb +0 -10
  152. data/spec/support/shared_examples.rb +0 -13
@@ -1,27 +0,0 @@
1
- Feature: define diffable matcher
2
-
3
- When a matcher is defined as diffable, and the --diff
4
- flag is set, the output will include a diff of the submitted
5
- objects.
6
-
7
- @wip
8
- Scenario: define a diffable matcher
9
- Given a file named "diffable_matcher_spec.rb" with:
10
- """
11
- RSpec::Matchers.define :be_just_like do |expected|
12
- match do |actual|
13
- actual == expected
14
- end
15
-
16
- diffable
17
- end
18
-
19
- describe "this" do
20
- it {should be_just_like("that")}
21
- end
22
- """
23
- When I run `rspec ./diffable_matcher_spec.rb --diff`
24
- Then the exit status should not be 0
25
-
26
- And the output should contain "should be just like that"
27
- And the output should contain "Diff:\n@@ -1,2 +1,2 @@\n-that\n+this"
@@ -1,340 +0,0 @@
1
- Feature: define matcher
2
-
3
- In order to express my domain clearly in my code examples
4
- As an RSpec user
5
- I want a shortcut to define custom matchers
6
-
7
- Scenario: define a matcher with default messages
8
- Given a file named "matcher_with_default_message_spec.rb" with:
9
- """
10
- require 'rspec/expectations'
11
-
12
- RSpec::Matchers.define :be_a_multiple_of do |expected|
13
- match do |actual|
14
- actual % expected == 0
15
- end
16
- end
17
-
18
- describe 9 do
19
- it {should be_a_multiple_of(3)}
20
- end
21
-
22
- describe 9 do
23
- it {should_not be_a_multiple_of(4)}
24
- end
25
-
26
- # fail intentionally to generate expected output
27
- describe 9 do
28
- it {should be_a_multiple_of(4)}
29
- end
30
-
31
- # fail intentionally to generate expected output
32
- describe 9 do
33
- it {should_not be_a_multiple_of(3)}
34
- end
35
-
36
- """
37
- When I run `rspec ./matcher_with_default_message_spec.rb --format documentation`
38
- Then the exit status should not be 0
39
-
40
- And the output should contain "should be a multiple of 3"
41
- And the output should contain "should not be a multiple of 4"
42
- And the output should contain "Failure/Error: it {should be_a_multiple_of(4)}"
43
- And the output should contain "Failure/Error: it {should_not be_a_multiple_of(3)}"
44
-
45
- And the output should contain "4 examples, 2 failures"
46
- And the output should contain "expected 9 to be a multiple of 4"
47
- And the output should contain "expected 9 not to be a multiple of 3"
48
-
49
- Scenario: overriding the failure_message_for_should
50
- Given a file named "matcher_with_failure_message_spec.rb" with:
51
- """
52
- require 'rspec/expectations'
53
-
54
- RSpec::Matchers.define :be_a_multiple_of do |expected|
55
- match do |actual|
56
- actual % expected == 0
57
- end
58
- failure_message_for_should do |actual|
59
- "expected that #{actual} would be a multiple of #{expected}"
60
- end
61
- end
62
-
63
- # fail intentionally to generate expected output
64
- describe 9 do
65
- it {should be_a_multiple_of(4)}
66
- end
67
- """
68
- When I run `rspec ./matcher_with_failure_message_spec.rb`
69
- Then the exit status should not be 0
70
- And the stdout should contain "1 example, 1 failure"
71
- And the stdout should contain "expected that 9 would be a multiple of 4"
72
-
73
- Scenario: overriding the failure_message_for_should_not
74
- Given a file named "matcher_with_failure_for_message_spec.rb" with:
75
- """
76
- require 'rspec/expectations'
77
-
78
- RSpec::Matchers.define :be_a_multiple_of do |expected|
79
- match do |actual|
80
- actual % expected == 0
81
- end
82
- failure_message_for_should_not do |actual|
83
- "expected that #{actual} would not be a multiple of #{expected}"
84
- end
85
- end
86
-
87
- # fail intentionally to generate expected output
88
- describe 9 do
89
- it {should_not be_a_multiple_of(3)}
90
- end
91
- """
92
- When I run `rspec ./matcher_with_failure_for_message_spec.rb`
93
- Then the exit status should not be 0
94
- And the stdout should contain "1 example, 1 failure"
95
- And the stdout should contain "expected that 9 would not be a multiple of 3"
96
-
97
- Scenario: overriding the description
98
- Given a file named "matcher_overriding_description_spec.rb" with:
99
- """
100
- require 'rspec/expectations'
101
-
102
- RSpec::Matchers.define :be_a_multiple_of do |expected|
103
- match do |actual|
104
- actual % expected == 0
105
- end
106
- description do
107
- "be multiple of #{expected}"
108
- end
109
- end
110
-
111
- describe 9 do
112
- it {should be_a_multiple_of(3)}
113
- end
114
-
115
- describe 9 do
116
- it {should_not be_a_multiple_of(4)}
117
- end
118
- """
119
- When I run `rspec ./matcher_overriding_description_spec.rb --format documentation`
120
- Then the exit status should be 0
121
- And the stdout should contain "2 examples, 0 failures"
122
- And the stdout should contain "should be multiple of 3"
123
- And the stdout should contain "should not be multiple of 4"
124
-
125
- Scenario: with no args
126
- Given a file named "matcher_with_no_args_spec.rb" with:
127
- """
128
- require 'rspec/expectations'
129
-
130
- RSpec::Matchers.define :have_7_fingers do
131
- match do |thing|
132
- thing.fingers.length == 7
133
- end
134
- end
135
-
136
- class Thing
137
- def fingers; (1..7).collect {"finger"}; end
138
- end
139
-
140
- describe Thing do
141
- it {should have_7_fingers}
142
- end
143
- """
144
- When I run `rspec ./matcher_with_no_args_spec.rb --format documentation`
145
- Then the exit status should be 0
146
- And the stdout should contain "1 example, 0 failures"
147
- And the stdout should contain "should have 7 fingers"
148
-
149
- Scenario: with multiple args
150
- Given a file named "matcher_with_multiple_args_spec.rb" with:
151
- """
152
- require 'rspec/expectations'
153
-
154
- RSpec::Matchers.define :be_the_sum_of do |a,b,c,d|
155
- match do |sum|
156
- a + b + c + d == sum
157
- end
158
- end
159
-
160
- describe 10 do
161
- it {should be_the_sum_of(1,2,3,4)}
162
- end
163
- """
164
- When I run `rspec ./matcher_with_multiple_args_spec.rb --format documentation`
165
- Then the exit status should be 0
166
- And the stdout should contain "1 example, 0 failures"
167
- And the stdout should contain "should be the sum of 1, 2, 3, and 4"
168
-
169
- Scenario: with helper methods
170
- Given a file named "matcher_with_internal_helper_spec.rb" with:
171
- """
172
- require 'rspec/expectations'
173
-
174
- RSpec::Matchers.define :have_same_elements_as do |sample|
175
- match do |actual|
176
- similar?(sample, actual)
177
- end
178
-
179
- def similar?(a, b)
180
- a.sort == b.sort
181
- end
182
- end
183
-
184
- describe "these two arrays" do
185
- specify "should be similar" do
186
- [1,2,3].should have_same_elements_as([2,3,1])
187
- end
188
- end
189
- """
190
- When I run `rspec ./matcher_with_internal_helper_spec.rb`
191
- Then the exit status should be 0
192
- And the stdout should contain "1 example, 0 failures"
193
-
194
- Scenario: scoped in a module
195
- Given a file named "scoped_matcher_spec.rb" with:
196
- """
197
- require 'rspec/expectations'
198
-
199
- module MyHelpers
200
- extend RSpec::Matchers::DSL
201
-
202
- matcher :be_just_like do |expected|
203
- match {|actual| actual == expected}
204
- end
205
- end
206
-
207
- describe "group with MyHelpers" do
208
- include MyHelpers
209
- it "has access to the defined matcher" do
210
- 5.should be_just_like(5)
211
- end
212
- end
213
-
214
- describe "group without MyHelpers" do
215
- it "does not have access to the defined matcher" do
216
- expect do
217
- 5.should be_just_like(5)
218
- end.to raise_exception
219
- end
220
- end
221
- """
222
-
223
- When I run `rspec ./scoped_matcher_spec.rb`
224
- Then the stdout should contain "2 examples, 0 failures"
225
-
226
- Scenario: scoped in an example group
227
- Given a file named "scoped_matcher_spec.rb" with:
228
- """
229
- require 'rspec/expectations'
230
-
231
- describe "group with matcher" do
232
- matcher :be_just_like do |expected|
233
- match {|actual| actual == expected}
234
- end
235
-
236
- it "has access to the defined matcher" do
237
- 5.should be_just_like(5)
238
- end
239
-
240
- describe "nested group" do
241
- it "has access to the defined matcher" do
242
- 5.should be_just_like(5)
243
- end
244
- end
245
-
246
- end
247
-
248
- describe "group without matcher" do
249
- it "does not have access to the defined matcher" do
250
- expect do
251
- 5.should be_just_like(5)
252
- end.to raise_exception
253
- end
254
- end
255
- """
256
-
257
- When I run `rspec scoped_matcher_spec.rb`
258
- Then the output should contain "3 examples, 0 failures"
259
-
260
- Scenario: matcher with separate logic for should and should_not
261
- Given a file named "matcher_with_separate_should_not_logic_spec.rb" with:
262
- """
263
- RSpec::Matchers.define :contain do |*expected|
264
- match_for_should do |actual|
265
- expected.all? { |e| actual.include?(e) }
266
- end
267
-
268
- match_for_should_not do |actual|
269
- expected.none? { |e| actual.include?(e) }
270
- end
271
- end
272
-
273
- describe [1, 2, 3] do
274
- it { should contain(1, 2) }
275
- it { should_not contain(4, 5, 6) }
276
-
277
- # deliberate failures
278
- it { should contain(1, 4) }
279
- it { should_not contain(1, 4) }
280
- end
281
- """
282
- When I run `rspec matcher_with_separate_should_not_logic_spec.rb`
283
- Then the output should contain all of these:
284
- | 4 examples, 2 failures |
285
- | expected [1, 2, 3] to contain 1 and 4 |
286
- | expected [1, 2, 3] not to contain 1 and 4 |
287
-
288
- Scenario: use define_method to create a helper method with access to matcher params
289
- Given a file named "define_method_spec.rb" with:
290
- """
291
- RSpec::Matchers.define :be_a_multiple_of do |expected|
292
- define_method :is_multiple? do |actual|
293
- actual % expected == 0
294
- end
295
- match { |actual| is_multiple?(actual) }
296
- end
297
-
298
- describe 9 do
299
- it { should be_a_multiple_of(3) }
300
- it { should_not be_a_multiple_of(4) }
301
-
302
- # deliberate failures
303
- it { should be_a_multiple_of(2) }
304
- it { should_not be_a_multiple_of(3) }
305
- end
306
- """
307
- When I run `rspec define_method_spec.rb`
308
- Then the output should contain all of these:
309
- | 4 examples, 2 failures |
310
- | expected 9 to be a multiple of 2 |
311
- | expected 9 not to be a multiple of 3 |
312
-
313
- Scenario: include a module with helper methods in the matcher
314
- Given a file named "include_module_spec.rb" with:
315
- """
316
- module MatcherHelpers
317
- def is_multiple?(actual, expected)
318
- actual % expected == 0
319
- end
320
- end
321
-
322
- RSpec::Matchers.define :be_a_multiple_of do |expected|
323
- include MatcherHelpers
324
- match { |actual| is_multiple?(actual, expected) }
325
- end
326
-
327
- describe 9 do
328
- it { should be_a_multiple_of(3) }
329
- it { should_not be_a_multiple_of(4) }
330
-
331
- # deliberate failures
332
- it { should be_a_multiple_of(2) }
333
- it { should_not be_a_multiple_of(3) }
334
- end
335
- """
336
- When I run `rspec include_module_spec.rb`
337
- Then the output should contain all of these:
338
- | 4 examples, 2 failures |
339
- | expected 9 to be a multiple of 2 |
340
- | expected 9 not to be a multiple of 3 |
@@ -1,38 +0,0 @@
1
- Feature: define matcher outside rspec
2
-
3
- In order to express my domain clearly in my code examples
4
- As a non-rspec user
5
- I want a shortcut to define custom matchers
6
-
7
- Scenario: define a matcher with default messages
8
- Given a file named "test_multiples.rb" with:
9
- """
10
- require "rspec/expectations"
11
- require "test/unit"
12
-
13
- RSpec::Matchers.define :be_a_multiple_of do |expected|
14
- match do |actual|
15
- actual % expected == 0
16
- end
17
- end
18
-
19
- class Test::Unit::TestCase
20
- include RSpec::Matchers
21
- end
22
-
23
- class TestMultiples < Test::Unit::TestCase
24
-
25
- def test_9_should_be_a_multiple_of_3
26
- 9.should be_a_multiple_of(3)
27
- end
28
-
29
- def test_9_should_be_a_multiple_of_4
30
- 9.should be_a_multiple_of(4)
31
- end
32
-
33
- end
34
- """
35
- When I run `ruby test_multiples.rb`
36
- Then the exit status should not be 0
37
- And the output should contain "expected 9 to be a multiple of 4"
38
- And the output should contain "2 tests, 0 assertions, 0 failures, 1 errors"
@@ -1,24 +0,0 @@
1
- Feature: define matcher with fluent interface
2
-
3
- Use the chain() method to define matchers with a fluent interface.
4
-
5
- Scenario: chained method with argumetn
6
- Given a file named "between_spec.rb" with:
7
- """
8
- RSpec::Matchers.define :be_bigger_than do |first|
9
- match do |actual|
10
- (actual > first) && (actual < @second)
11
- end
12
-
13
- chain :but_smaller_than do |second|
14
- @second = second
15
- end
16
- end
17
-
18
- describe 5 do
19
- it { should be_bigger_than(4).but_smaller_than(6) }
20
- end
21
- """
22
- When I run `rspec between_spec.rb --format documentation`
23
- Then the output should contain "1 example, 0 failures"
24
- And the output should contain "should be bigger than 4"
@@ -1,22 +0,0 @@
1
- Feature: customized message
2
-
3
- RSpec tries to provide useful failure messages, but for cases in which you
4
- want more specific information, you can define your own message right in the
5
- example. This works for any matcher _other than the operator matchers_.
6
-
7
- Scenario: customize failure message
8
- Given a file named "example_spec.rb" with:
9
- """
10
- describe Array do
11
- context "when created with `new`" do
12
- it "is empty" do
13
- array = Array.new
14
- array << 1 # trigger a failure to demonstrate the message
15
- array.should be_empty, "expected empty array, got #{array.inspect}"
16
- end
17
- end
18
- end
19
-
20
- """
21
- When I run `rspec example_spec.rb --format documentation`
22
- Then the output should contain "expected empty array, got [1]"
@@ -1,85 +0,0 @@
1
- Feature: diffing
2
-
3
- When appropriate, failure messages will automatically include a diff.
4
-
5
- Scenario: diff for a multiline string
6
- Given a file named "example_spec.rb" with:
7
- """
8
- describe "a multiline string" do
9
- it "is like another string" do
10
- expected = <<-EXPECTED
11
- this is the
12
- expected
13
- string
14
- EXPECTED
15
- actual = <<-ACTUAL
16
- this is the
17
- actual
18
- string
19
- ACTUAL
20
- actual.should eq(expected)
21
- end
22
- end
23
- """
24
- When I run `rspec example_spec.rb`
25
- Then the output should contain:
26
- """
27
- Diff:
28
- @@ -1,4 +1,4 @@
29
- this is the
30
- - expected
31
- + actual
32
- string
33
- """
34
-
35
- Scenario: diff for a multiline string and a regexp
36
- Given a file named "example_spec.rb" with:
37
- """
38
- describe "a multiline string" do
39
- it "is like another string" do
40
- expected = /expected/m
41
- actual = <<-ACTUAL
42
- this is the
43
- actual
44
- string
45
- ACTUAL
46
- actual.should =~ expected
47
- end
48
- end
49
- """
50
- When I run `rspec example_spec.rb`
51
- Then the output should contain:
52
- """
53
- Diff:
54
- @@ -1,2 +1,4 @@
55
- -/expected/m
56
- +this is the
57
- + actual
58
- + string
59
- """
60
-
61
- Scenario: no diff for a single line strings
62
- Given a file named "example_spec.rb" with:
63
- """
64
- describe "a single line string" do
65
- it "is like another string" do
66
- expected = "this string"
67
- actual = "that string"
68
- actual.should eq(expected)
69
- end
70
- end
71
- """
72
- When I run `rspec example_spec.rb`
73
- Then the output should not contain "Diff:"
74
-
75
- Scenario: no diff for numbers
76
- Given a file named "example_spec.rb" with:
77
- """
78
- describe "a number" do
79
- it "is like another number" do
80
- 1.should eq(2)
81
- end
82
- end
83
- """
84
- When I run `rspec example_spec.rb`
85
- Then the output should not contain "Diff:"
@@ -1,52 +0,0 @@
1
- Feature: implicit docstrings
2
-
3
- As an RSpec user
4
- I want examples to generate their own names
5
- So that I can reduce duplication between example names and example code
6
-
7
- Scenario: run passing examples
8
- Given a file named "implicit_docstrings_spec.rb" with:
9
- """
10
- describe "Examples with no docstrings generate their own:" do
11
-
12
- specify { 3.should be < 5 }
13
-
14
- specify { [1,2,3].should include(2) }
15
-
16
- specify { [1,2,3].should respond_to(:size) }
17
-
18
- end
19
- """
20
-
21
- When I run `rspec ./implicit_docstrings_spec.rb -fdoc`
22
-
23
- Then the output should contain "should be < 5"
24
- And the output should contain "should include 2"
25
- And the output should contain "should respond to #size"
26
-
27
- Scenario: run failing examples
28
- Given a file named "failing_implicit_docstrings_spec.rb" with:
29
- """
30
- describe "Failing examples with no descriptions" do
31
-
32
- # description is auto-generated as "should equal(5)" based on the last #should
33
- it do
34
- 3.should equal(2)
35
- 5.should equal(5)
36
- end
37
-
38
- it { 3.should be > 5 }
39
-
40
- it { [1,2,3].should include(4) }
41
-
42
- it { [1,2,3].should_not respond_to(:size) }
43
-
44
- end
45
- """
46
-
47
- When I run `rspec ./failing_implicit_docstrings_spec.rb -fdoc`
48
-
49
- Then the output should contain "should equal 2"
50
- And the output should contain "should be > 5"
51
- And the output should contain "should include 4"
52
- And the output should contain "should not respond to #size"
@@ -1,22 +0,0 @@
1
- # Useful for when the output is slightly different on different versions of ruby
2
- Then /^the output should contain "([^"]*)" or "([^"]*)"$/ do |string1, string2|
3
- unless [string1, string2].any? { |s| all_output =~ regexp(s) }
4
- fail %Q{Neither "#{string1}" or "#{string2}" were found in:\n#{all_output}}
5
- end
6
- end
7
-
8
- Then /^the output should contain all of these:$/ do |table|
9
- table.raw.flatten.each do |string|
10
- assert_partial_output(string, all_output)
11
- end
12
- end
13
-
14
- Then /^the example(?:s)? should(?: all)? pass$/ do
15
- step %q{the output should contain "0 failures"}
16
- step %q{the exit status should be 0}
17
- end
18
-
19
- Then /^the example should fail$/ do
20
- step %q{the output should contain "1 failure"}
21
- step %q{the exit status should not be 0}
22
- end
@@ -1,5 +0,0 @@
1
- require 'aruba/cucumber'
2
-
3
- Before do
4
- @aruba_timeout_seconds = 15
5
- end
@@ -1,68 +0,0 @@
1
- Feature: Syntax Configuration
2
-
3
- In addition to the long-supported `should` syntax, rspec-expectations
4
- supports an alternate `expect` syntax. If you want your project to
5
- only use one syntax, you can configure the available syntaxes.
6
-
7
- Background:
8
- Given a file named "syntaxes_spec.rb" with:
9
- """ruby
10
- describe "using the should syntax" do
11
- specify { 3.should eq(3) }
12
- specify { 3.should_not eq(4) }
13
- specify { lambda { raise "boom" }.should raise_error("boom") }
14
- specify { lambda { }.should_not raise_error }
15
- end
16
-
17
- describe "using the expect syntax" do
18
- specify { expect(3).to eq(3) }
19
- specify { expect(3).not_to eq(4) }
20
- specify { expect { raise "boom" }.to raise_error("boom") }
21
- specify { expect { }.not_to raise_error }
22
- end
23
- """
24
-
25
- Scenario: Both syntaxes are available by default
26
- When I run `rspec syntaxes_spec.rb`
27
- Then the examples should all pass
28
-
29
- Scenario: Disable should syntax
30
- Given a file named "disable_should_syntax.rb" with:
31
- """ruby
32
- RSpec.configure do |config|
33
- config.expect_with :rspec do |c|
34
- c.syntax = :expect
35
- end
36
- end
37
- """
38
- When I run `rspec disable_should_syntax.rb syntaxes_spec.rb`
39
- Then the output should contain all of these:
40
- | 8 examples, 4 failures |
41
- | undefined method `should' |
42
-
43
- Scenario: Disable expect syntax
44
- Given a file named "disable_expect_syntax.rb" with:
45
- """ruby
46
- RSpec.configure do |config|
47
- config.expect_with :rspec do |c|
48
- c.syntax = :should
49
- end
50
- end
51
- """
52
- When I run `rspec disable_expect_syntax.rb syntaxes_spec.rb`
53
- Then the output should contain all of these:
54
- | 8 examples, 4 failures |
55
- | undefined method `expect' |
56
-
57
- Scenario: Explicitly enable both syntaxes
58
- Given a file named "enable_both_syntaxes.rb" with:
59
- """ruby
60
- RSpec.configure do |config|
61
- config.expect_with :rspec do |c|
62
- c.syntax = [:should, :expect]
63
- end
64
- end
65
- """
66
- When I run `rspec enable_both_syntaxes.rb syntaxes_spec.rb`
67
- Then the examples should all pass
68
-