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.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/.document +1 -1
- data/.yardopts +1 -1
- data/Changelog.md +976 -25
- data/{License.txt → LICENSE.md} +5 -3
- data/README.md +162 -26
- data/lib/rspec/expectations/block_snippet_extractor.rb +253 -0
- data/lib/rspec/expectations/configuration.rb +230 -0
- data/lib/rspec/expectations/expectation_target.rb +127 -51
- data/lib/rspec/expectations/fail_with.rb +17 -57
- data/lib/rspec/expectations/failure_aggregator.rb +229 -0
- data/lib/rspec/expectations/handler.rb +146 -32
- data/lib/rspec/expectations/minitest_integration.rb +58 -0
- data/lib/rspec/expectations/syntax.rb +68 -100
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/expectations.rb +58 -23
- data/lib/rspec/matchers/aliased_matcher.rb +116 -0
- data/lib/rspec/matchers/built_in/all.rb +86 -0
- data/lib/rspec/matchers/built_in/base_matcher.rb +191 -20
- data/lib/rspec/matchers/built_in/be.rb +114 -114
- data/lib/rspec/matchers/built_in/be_between.rb +77 -0
- data/lib/rspec/matchers/built_in/be_instance_of.rb +15 -4
- data/lib/rspec/matchers/built_in/be_kind_of.rb +10 -1
- data/lib/rspec/matchers/built_in/be_within.rb +35 -18
- data/lib/rspec/matchers/built_in/change.rb +389 -80
- data/lib/rspec/matchers/built_in/compound.rb +290 -0
- data/lib/rspec/matchers/built_in/contain_exactly.rb +310 -0
- data/lib/rspec/matchers/built_in/count_expectation.rb +169 -0
- data/lib/rspec/matchers/built_in/cover.rb +3 -0
- data/lib/rspec/matchers/built_in/eq.rb +30 -8
- data/lib/rspec/matchers/built_in/eql.rb +23 -8
- data/lib/rspec/matchers/built_in/equal.rb +55 -22
- data/lib/rspec/matchers/built_in/exist.rb +74 -10
- data/lib/rspec/matchers/built_in/has.rb +141 -22
- data/lib/rspec/matchers/built_in/have_attributes.rb +114 -0
- data/lib/rspec/matchers/built_in/include.rb +184 -32
- data/lib/rspec/matchers/built_in/match.rb +95 -1
- data/lib/rspec/matchers/built_in/operators.rb +128 -0
- data/lib/rspec/matchers/built_in/output.rb +207 -0
- data/lib/rspec/matchers/built_in/raise_error.rb +192 -44
- data/lib/rspec/matchers/built_in/respond_to.rb +154 -28
- data/lib/rspec/matchers/built_in/satisfy.rb +39 -9
- data/lib/rspec/matchers/built_in/start_or_end_with.rb +94 -0
- data/lib/rspec/matchers/built_in/throw_symbol.rb +58 -14
- data/lib/rspec/matchers/built_in/yield.rb +240 -161
- data/lib/rspec/matchers/built_in.rb +47 -33
- data/lib/rspec/matchers/composable.rb +171 -0
- data/lib/rspec/matchers/dsl.rb +531 -10
- data/lib/rspec/matchers/english_phrasing.rb +58 -0
- data/lib/rspec/matchers/fail_matchers.rb +42 -0
- data/lib/rspec/matchers/generated_descriptions.rb +14 -8
- data/lib/rspec/matchers/matcher_delegator.rb +61 -0
- data/lib/rspec/matchers/matcher_protocol.rb +105 -0
- data/lib/rspec/matchers/multi_matcher_diff.rb +82 -0
- data/lib/rspec/matchers.rb +520 -173
- data.tar.gz.sig +0 -0
- metadata +141 -242
- metadata.gz.sig +2 -0
- data/features/README.md +0 -48
- data/features/Upgrade.md +0 -53
- data/features/built_in_matchers/README.md +0 -90
- data/features/built_in_matchers/be.feature +0 -175
- data/features/built_in_matchers/be_within.feature +0 -48
- data/features/built_in_matchers/cover.feature +0 -47
- data/features/built_in_matchers/end_with.feature +0 -48
- data/features/built_in_matchers/equality.feature +0 -139
- data/features/built_in_matchers/exist.feature +0 -45
- data/features/built_in_matchers/expect_change.feature +0 -59
- data/features/built_in_matchers/expect_error.feature +0 -144
- data/features/built_in_matchers/have.feature +0 -109
- data/features/built_in_matchers/include.feature +0 -174
- data/features/built_in_matchers/match.feature +0 -52
- data/features/built_in_matchers/operators.feature +0 -227
- data/features/built_in_matchers/predicates.feature +0 -137
- data/features/built_in_matchers/respond_to.feature +0 -84
- data/features/built_in_matchers/satisfy.feature +0 -33
- data/features/built_in_matchers/start_with.feature +0 -48
- data/features/built_in_matchers/throw_symbol.feature +0 -91
- data/features/built_in_matchers/types.feature +0 -116
- data/features/built_in_matchers/yield.feature +0 -161
- data/features/custom_matchers/access_running_example.feature +0 -53
- data/features/custom_matchers/define_diffable_matcher.feature +0 -27
- data/features/custom_matchers/define_matcher.feature +0 -368
- data/features/custom_matchers/define_matcher_outside_rspec.feature +0 -38
- data/features/custom_matchers/define_matcher_with_fluent_interface.feature +0 -24
- data/features/customized_message.feature +0 -22
- data/features/diffing.feature +0 -85
- data/features/implicit_docstrings.feature +0 -52
- data/features/step_definitions/additional_cli_steps.rb +0 -22
- data/features/support/env.rb +0 -14
- data/features/syntax_configuration.feature +0 -71
- data/features/test_frameworks/test_unit.feature +0 -44
- data/lib/rspec/expectations/deprecation.rb +0 -17
- data/lib/rspec/expectations/differ.rb +0 -133
- data/lib/rspec/expectations/errors.rb +0 -9
- data/lib/rspec/expectations/extensions/array.rb +0 -9
- data/lib/rspec/expectations/extensions/object.rb +0 -29
- data/lib/rspec/expectations/extensions.rb +0 -2
- data/lib/rspec/matchers/be_close.rb +0 -9
- data/lib/rspec/matchers/built_in/have.rb +0 -124
- data/lib/rspec/matchers/built_in/match_array.rb +0 -51
- data/lib/rspec/matchers/built_in/start_and_end_with.rb +0 -48
- data/lib/rspec/matchers/compatibility.rb +0 -14
- data/lib/rspec/matchers/configuration.rb +0 -108
- data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +0 -39
- data/lib/rspec/matchers/matcher.rb +0 -300
- data/lib/rspec/matchers/method_missing.rb +0 -12
- data/lib/rspec/matchers/operator_matcher.rb +0 -109
- data/lib/rspec/matchers/pretty.rb +0 -70
- data/lib/rspec/matchers/test_unit_integration.rb +0 -11
- data/lib/rspec-expectations.rb +0 -1
- data/spec/rspec/expectations/differ_spec.rb +0 -192
- data/spec/rspec/expectations/expectation_target_spec.rb +0 -82
- data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
- data/spec/rspec/expectations/fail_with_spec.rb +0 -114
- data/spec/rspec/expectations/handler_spec.rb +0 -227
- data/spec/rspec/expectations/syntax_spec.rb +0 -139
- data/spec/rspec/matchers/base_matcher_spec.rb +0 -62
- data/spec/rspec/matchers/be_close_spec.rb +0 -22
- data/spec/rspec/matchers/be_instance_of_spec.rb +0 -63
- data/spec/rspec/matchers/be_kind_of_spec.rb +0 -41
- data/spec/rspec/matchers/be_spec.rb +0 -516
- data/spec/rspec/matchers/be_within_spec.rb +0 -137
- data/spec/rspec/matchers/change_spec.rb +0 -553
- data/spec/rspec/matchers/configuration_spec.rb +0 -206
- data/spec/rspec/matchers/cover_spec.rb +0 -69
- data/spec/rspec/matchers/description_generation_spec.rb +0 -190
- data/spec/rspec/matchers/dsl_spec.rb +0 -57
- data/spec/rspec/matchers/eq_spec.rb +0 -60
- data/spec/rspec/matchers/eql_spec.rb +0 -41
- data/spec/rspec/matchers/equal_spec.rb +0 -78
- data/spec/rspec/matchers/exist_spec.rb +0 -124
- data/spec/rspec/matchers/has_spec.rb +0 -122
- data/spec/rspec/matchers/have_spec.rb +0 -455
- data/spec/rspec/matchers/include_matcher_integration_spec.rb +0 -30
- data/spec/rspec/matchers/include_spec.rb +0 -531
- data/spec/rspec/matchers/match_array_spec.rb +0 -194
- data/spec/rspec/matchers/match_spec.rb +0 -61
- data/spec/rspec/matchers/matcher_spec.rb +0 -471
- data/spec/rspec/matchers/matchers_spec.rb +0 -37
- data/spec/rspec/matchers/method_missing_spec.rb +0 -28
- data/spec/rspec/matchers/operator_matcher_spec.rb +0 -223
- data/spec/rspec/matchers/raise_error_spec.rb +0 -485
- data/spec/rspec/matchers/respond_to_spec.rb +0 -292
- data/spec/rspec/matchers/satisfy_spec.rb +0 -44
- data/spec/rspec/matchers/start_with_end_with_spec.rb +0 -186
- data/spec/rspec/matchers/throw_symbol_spec.rb +0 -116
- data/spec/rspec/matchers/yield_spec.rb +0 -514
- data/spec/spec_helper.rb +0 -54
- data/spec/support/classes.rb +0 -56
- data/spec/support/in_sub_process.rb +0 -38
- data/spec/support/matchers.rb +0 -22
- data/spec/support/ruby_version.rb +0 -10
- data/spec/support/shared_examples.rb +0 -13
@@ -1,368 +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
|
-
"""ruby
|
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
|
-
"""ruby
|
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
|
-
"""ruby
|
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
|
-
"""ruby
|
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
|
-
"""ruby
|
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
|
-
"""ruby
|
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
|
-
"""ruby
|
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
|
-
"""ruby
|
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
|
-
"""ruby
|
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
|
-
"""ruby
|
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
|
-
"""ruby
|
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
|
-
"""ruby
|
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 |
|
341
|
-
|
342
|
-
Scenario: matching against a regular expression
|
343
|
-
Given a file named "regular_expression_matcher_spec.rb" with:
|
344
|
-
"""ruby
|
345
|
-
# Due to Ruby's method dispatch mechanism, use the `#match_regex` alias
|
346
|
-
# rather than the `#match` matcher when defining custom matchers via the
|
347
|
-
# DSL.
|
348
|
-
|
349
|
-
RSpec::Matchers.define :be_valid_us_zipcode do
|
350
|
-
match do |actual|
|
351
|
-
expect(actual).to match_regex(/\A\d{5}(-\d{4})?\z/)
|
352
|
-
end
|
353
|
-
end
|
354
|
-
|
355
|
-
describe "30316" do
|
356
|
-
it { should be_valid_us_zipcode }
|
357
|
-
end
|
358
|
-
|
359
|
-
describe "30316-0001" do
|
360
|
-
it { should be_valid_us_zipcode }
|
361
|
-
end
|
362
|
-
|
363
|
-
describe "1000-61303" do
|
364
|
-
it { should_not be_valid_us_zipcode }
|
365
|
-
end
|
366
|
-
"""
|
367
|
-
When I run `rspec regular_expression_matcher_spec.rb`
|
368
|
-
Then the stdout should contain "3 examples, 0 failures"
|
@@ -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
|
-
"""ruby
|
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
|
-
"""ruby
|
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
|
-
"""ruby
|
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]"
|
data/features/diffing.feature
DELETED
@@ -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
|
-
"""ruby
|
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
|
-
"""ruby
|
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
|
-
"""ruby
|
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
|
-
"""ruby
|
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
|
-
"""ruby
|
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
|
-
"""ruby
|
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
|
data/features/support/env.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'aruba/cucumber'
|
2
|
-
|
3
|
-
timeouts = { 'java' => 60 }
|
4
|
-
|
5
|
-
Before do
|
6
|
-
@aruba_timeout_seconds = timeouts.fetch(RUBY_PLATFORM) { 15 }
|
7
|
-
end
|
8
|
-
|
9
|
-
Aruba.configure do |config|
|
10
|
-
config.before_cmd do |cmd|
|
11
|
-
set_env('JRUBY_OPTS', "-X-C #{ENV['JRUBY_OPTS']}") # disable JIT since these processes are so short lived
|
12
|
-
end
|
13
|
-
end if RUBY_PLATFORM == 'java'
|
14
|
-
|
@@ -1,71 +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
|
-
config.mock_with :rspec do |c|
|
51
|
-
c.syntax = :should
|
52
|
-
end
|
53
|
-
end
|
54
|
-
"""
|
55
|
-
When I run `rspec disable_expect_syntax.rb syntaxes_spec.rb`
|
56
|
-
Then the output should contain all of these:
|
57
|
-
| 8 examples, 4 failures |
|
58
|
-
| undefined method `expect' |
|
59
|
-
|
60
|
-
Scenario: Explicitly enable both syntaxes
|
61
|
-
Given a file named "enable_both_syntaxes.rb" with:
|
62
|
-
"""ruby
|
63
|
-
RSpec.configure do |config|
|
64
|
-
config.expect_with :rspec do |c|
|
65
|
-
c.syntax = [:should, :expect]
|
66
|
-
end
|
67
|
-
end
|
68
|
-
"""
|
69
|
-
When I run `rspec enable_both_syntaxes.rb syntaxes_spec.rb`
|
70
|
-
Then the examples should all pass
|
71
|
-
|