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,116 +0,0 @@
|
|
1
|
-
Feature: specify types of objects
|
2
|
-
|
3
|
-
rspec-expectations includes two matchers to specify types of objects:
|
4
|
-
|
5
|
-
* `obj.should be_kind_of(type)`: calls `obj.kind_of?(type)`, which returns
|
6
|
-
true if type is in obj's class hierarchy or is a module and is
|
7
|
-
included in a class in obj's class hierarchy.
|
8
|
-
* `obj.should be_instance_of(type)`: calls `obj.instance_of?(type)`, which
|
9
|
-
returns true if and only if type if obj's class.
|
10
|
-
|
11
|
-
Both of these matchers have aliases:
|
12
|
-
|
13
|
-
```ruby
|
14
|
-
obj.should be_a_kind_of(type) # same as obj.should be_kind_of(type)
|
15
|
-
obj.should be_a(type) # same as obj.should be_kind_of(type)
|
16
|
-
obj.should be_an(type) # same as obj.should be_kind_of(type)
|
17
|
-
obj.should be_an_instance_of(type) # same as obj.should be_instance_of(type)
|
18
|
-
```
|
19
|
-
|
20
|
-
Scenario: be_(a_)kind_of matcher
|
21
|
-
Given a file named "be_kind_of_matcher_spec.rb" with:
|
22
|
-
"""ruby
|
23
|
-
module MyModule; end
|
24
|
-
|
25
|
-
class Fixnum
|
26
|
-
include MyModule
|
27
|
-
end
|
28
|
-
|
29
|
-
describe 17 do
|
30
|
-
# the actual class
|
31
|
-
it { should be_kind_of(Fixnum) }
|
32
|
-
it { should be_a_kind_of(Fixnum) }
|
33
|
-
it { should be_a(Fixnum) }
|
34
|
-
|
35
|
-
# the superclass
|
36
|
-
it { should be_kind_of(Integer) }
|
37
|
-
it { should be_a_kind_of(Integer) }
|
38
|
-
it { should be_an(Integer) }
|
39
|
-
|
40
|
-
# an included module
|
41
|
-
it { should be_kind_of(MyModule) }
|
42
|
-
it { should be_a_kind_of(MyModule) }
|
43
|
-
it { should be_a(MyModule) }
|
44
|
-
|
45
|
-
# negative passing case
|
46
|
-
it { should_not be_kind_of(String) }
|
47
|
-
it { should_not be_a_kind_of(String) }
|
48
|
-
it { should_not be_a(String) }
|
49
|
-
|
50
|
-
# deliberate failures
|
51
|
-
it { should_not be_kind_of(Fixnum) }
|
52
|
-
it { should_not be_a_kind_of(Fixnum) }
|
53
|
-
it { should_not be_a(Fixnum) }
|
54
|
-
it { should_not be_kind_of(Integer) }
|
55
|
-
it { should_not be_a_kind_of(Integer) }
|
56
|
-
it { should_not be_an(Integer) }
|
57
|
-
it { should_not be_kind_of(MyModule) }
|
58
|
-
it { should_not be_a_kind_of(MyModule) }
|
59
|
-
it { should_not be_a(MyModule) }
|
60
|
-
it { should be_kind_of(String) }
|
61
|
-
it { should be_a_kind_of(String) }
|
62
|
-
it { should be_a(String) }
|
63
|
-
end
|
64
|
-
"""
|
65
|
-
When I run `rspec be_kind_of_matcher_spec.rb`
|
66
|
-
Then the output should contain all of these:
|
67
|
-
| 24 examples, 12 failures |
|
68
|
-
| expected 17 not to be a kind of Fixnum |
|
69
|
-
| expected 17 not to be a kind of Integer |
|
70
|
-
| expected 17 not to be a kind of MyModule |
|
71
|
-
| expected 17 to be a kind of String |
|
72
|
-
|
73
|
-
Scenario: be_(an_)instance_of matcher
|
74
|
-
Given a file named "be_instance_of_matcher_spec.rb" with:
|
75
|
-
"""ruby
|
76
|
-
module MyModule; end
|
77
|
-
|
78
|
-
class Fixnum
|
79
|
-
include MyModule
|
80
|
-
end
|
81
|
-
|
82
|
-
describe 17 do
|
83
|
-
# the actual class
|
84
|
-
it { should be_instance_of(Fixnum) }
|
85
|
-
it { should be_an_instance_of(Fixnum) }
|
86
|
-
|
87
|
-
# the superclass
|
88
|
-
it { should_not be_instance_of(Integer) }
|
89
|
-
it { should_not be_an_instance_of(Integer) }
|
90
|
-
|
91
|
-
# an included module
|
92
|
-
it { should_not be_instance_of(MyModule) }
|
93
|
-
it { should_not be_an_instance_of(MyModule) }
|
94
|
-
|
95
|
-
# another class with no relation to the subject's hierarchy
|
96
|
-
it { should_not be_instance_of(String) }
|
97
|
-
it { should_not be_an_instance_of(String) }
|
98
|
-
|
99
|
-
# deliberate failures
|
100
|
-
it { should_not be_instance_of(Fixnum) }
|
101
|
-
it { should_not be_an_instance_of(Fixnum) }
|
102
|
-
it { should be_instance_of(Integer) }
|
103
|
-
it { should be_an_instance_of(Integer) }
|
104
|
-
it { should be_instance_of(MyModule) }
|
105
|
-
it { should be_an_instance_of(MyModule) }
|
106
|
-
it { should be_instance_of(String) }
|
107
|
-
it { should be_an_instance_of(String) }
|
108
|
-
end
|
109
|
-
"""
|
110
|
-
When I run `rspec be_instance_of_matcher_spec.rb`
|
111
|
-
Then the output should contain all of these:
|
112
|
-
| 16 examples, 8 failures |
|
113
|
-
| expected 17 not to be an instance of Fixnum |
|
114
|
-
| expected 17 to be an instance of Integer |
|
115
|
-
| expected 17 to be an instance of MyModule |
|
116
|
-
| expected 17 to be an instance of String |
|
@@ -1,161 +0,0 @@
|
|
1
|
-
Feature: yield matchers
|
2
|
-
|
3
|
-
There are four related matchers that allow you to specify whether
|
4
|
-
or not a method yields, how many times it yields, whether or not
|
5
|
-
it yields with arguments, and what those arguments are.
|
6
|
-
|
7
|
-
* `yield_control` matches if the method-under-test yields, regardless
|
8
|
-
of whether or not arguments are yielded.
|
9
|
-
* `yield_with_args` matches if the method-under-test yields with
|
10
|
-
arguments. If arguments are provided to this matcher, it will
|
11
|
-
only pass if the actual yielded arguments match the expected ones
|
12
|
-
using `===` or `==`.
|
13
|
-
* `yield_with_no_args` matches if the method-under-test yields with
|
14
|
-
no arguments.
|
15
|
-
* `yield_successive_args` is designed for iterators, and will match
|
16
|
-
if the method-under-test yields the same number of times as arguments
|
17
|
-
passed to this matcher, and all actual yielded arguments match the
|
18
|
-
expected ones using `===` or `==`.
|
19
|
-
|
20
|
-
Note: your expect block _must_ accept an argument that is then passed on to
|
21
|
-
the method-under-test as a block. This acts as a "probe" that allows the matcher
|
22
|
-
to detect whether or not your method yields, and, if so, how many times and what
|
23
|
-
the yielded arguments are.
|
24
|
-
|
25
|
-
Background:
|
26
|
-
Given a file named "my_class.rb" with:
|
27
|
-
"""ruby
|
28
|
-
class MyClass
|
29
|
-
def self.yield_once_with(*args)
|
30
|
-
yield *args
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.yield_twice_with(*args)
|
34
|
-
2.times { yield *args }
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.raw_yield
|
38
|
-
yield
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.dont_yield
|
42
|
-
end
|
43
|
-
end
|
44
|
-
"""
|
45
|
-
|
46
|
-
Scenario: yield_control matcher
|
47
|
-
Given a file named "yield_control_spec.rb" with:
|
48
|
-
"""ruby
|
49
|
-
require './my_class'
|
50
|
-
|
51
|
-
describe "yield_control matcher" do
|
52
|
-
specify { expect { |b| MyClass.yield_once_with(1, &b) }.to yield_control }
|
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 }
|
58
|
-
|
59
|
-
# deliberate failures
|
60
|
-
specify { expect { |b| MyClass.yield_once_with(1, &b) }.not_to yield_control }
|
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 }
|
67
|
-
end
|
68
|
-
"""
|
69
|
-
When I run `rspec yield_control_spec.rb`
|
70
|
-
Then the output should contain all of these:
|
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 |
|
76
|
-
|
77
|
-
Scenario: yield_with_args matcher
|
78
|
-
Given a file named "yield_with_args_spec.rb" with:
|
79
|
-
"""ruby
|
80
|
-
require './my_class'
|
81
|
-
|
82
|
-
describe "yield_with_args matcher" do
|
83
|
-
specify { expect { |b| MyClass.yield_once_with("foo", &b) }.to yield_with_args }
|
84
|
-
specify { expect { |b| MyClass.yield_once_with("foo", &b) }.to yield_with_args("foo") }
|
85
|
-
specify { expect { |b| MyClass.yield_once_with("foo", &b) }.to yield_with_args(String) }
|
86
|
-
specify { expect { |b| MyClass.yield_once_with("foo", &b) }.to yield_with_args(/oo/) }
|
87
|
-
|
88
|
-
specify { expect { |b| MyClass.yield_once_with("foo", "bar", &b) }.to yield_with_args("foo", "bar") }
|
89
|
-
specify { expect { |b| MyClass.yield_once_with("foo", "bar", &b) }.to yield_with_args(String, String) }
|
90
|
-
specify { expect { |b| MyClass.yield_once_with("foo", "bar", &b) }.to yield_with_args(/fo/, /ar/) }
|
91
|
-
|
92
|
-
specify { expect { |b| MyClass.yield_once_with("foo", "bar", &b) }.not_to yield_with_args(17, "baz") }
|
93
|
-
|
94
|
-
# deliberate failures
|
95
|
-
specify { expect { |b| MyClass.yield_once_with("foo", &b) }.not_to yield_with_args }
|
96
|
-
specify { expect { |b| MyClass.yield_once_with("foo", &b) }.not_to yield_with_args("foo") }
|
97
|
-
specify { expect { |b| MyClass.yield_once_with("foo", &b) }.not_to yield_with_args(String) }
|
98
|
-
specify { expect { |b| MyClass.yield_once_with("foo", &b) }.not_to yield_with_args(/oo/) }
|
99
|
-
specify { expect { |b| MyClass.yield_once_with("foo", "bar", &b) }.not_to yield_with_args("foo", "bar") }
|
100
|
-
specify { expect { |b| MyClass.yield_once_with("foo", "bar", &b) }.to yield_with_args(17, "baz") }
|
101
|
-
end
|
102
|
-
"""
|
103
|
-
When I run `rspec yield_with_args_spec.rb`
|
104
|
-
Then the output should contain all of these:
|
105
|
-
| 14 examples, 6 failures |
|
106
|
-
| expected given block not to yield with arguments, but did |
|
107
|
-
| expected given block not to yield with arguments, but yielded with expected arguments |
|
108
|
-
| expected given block to yield with arguments, but yielded with unexpected arguments |
|
109
|
-
|
110
|
-
Scenario: yield_with_no_args matcher
|
111
|
-
Given a file named "yield_with_no_args_spec.rb" with:
|
112
|
-
"""ruby
|
113
|
-
require './my_class'
|
114
|
-
|
115
|
-
describe "yield_with_no_args matcher" do
|
116
|
-
specify { expect { |b| MyClass.raw_yield(&b) }.to yield_with_no_args }
|
117
|
-
specify { expect { |b| MyClass.dont_yield(&b) }.not_to yield_with_no_args }
|
118
|
-
specify { expect { |b| MyClass.yield_once_with("a", &b) }.not_to yield_with_no_args }
|
119
|
-
|
120
|
-
# deliberate failures
|
121
|
-
specify { expect { |b| MyClass.raw_yield(&b) }.not_to yield_with_no_args }
|
122
|
-
specify { expect { |b| MyClass.dont_yield(&b) }.to yield_with_no_args }
|
123
|
-
specify { expect { |b| MyClass.yield_once_with("a", &b) }.to yield_with_no_args }
|
124
|
-
end
|
125
|
-
"""
|
126
|
-
When I run `rspec yield_with_no_args_spec.rb`
|
127
|
-
Then the output should contain all of these:
|
128
|
-
| 6 examples, 3 failures |
|
129
|
-
| expected given block not to yield with no arguments, but did |
|
130
|
-
| expected given block to yield with no arguments, but did not yield |
|
131
|
-
| expected given block to yield with no arguments, but yielded with arguments: ["a"] |
|
132
|
-
|
133
|
-
Scenario: yield_successive_args matcher
|
134
|
-
Given a file named "yield_successive_args_spec.rb" with:
|
135
|
-
"""ruby
|
136
|
-
def array
|
137
|
-
[1, 2, 3]
|
138
|
-
end
|
139
|
-
|
140
|
-
def array_of_tuples
|
141
|
-
[[:a, :b], [:c, :d]]
|
142
|
-
end
|
143
|
-
|
144
|
-
describe "yield_successive_args matcher" do
|
145
|
-
specify { expect { |b| array.each(&b) }.to yield_successive_args(1, 2, 3) }
|
146
|
-
specify { expect { |b| array_of_tuples.each(&b) }.to yield_successive_args([:a, :b], [:c, :d]) }
|
147
|
-
specify { expect { |b| array.each(&b) }.to yield_successive_args(Fixnum, Fixnum, Fixnum) }
|
148
|
-
specify { expect { |b| array.each(&b) }.not_to yield_successive_args(1, 2) }
|
149
|
-
|
150
|
-
# deliberate failures
|
151
|
-
specify { expect { |b| array.each(&b) }.not_to yield_successive_args(1, 2, 3) }
|
152
|
-
specify { expect { |b| array_of_tuples.each(&b) }.not_to yield_successive_args([:a, :b], [:c, :d]) }
|
153
|
-
specify { expect { |b| array.each(&b) }.not_to yield_successive_args(Fixnum, Fixnum, Fixnum) }
|
154
|
-
specify { expect { |b| array.each(&b) }.to yield_successive_args(1, 2) }
|
155
|
-
end
|
156
|
-
"""
|
157
|
-
When I run `rspec yield_successive_args_spec.rb`
|
158
|
-
Then the output should contain all of these:
|
159
|
-
| 8 examples, 4 failures |
|
160
|
-
| expected given block not to yield successively with arguments, but yielded with expected arguments |
|
161
|
-
| expected given block to yield successively with arguments, but yielded with unexpected arguments |
|
@@ -1,53 +0,0 @@
|
|
1
|
-
Feature: access running example
|
2
|
-
|
3
|
-
In order to take advantage of services that are available
|
4
|
-
in my examples when I'm writing matchers
|
5
|
-
As a spec author
|
6
|
-
I want to call methods on the running example
|
7
|
-
|
8
|
-
If the method exists in the context of the example, it gets
|
9
|
-
called. If not, a NoMethodError is raised on the Matcher itself
|
10
|
-
(not the example).
|
11
|
-
|
12
|
-
Scenario: call method defined on example from matcher
|
13
|
-
Given a file named "example_spec.rb" with:
|
14
|
-
"""ruby
|
15
|
-
RSpec::Matchers.define :bar do
|
16
|
-
match do |_|
|
17
|
-
foo == "foo"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "something" do
|
22
|
-
def foo
|
23
|
-
"foo"
|
24
|
-
end
|
25
|
-
|
26
|
-
it "does something" do
|
27
|
-
"foo".should bar
|
28
|
-
end
|
29
|
-
end
|
30
|
-
"""
|
31
|
-
When I run `rspec ./example_spec.rb`
|
32
|
-
Then the output should contain "1 example, 0 failures"
|
33
|
-
|
34
|
-
Scenario: call method _not_ defined on example from matcher
|
35
|
-
Given a file named "example_spec.rb" with:
|
36
|
-
"""ruby
|
37
|
-
RSpec::Matchers.define :bar do
|
38
|
-
match do |_|
|
39
|
-
foo == "foo"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "something" do
|
44
|
-
it "does something" do
|
45
|
-
"foo".should bar
|
46
|
-
end
|
47
|
-
end
|
48
|
-
"""
|
49
|
-
When I run `rspec ./example_spec.rb`
|
50
|
-
Then the output should contain "1 example, 1 failure"
|
51
|
-
And the output should match /undefined.*method/
|
52
|
-
And the output should contain "RSpec::Matchers::DSL::Matcher"
|
53
|
-
And the output should not contain "ExampleGroup"
|
@@ -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
|
-
"""ruby
|
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"
|