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,30 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module RSpec
|
4
|
-
module Matchers
|
5
|
-
describe "include() interaction with built-in matchers" do
|
6
|
-
it "works with be_within(delta).of(expected)" do
|
7
|
-
expect([10, 20, 30]).to include( be_within(5).of(24) )
|
8
|
-
expect([10, 20, 30]).not_to include( be_within(3).of(24) )
|
9
|
-
end
|
10
|
-
|
11
|
-
it "works with be_instance_of(klass)" do
|
12
|
-
expect(["foo", 123, {:foo => "bar"}]).to include( be_instance_of(Hash) )
|
13
|
-
expect(["foo", 123, {:foo => "bar"}]).not_to include( be_instance_of(Range) )
|
14
|
-
end
|
15
|
-
|
16
|
-
it "works with be_kind_of(klass)" do
|
17
|
-
class StringSubclass < String; end
|
18
|
-
class NotHashSubclass; end
|
19
|
-
|
20
|
-
expect([StringSubclass.new("baz")]).to include( be_kind_of(String) )
|
21
|
-
expect([NotHashSubclass.new]).not_to include( be_kind_of(Hash) )
|
22
|
-
end
|
23
|
-
|
24
|
-
it "works with be_[some predicate]" do
|
25
|
-
expect([double("actual", :happy? => true)]).to include( be_happy )
|
26
|
-
expect([double("actual", :happy? => false)]).not_to include( be_happy )
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,531 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'uri'
|
3
|
-
|
4
|
-
describe "#include matcher" do
|
5
|
-
it "is diffable" do
|
6
|
-
expect(include("a")).to be_diffable
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "expect(...).to include(with_one_arg)" do
|
10
|
-
it_behaves_like "an RSpec matcher", :valid_value => [1, 2], :invalid_value => [1] do
|
11
|
-
let(:matcher) { include(2) }
|
12
|
-
end
|
13
|
-
|
14
|
-
context "for a string target" do
|
15
|
-
it "passes if target includes expected" do
|
16
|
-
expect("abc").to include("a")
|
17
|
-
end
|
18
|
-
|
19
|
-
it "fails if target does not include expected" do
|
20
|
-
expect {
|
21
|
-
expect("abc").to include("d")
|
22
|
-
}.to fail_matching("expected \"abc\" to include \"d\"")
|
23
|
-
end
|
24
|
-
|
25
|
-
it "includes a diff when actual is multiline" do
|
26
|
-
expect {
|
27
|
-
expect("abc\ndef").to include("g")
|
28
|
-
}.to fail_matching("expected \"abc\\ndef\" to include \"g\"\nDiff")
|
29
|
-
end
|
30
|
-
|
31
|
-
it "includes a diff when actual is multiline and there are multiple expecteds" do
|
32
|
-
expect {
|
33
|
-
expect("abc\ndef").to include("g", "h")
|
34
|
-
}.to fail_matching("expected \"abc\\ndef\" to include \"g\" and \"h\"\nDiff")
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context "for an array target" do
|
39
|
-
it "passes if target includes expected" do
|
40
|
-
expect([1,2,3]).to include(3)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "fails if target does not include expected" do
|
44
|
-
expect {
|
45
|
-
expect([1,2,3]).to include(4)
|
46
|
-
}.to fail_matching("expected [1, 2, 3] to include 4")
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'fails when given differing null doubles' do
|
50
|
-
dbl_1 = double.as_null_object
|
51
|
-
dbl_2 = double.as_null_object
|
52
|
-
|
53
|
-
expect {
|
54
|
-
expect([dbl_1]).to include(dbl_2)
|
55
|
-
}.to fail_matching("expected [#{dbl_1.inspect}] to include")
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'passes when given the same null double' do
|
59
|
-
dbl = double.as_null_object
|
60
|
-
expect([dbl]).to include(dbl)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context "for a hash target" do
|
65
|
-
it 'passes if target has the expected as a key' do
|
66
|
-
expect({:key => 'value'}).to include(:key)
|
67
|
-
end
|
68
|
-
|
69
|
-
it "fails if target does not include expected" do
|
70
|
-
expect {
|
71
|
-
expect({:key => 'value'}).to include(:other)
|
72
|
-
}.to fail_matching(%Q|expected {:key=>"value"} to include :other|)
|
73
|
-
end
|
74
|
-
|
75
|
-
it "fails if target doesn't have a key and we expect nil" do
|
76
|
-
expect {
|
77
|
-
expect({}).to include(:something => nil)
|
78
|
-
}.to fail_matching(%Q|expected {} to include {:something=>nil}|)
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'works even when an entry in the hash overrides #send' do
|
82
|
-
hash = { :key => 'value' }
|
83
|
-
def hash.send; :sent; end
|
84
|
-
expect(hash).to include(hash)
|
85
|
-
end
|
86
|
-
|
87
|
-
context 'that overrides #send' do
|
88
|
-
it 'still works' do
|
89
|
-
array = [1, 2]
|
90
|
-
def array.send; :sent; end
|
91
|
-
|
92
|
-
expect(array).to include(*array)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe "expect(...).to include(with, multiple, args)" do
|
99
|
-
it "has a description" do
|
100
|
-
matcher = include("a")
|
101
|
-
expect(matcher.description).to eq("include \"a\"")
|
102
|
-
end
|
103
|
-
context "for a string target" do
|
104
|
-
it "passes if target includes all items" do
|
105
|
-
expect("a string").to include("str", "a")
|
106
|
-
end
|
107
|
-
|
108
|
-
it "fails if target does not include any one of the items" do
|
109
|
-
expect {
|
110
|
-
expect("a string").to include("str", "a", "foo")
|
111
|
-
}.to fail_matching(%Q{expected "a string" to include "str", "a", and "foo"})
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
context "for an array target" do
|
116
|
-
it "passes if target includes all items" do
|
117
|
-
expect([1,2,3]).to include(1,2,3)
|
118
|
-
end
|
119
|
-
|
120
|
-
it "fails if target does not include any one of the items" do
|
121
|
-
expect {
|
122
|
-
expect([1,2,3]).to include(1,2,4)
|
123
|
-
}.to fail_matching("expected [1, 2, 3] to include 1, 2, and 4")
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
context "for a hash target" do
|
128
|
-
it 'passes if target includes all items as keys' do
|
129
|
-
expect({:key => 'value', :other => 'value'}).to include(:key, :other)
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'fails if target is missing any item as a key' do
|
133
|
-
expect {
|
134
|
-
expect({:key => 'value'}).to include(:key, :other)
|
135
|
-
}.to fail_matching(%Q|expected {:key=>"value"} to include :key and :other|)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
describe "expect(...).not_to include(expected)" do
|
141
|
-
context "for a string target" do
|
142
|
-
it "passes if target does not include expected" do
|
143
|
-
expect("abc").not_to include("d")
|
144
|
-
end
|
145
|
-
|
146
|
-
it "fails if target includes expected" do
|
147
|
-
expect {
|
148
|
-
expect("abc").not_to include("c")
|
149
|
-
}.to fail_with("expected \"abc\" not to include \"c\"")
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
context "for an array target" do
|
154
|
-
it "passes if target does not include expected" do
|
155
|
-
expect([1,2,3]).not_to include(4)
|
156
|
-
end
|
157
|
-
|
158
|
-
it "fails if target includes expected" do
|
159
|
-
expect {
|
160
|
-
expect([1,2,3]).not_to include(3)
|
161
|
-
}.to fail_with("expected [1, 2, 3] not to include 3")
|
162
|
-
end
|
163
|
-
|
164
|
-
it 'passes when given differing null doubles' do
|
165
|
-
expect([double.as_null_object]).not_to include(double.as_null_object)
|
166
|
-
end
|
167
|
-
|
168
|
-
it 'fails when given the same null double' do
|
169
|
-
dbl = double.as_null_object
|
170
|
-
|
171
|
-
expect {
|
172
|
-
expect([dbl]).not_to include(dbl)
|
173
|
-
}.to fail_matching("expected [#{dbl.inspect}] not to include")
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
context "for a hash target" do
|
178
|
-
it 'passes if target does not have the expected as a key' do
|
179
|
-
expect({:other => 'value'}).not_to include(:key)
|
180
|
-
end
|
181
|
-
|
182
|
-
it "fails if target includes expected key" do
|
183
|
-
expect {
|
184
|
-
expect({:key => 'value'}).not_to include(:key)
|
185
|
-
}.to fail_matching(%Q|expected {:key=>"value"} not to include :key|)
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
end
|
190
|
-
|
191
|
-
describe "expect(...).not_to include(with, multiple, args)" do
|
192
|
-
context "for a string target" do
|
193
|
-
it "passes if the target does not include any of the expected" do
|
194
|
-
expect("abc").not_to include("d", "e", "f")
|
195
|
-
end
|
196
|
-
|
197
|
-
it "fails if the target includes all of the expected" do
|
198
|
-
expect {
|
199
|
-
expect("abc").not_to include("c", "a")
|
200
|
-
}.to fail_with('expected "abc" not to include "c" and "a"')
|
201
|
-
end
|
202
|
-
|
203
|
-
it "fails if the target includes some (but not all) of the expected" do
|
204
|
-
expect {
|
205
|
-
expect("abc").not_to include("d", "a")
|
206
|
-
}.to fail_with(%q{expected "abc" not to include "d" and "a"})
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
context "for a hash target" do
|
211
|
-
it "passes if it does not include any of the expected keys" do
|
212
|
-
expect({ :a => 1, :b => 2 }).not_to include(:c, :d)
|
213
|
-
end
|
214
|
-
|
215
|
-
it "fails if the target includes all of the expected keys" do
|
216
|
-
expect {
|
217
|
-
expect({ :a => 1, :b => 2 }).not_to include(:a, :b)
|
218
|
-
}.to fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} not to include :a and :b|)
|
219
|
-
end
|
220
|
-
|
221
|
-
it "fails if the target includes some (but not all) of the expected keys" do
|
222
|
-
expect {
|
223
|
-
expect({ :a => 1, :b => 2 }).not_to include(:d, :b)
|
224
|
-
}.to fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} not to include :d and :b|)
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
context "for an array target" do
|
229
|
-
it "passes if the target does not include any of the expected" do
|
230
|
-
expect([1, 2, 3]).not_to include(4, 5, 6)
|
231
|
-
end
|
232
|
-
|
233
|
-
it "fails if the target includes all of the expected" do
|
234
|
-
expect {
|
235
|
-
expect([1, 2, 3]).not_to include(3, 1)
|
236
|
-
}.to fail_with(%q{expected [1, 2, 3] not to include 3 and 1})
|
237
|
-
end
|
238
|
-
|
239
|
-
it "fails if the target includes some (but not all) of the expected" do
|
240
|
-
expect {
|
241
|
-
expect([1, 2, 3]).not_to include(4, 1)
|
242
|
-
}.to fail_with(%q{expected [1, 2, 3] not to include 4 and 1})
|
243
|
-
end
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
describe "expect(...).to include(:key => value)" do
|
248
|
-
context 'for a hash target' do
|
249
|
-
it "passes if target includes the key/value pair" do
|
250
|
-
expect({:key => 'value'}).to include(:key => 'value')
|
251
|
-
end
|
252
|
-
|
253
|
-
it "passes if target includes the key/value pair among others" do
|
254
|
-
expect({:key => 'value', :other => 'different'}).to include(:key => 'value')
|
255
|
-
end
|
256
|
-
|
257
|
-
it "fails if target has a different value for key" do
|
258
|
-
expect {
|
259
|
-
expect({:key => 'different'}).to include(:key => 'value')
|
260
|
-
}.to fail_matching(%Q|expected {:key=>"different"} to include {:key=>"value"}|)
|
261
|
-
end
|
262
|
-
|
263
|
-
it "fails if target has a different key" do
|
264
|
-
expect {
|
265
|
-
expect({:other => 'value'}).to include(:key => 'value')
|
266
|
-
}.to fail_matching(%Q|expected {:other=>"value"} to include {:key=>"value"}|)
|
267
|
-
end
|
268
|
-
end
|
269
|
-
|
270
|
-
context 'for a non-hash target' do
|
271
|
-
it "fails if the target does not contain the given hash" do
|
272
|
-
expect {
|
273
|
-
expect(['a', 'b']).to include(:key => 'value')
|
274
|
-
}.to fail_matching(%q|expected ["a", "b"] to include {:key=>"value"}|)
|
275
|
-
end
|
276
|
-
|
277
|
-
it "passes if the target contains the given hash" do
|
278
|
-
expect(['a', { :key => 'value' } ]).to include(:key => 'value')
|
279
|
-
end
|
280
|
-
end
|
281
|
-
end
|
282
|
-
|
283
|
-
describe "expect(...).not_to include(:key => value)" do
|
284
|
-
context 'for a hash target' do
|
285
|
-
it "fails if target includes the key/value pair" do
|
286
|
-
expect {
|
287
|
-
expect({:key => 'value'}).not_to include(:key => 'value')
|
288
|
-
}.to fail_matching(%Q|expected {:key=>"value"} not to include {:key=>"value"}|)
|
289
|
-
end
|
290
|
-
|
291
|
-
it "fails if target includes the key/value pair among others" do
|
292
|
-
expect {
|
293
|
-
expect({:key => 'value', :other => 'different'}).not_to include(:key => 'value')
|
294
|
-
}.to fail_matching(%Q|expected #{{:key=>"value", :other=>"different"}.inspect} not to include {:key=>"value"}|)
|
295
|
-
end
|
296
|
-
|
297
|
-
it "passes if target has a different value for key" do
|
298
|
-
expect({:key => 'different'}).not_to include(:key => 'value')
|
299
|
-
end
|
300
|
-
|
301
|
-
it "passes if target has a different key" do
|
302
|
-
expect({:other => 'value'}).not_to include(:key => 'value')
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
|
-
context "for a non-hash target" do
|
307
|
-
it "passes if the target does not contain the given hash" do
|
308
|
-
expect(['a', 'b']).not_to include(:key => 'value')
|
309
|
-
end
|
310
|
-
|
311
|
-
it "fails if the target contains the given hash" do
|
312
|
-
expect {
|
313
|
-
expect(['a', { :key => 'value' } ]).not_to include(:key => 'value')
|
314
|
-
}.to fail_matching(%Q|expected ["a", {:key=>"value"}] not to include {:key=>"value"}|)
|
315
|
-
end
|
316
|
-
end
|
317
|
-
end
|
318
|
-
|
319
|
-
describe "expect(...).to include(:key1 => value1, :key2 => value2)" do
|
320
|
-
context 'for a hash target' do
|
321
|
-
it "passes if target includes the key/value pairs" do
|
322
|
-
expect({:a => 1, :b => 2}).to include(:b => 2, :a => 1)
|
323
|
-
end
|
324
|
-
|
325
|
-
it "passes if target includes the key/value pairs among others" do
|
326
|
-
expect({:a => 1, :c => 3, :b => 2}).to include(:b => 2, :a => 1)
|
327
|
-
end
|
328
|
-
|
329
|
-
it "fails if target has a different value for one of the keys" do
|
330
|
-
expect {
|
331
|
-
expect({:a => 1, :b => 2}).to include(:a => 2, :b => 2)
|
332
|
-
}.to fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} to include #{{:a=>2, :b=>2}.inspect}|)
|
333
|
-
end
|
334
|
-
|
335
|
-
it "fails if target has a different value for both of the keys" do
|
336
|
-
expect {
|
337
|
-
expect({:a => 1, :b => 1}).to include(:a => 2, :b => 2)
|
338
|
-
}.to fail_matching(%Q|expected #{{:a=>1, :b=>1}.inspect} to include #{{:a=>2, :b=>2}.inspect}|)
|
339
|
-
end
|
340
|
-
|
341
|
-
it "fails if target lacks one of the keys" do
|
342
|
-
expect {
|
343
|
-
expect({:a => 1, :b => 1}).to include(:a => 1, :c => 1)
|
344
|
-
}.to fail_matching(%Q|expected #{{:a=>1, :b=>1}.inspect} to include #{{:a=>1, :c=>1}.inspect}|)
|
345
|
-
end
|
346
|
-
|
347
|
-
it "fails if target lacks both of the keys" do
|
348
|
-
expect {
|
349
|
-
expect({:a => 1, :b => 1}).to include(:c => 1, :d => 1)
|
350
|
-
}.to fail_matching(%Q|expected #{{:a=>1, :b=>1}.inspect} to include #{{:c=>1, :d=>1}.inspect}|)
|
351
|
-
end
|
352
|
-
end
|
353
|
-
|
354
|
-
context 'for a non-hash target' do
|
355
|
-
it "fails if the target does not contain the given hash" do
|
356
|
-
expect {
|
357
|
-
expect(['a', 'b']).to include(:a => 1, :b => 1)
|
358
|
-
}.to fail_matching(%Q|expected ["a", "b"] to include #{{:a=>1, :b=>1}.inspect}|)
|
359
|
-
end
|
360
|
-
|
361
|
-
it "passes if the target contains the given hash" do
|
362
|
-
expect(['a', { :a => 1, :b => 2 } ]).to include(:a => 1, :b => 2)
|
363
|
-
end
|
364
|
-
end
|
365
|
-
end
|
366
|
-
|
367
|
-
describe "expect(...).not_to include(:key1 => value1, :key2 => value2)" do
|
368
|
-
context 'for a hash target' do
|
369
|
-
it "fails if target includes the key/value pairs" do
|
370
|
-
expect {
|
371
|
-
expect({:a => 1, :b => 2}).not_to include(:a => 1, :b => 2)
|
372
|
-
}.to fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} not to include #{{:a=>1, :b=>2}.inspect}|)
|
373
|
-
end
|
374
|
-
|
375
|
-
it "fails if target includes the key/value pairs among others" do
|
376
|
-
hash = {:a => 1, :b => 2, :c => 3}
|
377
|
-
expect {
|
378
|
-
expect(hash).not_to include(:a => 1, :b => 2)
|
379
|
-
}.to fail_matching(%Q|expected #{hash.inspect} not to include #{{:a=>1, :b=>2}.inspect}|)
|
380
|
-
end
|
381
|
-
|
382
|
-
it "fails if target has a different value for one of the keys" do
|
383
|
-
expect {
|
384
|
-
expect({:a => 1, :b => 2}).not_to include(:a => 2, :b => 2)
|
385
|
-
}.to fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} not to include #{{:a=>2, :b=>2}.inspect}|)
|
386
|
-
end
|
387
|
-
|
388
|
-
it "passes if target has a different value for both of the keys" do
|
389
|
-
expect({:a => 1, :b => 1}).not_to include(:a => 2, :b => 2)
|
390
|
-
end
|
391
|
-
|
392
|
-
it "fails if target lacks one of the keys" do
|
393
|
-
expect {
|
394
|
-
expect({:a => 1, :b => 1}).not_to include(:a => 1, :c => 1)
|
395
|
-
}.to fail_matching(%Q|expected #{{:a=>1, :b=>1}.inspect} not to include #{{:a=>1, :c=>1}.inspect}|)
|
396
|
-
end
|
397
|
-
|
398
|
-
it "passes if target lacks both of the keys" do
|
399
|
-
expect({:a => 1, :b => 1}).not_to include(:c => 1, :d => 1)
|
400
|
-
end
|
401
|
-
end
|
402
|
-
|
403
|
-
context 'for a non-hash target' do
|
404
|
-
it "passes if the target does not contain the given hash" do
|
405
|
-
expect(['a', 'b']).not_to include(:a => 1, :b => 1)
|
406
|
-
end
|
407
|
-
|
408
|
-
it "fails if the target contains the given hash" do
|
409
|
-
expect {
|
410
|
-
expect(['a', { :a => 1, :b => 2 } ]).not_to include(:a => 1, :b => 2)
|
411
|
-
}.to fail_matching(%Q|expected #{["a", {:a=>1, :b=>2}].inspect} not to include #{{:a=>1, :b=>2}.inspect}|)
|
412
|
-
end
|
413
|
-
end
|
414
|
-
end
|
415
|
-
end
|
416
|
-
|
417
|
-
RSpec::Matchers.define :a_string_containing do |expected|
|
418
|
-
match do |actual|
|
419
|
-
actual.include?(expected)
|
420
|
-
end
|
421
|
-
|
422
|
-
description do
|
423
|
-
"a string containing '#{expected}'"
|
424
|
-
end
|
425
|
-
end
|
426
|
-
|
427
|
-
describe "expect(...).to include(matcher)" do
|
428
|
-
context 'for an array target' do
|
429
|
-
it "passes if target includes an object that satisfies the matcher" do
|
430
|
-
expect(['foo', 'bar', 'baz']).to include(a_string_containing("ar"))
|
431
|
-
end
|
432
|
-
|
433
|
-
it "fails if target doesn't include object that satisfies the matcher" do
|
434
|
-
expect {
|
435
|
-
expect(['foo', 'bar', 'baz']).to include(a_string_containing("abc"))
|
436
|
-
}.to fail_matching(%Q|expected #{['foo', 'bar', 'baz'].inspect} to include a string containing 'abc'|)
|
437
|
-
end
|
438
|
-
|
439
|
-
it 'does not include a diff when the match fails' do
|
440
|
-
expect {
|
441
|
-
expect(['foo', 'bar', 'baz']).to include(a_string_containing("abc"))
|
442
|
-
}.to raise_error { |e|
|
443
|
-
expect(e.message).not_to match(/diff/i)
|
444
|
-
}
|
445
|
-
end
|
446
|
-
|
447
|
-
it 'does not treat an object that only implements #matches? as a matcher' do
|
448
|
-
domain = Struct.new(:domain) do
|
449
|
-
def matches?(url)
|
450
|
-
URI(url).host == self.domain
|
451
|
-
end
|
452
|
-
end
|
453
|
-
|
454
|
-
expect([domain.new("rspec.info")]).to include(domain.new("rspec.info"))
|
455
|
-
|
456
|
-
expect {
|
457
|
-
expect([domain.new("rspec.info")]).to include(domain.new("foo.com"))
|
458
|
-
}.to fail_matching("expected [#{domain.new("rspec.info").inspect}] to include")
|
459
|
-
end
|
460
|
-
|
461
|
-
it 'works with an old-style matcher that implements failure_message rather than failure_message_for_should' do
|
462
|
-
a_multiple_of = Class.new do
|
463
|
-
def initialize(expected)
|
464
|
-
@expected = expected
|
465
|
-
end
|
466
|
-
|
467
|
-
def matches?(actual)
|
468
|
-
(actual % @expected).zero?
|
469
|
-
end
|
470
|
-
|
471
|
-
def failure_message
|
472
|
-
"expected a multiple of #{@expected}"
|
473
|
-
end
|
474
|
-
end
|
475
|
-
|
476
|
-
# Verify the matcher works normally
|
477
|
-
expect(10).to a_multiple_of.new(5)
|
478
|
-
|
479
|
-
expect {
|
480
|
-
expect(10).to a_multiple_of.new(7)
|
481
|
-
}.to fail_with("expected a multiple of 7")
|
482
|
-
|
483
|
-
expect([12, 13, 14]).to include(a_multiple_of.new(6))
|
484
|
-
|
485
|
-
expect {
|
486
|
-
expect([12, 13, 14]).to include(a_multiple_of.new(10))
|
487
|
-
}.to fail_matching("expected [12, 13, 14] to include")
|
488
|
-
end
|
489
|
-
end
|
490
|
-
end
|
491
|
-
|
492
|
-
describe "expect(...).to include(multiple, matcher, arguments)" do
|
493
|
-
context 'for an array target' do
|
494
|
-
it "passes if target includes items satisfying all matchers" do
|
495
|
-
expect(['foo', 'bar', 'baz']).to include(a_string_containing("ar"), a_string_containing('oo'))
|
496
|
-
end
|
497
|
-
|
498
|
-
it "fails if target does not include an item satisfying any one of the items" do
|
499
|
-
expect {
|
500
|
-
expect(['foo', 'bar', 'baz']).to include(a_string_containing("ar"), a_string_containing("abc"))
|
501
|
-
}.to fail_matching(%Q|expected #{['foo', 'bar', 'baz'].inspect} to include a string containing 'ar' and a string containing 'abc'|)
|
502
|
-
end
|
503
|
-
|
504
|
-
it 'does not include a diff when the match fails' do
|
505
|
-
expect {
|
506
|
-
expect(['foo', 'bar', 'baz']).to include(a_string_containing("ar"), a_string_containing("abc"))
|
507
|
-
}.to raise_error { |e|
|
508
|
-
expect(e.message).not_to match(/diff/i)
|
509
|
-
}
|
510
|
-
end
|
511
|
-
end
|
512
|
-
end
|
513
|
-
|
514
|
-
describe "expect(...).not_to include(multiple, matcher, arguments)" do
|
515
|
-
it "passes if none of the target values satisfies any of the matchers" do
|
516
|
-
expect(['foo', 'bar', 'baz']).not_to include(a_string_containing("gh"), a_string_containing('de'))
|
517
|
-
end
|
518
|
-
|
519
|
-
it 'fails if all of the matchers are satisfied by one of the target values' do
|
520
|
-
expect {
|
521
|
-
expect(['foo', 'bar', 'baz']).not_to include(a_string_containing("ar"), a_string_containing('az'))
|
522
|
-
}.to fail_matching(%Q|expected #{['foo', 'bar', 'baz'].inspect} not to include a string containing 'ar' and a string containing 'az'|)
|
523
|
-
end
|
524
|
-
|
525
|
-
it 'fails if the some (but not all) of the matchers are satisifed' do
|
526
|
-
expect {
|
527
|
-
expect(['foo', 'bar', 'baz']).not_to include(a_string_containing("ar"), a_string_containing('bz'))
|
528
|
-
}.to fail_matching(%Q|expected #{['foo', 'bar', 'baz'].inspect} not to include a string containing 'ar' and a string containing 'bz'|)
|
529
|
-
end
|
530
|
-
end
|
531
|
-
|