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,144 +0,0 @@
|
|
1
|
-
Feature: raise_error matcher
|
2
|
-
|
3
|
-
Use the `raise_error` matcher to specify that a block of code raises an
|
4
|
-
error. The most basic form passes if any error is thrown:
|
5
|
-
|
6
|
-
```ruby
|
7
|
-
expect { raise StandardError }.to raise_error
|
8
|
-
```
|
9
|
-
|
10
|
-
You can use `raise_exception` instead if you prefer that wording:
|
11
|
-
|
12
|
-
```ruby
|
13
|
-
expect { 3 / 0 }.to raise_exception
|
14
|
-
```
|
15
|
-
|
16
|
-
`raise_error` and `raise_exception` are functionally interchangeable, so use
|
17
|
-
the one that makes the most sense to you in any given context.
|
18
|
-
|
19
|
-
In addition to the basic form, above, there are a number of ways to specify
|
20
|
-
details of an error/exception:
|
21
|
-
|
22
|
-
```ruby
|
23
|
-
expect { raise "oops" }.to raise_error
|
24
|
-
expect { raise "oops" }.to raise_error(RuntimeError)
|
25
|
-
expect { raise "oops" }.to raise_error("oops")
|
26
|
-
expect { raise "oops" }.to raise_error(/op/)
|
27
|
-
expect { raise "oops" }.to raise_error(RuntimeError, "oops")
|
28
|
-
expect { raise "oops" }.to raise_error(RuntimeError, /op/)
|
29
|
-
```
|
30
|
-
|
31
|
-
Scenario: expect any error
|
32
|
-
Given a file named "example_spec" with:
|
33
|
-
"""
|
34
|
-
describe "calling a missing method" do
|
35
|
-
it "raises" do
|
36
|
-
expect { Object.new.foo }.to raise_error
|
37
|
-
end
|
38
|
-
end
|
39
|
-
"""
|
40
|
-
When I run `rspec example_spec`
|
41
|
-
Then the example should pass
|
42
|
-
|
43
|
-
Scenario: expect specific error
|
44
|
-
Given a file named "example_spec" with:
|
45
|
-
"""
|
46
|
-
describe "calling a missing method" do
|
47
|
-
it "raises" do
|
48
|
-
expect { Object.new.foo }.to raise_error(NameError)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
"""
|
52
|
-
When I run `rspec example_spec`
|
53
|
-
Then the example should pass
|
54
|
-
|
55
|
-
Scenario: match message with a string
|
56
|
-
Given a file named "example_spec.rb" with:
|
57
|
-
"""ruby
|
58
|
-
describe "matching error message with string" do
|
59
|
-
it "matches the error message" do
|
60
|
-
expect { raise StandardError, 'this message exactly'}.
|
61
|
-
to raise_error('this message exactly')
|
62
|
-
end
|
63
|
-
end
|
64
|
-
"""
|
65
|
-
When I run `rspec example_spec.rb`
|
66
|
-
Then the example should pass
|
67
|
-
|
68
|
-
Scenario: match message with a regexp
|
69
|
-
Given a file named "example_spec.rb" with:
|
70
|
-
"""ruby
|
71
|
-
describe "matching error message with regex" do
|
72
|
-
it "matches the error message" do
|
73
|
-
expect { raise StandardError, "my message" }.
|
74
|
-
to raise_error(/my mess/)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
"""
|
78
|
-
When I run `rspec example_spec.rb`
|
79
|
-
Then the example should pass
|
80
|
-
|
81
|
-
Scenario: match type + message with string
|
82
|
-
Given a file named "example_spec.rb" with:
|
83
|
-
"""ruby
|
84
|
-
describe "matching error message with string" do
|
85
|
-
it "matches the error message" do
|
86
|
-
expect { raise StandardError, 'this message exactly'}.
|
87
|
-
to raise_error(StandardError, 'this message exactly')
|
88
|
-
end
|
89
|
-
end
|
90
|
-
"""
|
91
|
-
When I run `rspec example_spec.rb`
|
92
|
-
Then the example should pass
|
93
|
-
|
94
|
-
Scenario: match type + message with regexp
|
95
|
-
Given a file named "example_spec.rb" with:
|
96
|
-
"""ruby
|
97
|
-
describe "matching error message with regex" do
|
98
|
-
it "matches the error message" do
|
99
|
-
expect { raise StandardError, "my message" }.
|
100
|
-
to raise_error(StandardError, /my mess/)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
"""
|
104
|
-
When I run `rspec example_spec.rb`
|
105
|
-
Then the example should pass
|
106
|
-
|
107
|
-
Scenario: set expectations on error object passed to block
|
108
|
-
Given a file named "example_spec" with:
|
109
|
-
"""
|
110
|
-
describe "#foo" do
|
111
|
-
it "raises NameError" do
|
112
|
-
expect { Object.new.foo }.to raise_error { |error|
|
113
|
-
error.should be_a(NameError)
|
114
|
-
}
|
115
|
-
end
|
116
|
-
end
|
117
|
-
"""
|
118
|
-
When I run `rspec example_spec`
|
119
|
-
Then the example should pass
|
120
|
-
|
121
|
-
Scenario: expect no occurence of a specific error
|
122
|
-
Given a file named "example_spec" with:
|
123
|
-
"""
|
124
|
-
describe Object, "#public_instance_methods" do
|
125
|
-
it "does not raise" do
|
126
|
-
expect { Object.public_instance_methods }.
|
127
|
-
not_to raise_error(NameError)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
"""
|
131
|
-
When I run `rspec example_spec`
|
132
|
-
Then the example should pass
|
133
|
-
|
134
|
-
Scenario: expect no error at all
|
135
|
-
Given a file named "example_spec" with:
|
136
|
-
"""
|
137
|
-
describe "#to_s" do
|
138
|
-
it "does not raise" do
|
139
|
-
expect { Object.new.to_s }.not_to raise_error
|
140
|
-
end
|
141
|
-
end
|
142
|
-
"""
|
143
|
-
When I run `rspec example_spec`
|
144
|
-
Then the example should pass
|
@@ -1,109 +0,0 @@
|
|
1
|
-
Feature: have(n).items matcher
|
2
|
-
|
3
|
-
RSpec provides several matchers that make it easy to set expectations about the
|
4
|
-
size of a collection. There are three basic forms:
|
5
|
-
|
6
|
-
```ruby
|
7
|
-
collection.should have(x).items
|
8
|
-
collection.should have_at_least(x).items
|
9
|
-
collection.should have_at_most(x).items
|
10
|
-
```
|
11
|
-
|
12
|
-
In addition, #have_exactly is provided as an alias to #have.
|
13
|
-
|
14
|
-
These work on any collection-like object--the object just needs to respond to #size
|
15
|
-
or #length (or both). When the matcher is called directly on a collection object,
|
16
|
-
the #items call is pure syntactic sugar. You can use anything you want here. These
|
17
|
-
are equivalent:
|
18
|
-
|
19
|
-
```ruby
|
20
|
-
collection.should have(x).items
|
21
|
-
collection.should have(x).things
|
22
|
-
```
|
23
|
-
|
24
|
-
You can also use this matcher on a non-collection object that returns a collection
|
25
|
-
from one of its methods. For example, Dir#entries returns an array, so you could
|
26
|
-
set an expectation using the following:
|
27
|
-
|
28
|
-
```ruby
|
29
|
-
Dir.new("my/directory").should have(7).entries
|
30
|
-
```
|
31
|
-
|
32
|
-
Scenario: have(x).items on a collection
|
33
|
-
Given a file named "have_items_spec.rb" with:
|
34
|
-
"""ruby
|
35
|
-
describe [1, 2, 3] do
|
36
|
-
it { should have(3).items }
|
37
|
-
it { should_not have(2).items }
|
38
|
-
it { should_not have(4).items }
|
39
|
-
|
40
|
-
it { should have_exactly(3).items }
|
41
|
-
it { should_not have_exactly(2).items }
|
42
|
-
it { should_not have_exactly(4).items }
|
43
|
-
|
44
|
-
it { should have_at_least(2).items }
|
45
|
-
it { should have_at_most(4).items }
|
46
|
-
|
47
|
-
# deliberate failures
|
48
|
-
it { should_not have(3).items }
|
49
|
-
it { should have(2).items }
|
50
|
-
it { should have(4).items }
|
51
|
-
|
52
|
-
it { should_not have_exactly(3).items }
|
53
|
-
it { should have_exactly(2).items }
|
54
|
-
it { should have_exactly(4).items }
|
55
|
-
|
56
|
-
it { should have_at_least(4).items }
|
57
|
-
it { should have_at_most(2).items }
|
58
|
-
end
|
59
|
-
"""
|
60
|
-
When I run `rspec have_items_spec.rb`
|
61
|
-
Then the output should contain "16 examples, 8 failures"
|
62
|
-
And the output should contain "expected target not to have 3 items, got 3"
|
63
|
-
And the output should contain "expected 2 items, got 3"
|
64
|
-
And the output should contain "expected 4 items, got 3"
|
65
|
-
And the output should contain "expected at least 4 items, got 3"
|
66
|
-
And the output should contain "expected at most 2 items, got 3"
|
67
|
-
|
68
|
-
Scenario: have(x).words on a String when String#words is defined
|
69
|
-
Given a file named "have_words_spec.rb" with:
|
70
|
-
"""ruby
|
71
|
-
class String
|
72
|
-
def words
|
73
|
-
split(' ')
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe "a sentence with some words" do
|
78
|
-
it { should have(5).words }
|
79
|
-
it { should_not have(4).words }
|
80
|
-
it { should_not have(6).words }
|
81
|
-
|
82
|
-
it { should have_exactly(5).words }
|
83
|
-
it { should_not have_exactly(4).words }
|
84
|
-
it { should_not have_exactly(6).words }
|
85
|
-
|
86
|
-
it { should have_at_least(4).words }
|
87
|
-
it { should have_at_most(6).words }
|
88
|
-
|
89
|
-
# deliberate failures
|
90
|
-
it { should_not have(5).words }
|
91
|
-
it { should have(4).words }
|
92
|
-
it { should have(6).words }
|
93
|
-
|
94
|
-
it { should_not have_exactly(5).words }
|
95
|
-
it { should have_exactly(4).words }
|
96
|
-
it { should have_exactly(6).words }
|
97
|
-
|
98
|
-
it { should have_at_least(6).words }
|
99
|
-
it { should have_at_most(4).words }
|
100
|
-
end
|
101
|
-
"""
|
102
|
-
When I run `rspec have_words_spec.rb`
|
103
|
-
Then the output should contain "16 examples, 8 failures"
|
104
|
-
And the output should contain "expected target not to have 5 words, got 5"
|
105
|
-
And the output should contain "expected 4 words, got 5"
|
106
|
-
And the output should contain "expected 6 words, got 5"
|
107
|
-
And the output should contain "expected at least 6 words, got 5"
|
108
|
-
And the output should contain "expected at most 4 words, got 5"
|
109
|
-
|
@@ -1,174 +0,0 @@
|
|
1
|
-
Feature: include matcher
|
2
|
-
|
3
|
-
Use the include matcher to specify that a collection includes one or more
|
4
|
-
expected objects. This works on any object that responds to #include? (such
|
5
|
-
as a string or array):
|
6
|
-
|
7
|
-
```ruby
|
8
|
-
"a string".should include("a")
|
9
|
-
"a string".should include("str")
|
10
|
-
"a string".should include("str", "g")
|
11
|
-
"a string".should_not include("foo")
|
12
|
-
|
13
|
-
[1, 2].should include(1)
|
14
|
-
[1, 2].should include(1, 2)
|
15
|
-
[1, 2].should_not include(17)
|
16
|
-
```
|
17
|
-
|
18
|
-
The matcher also provides flexible handling for hashes:
|
19
|
-
|
20
|
-
```ruby
|
21
|
-
{:a => 1, :b => 2}.should include(:a)
|
22
|
-
{:a => 1, :b => 2}.should include(:a, :b)
|
23
|
-
{:a => 1, :b => 2}.should include(:a => 1)
|
24
|
-
{:a => 1, :b => 2}.should include(:b => 2, :a => 1)
|
25
|
-
{:a => 1, :b => 2}.should_not include(:c)
|
26
|
-
{:a => 1, :b => 2}.should_not include(:a => 2)
|
27
|
-
{:a => 1, :b => 2}.should_not include(:c => 3)
|
28
|
-
```
|
29
|
-
|
30
|
-
Scenario: array usage
|
31
|
-
Given a file named "array_include_matcher_spec.rb" with:
|
32
|
-
"""ruby
|
33
|
-
describe [1, 3, 7] do
|
34
|
-
it { should include(1) }
|
35
|
-
it { should include(3) }
|
36
|
-
it { should include(7) }
|
37
|
-
it { should include(1, 7) }
|
38
|
-
it { should include(1, 3, 7) }
|
39
|
-
it { should_not include(17) }
|
40
|
-
it { should_not include(43, 100) }
|
41
|
-
|
42
|
-
# deliberate failures
|
43
|
-
it { should include(4) }
|
44
|
-
it { should_not include(1) }
|
45
|
-
it { should_not include(3) }
|
46
|
-
it { should_not include(7) }
|
47
|
-
it { should_not include(1, 3, 7) }
|
48
|
-
|
49
|
-
# both of these should fail since it includes 1 but not 9
|
50
|
-
it { should include(1, 9) }
|
51
|
-
it { should_not include(1, 9) }
|
52
|
-
end
|
53
|
-
"""
|
54
|
-
When I run `rspec array_include_matcher_spec.rb`
|
55
|
-
Then the output should contain all of these:
|
56
|
-
| 14 examples, 7 failures |
|
57
|
-
| expected [1, 3, 7] to include 4 |
|
58
|
-
| expected [1, 3, 7] not to include 1 |
|
59
|
-
| expected [1, 3, 7] not to include 3 |
|
60
|
-
| expected [1, 3, 7] not to include 7 |
|
61
|
-
| expected [1, 3, 7] not to include 1, 3, and 7 |
|
62
|
-
| expected [1, 3, 7] to include 1 and 9 |
|
63
|
-
| expected [1, 3, 7] not to include 1 and 9 |
|
64
|
-
|
65
|
-
Scenario: string usage
|
66
|
-
Given a file named "string_include_matcher_spec.rb" with:
|
67
|
-
"""ruby
|
68
|
-
describe "a string" do
|
69
|
-
it { should include("str") }
|
70
|
-
it { should include("a", "str", "ng") }
|
71
|
-
it { should_not include("foo") }
|
72
|
-
it { should_not include("foo", "bar") }
|
73
|
-
|
74
|
-
# deliberate failures
|
75
|
-
it { should include("foo") }
|
76
|
-
it { should_not include("str") }
|
77
|
-
it { should include("str", "foo") }
|
78
|
-
it { should_not include("str", "foo") }
|
79
|
-
end
|
80
|
-
"""
|
81
|
-
When I run `rspec string_include_matcher_spec.rb`
|
82
|
-
Then the output should contain all of these:
|
83
|
-
| 8 examples, 4 failures |
|
84
|
-
| expected "a string" to include "foo" |
|
85
|
-
| expected "a string" not to include "str" |
|
86
|
-
| expected "a string" to include "str" and "foo" |
|
87
|
-
| expected "a string" not to include "str" and "foo" |
|
88
|
-
|
89
|
-
Scenario: hash usage
|
90
|
-
Given a file named "hash_include_matcher_spec.rb" with:
|
91
|
-
"""ruby
|
92
|
-
describe Hash do
|
93
|
-
subject { { :a => 7, :b => 5 } }
|
94
|
-
|
95
|
-
it { should include(:a) }
|
96
|
-
it { should include(:b, :a) }
|
97
|
-
it { should include(:a => 7) }
|
98
|
-
it { should include(:b => 5, :a => 7) }
|
99
|
-
it { should_not include(:c) }
|
100
|
-
it { should_not include(:c, :d) }
|
101
|
-
it { should_not include(:d => 2) }
|
102
|
-
it { should_not include(:a => 5) }
|
103
|
-
it { should_not include(:b => 7, :a => 5) }
|
104
|
-
|
105
|
-
# deliberate failures
|
106
|
-
it { should_not include(:a) }
|
107
|
-
it { should_not include(:b, :a) }
|
108
|
-
it { should_not include(:a => 7) }
|
109
|
-
it { should_not include(:a => 7, :b => 5) }
|
110
|
-
it { should include(:c) }
|
111
|
-
it { should include(:c, :d) }
|
112
|
-
it { should include(:d => 2) }
|
113
|
-
it { should include(:a => 5) }
|
114
|
-
it { should include(:a => 5, :b => 7) }
|
115
|
-
|
116
|
-
# Mixed cases--the hash includes one but not the other.
|
117
|
-
# All 4 of these cases should fail.
|
118
|
-
it { should include(:a, :d) }
|
119
|
-
it { should_not include(:a, :d) }
|
120
|
-
it { should include(:a => 7, :d => 3) }
|
121
|
-
it { should_not include(:a => 7, :d => 3) }
|
122
|
-
end
|
123
|
-
"""
|
124
|
-
When I run `rspec hash_include_matcher_spec.rb`
|
125
|
-
Then the output should contain "13 failure"
|
126
|
-
|
127
|
-
Scenario: fuzzy usage with matchers
|
128
|
-
Given a file named "fuzzy_include_matcher_spec.rb" with:
|
129
|
-
"""
|
130
|
-
require 'ostruct'
|
131
|
-
|
132
|
-
class User < OpenStruct
|
133
|
-
def inspect
|
134
|
-
name
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
RSpec::Matchers.define :a_user_named do |expected|
|
139
|
-
match do |actual|
|
140
|
-
actual.is_a?(User) && (actual.name == expected)
|
141
|
-
end
|
142
|
-
description do
|
143
|
-
"a user named '#{expected}'"
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
describe "Collection of users" do
|
148
|
-
subject do
|
149
|
-
[User.new(:name => "Joe"),
|
150
|
-
User.new(:name => "Fred"),
|
151
|
-
User.new(:name => "John"),
|
152
|
-
User.new(:name => "Luke"),
|
153
|
-
User.new(:name => "David")]
|
154
|
-
end
|
155
|
-
|
156
|
-
it { should include( a_user_named "Joe" ) }
|
157
|
-
it { should include( a_user_named "Luke" ) }
|
158
|
-
it { should_not include( a_user_named "Richard" ) }
|
159
|
-
it { should_not include( a_user_named "Hayley" ) }
|
160
|
-
|
161
|
-
# deliberate failures
|
162
|
-
it { should include( a_user_named "Richard" ) }
|
163
|
-
it { should_not include( a_user_named "Fred" ) }
|
164
|
-
it { should include( a_user_named "Sarah" ) }
|
165
|
-
it { should_not include( a_user_named "Luke" ) }
|
166
|
-
end
|
167
|
-
"""
|
168
|
-
When I run `rspec fuzzy_include_matcher_spec.rb`
|
169
|
-
Then the output should contain all of these:
|
170
|
-
| 8 examples, 4 failures |
|
171
|
-
| expected [Joe, Fred, John, Luke, David] to include a user named 'Richard' |
|
172
|
-
| expected [Joe, Fred, John, Luke, David] not to include a user named 'Fred' |
|
173
|
-
| expected [Joe, Fred, John, Luke, David] to include a user named 'Sarah' |
|
174
|
-
| expected [Joe, Fred, John, Luke, David] not to include a user named 'Luke' |
|
@@ -1,52 +0,0 @@
|
|
1
|
-
Feature: match matcher
|
2
|
-
|
3
|
-
The match matcher calls #match on the object, passing if #match returns a
|
4
|
-
truthy (not false or nil) value. Regexp and String both provide a #match
|
5
|
-
method.
|
6
|
-
|
7
|
-
```ruby
|
8
|
-
"a string".should match(/str/) # passes
|
9
|
-
"a string".should match(/foo/) # fails
|
10
|
-
/foo/.should match("food") # passes
|
11
|
-
/foo/.should match("drinks") # fails
|
12
|
-
```
|
13
|
-
|
14
|
-
This is equivalent to using the =~ matcher (see the operator matchers
|
15
|
-
feature for more details).
|
16
|
-
|
17
|
-
Scenario: string usage
|
18
|
-
Given a file named "string_match_spec.rb" with:
|
19
|
-
"""ruby
|
20
|
-
describe "a string" do
|
21
|
-
it { should match(/str/) }
|
22
|
-
it { should_not match(/foo/) }
|
23
|
-
|
24
|
-
# deliberate failures
|
25
|
-
it { should_not match(/str/) }
|
26
|
-
it { should match(/foo/) }
|
27
|
-
end
|
28
|
-
"""
|
29
|
-
When I run `rspec string_match_spec.rb`
|
30
|
-
Then the output should contain all of these:
|
31
|
-
| 4 examples, 2 failures |
|
32
|
-
| expected "a string" not to match /str/ |
|
33
|
-
| expected "a string" to match /foo/ |
|
34
|
-
|
35
|
-
Scenario: regular expression usage
|
36
|
-
Given a file named "regexp_match_spec.rb" with:
|
37
|
-
"""ruby
|
38
|
-
describe /foo/ do
|
39
|
-
it { should match("food") }
|
40
|
-
it { should_not match("drinks") }
|
41
|
-
|
42
|
-
# deliberate failures
|
43
|
-
it { should_not match("food") }
|
44
|
-
it { should match("drinks") }
|
45
|
-
end
|
46
|
-
"""
|
47
|
-
When I run `rspec regexp_match_spec.rb`
|
48
|
-
Then the output should contain all of these:
|
49
|
-
| 4 examples, 2 failures |
|
50
|
-
| expected /foo/ not to match "food" |
|
51
|
-
| expected /foo/ to match "drinks" |
|
52
|
-
|