rspec-expectations 2.0.0.beta.22 → 2.6.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.
- data/.gitignore +1 -1
- data/.travis.yml +7 -0
- data/Gemfile +35 -13
- data/Guardfile +5 -0
- data/License.txt +1 -1
- data/README.md +43 -0
- data/Rakefile +51 -9
- data/cucumber.yml +9 -2
- data/features/.nav +29 -0
- data/features/Changelog.md +101 -0
- data/features/README.markdown +45 -8
- data/features/built_in_matchers/README.md +71 -0
- data/features/built_in_matchers/be.feature +135 -0
- data/features/built_in_matchers/be_within.feature +43 -0
- data/features/built_in_matchers/cover.feature +45 -0
- data/features/{matchers → built_in_matchers}/equality.feature +16 -13
- data/features/built_in_matchers/exist.feature +43 -0
- data/features/built_in_matchers/expect_change.feature +59 -0
- data/features/built_in_matchers/expect_error.feature +105 -0
- data/features/built_in_matchers/have.feature +103 -0
- data/features/built_in_matchers/include.feature +121 -0
- data/features/built_in_matchers/match.feature +50 -0
- data/features/built_in_matchers/operators.feature +221 -0
- data/features/built_in_matchers/predicates.feature +128 -0
- data/features/built_in_matchers/respond_to.feature +78 -0
- data/features/built_in_matchers/satisfy.feature +31 -0
- data/features/built_in_matchers/throw_symbol.feature +85 -0
- data/features/built_in_matchers/types.feature +114 -0
- data/features/{matchers → custom_matchers}/access_running_example.feature +2 -2
- data/features/{matchers → custom_matchers}/define_diffable_matcher.feature +1 -1
- data/features/{matchers → custom_matchers}/define_matcher.feature +91 -9
- data/features/{matchers → custom_matchers}/define_matcher_outside_rspec.feature +1 -1
- data/features/{matchers → custom_matchers}/define_matcher_with_fluent_interface.feature +8 -11
- data/features/customized_message.feature +22 -0
- data/features/{expectations/diffing.feature → diffing.feature} +16 -16
- data/features/{expectations/implicit_docstrings.feature → implicit_docstrings.feature} +4 -4
- data/features/step_definitions/additional_cli_steps.rb +22 -0
- data/features/support/env.rb +5 -1
- data/features/test_frameworks/test_unit.feature +46 -0
- data/lib/rspec/expectations/backward_compatibility.rb +22 -1
- data/lib/rspec/expectations/deprecation.rb +36 -0
- data/lib/rspec/expectations/extensions.rb +0 -1
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/expectations.rb +2 -1
- data/lib/rspec/matchers/be.rb +4 -4
- data/lib/rspec/matchers/be_close.rb +2 -17
- data/lib/rspec/matchers/be_within.rb +40 -0
- data/lib/rspec/matchers/block_aliases.rb +19 -0
- data/lib/rspec/matchers/change.rb +74 -49
- data/lib/rspec/matchers/cover.rb +35 -0
- data/lib/rspec/matchers/exist.rb +13 -3
- data/lib/rspec/matchers/has.rb +15 -11
- data/lib/rspec/matchers/have.rb +5 -5
- data/lib/rspec/matchers/include.rb +14 -5
- data/lib/rspec/matchers/matcher.rb +39 -13
- data/lib/rspec/matchers/method_missing.rb +6 -3
- data/lib/rspec/matchers/operator_matcher.rb +12 -3
- data/lib/rspec/matchers/respond_to.rb +23 -9
- data/lib/rspec/matchers/satisfy.rb +4 -0
- data/lib/rspec/matchers/throw_symbol.rb +43 -26
- data/lib/rspec/matchers.rb +15 -3
- data/rspec-expectations.gemspec +2 -6
- data/spec/rspec/matchers/be_close_spec.rb +11 -39
- data/spec/rspec/matchers/be_spec.rb +8 -8
- data/spec/rspec/matchers/be_within_spec.rb +64 -0
- data/spec/rspec/matchers/change_spec.rb +88 -9
- data/spec/rspec/matchers/cover_spec.rb +65 -0
- data/spec/rspec/matchers/description_generation_spec.rb +41 -25
- data/spec/rspec/matchers/exist_spec.rb +90 -51
- data/spec/rspec/matchers/has_spec.rb +2 -2
- data/spec/rspec/matchers/have_spec.rb +291 -291
- data/spec/rspec/matchers/include_spec.rb +318 -65
- data/spec/rspec/matchers/matcher_spec.rb +91 -0
- data/spec/rspec/matchers/matchers_spec.rb +29 -0
- data/spec/rspec/matchers/method_missing_spec.rb +23 -0
- data/spec/rspec/matchers/operator_matcher_spec.rb +36 -10
- data/spec/rspec/matchers/respond_to_spec.rb +177 -1
- data/spec/rspec/matchers/satisfy_spec.rb +4 -0
- data/spec/rspec/matchers/throw_symbol_spec.rb +27 -10
- data/spec/spec_helper.rb +10 -35
- data/spec/support/classes.rb +1 -1
- data/spec/support/matchers.rb +22 -0
- data/spec/support/ruby_version.rb +10 -0
- metadata +95 -114
- data/History.md +0 -16
- data/README.markdown +0 -23
- data/features/expectations/attribute_of_subject.feature +0 -19
- data/features/expectations/customized_message.feature +0 -54
- data/features/matchers/expect_change.feature +0 -65
- data/features/matchers/expect_error.feature +0 -44
- data/lib/rspec/expectations/extensions/rspec/core/example_group.rb +0 -19
- data/spec/suite.rb +0 -1
- /data/{Upgrade.markdown → features/Upgrade.md} +0 -0
|
@@ -34,7 +34,7 @@ Feature: define matcher
|
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
"""
|
|
37
|
-
When I run
|
|
37
|
+
When I run `rspec ./matcher_with_default_message_spec.rb --format documentation`
|
|
38
38
|
Then the exit status should not be 0
|
|
39
39
|
|
|
40
40
|
And the output should contain "should be a multiple of 3"
|
|
@@ -65,7 +65,7 @@ Feature: define matcher
|
|
|
65
65
|
it {should be_a_multiple_of(4)}
|
|
66
66
|
end
|
|
67
67
|
"""
|
|
68
|
-
When I run
|
|
68
|
+
When I run `rspec ./matcher_with_failure_message_spec.rb`
|
|
69
69
|
Then the exit status should not be 0
|
|
70
70
|
And the stdout should contain "1 example, 1 failure"
|
|
71
71
|
And the stdout should contain "expected that 9 would be a multiple of 4"
|
|
@@ -89,7 +89,7 @@ Feature: define matcher
|
|
|
89
89
|
it {should_not be_a_multiple_of(3)}
|
|
90
90
|
end
|
|
91
91
|
"""
|
|
92
|
-
When I run
|
|
92
|
+
When I run `rspec ./matcher_with_failure_for_message_spec.rb`
|
|
93
93
|
Then the exit status should not be 0
|
|
94
94
|
And the stdout should contain "1 example, 1 failure"
|
|
95
95
|
And the stdout should contain "expected that 9 would not be a multiple of 3"
|
|
@@ -116,7 +116,7 @@ Feature: define matcher
|
|
|
116
116
|
it {should_not be_a_multiple_of(4)}
|
|
117
117
|
end
|
|
118
118
|
"""
|
|
119
|
-
When I run
|
|
119
|
+
When I run `rspec ./matcher_overriding_description_spec.rb --format documentation`
|
|
120
120
|
Then the exit status should be 0
|
|
121
121
|
And the stdout should contain "2 examples, 0 failures"
|
|
122
122
|
And the stdout should contain "should be multiple of 3"
|
|
@@ -141,7 +141,7 @@ Feature: define matcher
|
|
|
141
141
|
it {should have_7_fingers}
|
|
142
142
|
end
|
|
143
143
|
"""
|
|
144
|
-
When I run
|
|
144
|
+
When I run `rspec ./matcher_with_no_args_spec.rb --format documentation`
|
|
145
145
|
Then the exit status should be 0
|
|
146
146
|
And the stdout should contain "1 example, 0 failures"
|
|
147
147
|
And the stdout should contain "should have 7 fingers"
|
|
@@ -161,7 +161,7 @@ Feature: define matcher
|
|
|
161
161
|
it {should be_the_sum_of(1,2,3,4)}
|
|
162
162
|
end
|
|
163
163
|
"""
|
|
164
|
-
When I run
|
|
164
|
+
When I run `rspec ./matcher_with_multiple_args_spec.rb --format documentation`
|
|
165
165
|
Then the exit status should be 0
|
|
166
166
|
And the stdout should contain "1 example, 0 failures"
|
|
167
167
|
And the stdout should contain "should be the sum of 1, 2, 3, and 4"
|
|
@@ -187,7 +187,7 @@ Feature: define matcher
|
|
|
187
187
|
end
|
|
188
188
|
end
|
|
189
189
|
"""
|
|
190
|
-
When I run
|
|
190
|
+
When I run `rspec ./matcher_with_internal_helper_spec.rb`
|
|
191
191
|
Then the exit status should be 0
|
|
192
192
|
And the stdout should contain "1 example, 0 failures"
|
|
193
193
|
|
|
@@ -220,7 +220,7 @@ Feature: define matcher
|
|
|
220
220
|
end
|
|
221
221
|
"""
|
|
222
222
|
|
|
223
|
-
When I run
|
|
223
|
+
When I run `rspec ./scoped_matcher_spec.rb`
|
|
224
224
|
Then the stdout should contain "2 examples, 0 failures"
|
|
225
225
|
|
|
226
226
|
Scenario: scoped in an example group
|
|
@@ -254,5 +254,87 @@ Feature: define matcher
|
|
|
254
254
|
end
|
|
255
255
|
"""
|
|
256
256
|
|
|
257
|
-
When I run
|
|
257
|
+
When I run `rspec scoped_matcher_spec.rb`
|
|
258
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 |
|
|
@@ -32,7 +32,7 @@ Feature: define matcher outside rspec
|
|
|
32
32
|
|
|
33
33
|
end
|
|
34
34
|
"""
|
|
35
|
-
When I run
|
|
35
|
+
When I run `ruby test_multiples.rb`
|
|
36
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,27 +1,24 @@
|
|
|
1
|
-
Feature: define matcher
|
|
1
|
+
Feature: define matcher with fluent interface
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
As an RSpec user
|
|
5
|
-
I want to define matchers with fluent interfaces
|
|
3
|
+
Use the chain() method to define matchers with a fluent interface.
|
|
6
4
|
|
|
7
|
-
Scenario:
|
|
5
|
+
Scenario: chained method with argumetn
|
|
8
6
|
Given a file named "between_spec.rb" with:
|
|
9
7
|
"""
|
|
10
8
|
RSpec::Matchers.define :be_bigger_than do |first|
|
|
11
|
-
def but_smaller_than(second)
|
|
12
|
-
@second = second
|
|
13
|
-
self
|
|
14
|
-
end
|
|
15
|
-
|
|
16
9
|
match do |actual|
|
|
17
10
|
(actual > first) && (actual < @second)
|
|
18
11
|
end
|
|
12
|
+
|
|
13
|
+
chain :but_smaller_than do |second|
|
|
14
|
+
@second = second
|
|
15
|
+
end
|
|
19
16
|
end
|
|
20
17
|
|
|
21
18
|
describe 5 do
|
|
22
19
|
it { should be_bigger_than(4).but_smaller_than(6) }
|
|
23
20
|
end
|
|
24
21
|
"""
|
|
25
|
-
When I run
|
|
22
|
+
When I run `rspec between_spec.rb --format documentation`
|
|
26
23
|
Then the output should contain "1 example, 0 failures"
|
|
27
24
|
And the output should contain "should be bigger than 4"
|
|
@@ -0,0 +1,22 @@
|
|
|
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]"
|
|
@@ -21,15 +21,15 @@ Feature: diffing
|
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
23
|
"""
|
|
24
|
-
When I run
|
|
24
|
+
When I run `rspec example_spec.rb`
|
|
25
25
|
Then the output should contain:
|
|
26
26
|
"""
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
Diff:
|
|
28
|
+
@@ -1,4 +1,4 @@
|
|
29
|
+
this is the
|
|
30
|
+
- expected
|
|
31
|
+
+ actual
|
|
32
|
+
string
|
|
33
33
|
"""
|
|
34
34
|
|
|
35
35
|
Scenario: diff for a multiline string and a regexp
|
|
@@ -47,15 +47,15 @@ Feature: diffing
|
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
49
|
"""
|
|
50
|
-
When I run
|
|
50
|
+
When I run `rspec example_spec.rb`
|
|
51
51
|
Then the output should contain:
|
|
52
52
|
"""
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
Diff:
|
|
54
|
+
@@ -1,2 +1,4 @@
|
|
55
|
+
-/expected/m
|
|
56
|
+
+this is the
|
|
57
|
+
+ actual
|
|
58
|
+
+ string
|
|
59
59
|
"""
|
|
60
60
|
|
|
61
61
|
Scenario: no diff for a single line strings
|
|
@@ -69,7 +69,7 @@ Feature: diffing
|
|
|
69
69
|
end
|
|
70
70
|
end
|
|
71
71
|
"""
|
|
72
|
-
When I run
|
|
72
|
+
When I run `rspec example_spec.rb`
|
|
73
73
|
Then the output should not contain "Diff:"
|
|
74
74
|
|
|
75
75
|
Scenario: no diff for numbers
|
|
@@ -81,5 +81,5 @@ Feature: diffing
|
|
|
81
81
|
end
|
|
82
82
|
end
|
|
83
83
|
"""
|
|
84
|
-
When I run
|
|
84
|
+
When I run `rspec example_spec.rb`
|
|
85
85
|
Then the output should not contain "Diff:"
|
|
@@ -18,13 +18,13 @@ Feature: implicit docstrings
|
|
|
18
18
|
end
|
|
19
19
|
"""
|
|
20
20
|
|
|
21
|
-
When I run
|
|
21
|
+
When I run `rspec ./implicit_docstrings_spec.rb -fdoc`
|
|
22
22
|
|
|
23
23
|
Then the output should contain "should be < 5"
|
|
24
24
|
And the output should contain "should include 2"
|
|
25
25
|
And the output should contain "should respond to #size"
|
|
26
26
|
|
|
27
|
-
Scenario
|
|
27
|
+
Scenario: run failing examples
|
|
28
28
|
Given a file named "failing_implicit_docstrings_spec.rb" with:
|
|
29
29
|
"""
|
|
30
30
|
describe "Failing examples with no descriptions" do
|
|
@@ -44,9 +44,9 @@ Feature: implicit docstrings
|
|
|
44
44
|
end
|
|
45
45
|
"""
|
|
46
46
|
|
|
47
|
-
When I run
|
|
47
|
+
When I run `rspec ./failing_implicit_docstrings_spec.rb -fdoc`
|
|
48
48
|
|
|
49
49
|
Then the output should contain "should equal 2"
|
|
50
50
|
And the output should contain "should be > 5"
|
|
51
|
-
And the output should contain "should include "
|
|
51
|
+
And the output should contain "should include 4"
|
|
52
52
|
And the output should contain "should not respond to #size"
|
|
@@ -0,0 +1,22 @@
|
|
|
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)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
Then /^the example(?:s)? should(?: all)? pass$/ do
|
|
15
|
+
Then %q{the output should contain "0 failures"}
|
|
16
|
+
Then %q{the exit status should be 0}
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
Then /^the example should fail$/ do
|
|
20
|
+
Then %q{the output should contain "1 failure"}
|
|
21
|
+
Then %q{the exit status should not be 0}
|
|
22
|
+
end
|
data/features/support/env.rb
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Feature: Test::Unit integration
|
|
2
|
+
|
|
3
|
+
RSpec-expectations is a stand-alone gem that can be used without
|
|
4
|
+
the rest of RSpec. It can easily be used with another test
|
|
5
|
+
framework such as Test::Unit if you like RSpec's should/should_not
|
|
6
|
+
syntax but prefer the test organization of another framework.
|
|
7
|
+
|
|
8
|
+
Scenario: Basic Test::Unit usage
|
|
9
|
+
Given a file named "rspec_expectations_test.rb" with:
|
|
10
|
+
"""
|
|
11
|
+
require 'test/unit'
|
|
12
|
+
require 'rspec/expectations'
|
|
13
|
+
|
|
14
|
+
class RSpecExpectationsTest < Test::Unit::TestCase
|
|
15
|
+
RSpec::Matchers.define :be_an_integer do
|
|
16
|
+
match { |actual| Integer === actual }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def be_an_int
|
|
20
|
+
RSpec.deprecate(:be_an_int, :be_an_integer)
|
|
21
|
+
be_an_integer
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_passing_expectation
|
|
25
|
+
x = 1 + 3
|
|
26
|
+
x.should == 4
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_failing_expectation
|
|
30
|
+
array = [1, 2]
|
|
31
|
+
array.should be_empty
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_expect_matcher
|
|
35
|
+
expect { @a = 5 }.to change { @a }.from(nil).to(5)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_custom_matcher_and_deprecation_warning
|
|
39
|
+
1.should be_an_int
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
"""
|
|
43
|
+
When I run `ruby rspec_expectations_test.rb`
|
|
44
|
+
Then the output should contain "4 tests, 0 assertions, 1 failures, 0 errors" or "4 tests, 0 assertions, 0 failures, 1 errors"
|
|
45
|
+
And the output should contain "expected empty? to return true, got false"
|
|
46
|
+
And the output should contain "be_an_int is deprecated"
|
|
@@ -3,7 +3,28 @@ module RSpec
|
|
|
3
3
|
module Expectations
|
|
4
4
|
module ConstMissing
|
|
5
5
|
def const_missing(name)
|
|
6
|
-
|
|
6
|
+
case name
|
|
7
|
+
when :Rspec, :Spec
|
|
8
|
+
RSpec.warn_deprecation <<-WARNING
|
|
9
|
+
*****************************************************************
|
|
10
|
+
DEPRECATION WARNING: you are using a deprecated constant that will
|
|
11
|
+
be removed from a future version of RSpec.
|
|
12
|
+
|
|
13
|
+
#{caller(0)[2]}
|
|
14
|
+
|
|
15
|
+
* #{name} is deprecated.
|
|
16
|
+
* RSpec is the new top-level module in RSpec-2
|
|
17
|
+
***************************************************************
|
|
18
|
+
WARNING
|
|
19
|
+
RSpec
|
|
20
|
+
else
|
|
21
|
+
begin
|
|
22
|
+
super
|
|
23
|
+
rescue Exception => e
|
|
24
|
+
e.backtrace.reject! {|l| l =~ Regexp.compile(__FILE__) }
|
|
25
|
+
raise e
|
|
26
|
+
end
|
|
27
|
+
end
|
|
7
28
|
end
|
|
8
29
|
end
|
|
9
30
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module RSpec
|
|
2
|
+
|
|
3
|
+
# This is defined in rspec-core, but we can't assume it's loaded since
|
|
4
|
+
# rspec-expectations should be usable w/o rspec-core.
|
|
5
|
+
unless respond_to?(:deprecate)
|
|
6
|
+
class << self
|
|
7
|
+
def deprecate(method, alternate_method=nil, version=nil)
|
|
8
|
+
version_string = version ? "rspec-#{version}" : "a future version of RSpec"
|
|
9
|
+
|
|
10
|
+
message = <<-NOTICE
|
|
11
|
+
|
|
12
|
+
*****************************************************************
|
|
13
|
+
DEPRECATION WARNING: you are using deprecated behaviour that will
|
|
14
|
+
be removed from #{version_string}.
|
|
15
|
+
|
|
16
|
+
#{caller(0)[2]}
|
|
17
|
+
|
|
18
|
+
* #{method} is deprecated.
|
|
19
|
+
NOTICE
|
|
20
|
+
if alternate_method
|
|
21
|
+
message << <<-ADDITIONAL
|
|
22
|
+
* please use #{alternate_method} instead.
|
|
23
|
+
ADDITIONAL
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
message << "*****************************************************************"
|
|
27
|
+
warn_deprecation(message)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def warn_deprecation(message)
|
|
31
|
+
send :warn, message
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
data/lib/rspec/expectations.rb
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
require 'rspec/expectations/extensions'
|
|
1
2
|
require 'rspec/matchers'
|
|
2
3
|
require 'rspec/expectations/fail_with'
|
|
3
4
|
require 'rspec/expectations/errors'
|
|
4
|
-
require 'rspec/expectations/
|
|
5
|
+
require 'rspec/expectations/deprecation'
|
|
5
6
|
require 'rspec/expectations/handler'
|
|
6
7
|
require 'rspec/expectations/version'
|
|
7
8
|
require 'rspec/expectations/backward_compatibility'
|
data/lib/rspec/matchers/be.rb
CHANGED
|
@@ -2,7 +2,7 @@ require 'rspec/matchers/dsl'
|
|
|
2
2
|
|
|
3
3
|
RSpec::Matchers.define :be_true do
|
|
4
4
|
match do |actual|
|
|
5
|
-
|
|
5
|
+
actual
|
|
6
6
|
end
|
|
7
7
|
end
|
|
8
8
|
|
|
@@ -18,11 +18,11 @@ RSpec::Matchers.define :be_nil do
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
failure_message_for_should do |actual|
|
|
21
|
-
"expected nil
|
|
21
|
+
"expected: nil\n got: #{actual.inspect}"
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
failure_message_for_should_not do
|
|
25
|
-
"expected not nil
|
|
25
|
+
"expected: not nil\n got: nil"
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
|
|
@@ -96,7 +96,7 @@ module RSpec
|
|
|
96
96
|
end
|
|
97
97
|
|
|
98
98
|
def failure_message_for_should
|
|
99
|
-
"expected #{@operator} #{@expected}
|
|
99
|
+
"expected: #{@operator} #{@expected.inspect}\n got: #{@operator.to_s.gsub(/./, ' ')} #{@actual.inspect}"
|
|
100
100
|
end
|
|
101
101
|
|
|
102
102
|
def failure_message_for_should_not
|
|
@@ -10,23 +10,8 @@ module RSpec
|
|
|
10
10
|
#
|
|
11
11
|
# result.should be_close(3.0, 0.5)
|
|
12
12
|
def be_close(expected, delta)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
(actual - _expected_).abs < _delta_
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
failure_message_for_should do |actual|
|
|
19
|
-
"expected #{_expected_} +/- (< #{_delta_}), got #{actual}"
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
failure_message_for_should_not do |actual|
|
|
23
|
-
"expected #{_expected_} +/- (< #{_delta_}), got #{actual}"
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
description do
|
|
27
|
-
"be close to #{_expected_} (within +- #{_delta_})"
|
|
28
|
-
end
|
|
29
|
-
end
|
|
13
|
+
RSpec.deprecate("be_close(#{expected}, #{delta})", "be_within(#{delta}).of(#{expected})")
|
|
14
|
+
be_within(delta).of(expected)
|
|
30
15
|
end
|
|
31
16
|
end
|
|
32
17
|
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module RSpec
|
|
2
|
+
module Matchers
|
|
3
|
+
# :call-seq:
|
|
4
|
+
# should be_within(delta).of(expected)
|
|
5
|
+
# should_not be_within(delta).of(expected)
|
|
6
|
+
#
|
|
7
|
+
# Passes if actual == expected +/- delta
|
|
8
|
+
#
|
|
9
|
+
# == Example
|
|
10
|
+
#
|
|
11
|
+
# result.should be_within(0.5).of(3.0)
|
|
12
|
+
def be_within(delta)
|
|
13
|
+
Matcher.new :be_within, delta do |_delta_|
|
|
14
|
+
chain :of do |_expected_|
|
|
15
|
+
@_expected = _expected_
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
match do |actual|
|
|
19
|
+
unless @_expected
|
|
20
|
+
raise ArgumentError.new("You must set an expected value using #of: be_within(#{_delta_}).of(expected_value)")
|
|
21
|
+
end
|
|
22
|
+
(actual - @_expected).abs < _delta_
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
failure_message_for_should do |actual|
|
|
26
|
+
"expected #{actual} to #{description}"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
failure_message_for_should_not do |actual|
|
|
30
|
+
"expected #{actual} not to #{description}"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
description do
|
|
34
|
+
"be within #{_delta_} of #{@_expected}"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module RSpec
|
|
2
|
+
module Matchers
|
|
3
|
+
module BlockAliases
|
|
4
|
+
alias_method :to, :should
|
|
5
|
+
alias_method :to_not, :should_not
|
|
6
|
+
alias_method :not_to, :should_not
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
# Extends the submitted block with aliases to and to_not
|
|
10
|
+
# for should and should_not. Allows expectations like this:
|
|
11
|
+
#
|
|
12
|
+
# expect { this_block }.to change{this.expression}.from(old_value).to(new_value)
|
|
13
|
+
# expect { this_block }.to raise_error
|
|
14
|
+
def expect(&block)
|
|
15
|
+
block.extend BlockAliases
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|