rspec-expectations 2.13.0 → 2.99.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 +15 -0
- data/Changelog.md +204 -23
- data/README.md +43 -87
- data/features/README.md +10 -10
- data/features/built_in_matchers/README.md +41 -41
- data/features/built_in_matchers/be.feature +40 -40
- data/features/built_in_matchers/be_within.feature +3 -3
- data/features/built_in_matchers/expect_change.feature +6 -6
- data/features/built_in_matchers/expect_error.feature +2 -2
- data/features/built_in_matchers/start_with.feature +1 -1
- data/features/built_in_matchers/throw_symbol.feature +11 -11
- data/features/built_in_matchers/yield.feature +18 -3
- data/features/custom_matchers/define_diffable_matcher.feature +1 -1
- data/features/custom_matchers/define_matcher_outside_rspec.feature +6 -6
- data/features/custom_matchers/define_matcher_with_fluent_interface.feature +1 -1
- data/features/customized_message.feature +1 -1
- data/features/diffing.feature +1 -1
- data/features/step_definitions/additional_cli_steps.rb +10 -0
- data/features/support/env.rb +10 -1
- data/features/support/rubinius.rb +6 -0
- data/features/syntax_configuration.feature +3 -0
- data/features/test_frameworks/test_unit.feature +55 -17
- data/lib/rspec/expectations/caller_filter.rb +60 -0
- data/lib/rspec/{matchers → expectations}/configuration.rb +5 -3
- data/lib/rspec/expectations/deprecation.rb +20 -31
- data/lib/rspec/expectations/differ.rb +48 -9
- data/lib/rspec/expectations/expectation_target.rb +81 -15
- data/lib/rspec/expectations/extensions/object.rb +2 -12
- data/lib/rspec/expectations/fail_with.rb +11 -1
- data/lib/rspec/expectations/handler.rb +16 -7
- data/lib/rspec/expectations/syntax.rb +5 -7
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/expectations.rb +28 -2
- data/lib/rspec/matchers/be_close.rb +4 -1
- data/lib/rspec/matchers/built_in/base_matcher.rb +17 -10
- data/lib/rspec/matchers/built_in/be.rb +69 -32
- data/lib/rspec/matchers/built_in/be_within.rb +9 -3
- data/lib/rspec/matchers/built_in/change.rb +49 -3
- data/lib/rspec/matchers/built_in/has.rb +40 -7
- data/lib/rspec/matchers/built_in/have.rb +170 -5
- data/lib/rspec/matchers/built_in/include.rb +3 -11
- data/lib/rspec/matchers/built_in/match.rb +5 -0
- data/lib/rspec/matchers/built_in/match_array.rb +1 -1
- data/lib/rspec/matchers/built_in/raise_error.rb +34 -8
- data/lib/rspec/matchers/built_in/respond_to.rb +7 -1
- data/lib/rspec/matchers/built_in/satisfy.rb +7 -1
- data/lib/rspec/matchers/built_in/throw_symbol.rb +10 -2
- data/lib/rspec/matchers/built_in/yield.rb +102 -5
- data/lib/rspec/matchers/built_in.rb +2 -2
- data/lib/rspec/matchers/differentiate_block_method_types.rb +55 -0
- data/lib/rspec/matchers/dsl.rb +2 -1
- data/lib/rspec/matchers/match_aliases.rb +22 -0
- data/lib/rspec/matchers/matcher.rb +131 -10
- data/lib/rspec/matchers/operator_matcher.rb +70 -66
- data/lib/rspec/matchers/pretty.rb +11 -1
- data/lib/rspec/matchers/test_unit_integration.rb +28 -0
- data/lib/rspec/matchers.rb +175 -146
- data/lib/rspec-expectations.rb +5 -0
- data/spec/rspec/{matchers → expectations}/configuration_spec.rb +78 -91
- data/spec/rspec/expectations/differ_spec.rb +65 -6
- data/spec/rspec/expectations/expectation_target_spec.rb +72 -3
- data/spec/rspec/expectations/extensions/kernel_spec.rb +9 -5
- data/spec/rspec/expectations/fail_with_spec.rb +19 -0
- data/spec/rspec/expectations/handler_spec.rb +43 -22
- data/spec/rspec/expectations/syntax_spec.rb +51 -9
- data/spec/rspec/expectations_spec.rb +71 -0
- data/spec/rspec/matchers/base_matcher_spec.rb +33 -18
- data/spec/rspec/matchers/be_close_spec.rb +9 -6
- data/spec/rspec/matchers/be_spec.rb +146 -45
- data/spec/rspec/matchers/be_within_spec.rb +8 -0
- data/spec/rspec/matchers/change_spec.rb +107 -7
- data/spec/rspec/matchers/description_generation_spec.rb +38 -20
- data/spec/rspec/matchers/differentiate_block_method_types_spec.rb +39 -0
- data/spec/rspec/matchers/eq_spec.rb +1 -1
- data/spec/rspec/matchers/equal_spec.rb +26 -0
- data/spec/rspec/matchers/exist_spec.rb +9 -9
- data/spec/rspec/matchers/has_spec.rb +25 -1
- data/spec/rspec/matchers/have_spec.rb +411 -3
- data/spec/rspec/matchers/include_matcher_integration_spec.rb +2 -2
- data/spec/rspec/matchers/include_spec.rb +4 -4
- data/spec/rspec/matchers/match_array_spec.rb +1 -1
- data/spec/rspec/matchers/match_spec.rb +14 -1
- data/spec/rspec/matchers/matcher_spec.rb +213 -24
- data/spec/rspec/matchers/operator_matcher_spec.rb +56 -8
- data/spec/rspec/matchers/pretty_spec.rb +23 -0
- data/spec/rspec/matchers/raise_error_spec.rb +242 -102
- data/spec/rspec/matchers/respond_to_spec.rb +4 -4
- data/spec/rspec/matchers/satisfy_spec.rb +1 -1
- data/spec/rspec/matchers/start_with_end_with_spec.rb +2 -2
- data/spec/rspec/matchers/throw_symbol_spec.rb +14 -14
- data/spec/rspec/matchers/yield_spec.rb +81 -4
- data/spec/spec_helper.rb +5 -3
- data/spec/support/helper_methods.rb +42 -0
- data/spec/support/shared_examples.rb +42 -0
- metadata +40 -44
- data/spec/rspec/matchers/matchers_spec.rb +0 -37
|
@@ -1,55 +1,55 @@
|
|
|
1
1
|
# Built-in Matchers
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
can be used with `
|
|
3
|
+
rspec-expectations ships with a number of built-in matchers.
|
|
4
|
+
Each matcher can be used with `expect(..).to` or `expect(..).not_to` to define
|
|
5
|
+
positive and negative expectations respectively on an object. Most matchers can
|
|
6
|
+
also be accessed using the `(...).should` and `(...).should_not` syntax, see
|
|
7
|
+
[using should syntax](https://github.com/rspec/rspec-expectations/blob/master/Should.md)
|
|
8
|
+
for why we recommend using `expect`.
|
|
5
9
|
|
|
6
|
-
|
|
7
|
-
|
|
10
|
+
e.g.
|
|
11
|
+
|
|
12
|
+
expect(result).to eq(3)
|
|
13
|
+
expect(list).not_to be_empty
|
|
14
|
+
pi.should be > 3
|
|
8
15
|
|
|
9
16
|
## Object identity
|
|
10
17
|
|
|
11
|
-
actual.
|
|
12
|
-
|
|
18
|
+
expect(actual).to be(expected) # passes if actual.equal?(expected)
|
|
19
|
+
|
|
13
20
|
## Object equivalence
|
|
14
21
|
|
|
15
|
-
actual.
|
|
22
|
+
expect(actual).to eq(expected) # passes if actual == expected
|
|
16
23
|
|
|
17
24
|
## Optional APIs for identity/equivalence
|
|
18
25
|
|
|
19
|
-
actual.
|
|
20
|
-
actual.
|
|
21
|
-
actual.should equal(expected) # passes if actual.equal?(expected)
|
|
26
|
+
expect(actual).to eql(expected) # passes if actual.eql?(expected)
|
|
27
|
+
expect(actual).to equal(expected) # passes if actual.equal?(expected)
|
|
22
28
|
|
|
23
|
-
# NOTE:
|
|
24
|
-
# actual.should != expected
|
|
25
|
-
# The reason is that Ruby 1.8 parses it as:
|
|
26
|
-
# !(actual.should.==(expected)),
|
|
27
|
-
# so by the time RSpec sees it it has no way to know that it's
|
|
28
|
-
# been negated. Use either of these instead:
|
|
29
|
-
# actual.should_not eq(expected)
|
|
30
|
-
# actual.should_not == expected
|
|
29
|
+
# NOTE: `expect` does not support `==` matcher.
|
|
31
30
|
|
|
32
31
|
## Comparisons
|
|
33
32
|
|
|
34
|
-
actual.
|
|
35
|
-
actual.
|
|
36
|
-
actual.
|
|
37
|
-
actual.
|
|
38
|
-
actual.
|
|
39
|
-
actual.
|
|
40
|
-
|
|
33
|
+
expect(actual).to be > expected
|
|
34
|
+
expect(actual).to be >= expected
|
|
35
|
+
expect(actual).to be <= expected
|
|
36
|
+
expect(actual).to be < expected
|
|
37
|
+
expect(actual).to match(/expression/)
|
|
38
|
+
expect(actual).to be_within(delta).of(expected)
|
|
39
|
+
|
|
40
|
+
# NOTE: `expect` does not support `=~` matcher.
|
|
41
41
|
|
|
42
42
|
## Types/classes
|
|
43
43
|
|
|
44
|
-
actual.
|
|
45
|
-
actual.
|
|
44
|
+
expect(actual).to be_instance_of(expected)
|
|
45
|
+
expect(actual).to be_kind_of(expected)
|
|
46
46
|
|
|
47
47
|
## Truthiness and existentialism
|
|
48
48
|
|
|
49
|
-
actual.
|
|
50
|
-
actual.
|
|
51
|
-
actual.
|
|
52
|
-
actual.
|
|
49
|
+
expect(actual).to be_true # passes if actual is truthy (not nil or false)
|
|
50
|
+
expect(actual).to be_false # passes if actual is falsy (nil or false)
|
|
51
|
+
expect(actual).to be_nil # passes if actual is nil
|
|
52
|
+
expect(actual).to be # passes if actual is truthy (not nil or false)
|
|
53
53
|
|
|
54
54
|
## Expecting errors
|
|
55
55
|
|
|
@@ -66,25 +66,25 @@ can be used with `should` or `should_not` e.g.
|
|
|
66
66
|
|
|
67
67
|
## Predicate matchers
|
|
68
68
|
|
|
69
|
-
actual.
|
|
70
|
-
actual.
|
|
69
|
+
expect(actual).to be_xxx # passes if actual.xxx?
|
|
70
|
+
expect(actual).to have_xxx(:arg) # passes if actual.has_xxx?(:arg)
|
|
71
71
|
|
|
72
72
|
### Examples
|
|
73
73
|
|
|
74
|
-
[].
|
|
75
|
-
|
|
74
|
+
expect([]).to be_empty
|
|
75
|
+
expect(:a => 1).to have_key(:a)
|
|
76
76
|
|
|
77
77
|
## Collection membership
|
|
78
78
|
|
|
79
|
-
actual.
|
|
79
|
+
expect(actual).to include(expected)
|
|
80
80
|
|
|
81
81
|
### Examples
|
|
82
82
|
|
|
83
|
-
[1,2,3].
|
|
84
|
-
[1,2,3].
|
|
85
|
-
|
|
86
|
-
"this string".
|
|
83
|
+
expect([1,2,3]).to include(1)
|
|
84
|
+
expect([1,2,3]).to include(1, 2)
|
|
85
|
+
expect(:a => 'b').to include(:a => 'b')
|
|
86
|
+
expect("this string").to include("is str")
|
|
87
87
|
|
|
88
88
|
## Ranges (1.9 only)
|
|
89
89
|
|
|
90
|
-
(1..10).
|
|
90
|
+
expect(1..10).to cover(3)
|
|
@@ -3,101 +3,101 @@ Feature: "be" matchers
|
|
|
3
3
|
There are several related "be" matchers:
|
|
4
4
|
|
|
5
5
|
```ruby
|
|
6
|
-
obj.should
|
|
7
|
-
obj.should
|
|
6
|
+
obj.should be_truthy # passes if obj is truthy (not nil or false)
|
|
7
|
+
obj.should be_falsey # passes if obj is falsy (nil or false)
|
|
8
8
|
obj.should be_nil # passes if obj is nil
|
|
9
9
|
obj.should be # passes if obj is truthy (not nil or false)
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
Scenario:
|
|
13
|
-
Given a file named "
|
|
12
|
+
Scenario: be_truthy matcher
|
|
13
|
+
Given a file named "be_truthy_spec.rb" with:
|
|
14
14
|
"""ruby
|
|
15
|
-
describe "
|
|
16
|
-
specify { true.should
|
|
17
|
-
specify { 7.should
|
|
18
|
-
specify { "foo".should
|
|
19
|
-
specify { nil.should_not
|
|
20
|
-
specify { false.should_not
|
|
15
|
+
describe "be_truthy matcher" do
|
|
16
|
+
specify { true.should be_truthy }
|
|
17
|
+
specify { 7.should be_truthy }
|
|
18
|
+
specify { "foo".should be_truthy }
|
|
19
|
+
specify { nil.should_not be_truthy }
|
|
20
|
+
specify { false.should_not be_truthy }
|
|
21
21
|
|
|
22
22
|
# deliberate failures
|
|
23
|
-
specify { true.should_not
|
|
24
|
-
specify { 7.should_not
|
|
25
|
-
specify { "foo".should_not
|
|
26
|
-
specify { nil.should
|
|
27
|
-
specify { false.should
|
|
23
|
+
specify { true.should_not be_truthy }
|
|
24
|
+
specify { 7.should_not be_truthy }
|
|
25
|
+
specify { "foo".should_not be_truthy }
|
|
26
|
+
specify { nil.should be_truthy }
|
|
27
|
+
specify { false.should be_truthy }
|
|
28
28
|
end
|
|
29
29
|
"""
|
|
30
|
-
When I run `rspec
|
|
30
|
+
When I run `rspec be_truthy_spec.rb`
|
|
31
31
|
Then the output should contain "10 examples, 5 failures"
|
|
32
32
|
And the output should contain:
|
|
33
33
|
"""
|
|
34
|
-
expected:
|
|
34
|
+
expected: falsey value
|
|
35
35
|
got: true
|
|
36
36
|
"""
|
|
37
37
|
And the output should contain:
|
|
38
38
|
"""
|
|
39
|
-
expected:
|
|
39
|
+
expected: falsey value
|
|
40
40
|
got: 7
|
|
41
41
|
"""
|
|
42
42
|
And the output should contain:
|
|
43
43
|
"""
|
|
44
|
-
expected:
|
|
44
|
+
expected: falsey value
|
|
45
45
|
got: "foo"
|
|
46
46
|
"""
|
|
47
47
|
And the output should contain:
|
|
48
48
|
"""
|
|
49
|
-
expected:
|
|
49
|
+
expected: truthy value
|
|
50
50
|
got: nil
|
|
51
51
|
"""
|
|
52
52
|
And the output should contain:
|
|
53
53
|
"""
|
|
54
|
-
expected:
|
|
54
|
+
expected: truthy value
|
|
55
55
|
got: false
|
|
56
56
|
"""
|
|
57
57
|
|
|
58
|
-
Scenario:
|
|
59
|
-
Given a file named "
|
|
58
|
+
Scenario: be_falsey matcher
|
|
59
|
+
Given a file named "be_falsey_spec.rb" with:
|
|
60
60
|
"""ruby
|
|
61
|
-
describe "
|
|
62
|
-
specify { nil.should
|
|
63
|
-
specify { false.should
|
|
64
|
-
specify { true.should_not
|
|
65
|
-
specify { 7.should_not
|
|
66
|
-
specify { "foo".should_not
|
|
61
|
+
describe "be_falsey matcher" do
|
|
62
|
+
specify { nil.should be_falsey }
|
|
63
|
+
specify { false.should be_falsey }
|
|
64
|
+
specify { true.should_not be_falsey }
|
|
65
|
+
specify { 7.should_not be_falsey }
|
|
66
|
+
specify { "foo".should_not be_falsey }
|
|
67
67
|
|
|
68
68
|
# deliberate failures
|
|
69
|
-
specify { nil.should_not
|
|
70
|
-
specify { false.should_not
|
|
71
|
-
specify { true.should
|
|
72
|
-
specify { 7.should
|
|
73
|
-
specify { "foo".should
|
|
69
|
+
specify { nil.should_not be_falsey }
|
|
70
|
+
specify { false.should_not be_falsey }
|
|
71
|
+
specify { true.should be_falsey }
|
|
72
|
+
specify { 7.should be_falsey }
|
|
73
|
+
specify { "foo".should be_falsey }
|
|
74
74
|
end
|
|
75
75
|
"""
|
|
76
|
-
When I run `rspec
|
|
76
|
+
When I run `rspec be_falsey_spec.rb`
|
|
77
77
|
Then the output should contain "10 examples, 5 failures"
|
|
78
78
|
And the output should contain:
|
|
79
79
|
"""
|
|
80
|
-
expected:
|
|
80
|
+
expected: truthy value
|
|
81
81
|
got: nil
|
|
82
82
|
"""
|
|
83
83
|
And the output should contain:
|
|
84
84
|
"""
|
|
85
|
-
expected:
|
|
85
|
+
expected: truthy value
|
|
86
86
|
got: false
|
|
87
87
|
"""
|
|
88
88
|
And the output should contain:
|
|
89
89
|
"""
|
|
90
|
-
expected:
|
|
90
|
+
expected: falsey value
|
|
91
91
|
got: true
|
|
92
92
|
"""
|
|
93
93
|
And the output should contain:
|
|
94
94
|
"""
|
|
95
|
-
expected:
|
|
95
|
+
expected: falsey value
|
|
96
96
|
got: 7
|
|
97
97
|
"""
|
|
98
98
|
And the output should contain:
|
|
99
99
|
"""
|
|
100
|
-
expected:
|
|
100
|
+
expected: falsey value
|
|
101
101
|
got: "foo"
|
|
102
102
|
"""
|
|
103
103
|
|
|
@@ -4,11 +4,11 @@ Feature: be_within matcher
|
|
|
4
4
|
Consider this irb session:
|
|
5
5
|
|
|
6
6
|
> radius = 3
|
|
7
|
-
=> 3
|
|
7
|
+
=> 3
|
|
8
8
|
> area_of_circle = radius * radius * Math::PI
|
|
9
|
-
=> 28.2743338823081
|
|
9
|
+
=> 28.2743338823081
|
|
10
10
|
> area_of_circle == 28.2743338823081
|
|
11
|
-
=> false
|
|
11
|
+
=> false
|
|
12
12
|
|
|
13
13
|
Instead, you should use the be_within matcher to check that the value
|
|
14
14
|
is within a delta of your expected value:
|
|
@@ -11,14 +11,14 @@ Feature: expect change
|
|
|
11
11
|
@count ||= 0
|
|
12
12
|
@count += 1
|
|
13
13
|
end
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
def count
|
|
16
16
|
@count ||= 0
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
"""
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
Scenario: expect change
|
|
23
23
|
Given a file named "spec/example_spec.rb" with:
|
|
24
24
|
"""ruby
|
|
@@ -45,13 +45,13 @@ Feature: expect change
|
|
|
45
45
|
require "counter"
|
|
46
46
|
|
|
47
47
|
describe Counter, "#increment" do
|
|
48
|
-
it "should not increment the count by 1 (using to_not)" do
|
|
49
|
-
expect { Counter.increment }.to_not change{Counter.count}
|
|
50
|
-
end
|
|
51
|
-
|
|
52
48
|
it "should not increment the count by 1 (using not_to)" do
|
|
53
49
|
expect { Counter.increment }.not_to change{Counter.count}
|
|
54
50
|
end
|
|
51
|
+
|
|
52
|
+
it "should not increment the count by 1 (using to_not)" do
|
|
53
|
+
expect { Counter.increment }.to_not change{Counter.count}
|
|
54
|
+
end
|
|
55
55
|
end
|
|
56
56
|
"""
|
|
57
57
|
When I run `rspec spec/example_spec.rb`
|
|
@@ -124,7 +124,7 @@ Feature: raise_error matcher
|
|
|
124
124
|
describe Object, "#public_instance_methods" do
|
|
125
125
|
it "does not raise" do
|
|
126
126
|
expect { Object.public_instance_methods }.
|
|
127
|
-
|
|
127
|
+
not_to raise_error(NameError)
|
|
128
128
|
end
|
|
129
129
|
end
|
|
130
130
|
"""
|
|
@@ -136,7 +136,7 @@ Feature: raise_error matcher
|
|
|
136
136
|
"""
|
|
137
137
|
describe "#to_s" do
|
|
138
138
|
it "does not raise" do
|
|
139
|
-
expect { Object.new.to_s }.
|
|
139
|
+
expect { Object.new.to_s }.not_to raise_error
|
|
140
140
|
end
|
|
141
141
|
end
|
|
142
142
|
"""
|
|
@@ -26,11 +26,11 @@ Feature: throw_symbol matcher
|
|
|
26
26
|
describe "throw" do
|
|
27
27
|
specify { expect { throw :foo }.to throw_symbol }
|
|
28
28
|
specify { expect { throw :bar, 7 }.to throw_symbol }
|
|
29
|
-
specify { expect { 5 + 5 }.
|
|
29
|
+
specify { expect { 5 + 5 }.not_to throw_symbol }
|
|
30
30
|
|
|
31
31
|
# deliberate failures
|
|
32
|
-
specify { expect { throw :foo }.
|
|
33
|
-
specify { expect { throw :bar, 7 }.
|
|
32
|
+
specify { expect { throw :foo }.not_to throw_symbol }
|
|
33
|
+
specify { expect { throw :bar, 7 }.not_to throw_symbol }
|
|
34
34
|
specify { expect { 5 + 5 }.to throw_symbol }
|
|
35
35
|
end
|
|
36
36
|
"""
|
|
@@ -47,12 +47,12 @@ Feature: throw_symbol matcher
|
|
|
47
47
|
describe "throw symbol" do
|
|
48
48
|
specify { expect { throw :foo }.to throw_symbol(:foo) }
|
|
49
49
|
specify { expect { throw :foo, 7 }.to throw_symbol(:foo) }
|
|
50
|
-
specify { expect { 5 + 5 }.
|
|
51
|
-
specify { expect { throw :bar }.
|
|
50
|
+
specify { expect { 5 + 5 }.not_to throw_symbol(:foo) }
|
|
51
|
+
specify { expect { throw :bar }.not_to throw_symbol(:foo) }
|
|
52
52
|
|
|
53
53
|
# deliberate failures
|
|
54
|
-
specify { expect { throw :foo }.
|
|
55
|
-
specify { expect { throw :foo, 7 }.
|
|
54
|
+
specify { expect { throw :foo }.not_to throw_symbol(:foo) }
|
|
55
|
+
specify { expect { throw :foo, 7 }.not_to throw_symbol(:foo) }
|
|
56
56
|
specify { expect { 5 + 5 }.to throw_symbol(:foo) }
|
|
57
57
|
specify { expect { throw :bar }.to throw_symbol(:foo) }
|
|
58
58
|
end
|
|
@@ -70,12 +70,12 @@ Feature: throw_symbol matcher
|
|
|
70
70
|
"""ruby
|
|
71
71
|
describe "throw symbol with argument" do
|
|
72
72
|
specify { expect { throw :foo, 7 }.to throw_symbol(:foo, 7) }
|
|
73
|
-
specify { expect { throw :foo, 8 }.
|
|
74
|
-
specify { expect { throw :bar, 7 }.
|
|
75
|
-
specify { expect { throw :foo }.
|
|
73
|
+
specify { expect { throw :foo, 8 }.not_to throw_symbol(:foo, 7) }
|
|
74
|
+
specify { expect { throw :bar, 7 }.not_to throw_symbol(:foo, 7) }
|
|
75
|
+
specify { expect { throw :foo }.not_to throw_symbol(:foo, 7) }
|
|
76
76
|
|
|
77
77
|
# deliberate failures
|
|
78
|
-
specify { expect { throw :foo, 7 }.
|
|
78
|
+
specify { expect { throw :foo, 7 }.not_to throw_symbol(:foo, 7) }
|
|
79
79
|
specify { expect { throw :foo, 8 }.to throw_symbol(:foo, 7) }
|
|
80
80
|
specify { expect { throw :bar, 7 }.to throw_symbol(:foo, 7) }
|
|
81
81
|
specify { expect { throw :foo }.to throw_symbol(:foo, 7) }
|
|
@@ -30,6 +30,10 @@ Feature: yield matchers
|
|
|
30
30
|
yield *args
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
+
def self.yield_twice_with(*args)
|
|
34
|
+
2.times { yield *args }
|
|
35
|
+
end
|
|
36
|
+
|
|
33
37
|
def self.raw_yield
|
|
34
38
|
yield
|
|
35
39
|
end
|
|
@@ -47,17 +51,28 @@ Feature: yield matchers
|
|
|
47
51
|
describe "yield_control matcher" do
|
|
48
52
|
specify { expect { |b| MyClass.yield_once_with(1, &b) }.to yield_control }
|
|
49
53
|
specify { expect { |b| MyClass.dont_yield(&b) }.not_to yield_control }
|
|
54
|
+
specify { expect { |b| MyClass.yield_twice_with(1, &b) }.to yield_control.twice }
|
|
55
|
+
specify { expect { |b| MyClass.yield_twice_with(1, &b) }.to yield_control.exactly(2).times }
|
|
56
|
+
specify { expect { |b| MyClass.yield_twice_with(1, &b) }.to yield_control.at_least(1) }
|
|
57
|
+
specify { expect { |b| MyClass.yield_twice_with(1, &b) }.to yield_control.at_most(3).times }
|
|
50
58
|
|
|
51
59
|
# deliberate failures
|
|
52
60
|
specify { expect { |b| MyClass.yield_once_with(1, &b) }.not_to yield_control }
|
|
53
61
|
specify { expect { |b| MyClass.dont_yield(&b) }.to yield_control }
|
|
62
|
+
specify { expect { |b| MyClass.yield_once_with(1, &b) }.to yield_control.at_least(2).times }
|
|
63
|
+
specify { expect { |b| MyClass.yield_twice_with(1, &b) }.not_to yield_control.twice }
|
|
64
|
+
specify { expect { |b| MyClass.yield_twice_with(1, &b) }.not_to yield_control.at_least(2).times }
|
|
65
|
+
specify { expect { |b| MyClass.yield_twice_with(1, &b) }.not_to yield_control.at_least(1) }
|
|
66
|
+
specify { expect { |b| MyClass.yield_twice_with(1, &b) }.not_to yield_control.at_most(3).times }
|
|
54
67
|
end
|
|
55
68
|
"""
|
|
56
69
|
When I run `rspec yield_control_spec.rb`
|
|
57
70
|
Then the output should contain all of these:
|
|
58
|
-
|
|
|
59
|
-
| expected given block to yield control
|
|
60
|
-
| expected given block not to yield control
|
|
71
|
+
| 13 examples, 7 failures |
|
|
72
|
+
| expected given block to yield control |
|
|
73
|
+
| expected given block not to yield control |
|
|
74
|
+
| expected given block not to yield control at least twice |
|
|
75
|
+
| expected given block not to yield control at most 3 times |
|
|
61
76
|
|
|
62
77
|
Scenario: yield_with_args matcher
|
|
63
78
|
Given a file named "yield_with_args_spec.rb" with:
|
|
@@ -9,19 +9,19 @@ Feature: define matcher outside rspec
|
|
|
9
9
|
"""ruby
|
|
10
10
|
require "rspec/expectations"
|
|
11
11
|
require "test/unit"
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
RSpec::Matchers.define :be_a_multiple_of do |expected|
|
|
14
14
|
match do |actual|
|
|
15
15
|
actual % expected == 0
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
class Test::Unit::TestCase
|
|
20
20
|
include RSpec::Matchers
|
|
21
21
|
end
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
class TestMultiples < Test::Unit::TestCase
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
def test_9_should_be_a_multiple_of_3
|
|
26
26
|
9.should be_a_multiple_of(3)
|
|
27
27
|
end
|
|
@@ -29,10 +29,10 @@ Feature: define matcher outside rspec
|
|
|
29
29
|
def test_9_should_be_a_multiple_of_4
|
|
30
30
|
9.should be_a_multiple_of(4)
|
|
31
31
|
end
|
|
32
|
-
|
|
32
|
+
|
|
33
33
|
end
|
|
34
34
|
"""
|
|
35
35
|
When I run `ruby test_multiples.rb`
|
|
36
|
-
Then the exit status should not be 0
|
|
36
|
+
Then the exit status should not be 0
|
|
37
37
|
And the output should contain "expected 9 to be a multiple of 4"
|
|
38
38
|
And the output should contain "2 tests, 0 assertions, 0 failures, 1 errors"
|
|
@@ -3,7 +3,7 @@ Feature: customized message
|
|
|
3
3
|
RSpec tries to provide useful failure messages, but for cases in which you
|
|
4
4
|
want more specific information, you can define your own message right in the
|
|
5
5
|
example. This works for any matcher _other than the operator matchers_.
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
Scenario: customize failure message
|
|
8
8
|
Given a file named "example_spec.rb" with:
|
|
9
9
|
"""ruby
|
data/features/diffing.feature
CHANGED
|
@@ -20,3 +20,13 @@ Then /^the example should fail$/ do
|
|
|
20
20
|
step %q{the output should contain "1 failure"}
|
|
21
21
|
step %q{the exit status should not be 0}
|
|
22
22
|
end
|
|
23
|
+
|
|
24
|
+
deprecation_message = /rspec-expectations' built-in integration with (Test::Unit|minitest < 5.x) is deprecated/
|
|
25
|
+
|
|
26
|
+
Then /^the output should contain a deprecation warning about rspec\-expecations' built\-in integration$/ do
|
|
27
|
+
expect(all_output).to match(deprecation_message)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
Then /^the output should not contain a deprecation warning about rspec\-expecations' built\-in integration$/ do
|
|
31
|
+
expect(all_output).not_to match(deprecation_message)
|
|
32
|
+
end
|
data/features/support/env.rb
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
require 'aruba/cucumber'
|
|
2
2
|
|
|
3
|
+
timeouts = { 'java' => 60 }
|
|
4
|
+
|
|
3
5
|
Before do
|
|
4
|
-
@aruba_timeout_seconds = 15
|
|
6
|
+
@aruba_timeout_seconds = timeouts.fetch(RUBY_PLATFORM) { 15 }
|
|
5
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
|
+
|