rspec-expectations 2.11.3 → 3.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/.document +1 -1
- data/.yardopts +1 -1
- data/Changelog.md +1026 -21
- data/{License.txt → LICENSE.md} +5 -3
- data/README.md +174 -78
- 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 +130 -55
- data/lib/rspec/expectations/fail_with.rb +17 -33
- data/lib/rspec/expectations/failure_aggregator.rb +212 -0
- data/lib/rspec/expectations/handler.rb +163 -29
- data/lib/rspec/expectations/minitest_integration.rb +58 -0
- data/lib/rspec/expectations/syntax.rb +68 -54
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/expectations.rb +59 -24
- 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 +150 -20
- data/lib/rspec/matchers/built_in/be.rb +115 -109
- data/lib/rspec/matchers/built_in/be_between.rb +77 -0
- data/lib/rspec/matchers/built_in/be_instance_of.rb +16 -1
- data/lib/rspec/matchers/built_in/be_kind_of.rb +10 -1
- data/lib/rspec/matchers/built_in/be_within.rb +43 -17
- data/lib/rspec/matchers/built_in/change.rb +392 -75
- data/lib/rspec/matchers/built_in/compound.rb +290 -0
- data/lib/rspec/matchers/built_in/contain_exactly.rb +302 -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 +26 -8
- data/lib/rspec/matchers/built_in/eql.rb +19 -8
- data/lib/rspec/matchers/built_in/equal.rb +56 -19
- 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 +175 -20
- 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 +212 -38
- data/lib/rspec/matchers/built_in/respond_to.rb +155 -29
- 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 +252 -98
- data/lib/rspec/matchers/built_in.rb +47 -33
- data/lib/rspec/matchers/composable.rb +171 -0
- data/lib/rspec/matchers/dsl.rb +530 -10
- data/lib/rspec/matchers/english_phrasing.rb +58 -0
- data/lib/rspec/matchers/expecteds_for_multiple_diffs.rb +82 -0
- data/lib/rspec/matchers/fail_matchers.rb +42 -0
- data/lib/rspec/matchers/generated_descriptions.rb +15 -10
- data/lib/rspec/matchers/matcher_delegator.rb +35 -0
- data/lib/rspec/matchers/matcher_protocol.rb +105 -0
- data/lib/rspec/matchers.rb +604 -252
- data.tar.gz.sig +0 -0
- metadata +178 -278
- metadata.gz.sig +0 -0
- data/features/README.md +0 -49
- data/features/Upgrade.md +0 -53
- data/features/built_in_matchers/README.md +0 -90
- data/features/built_in_matchers/be.feature +0 -173
- data/features/built_in_matchers/be_within.feature +0 -46
- data/features/built_in_matchers/cover.feature +0 -45
- data/features/built_in_matchers/end_with.feature +0 -46
- data/features/built_in_matchers/equality.feature +0 -145
- data/features/built_in_matchers/exist.feature +0 -43
- data/features/built_in_matchers/expect_change.feature +0 -59
- data/features/built_in_matchers/expect_error.feature +0 -138
- data/features/built_in_matchers/have.feature +0 -103
- data/features/built_in_matchers/include.feature +0 -121
- data/features/built_in_matchers/match.feature +0 -50
- data/features/built_in_matchers/operators.feature +0 -221
- data/features/built_in_matchers/predicates.feature +0 -128
- data/features/built_in_matchers/respond_to.feature +0 -78
- data/features/built_in_matchers/satisfy.feature +0 -31
- data/features/built_in_matchers/start_with.feature +0 -46
- data/features/built_in_matchers/throw_symbol.feature +0 -85
- data/features/built_in_matchers/types.feature +0 -114
- data/features/built_in_matchers/yield.feature +0 -146
- 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 -340
- 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 -5
- data/features/syntax_configuration.feature +0 -68
- data/features/test_frameworks/test_unit.feature +0 -46
- data/lib/rspec/expectations/deprecation.rb +0 -38
- data/lib/rspec/expectations/differ.rb +0 -81
- 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 -39
- 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 -108
- data/lib/rspec/matchers/built_in/match_array.rb +0 -45
- 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 -66
- data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +0 -39
- data/lib/rspec/matchers/matcher.rb +0 -299
- data/lib/rspec/matchers/method_missing.rb +0 -12
- data/lib/rspec/matchers/operator_matcher.rb +0 -84
- data/lib/rspec/matchers/pretty.rb +0 -60
- data/lib/rspec-expectations.rb +0 -1
- data/spec/rspec/expectations/differ_spec.rb +0 -153
- data/spec/rspec/expectations/expectation_target_spec.rb +0 -65
- data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
- data/spec/rspec/expectations/fail_with_spec.rb +0 -70
- data/spec/rspec/expectations/handler_spec.rb +0 -206
- data/spec/rspec/matchers/base_matcher_spec.rb +0 -60
- data/spec/rspec/matchers/be_close_spec.rb +0 -22
- data/spec/rspec/matchers/be_instance_of_spec.rb +0 -40
- data/spec/rspec/matchers/be_kind_of_spec.rb +0 -37
- data/spec/rspec/matchers/be_spec.rb +0 -452
- data/spec/rspec/matchers/be_within_spec.rb +0 -80
- data/spec/rspec/matchers/change_spec.rb +0 -528
- data/spec/rspec/matchers/configuration_spec.rb +0 -202
- data/spec/rspec/matchers/cover_spec.rb +0 -69
- data/spec/rspec/matchers/description_generation_spec.rb +0 -176
- data/spec/rspec/matchers/dsl_spec.rb +0 -57
- data/spec/rspec/matchers/eq_spec.rb +0 -54
- data/spec/rspec/matchers/eql_spec.rb +0 -41
- data/spec/rspec/matchers/equal_spec.rb +0 -60
- data/spec/rspec/matchers/exist_spec.rb +0 -110
- data/spec/rspec/matchers/has_spec.rb +0 -118
- data/spec/rspec/matchers/have_spec.rb +0 -461
- data/spec/rspec/matchers/include_spec.rb +0 -367
- data/spec/rspec/matchers/match_array_spec.rb +0 -124
- data/spec/rspec/matchers/match_spec.rb +0 -61
- data/spec/rspec/matchers/matcher_spec.rb +0 -434
- data/spec/rspec/matchers/matchers_spec.rb +0 -31
- data/spec/rspec/matchers/method_missing_spec.rb +0 -24
- data/spec/rspec/matchers/operator_matcher_spec.rb +0 -221
- data/spec/rspec/matchers/raise_error_spec.rb +0 -344
- data/spec/rspec/matchers/respond_to_spec.rb +0 -295
- data/spec/rspec/matchers/satisfy_spec.rb +0 -44
- data/spec/rspec/matchers/start_with_end_with_spec.rb +0 -182
- data/spec/rspec/matchers/throw_symbol_spec.rb +0 -116
- data/spec/rspec/matchers/yield_spec.rb +0 -402
- data/spec/spec_helper.rb +0 -27
- data/spec/support/classes.rb +0 -56
- data/spec/support/in_sub_process.rb +0 -31
- data/spec/support/matchers.rb +0 -22
- data/spec/support/ruby_version.rb +0 -10
- data/spec/support/shared_examples.rb +0 -13
@@ -1,138 +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
|
-
expect { raise StandardError }.to raise_error
|
7
|
-
|
8
|
-
You can use `raise_exception` instead if you prefer that wording:
|
9
|
-
|
10
|
-
expect { 3 / 0 }.to raise_exception
|
11
|
-
|
12
|
-
`raise_error` and `raise_exception` are functionally interchangeable, so use
|
13
|
-
the one that makes the most sense to you in any given context.
|
14
|
-
|
15
|
-
In addition to the basic form, above, there are a number of ways to specify
|
16
|
-
details of an error/exception:
|
17
|
-
|
18
|
-
expect { raise "oops" }.to raise_error
|
19
|
-
expect { raise "oops" }.to raise_error(RuntimeError)
|
20
|
-
expect { raise "oops" }.to raise_error("oops")
|
21
|
-
expect { raise "oops" }.to raise_error(/op/)
|
22
|
-
expect { raise "oops" }.to raise_error(RuntimeError, "oops")
|
23
|
-
expect { raise "oops" }.to raise_error(RuntimeError, /op/)
|
24
|
-
|
25
|
-
Scenario: expect any error
|
26
|
-
Given a file named "example_spec" with:
|
27
|
-
"""
|
28
|
-
describe "calling a missing method" do
|
29
|
-
it "raises" do
|
30
|
-
expect { Object.new.foo }.to raise_error
|
31
|
-
end
|
32
|
-
end
|
33
|
-
"""
|
34
|
-
When I run `rspec example_spec`
|
35
|
-
Then the example should pass
|
36
|
-
|
37
|
-
Scenario: expect specific error
|
38
|
-
Given a file named "example_spec" with:
|
39
|
-
"""
|
40
|
-
describe "calling a missing method" do
|
41
|
-
it "raises" do
|
42
|
-
expect { Object.new.foo }.to raise_error(NameError)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
"""
|
46
|
-
When I run `rspec example_spec`
|
47
|
-
Then the example should pass
|
48
|
-
|
49
|
-
Scenario: match message with a string
|
50
|
-
Given a file named "example_spec.rb" with:
|
51
|
-
"""
|
52
|
-
describe "matching error message with string" do
|
53
|
-
it "matches the error message" do
|
54
|
-
expect { raise StandardError, 'this message exactly'}.
|
55
|
-
to raise_error('this message exactly')
|
56
|
-
end
|
57
|
-
end
|
58
|
-
"""
|
59
|
-
When I run `rspec example_spec.rb`
|
60
|
-
Then the example should pass
|
61
|
-
|
62
|
-
Scenario: match message with a regexp
|
63
|
-
Given a file named "example_spec.rb" with:
|
64
|
-
"""
|
65
|
-
describe "matching error message with regex" do
|
66
|
-
it "matches the error message" do
|
67
|
-
expect { raise StandardError, "my message" }.
|
68
|
-
to raise_error(/my mess/)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
"""
|
72
|
-
When I run `rspec example_spec.rb`
|
73
|
-
Then the example should pass
|
74
|
-
|
75
|
-
Scenario: match type + message with string
|
76
|
-
Given a file named "example_spec.rb" with:
|
77
|
-
"""
|
78
|
-
describe "matching error message with string" do
|
79
|
-
it "matches the error message" do
|
80
|
-
expect { raise StandardError, 'this message exactly'}.
|
81
|
-
to raise_error(StandardError, 'this message exactly')
|
82
|
-
end
|
83
|
-
end
|
84
|
-
"""
|
85
|
-
When I run `rspec example_spec.rb`
|
86
|
-
Then the example should pass
|
87
|
-
|
88
|
-
Scenario: match type + message with regexp
|
89
|
-
Given a file named "example_spec.rb" with:
|
90
|
-
"""
|
91
|
-
describe "matching error message with regex" do
|
92
|
-
it "matches the error message" do
|
93
|
-
expect { raise StandardError, "my message" }.
|
94
|
-
to raise_error(StandardError, /my mess/)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
"""
|
98
|
-
When I run `rspec example_spec.rb`
|
99
|
-
Then the example should pass
|
100
|
-
|
101
|
-
Scenario: set expectations on error object passed to block
|
102
|
-
Given a file named "example_spec" with:
|
103
|
-
"""
|
104
|
-
describe "#foo" do
|
105
|
-
it "raises NameError" do
|
106
|
-
expect { Object.new.foo }.to raise_error { |error|
|
107
|
-
error.should be_a(NameError)
|
108
|
-
}
|
109
|
-
end
|
110
|
-
end
|
111
|
-
"""
|
112
|
-
When I run `rspec example_spec`
|
113
|
-
Then the example should pass
|
114
|
-
|
115
|
-
Scenario: expect no occurence of a specific error
|
116
|
-
Given a file named "example_spec" with:
|
117
|
-
"""
|
118
|
-
describe Object, "#public_instance_methods" do
|
119
|
-
it "does not raise" do
|
120
|
-
expect { Object.public_instance_methods }.
|
121
|
-
to_not raise_error(NameError)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
"""
|
125
|
-
When I run `rspec example_spec`
|
126
|
-
Then the example should pass
|
127
|
-
|
128
|
-
Scenario: expect no error at all
|
129
|
-
Given a file named "example_spec" with:
|
130
|
-
"""
|
131
|
-
describe "#to_s" do
|
132
|
-
it "does not raise" do
|
133
|
-
expect { Object.new.to_s }.to_not raise_error
|
134
|
-
end
|
135
|
-
end
|
136
|
-
"""
|
137
|
-
When I run `rspec example_spec`
|
138
|
-
Then the example should pass
|
@@ -1,103 +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
|
-
* collection.should have(x).items
|
7
|
-
* collection.should have\_at\_least(x).items
|
8
|
-
* collection.should have\_at\_most(x).items
|
9
|
-
|
10
|
-
In addition, #have_exactly is provided as an alias to #have.
|
11
|
-
|
12
|
-
These work on any collection-like object--the object just needs to respond to #size
|
13
|
-
or #length (or both). When the matcher is called directly on a collection object,
|
14
|
-
the #items call is pure syntactic sugar. You can use anything you want here. These
|
15
|
-
are equivalent:
|
16
|
-
|
17
|
-
* collection.should have(x).items
|
18
|
-
* collection.should have(x).things
|
19
|
-
|
20
|
-
You can also use this matcher on a non-collection object that returns a collection
|
21
|
-
from one of its methods. For example, Dir#entries returns an array, so you could
|
22
|
-
set an expectation using the following:
|
23
|
-
|
24
|
-
Dir.new("my/directory").should have(7).entries
|
25
|
-
|
26
|
-
Scenario: have(x).items on a collection
|
27
|
-
Given a file named "have_items_spec.rb" with:
|
28
|
-
"""
|
29
|
-
describe [1, 2, 3] do
|
30
|
-
it { should have(3).items }
|
31
|
-
it { should_not have(2).items }
|
32
|
-
it { should_not have(4).items }
|
33
|
-
|
34
|
-
it { should have_exactly(3).items }
|
35
|
-
it { should_not have_exactly(2).items }
|
36
|
-
it { should_not have_exactly(4).items }
|
37
|
-
|
38
|
-
it { should have_at_least(2).items }
|
39
|
-
it { should have_at_most(4).items }
|
40
|
-
|
41
|
-
# deliberate failures
|
42
|
-
it { should_not have(3).items }
|
43
|
-
it { should have(2).items }
|
44
|
-
it { should have(4).items }
|
45
|
-
|
46
|
-
it { should_not have_exactly(3).items }
|
47
|
-
it { should have_exactly(2).items }
|
48
|
-
it { should have_exactly(4).items }
|
49
|
-
|
50
|
-
it { should have_at_least(4).items }
|
51
|
-
it { should have_at_most(2).items }
|
52
|
-
end
|
53
|
-
"""
|
54
|
-
When I run `rspec have_items_spec.rb`
|
55
|
-
Then the output should contain "16 examples, 8 failures"
|
56
|
-
And the output should contain "expected target not to have 3 items, got 3"
|
57
|
-
And the output should contain "expected 2 items, got 3"
|
58
|
-
And the output should contain "expected 4 items, got 3"
|
59
|
-
And the output should contain "expected at least 4 items, got 3"
|
60
|
-
And the output should contain "expected at most 2 items, got 3"
|
61
|
-
|
62
|
-
Scenario: have(x).words on a String when String#words is defined
|
63
|
-
Given a file named "have_words_spec.rb" with:
|
64
|
-
"""
|
65
|
-
class String
|
66
|
-
def words
|
67
|
-
split(' ')
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe "a sentence with some words" do
|
72
|
-
it { should have(5).words }
|
73
|
-
it { should_not have(4).words }
|
74
|
-
it { should_not have(6).words }
|
75
|
-
|
76
|
-
it { should have_exactly(5).words }
|
77
|
-
it { should_not have_exactly(4).words }
|
78
|
-
it { should_not have_exactly(6).words }
|
79
|
-
|
80
|
-
it { should have_at_least(4).words }
|
81
|
-
it { should have_at_most(6).words }
|
82
|
-
|
83
|
-
# deliberate failures
|
84
|
-
it { should_not have(5).words }
|
85
|
-
it { should have(4).words }
|
86
|
-
it { should have(6).words }
|
87
|
-
|
88
|
-
it { should_not have_exactly(5).words }
|
89
|
-
it { should have_exactly(4).words }
|
90
|
-
it { should have_exactly(6).words }
|
91
|
-
|
92
|
-
it { should have_at_least(6).words }
|
93
|
-
it { should have_at_most(4).words }
|
94
|
-
end
|
95
|
-
"""
|
96
|
-
When I run `rspec have_words_spec.rb`
|
97
|
-
Then the output should contain "16 examples, 8 failures"
|
98
|
-
And the output should contain "expected target not to have 5 words, got 5"
|
99
|
-
And the output should contain "expected 4 words, got 5"
|
100
|
-
And the output should contain "expected 6 words, got 5"
|
101
|
-
And the output should contain "expected at least 6 words, got 5"
|
102
|
-
And the output should contain "expected at most 4 words, got 5"
|
103
|
-
|
@@ -1,121 +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
|
-
"a string".should include("a")
|
8
|
-
"a string".should include("str")
|
9
|
-
"a string".should include("str", "g")
|
10
|
-
"a string".should_not include("foo")
|
11
|
-
|
12
|
-
[1, 2].should include(1)
|
13
|
-
[1, 2].should include(1, 2)
|
14
|
-
[1, 2].should_not include(17)
|
15
|
-
|
16
|
-
The matcher also provides flexible handling for hashes:
|
17
|
-
|
18
|
-
{:a => 1, :b => 2}.should include(:a)
|
19
|
-
{:a => 1, :b => 2}.should include(:a, :b)
|
20
|
-
{:a => 1, :b => 2}.should include(:a => 1)
|
21
|
-
{:a => 1, :b => 2}.should include(:b => 2, :a => 1)
|
22
|
-
{:a => 1, :b => 2}.should_not include(:c)
|
23
|
-
{:a => 1, :b => 2}.should_not include(:a => 2)
|
24
|
-
{:a => 1, :b => 2}.should_not include(:c => 3)
|
25
|
-
|
26
|
-
Scenario: array usage
|
27
|
-
Given a file named "array_include_matcher_spec.rb" with:
|
28
|
-
"""
|
29
|
-
describe [1, 3, 7] do
|
30
|
-
it { should include(1) }
|
31
|
-
it { should include(3) }
|
32
|
-
it { should include(7) }
|
33
|
-
it { should include(1, 7) }
|
34
|
-
it { should include(1, 3, 7) }
|
35
|
-
it { should_not include(17) }
|
36
|
-
it { should_not include(43, 100) }
|
37
|
-
|
38
|
-
# deliberate failures
|
39
|
-
it { should include(4) }
|
40
|
-
it { should_not include(1) }
|
41
|
-
it { should_not include(3) }
|
42
|
-
it { should_not include(7) }
|
43
|
-
it { should_not include(1, 3, 7) }
|
44
|
-
|
45
|
-
# both of these should fail since it includes 1 but not 9
|
46
|
-
it { should include(1, 9) }
|
47
|
-
it { should_not include(1, 9) }
|
48
|
-
end
|
49
|
-
"""
|
50
|
-
When I run `rspec array_include_matcher_spec.rb`
|
51
|
-
Then the output should contain all of these:
|
52
|
-
| 14 examples, 7 failures |
|
53
|
-
| expected [1, 3, 7] to include 4 |
|
54
|
-
| expected [1, 3, 7] not to include 1 |
|
55
|
-
| expected [1, 3, 7] not to include 3 |
|
56
|
-
| expected [1, 3, 7] not to include 7 |
|
57
|
-
| expected [1, 3, 7] not to include 1, 3, and 7 |
|
58
|
-
| expected [1, 3, 7] to include 1 and 9 |
|
59
|
-
| expected [1, 3, 7] not to include 1 and 9 |
|
60
|
-
|
61
|
-
Scenario: string usage
|
62
|
-
Given a file named "string_include_matcher_spec.rb" with:
|
63
|
-
"""
|
64
|
-
describe "a string" do
|
65
|
-
it { should include("str") }
|
66
|
-
it { should include("a", "str", "ng") }
|
67
|
-
it { should_not include("foo") }
|
68
|
-
it { should_not include("foo", "bar") }
|
69
|
-
|
70
|
-
# deliberate failures
|
71
|
-
it { should include("foo") }
|
72
|
-
it { should_not include("str") }
|
73
|
-
it { should include("str", "foo") }
|
74
|
-
it { should_not include("str", "foo") }
|
75
|
-
end
|
76
|
-
"""
|
77
|
-
When I run `rspec string_include_matcher_spec.rb`
|
78
|
-
Then the output should contain all of these:
|
79
|
-
| 8 examples, 4 failures |
|
80
|
-
| expected "a string" to include "foo" |
|
81
|
-
| expected "a string" not to include "str" |
|
82
|
-
| expected "a string" to include "str" and "foo" |
|
83
|
-
| expected "a string" not to include "str" and "foo" |
|
84
|
-
|
85
|
-
Scenario: hash usage
|
86
|
-
Given a file named "hash_include_matcher_spec.rb" with:
|
87
|
-
"""
|
88
|
-
describe Hash do
|
89
|
-
subject { { :a => 7, :b => 5 } }
|
90
|
-
|
91
|
-
it { should include(:a) }
|
92
|
-
it { should include(:b, :a) }
|
93
|
-
it { should include(:a => 7) }
|
94
|
-
it { should include(:b => 5, :a => 7) }
|
95
|
-
it { should_not include(:c) }
|
96
|
-
it { should_not include(:c, :d) }
|
97
|
-
it { should_not include(:d => 2) }
|
98
|
-
it { should_not include(:a => 5) }
|
99
|
-
it { should_not include(:b => 7, :a => 5) }
|
100
|
-
|
101
|
-
# deliberate failures
|
102
|
-
it { should_not include(:a) }
|
103
|
-
it { should_not include(:b, :a) }
|
104
|
-
it { should_not include(:a => 7) }
|
105
|
-
it { should_not include(:a => 7, :b => 5) }
|
106
|
-
it { should include(:c) }
|
107
|
-
it { should include(:c, :d) }
|
108
|
-
it { should include(:d => 2) }
|
109
|
-
it { should include(:a => 5) }
|
110
|
-
it { should include(:a => 5, :b => 7) }
|
111
|
-
|
112
|
-
# Mixed cases--the hash includes one but not the other.
|
113
|
-
# All 4 of these cases should fail.
|
114
|
-
it { should include(:a, :d) }
|
115
|
-
it { should_not include(:a, :d) }
|
116
|
-
it { should include(:a => 7, :d => 3) }
|
117
|
-
it { should_not include(:a => 7, :d => 3) }
|
118
|
-
end
|
119
|
-
"""
|
120
|
-
When I run `rspec hash_include_matcher_spec.rb`
|
121
|
-
Then the output should contain "13 failure"
|
@@ -1,50 +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
|
-
"a string".should match(/str/) # passes
|
8
|
-
"a string".should match(/foo/) # fails
|
9
|
-
/foo/.should match("food") # passes
|
10
|
-
/foo/.should match("drinks") # fails
|
11
|
-
|
12
|
-
This is equivalent to using the =~ matcher (see the operator matchers
|
13
|
-
feature for more details).
|
14
|
-
|
15
|
-
Scenario: string usage
|
16
|
-
Given a file named "string_match_spec.rb" with:
|
17
|
-
"""
|
18
|
-
describe "a string" do
|
19
|
-
it { should match(/str/) }
|
20
|
-
it { should_not match(/foo/) }
|
21
|
-
|
22
|
-
# deliberate failures
|
23
|
-
it { should_not match(/str/) }
|
24
|
-
it { should match(/foo/) }
|
25
|
-
end
|
26
|
-
"""
|
27
|
-
When I run `rspec string_match_spec.rb`
|
28
|
-
Then the output should contain all of these:
|
29
|
-
| 4 examples, 2 failures |
|
30
|
-
| expected "a string" not to match /str/ |
|
31
|
-
| expected "a string" to match /foo/ |
|
32
|
-
|
33
|
-
Scenario: regular expression usage
|
34
|
-
Given a file named "regexp_match_spec.rb" with:
|
35
|
-
"""
|
36
|
-
describe /foo/ do
|
37
|
-
it { should match("food") }
|
38
|
-
it { should_not match("drinks") }
|
39
|
-
|
40
|
-
# deliberate failures
|
41
|
-
it { should_not match("food") }
|
42
|
-
it { should match("drinks") }
|
43
|
-
end
|
44
|
-
"""
|
45
|
-
When I run `rspec regexp_match_spec.rb`
|
46
|
-
Then the output should contain all of these:
|
47
|
-
| 4 examples, 2 failures |
|
48
|
-
| expected /foo/ not to match "food" |
|
49
|
-
| expected /foo/ to match "drinks" |
|
50
|
-
|
@@ -1,221 +0,0 @@
|
|
1
|
-
Feature: operator matchers
|
2
|
-
|
3
|
-
RSpec provides a number of matchers that are based on Ruby's built-in
|
4
|
-
operators. These pretty much work like you expect. For example, each of these
|
5
|
-
pass:
|
6
|
-
|
7
|
-
7.should == 7
|
8
|
-
[1, 2, 3].should == [1, 2, 3]
|
9
|
-
"this is a string".should =~ /^this/
|
10
|
-
"this is a string".should_not =~ /^that/
|
11
|
-
String.should === "this is a string"
|
12
|
-
|
13
|
-
You can also use comparison operators combined with the "be" matcher like
|
14
|
-
this:
|
15
|
-
|
16
|
-
37.should be < 100
|
17
|
-
37.should be <= 38
|
18
|
-
37.should be >= 2
|
19
|
-
37.should be > 7
|
20
|
-
|
21
|
-
RSpec also provides a `=~` matcher for arrays that disregards differences in
|
22
|
-
the ording between the actual and expected array. For example:
|
23
|
-
|
24
|
-
[1, 2, 3].should =~ [2, 3, 1] # pass
|
25
|
-
[:a, :c, :b].should =~ [:a, :c] # fail
|
26
|
-
|
27
|
-
Scenario: numeric operator matchers
|
28
|
-
Given a file named "numeric_operator_matchers_spec.rb" with:
|
29
|
-
"""
|
30
|
-
describe 18 do
|
31
|
-
it { should == 18 }
|
32
|
-
it { should be < 20 }
|
33
|
-
it { should be > 15 }
|
34
|
-
it { should be <= 19 }
|
35
|
-
it { should be >= 17 }
|
36
|
-
|
37
|
-
it { should_not == 28 }
|
38
|
-
|
39
|
-
# deliberate failures
|
40
|
-
it { should == 28 }
|
41
|
-
it { should be < 15 }
|
42
|
-
it { should be > 20 }
|
43
|
-
it { should be <= 17 }
|
44
|
-
it { should be >= 19 }
|
45
|
-
|
46
|
-
it { should_not == 18 }
|
47
|
-
end
|
48
|
-
"""
|
49
|
-
When I run `rspec numeric_operator_matchers_spec.rb`
|
50
|
-
Then the output should contain "12 examples, 6 failures"
|
51
|
-
And the output should contain:
|
52
|
-
"""
|
53
|
-
Failure/Error: it { should == 28 }
|
54
|
-
expected: 28
|
55
|
-
got: 18 (using ==)
|
56
|
-
"""
|
57
|
-
And the output should contain:
|
58
|
-
"""
|
59
|
-
Failure/Error: it { should be < 15 }
|
60
|
-
expected: < 15
|
61
|
-
got: 18
|
62
|
-
"""
|
63
|
-
And the output should contain:
|
64
|
-
"""
|
65
|
-
Failure/Error: it { should be > 20 }
|
66
|
-
expected: > 20
|
67
|
-
got: 18
|
68
|
-
"""
|
69
|
-
And the output should contain:
|
70
|
-
"""
|
71
|
-
Failure/Error: it { should be <= 17 }
|
72
|
-
expected: <= 17
|
73
|
-
got: 18
|
74
|
-
"""
|
75
|
-
And the output should contain:
|
76
|
-
"""
|
77
|
-
Failure/Error: it { should be >= 19 }
|
78
|
-
expected: >= 19
|
79
|
-
got: 18
|
80
|
-
"""
|
81
|
-
And the output should contain:
|
82
|
-
"""
|
83
|
-
Failure/Error: it { should_not == 18 }
|
84
|
-
expected not: == 18
|
85
|
-
got: 18
|
86
|
-
"""
|
87
|
-
|
88
|
-
Scenario: string operator matchers
|
89
|
-
Given a file named "string_operator_matchers_spec.rb" with:
|
90
|
-
"""
|
91
|
-
describe "Strawberry" do
|
92
|
-
it { should == "Strawberry" }
|
93
|
-
it { should be < "Tomato" }
|
94
|
-
it { should be > "Apple" }
|
95
|
-
it { should be <= "Turnip" }
|
96
|
-
it { should be >= "Banana" }
|
97
|
-
it { should =~ /berry/ }
|
98
|
-
|
99
|
-
it { should_not == "Peach" }
|
100
|
-
it { should_not =~ /apple/ }
|
101
|
-
|
102
|
-
it "reports that it is a string using ===" do
|
103
|
-
String.should === subject
|
104
|
-
end
|
105
|
-
|
106
|
-
# deliberate failures
|
107
|
-
it { should == "Peach" }
|
108
|
-
it { should be < "Cranberry" }
|
109
|
-
it { should be > "Zuchini" }
|
110
|
-
it { should be <= "Potato" }
|
111
|
-
it { should be >= "Tomato" }
|
112
|
-
it { should =~ /apple/ }
|
113
|
-
|
114
|
-
it { should_not == "Strawberry" }
|
115
|
-
it { should_not =~ /berry/ }
|
116
|
-
|
117
|
-
it "fails a spec asserting that it is a symbol" do
|
118
|
-
Symbol.should === subject
|
119
|
-
end
|
120
|
-
end
|
121
|
-
"""
|
122
|
-
When I run `rspec string_operator_matchers_spec.rb`
|
123
|
-
Then the output should contain "18 examples, 9 failures"
|
124
|
-
And the output should contain:
|
125
|
-
"""
|
126
|
-
Failure/Error: it { should == "Peach" }
|
127
|
-
expected: "Peach"
|
128
|
-
got: "Strawberry" (using ==)
|
129
|
-
"""
|
130
|
-
And the output should contain:
|
131
|
-
"""
|
132
|
-
Failure/Error: it { should be < "Cranberry" }
|
133
|
-
expected: < "Cranberry"
|
134
|
-
got: "Strawberry"
|
135
|
-
"""
|
136
|
-
And the output should contain:
|
137
|
-
"""
|
138
|
-
Failure/Error: it { should be > "Zuchini" }
|
139
|
-
expected: > "Zuchini"
|
140
|
-
got: "Strawberry"
|
141
|
-
"""
|
142
|
-
And the output should contain:
|
143
|
-
"""
|
144
|
-
Failure/Error: it { should be <= "Potato" }
|
145
|
-
expected: <= "Potato"
|
146
|
-
got: "Strawberry"
|
147
|
-
"""
|
148
|
-
And the output should contain:
|
149
|
-
"""
|
150
|
-
Failure/Error: it { should be >= "Tomato" }
|
151
|
-
expected: >= "Tomato"
|
152
|
-
got: "Strawberry"
|
153
|
-
"""
|
154
|
-
And the output should contain:
|
155
|
-
"""
|
156
|
-
Failure/Error: it { should =~ /apple/ }
|
157
|
-
expected: /apple/
|
158
|
-
got: "Strawberry" (using =~)
|
159
|
-
"""
|
160
|
-
And the output should contain:
|
161
|
-
"""
|
162
|
-
Failure/Error: it { should_not == "Strawberry" }
|
163
|
-
expected not: == "Strawberry"
|
164
|
-
got: "Strawberry"
|
165
|
-
"""
|
166
|
-
And the output should contain:
|
167
|
-
"""
|
168
|
-
Failure/Error: it { should_not =~ /berry/ }
|
169
|
-
expected not: =~ /berry/
|
170
|
-
got: "Strawberry"
|
171
|
-
"""
|
172
|
-
And the output should contain:
|
173
|
-
"""
|
174
|
-
Failure/Error: Symbol.should === subject
|
175
|
-
expected: "Strawberry"
|
176
|
-
got: Symbol (using ===)
|
177
|
-
"""
|
178
|
-
|
179
|
-
Scenario: array operator matchers
|
180
|
-
Given a file named "array_operator_matchers_spec.rb" with:
|
181
|
-
"""
|
182
|
-
describe [1, 2, 3] do
|
183
|
-
it { should == [1, 2, 3] }
|
184
|
-
it { should_not == [1, 3, 2] }
|
185
|
-
|
186
|
-
it { should =~ [1, 2, 3] }
|
187
|
-
it { should =~ [1, 3, 2] }
|
188
|
-
it { should =~ [2, 1, 3] }
|
189
|
-
it { should =~ [2, 3, 1] }
|
190
|
-
it { should =~ [3, 1, 2] }
|
191
|
-
it { should =~ [3, 2, 1] }
|
192
|
-
|
193
|
-
# deliberate failures
|
194
|
-
it { should_not == [1, 2, 3] }
|
195
|
-
it { should == [1, 3, 2] }
|
196
|
-
it { should =~ [1, 2, 1] }
|
197
|
-
end
|
198
|
-
"""
|
199
|
-
When I run `rspec array_operator_matchers_spec.rb`
|
200
|
-
Then the output should contain "11 examples, 3 failures"
|
201
|
-
And the output should contain:
|
202
|
-
"""
|
203
|
-
Failure/Error: it { should_not == [1, 2, 3] }
|
204
|
-
expected not: == [1, 2, 3]
|
205
|
-
got: [1, 2, 3]
|
206
|
-
"""
|
207
|
-
And the output should contain:
|
208
|
-
"""
|
209
|
-
Failure/Error: it { should == [1, 3, 2] }
|
210
|
-
expected: [1, 3, 2]
|
211
|
-
got: [1, 2, 3] (using ==)
|
212
|
-
"""
|
213
|
-
And the output should contain:
|
214
|
-
"""
|
215
|
-
Failure/Error: it { should =~ [1, 2, 1] }
|
216
|
-
expected collection contained: [1, 1, 2]
|
217
|
-
actual collection contained: [1, 2, 3]
|
218
|
-
the missing elements were: [1]
|
219
|
-
the extra elements were: [3]
|
220
|
-
"""
|
221
|
-
|