rspec-expectations 3.0.0.beta2 → 3.0.0.rc1
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.tar.gz.sig +2 -2
- data/.yardopts +0 -1
- data/Changelog.md +115 -35
- data/README.md +2 -2
- data/lib/rspec/expectations.rb +13 -8
- data/lib/rspec/{matchers → expectations}/configuration.rb +38 -13
- data/lib/rspec/expectations/expectation_target.rb +72 -8
- data/lib/rspec/expectations/fail_with.rb +10 -52
- data/lib/rspec/expectations/handler.rb +9 -11
- data/lib/rspec/expectations/syntax.rb +37 -35
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/matchers.rb +60 -9
- data/lib/rspec/matchers/aliased_matcher.rb +6 -0
- data/lib/rspec/matchers/built_in.rb +9 -1
- data/lib/rspec/matchers/built_in/all.rb +78 -0
- data/lib/rspec/matchers/built_in/base_matcher.rb +39 -1
- data/lib/rspec/matchers/built_in/be.rb +117 -42
- data/lib/rspec/matchers/built_in/be_between.rb +22 -0
- data/lib/rspec/matchers/built_in/be_instance_of.rb +11 -3
- data/lib/rspec/matchers/built_in/be_kind_of.rb +5 -0
- data/lib/rspec/matchers/built_in/be_within.rb +26 -6
- data/lib/rspec/matchers/built_in/change.rb +89 -13
- data/lib/rspec/matchers/built_in/compound.rb +19 -3
- data/lib/rspec/matchers/built_in/contain_exactly.rb +17 -6
- data/lib/rspec/matchers/built_in/cover.rb +3 -0
- data/lib/rspec/matchers/built_in/eq.rb +20 -5
- data/lib/rspec/matchers/built_in/eql.rb +15 -3
- data/lib/rspec/matchers/built_in/equal.rb +23 -6
- data/lib/rspec/matchers/built_in/exist.rb +74 -10
- data/lib/rspec/matchers/built_in/has.rb +58 -3
- data/lib/rspec/matchers/built_in/include.rb +16 -1
- data/lib/rspec/matchers/built_in/match.rb +14 -4
- data/lib/rspec/matchers/built_in/operators.rb +16 -0
- data/lib/rspec/matchers/built_in/output.rb +47 -5
- data/lib/rspec/matchers/built_in/raise_error.rb +40 -23
- data/lib/rspec/matchers/built_in/respond_to.rb +37 -16
- data/lib/rspec/matchers/built_in/satisfy.rb +15 -0
- data/lib/rspec/matchers/built_in/start_and_end_with.rb +29 -14
- data/lib/rspec/matchers/built_in/throw_symbol.rb +32 -3
- data/lib/rspec/matchers/built_in/yield.rb +148 -44
- data/lib/rspec/matchers/composable.rb +48 -7
- data/lib/rspec/matchers/dsl.rb +45 -17
- data/lib/rspec/matchers/generated_descriptions.rb +7 -0
- data/lib/rspec/matchers/matcher_delegator.rb +6 -2
- data/lib/rspec/matchers/pretty.rb +15 -19
- metadata +33 -236
- metadata.gz.sig +0 -0
- data/features/README.md +0 -48
- data/features/Upgrade.md +0 -53
- data/features/built_in_matchers/README.md +0 -96
- data/features/built_in_matchers/be.feature +0 -175
- data/features/built_in_matchers/be_within.feature +0 -48
- data/features/built_in_matchers/comparisons.feature +0 -97
- data/features/built_in_matchers/contain_exactly.feature +0 -46
- 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 -136
- 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/include.feature +0 -126
- data/features/built_in_matchers/match.feature +0 -51
- data/features/built_in_matchers/output.feature +0 -70
- data/features/built_in_matchers/predicates.feature +0 -161
- 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/composing_matchers.feature +0 -250
- data/features/compound_expectations.feature +0 -45
- 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 -34
- data/features/custom_matchers/define_matcher_with_fluent_interface.feature +0 -24
- data/features/customized_message.feature +0 -39
- 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 -21
- data/features/support/rubinius.rb +0 -6
- data/features/syntax_configuration.feature +0 -71
- data/features/test_frameworks/minitest.feature +0 -44
- data/lib/rspec-expectations.rb +0 -1
- data/lib/rspec/expectations/diff_presenter.rb +0 -141
- data/lib/rspec/expectations/differ.rb +0 -44
- data/lib/rspec/expectations/encoded_string.rb +0 -56
- data/spec/rspec/expectations/diff_presenter_spec.rb +0 -249
- data/spec/rspec/expectations/encoded_string_spec.rb +0 -74
- 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 -205
- data/spec/rspec/expectations/minitest_integration_spec.rb +0 -27
- data/spec/rspec/expectations/syntax_spec.rb +0 -89
- data/spec/rspec/expectations_spec.rb +0 -12
- data/spec/rspec/matchers/aliased_matcher_spec.rb +0 -48
- data/spec/rspec/matchers/aliases_spec.rb +0 -449
- data/spec/rspec/matchers/built_in/base_matcher_spec.rb +0 -83
- data/spec/rspec/matchers/built_in/be_between_spec.rb +0 -159
- data/spec/rspec/matchers/built_in/be_instance_of_spec.rb +0 -63
- data/spec/rspec/matchers/built_in/be_kind_of_spec.rb +0 -41
- data/spec/rspec/matchers/built_in/be_spec.rb +0 -592
- data/spec/rspec/matchers/built_in/be_within_spec.rb +0 -141
- data/spec/rspec/matchers/built_in/change_spec.rb +0 -808
- data/spec/rspec/matchers/built_in/compound_spec.rb +0 -292
- data/spec/rspec/matchers/built_in/contain_exactly_spec.rb +0 -441
- data/spec/rspec/matchers/built_in/cover_spec.rb +0 -69
- data/spec/rspec/matchers/built_in/eq_spec.rb +0 -156
- data/spec/rspec/matchers/built_in/eql_spec.rb +0 -41
- data/spec/rspec/matchers/built_in/equal_spec.rb +0 -106
- data/spec/rspec/matchers/built_in/exist_spec.rb +0 -124
- data/spec/rspec/matchers/built_in/has_spec.rb +0 -161
- data/spec/rspec/matchers/built_in/include_spec.rb +0 -540
- data/spec/rspec/matchers/built_in/match_spec.rb +0 -102
- data/spec/rspec/matchers/built_in/operators_spec.rb +0 -252
- data/spec/rspec/matchers/built_in/output_spec.rb +0 -165
- data/spec/rspec/matchers/built_in/raise_error_spec.rb +0 -461
- data/spec/rspec/matchers/built_in/respond_to_spec.rb +0 -292
- data/spec/rspec/matchers/built_in/satisfy_spec.rb +0 -44
- data/spec/rspec/matchers/built_in/start_and_end_with_spec.rb +0 -253
- data/spec/rspec/matchers/built_in/throw_symbol_spec.rb +0 -135
- data/spec/rspec/matchers/built_in/yield_spec.rb +0 -627
- data/spec/rspec/matchers/configuration_spec.rb +0 -213
- data/spec/rspec/matchers/description_generation_spec.rb +0 -191
- data/spec/rspec/matchers/dsl_spec.rb +0 -895
- data/spec/rspec/matchers/legacy_spec.rb +0 -101
- data/spec/rspec/matchers_spec.rb +0 -74
- data/spec/spec_helper.rb +0 -85
- data/spec/support/matchers.rb +0 -22
- data/spec/support/shared_examples.rb +0 -35
@@ -1,292 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "expect(...).to respond_to(:sym)" do
|
4
|
-
it_behaves_like "an RSpec matcher", :valid_value => "s", :invalid_value => 5 do
|
5
|
-
let(:matcher) { respond_to(:upcase) }
|
6
|
-
end
|
7
|
-
|
8
|
-
it "passes if target responds to :sym" do
|
9
|
-
expect(Object.new).to respond_to(:methods)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "fails if target does not respond to :sym" do
|
13
|
-
expect {
|
14
|
-
expect("this string").to respond_to(:some_method)
|
15
|
-
}.to fail_with(%q|expected "this string" to respond to :some_method|)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "expect(...).to respond_to(:sym).with(1).argument" do
|
20
|
-
it "passes if target responds to :sym with 1 arg" do
|
21
|
-
obj = Object.new
|
22
|
-
def obj.foo(arg); end
|
23
|
-
expect(obj).to respond_to(:foo).with(1).argument
|
24
|
-
end
|
25
|
-
|
26
|
-
it "passes if target responds to any number of arguments" do
|
27
|
-
obj = Object.new
|
28
|
-
def obj.foo(*args); end
|
29
|
-
expect(obj).to respond_to(:foo).with(1).argument
|
30
|
-
end
|
31
|
-
|
32
|
-
it "passes if target responds to one or more arguments" do
|
33
|
-
obj = Object.new
|
34
|
-
def obj.foo(a, *args); end
|
35
|
-
expect(obj).to respond_to(:foo).with(1).argument
|
36
|
-
end
|
37
|
-
|
38
|
-
it "fails if target does not respond to :sym" do
|
39
|
-
obj = Object.new
|
40
|
-
expect {
|
41
|
-
expect(obj).to respond_to(:some_method).with(1).argument
|
42
|
-
}.to fail_with(/expected .* to respond to :some_method/)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "fails if :sym expects 0 args" do
|
46
|
-
obj = Object.new
|
47
|
-
def obj.foo; end
|
48
|
-
expect {
|
49
|
-
expect(obj).to respond_to(:foo).with(1).argument
|
50
|
-
}.to fail_with(/expected #<Object.*> to respond to :foo with 1 argument/)
|
51
|
-
end
|
52
|
-
|
53
|
-
it "fails if :sym expects 2 args" do
|
54
|
-
obj = Object.new
|
55
|
-
def obj.foo(arg, arg2); end
|
56
|
-
expect {
|
57
|
-
expect(obj).to respond_to(:foo).with(1).argument
|
58
|
-
}.to fail_with(/expected #<Object.*> to respond to :foo with 1 argument/)
|
59
|
-
end
|
60
|
-
|
61
|
-
it "fails if :sym expects 2 or more args" do
|
62
|
-
obj = Object.new
|
63
|
-
def obj.foo(arg, arg2, *args); end
|
64
|
-
expect {
|
65
|
-
expect(obj).to respond_to(:foo).with(1).argument
|
66
|
-
}.to fail_with(/expected #<Object.*> to respond to :foo with 1 argument/)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe "expect(...).to respond_to(message1, message2)" do
|
71
|
-
it "passes if target responds to both messages" do
|
72
|
-
expect(Object.new).to respond_to('methods', 'inspect')
|
73
|
-
end
|
74
|
-
|
75
|
-
it "fails if target does not respond to first message" do
|
76
|
-
expect {
|
77
|
-
expect(Object.new).to respond_to('method_one', 'inspect')
|
78
|
-
}.to fail_with(/expected #<Object:.*> to respond to "method_one"/)
|
79
|
-
end
|
80
|
-
|
81
|
-
it "fails if target does not respond to second message" do
|
82
|
-
expect {
|
83
|
-
expect(Object.new).to respond_to('inspect', 'method_one')
|
84
|
-
}.to fail_with(/expected #<Object:.*> to respond to "method_one"/)
|
85
|
-
end
|
86
|
-
|
87
|
-
it "fails if target does not respond to either message" do
|
88
|
-
expect {
|
89
|
-
expect(Object.new).to respond_to('method_one', 'method_two')
|
90
|
-
}.to fail_with(/expected #<Object:.*> to respond to "method_one", "method_two"/)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
describe "expect(...).to respond_to(:sym).with(2).arguments" do
|
95
|
-
it "passes if target responds to :sym with 2 args" do
|
96
|
-
obj = Object.new
|
97
|
-
def obj.foo(a1, a2); end
|
98
|
-
expect(obj).to respond_to(:foo).with(2).arguments
|
99
|
-
end
|
100
|
-
|
101
|
-
it "passes if target responds to any number of arguments" do
|
102
|
-
obj = Object.new
|
103
|
-
def obj.foo(*args); end
|
104
|
-
expect(obj).to respond_to(:foo).with(2).arguments
|
105
|
-
end
|
106
|
-
|
107
|
-
it "passes if target responds to one or more arguments" do
|
108
|
-
obj = Object.new
|
109
|
-
def obj.foo(a, *args); end
|
110
|
-
expect(obj).to respond_to(:foo).with(2).arguments
|
111
|
-
end
|
112
|
-
|
113
|
-
it "passes if target responds to two or more arguments" do
|
114
|
-
obj = Object.new
|
115
|
-
def obj.foo(a, b, *args); end
|
116
|
-
expect(obj).to respond_to(:foo).with(2).arguments
|
117
|
-
end
|
118
|
-
|
119
|
-
it "fails if target does not respond to :sym" do
|
120
|
-
obj = Object.new
|
121
|
-
expect {
|
122
|
-
expect(obj).to respond_to(:some_method).with(2).arguments
|
123
|
-
}.to fail_with(/expected .* to respond to :some_method/)
|
124
|
-
end
|
125
|
-
|
126
|
-
it "fails if :sym expects 0 args" do
|
127
|
-
obj = Object.new
|
128
|
-
def obj.foo; end
|
129
|
-
expect {
|
130
|
-
expect(obj).to respond_to(:foo).with(2).arguments
|
131
|
-
}.to fail_with(/expected #<Object.*> to respond to :foo with 2 arguments/)
|
132
|
-
end
|
133
|
-
|
134
|
-
it "fails if :sym expects 1 args" do
|
135
|
-
obj = Object.new
|
136
|
-
def obj.foo(arg); end
|
137
|
-
expect {
|
138
|
-
expect(obj).to respond_to(:foo).with(2).arguments
|
139
|
-
}.to fail_with(/expected #<Object.*> to respond to :foo with 2 arguments/)
|
140
|
-
end
|
141
|
-
|
142
|
-
it "fails if :sym expects 3 or more args" do
|
143
|
-
obj = Object.new
|
144
|
-
def obj.foo(arg, arg2, arg3, *args); end
|
145
|
-
expect {
|
146
|
-
expect(obj).to respond_to(:foo).with(2).arguments
|
147
|
-
}.to fail_with(/expected #<Object.*> to respond to :foo with 2 arguments/)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
describe "expect(...).not_to respond_to(:sym)" do
|
152
|
-
it "passes if target does not respond to :sym" do
|
153
|
-
expect(Object.new).not_to respond_to(:some_method)
|
154
|
-
end
|
155
|
-
|
156
|
-
it "fails if target responds to :sym" do
|
157
|
-
expect {
|
158
|
-
expect(Object.new).not_to respond_to(:methods)
|
159
|
-
}.to fail_with(/expected #<Object:.*> not to respond to :methods/)
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
describe "expect(...).not_to respond_to(:sym).with(1).argument" do
|
164
|
-
it "fails if target responds to :sym with 1 arg" do
|
165
|
-
obj = Object.new
|
166
|
-
def obj.foo(arg); end
|
167
|
-
expect {
|
168
|
-
expect(obj).not_to respond_to(:foo).with(1).argument
|
169
|
-
}.to fail_with(/expected #<Object:.*> not to respond to :foo with 1 argument/)
|
170
|
-
end
|
171
|
-
|
172
|
-
it "fails if target responds to :sym with any number of args" do
|
173
|
-
obj = Object.new
|
174
|
-
def obj.foo(*args); end
|
175
|
-
expect {
|
176
|
-
expect(obj).not_to respond_to(:foo).with(1).argument
|
177
|
-
}.to fail_with(/expected #<Object:.*> not to respond to :foo with 1 argument/)
|
178
|
-
end
|
179
|
-
|
180
|
-
it "fails if target responds to :sym with one or more args" do
|
181
|
-
obj = Object.new
|
182
|
-
def obj.foo(a, *args); end
|
183
|
-
expect {
|
184
|
-
expect(obj).not_to respond_to(:foo).with(1).argument
|
185
|
-
}.to fail_with(/expected #<Object:.*> not to respond to :foo with 1 argument/)
|
186
|
-
end
|
187
|
-
|
188
|
-
it "passes if target does not respond to :sym" do
|
189
|
-
obj = Object.new
|
190
|
-
expect(obj).not_to respond_to(:some_method).with(1).argument
|
191
|
-
end
|
192
|
-
|
193
|
-
it "passes if :sym expects 0 args" do
|
194
|
-
obj = Object.new
|
195
|
-
def obj.foo; end
|
196
|
-
expect(obj).not_to respond_to(:foo).with(1).argument
|
197
|
-
end
|
198
|
-
|
199
|
-
it "passes if :sym expects 2 args" do
|
200
|
-
obj = Object.new
|
201
|
-
def obj.foo(arg, arg2); end
|
202
|
-
expect(obj).not_to respond_to(:foo).with(1).argument
|
203
|
-
end
|
204
|
-
|
205
|
-
it "passes if :sym expects 2 or more args" do
|
206
|
-
obj = Object.new
|
207
|
-
def obj.foo(arg, arg2, *args); end
|
208
|
-
expect(obj).not_to respond_to(:foo).with(1).argument
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
describe "expect(...).not_to respond_to(message1, message2)" do
|
213
|
-
it "passes if target does not respond to either message1 or message2" do
|
214
|
-
expect(Object.new).not_to respond_to(:some_method, :some_other_method)
|
215
|
-
end
|
216
|
-
|
217
|
-
it "fails if target responds to message1 but not message2" do
|
218
|
-
expect {
|
219
|
-
expect(Object.new).not_to respond_to(:object_id, :some_method)
|
220
|
-
}.to fail_with(/expected #<Object:.*> not to respond to :object_id/)
|
221
|
-
end
|
222
|
-
|
223
|
-
it "fails if target responds to message2 but not message1" do
|
224
|
-
expect {
|
225
|
-
expect(Object.new).not_to respond_to(:some_method, :object_id)
|
226
|
-
}.to fail_with(/expected #<Object:.*> not to respond to :object_id/)
|
227
|
-
end
|
228
|
-
|
229
|
-
it "fails if target responds to both message1 and message2" do
|
230
|
-
expect {
|
231
|
-
expect(Object.new).not_to respond_to(:class, :object_id)
|
232
|
-
}.to fail_with(/expected #<Object:.*> not to respond to :class, :object_id/)
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
describe "expect(...).not_to respond_to(:sym).with(2).arguments" do
|
237
|
-
it "fails if target responds to :sym with 2 args" do
|
238
|
-
obj = Object.new
|
239
|
-
def obj.foo(a1, a2); end
|
240
|
-
expect {
|
241
|
-
expect(obj).not_to respond_to(:foo).with(2).arguments
|
242
|
-
}.to fail_with(/expected .* not to respond to :foo with 2 arguments/)
|
243
|
-
end
|
244
|
-
|
245
|
-
it "fails if target responds to :sym with any number args" do
|
246
|
-
obj = Object.new
|
247
|
-
def obj.foo(*args); end
|
248
|
-
expect {
|
249
|
-
expect(obj).not_to respond_to(:foo).with(2).arguments
|
250
|
-
}.to fail_with(/expected .* not to respond to :foo with 2 arguments/)
|
251
|
-
end
|
252
|
-
|
253
|
-
it "fails if target responds to :sym with one or more args" do
|
254
|
-
obj = Object.new
|
255
|
-
def obj.foo(a, *args); end
|
256
|
-
expect {
|
257
|
-
expect(obj).not_to respond_to(:foo).with(2).arguments
|
258
|
-
}.to fail_with(/expected .* not to respond to :foo with 2 arguments/)
|
259
|
-
end
|
260
|
-
|
261
|
-
it "fails if target responds to :sym with two or more args" do
|
262
|
-
obj = Object.new
|
263
|
-
def obj.foo(a, b, *args); end
|
264
|
-
expect {
|
265
|
-
expect(obj).not_to respond_to(:foo).with(2).arguments
|
266
|
-
}.to fail_with(/expected .* not to respond to :foo with 2 arguments/)
|
267
|
-
end
|
268
|
-
|
269
|
-
it "passes if target does not respond to :sym" do
|
270
|
-
obj = Object.new
|
271
|
-
expect(obj).not_to respond_to(:some_method).with(2).arguments
|
272
|
-
end
|
273
|
-
|
274
|
-
it "passes if :sym expects 0 args" do
|
275
|
-
obj = Object.new
|
276
|
-
def obj.foo; end
|
277
|
-
expect(obj).not_to respond_to(:foo).with(2).arguments
|
278
|
-
end
|
279
|
-
|
280
|
-
it "passes if :sym expects 2 args" do
|
281
|
-
obj = Object.new
|
282
|
-
def obj.foo(arg); end
|
283
|
-
expect(obj).not_to respond_to(:foo).with(2).arguments
|
284
|
-
end
|
285
|
-
|
286
|
-
it "passes if :sym expects 3 or more args" do
|
287
|
-
obj = Object.new
|
288
|
-
def obj.foo(a, b, c, *arg); end
|
289
|
-
expect(obj).not_to respond_to(:foo).with(2).arguments
|
290
|
-
end
|
291
|
-
end
|
292
|
-
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "expect(...).to satisfy { block }" do
|
4
|
-
it_behaves_like "an RSpec matcher", :valid_value => true, :invalid_value => false do
|
5
|
-
let(:matcher) { satisfy { |v| v } }
|
6
|
-
end
|
7
|
-
|
8
|
-
it "describes itself" do
|
9
|
-
expect(satisfy.description).to eq("satisfy block")
|
10
|
-
end
|
11
|
-
|
12
|
-
it "passes if block returns true" do
|
13
|
-
expect(true).to satisfy { |val| val }
|
14
|
-
expect(true).to satisfy do |val|
|
15
|
-
val
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
it "fails if block returns false" do
|
20
|
-
expect {
|
21
|
-
expect(false).to satisfy { |val| val }
|
22
|
-
}.to fail_with("expected false to satisfy block")
|
23
|
-
expect do
|
24
|
-
expect(false).to satisfy do |val|
|
25
|
-
val
|
26
|
-
end
|
27
|
-
end.to fail_with("expected false to satisfy block")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "expect(...).not_to satisfy { block }" do
|
32
|
-
it "passes if block returns false" do
|
33
|
-
expect(false).not_to satisfy { |val| val }
|
34
|
-
expect(false).not_to satisfy do |val|
|
35
|
-
val
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
it "fails if block returns true" do
|
40
|
-
expect {
|
41
|
-
expect(true).not_to satisfy { |val| val }
|
42
|
-
}.to fail_with("expected true not to satisfy block")
|
43
|
-
end
|
44
|
-
end
|
@@ -1,253 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "expect(...).to start_with" do
|
4
|
-
it_behaves_like "an RSpec matcher", :valid_value => "ab", :invalid_value => "bc" do
|
5
|
-
let(:matcher) { start_with("a") }
|
6
|
-
end
|
7
|
-
|
8
|
-
context "with a string" do
|
9
|
-
it "passes if it matches the start of the actual string" do
|
10
|
-
expect("this string").to start_with "this str"
|
11
|
-
end
|
12
|
-
|
13
|
-
it "fails if it does not match the start of the actual string" do
|
14
|
-
expect {
|
15
|
-
expect("this string").to start_with "that str"
|
16
|
-
}.to fail_with("expected \"this string\" to start with \"that str\"")
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "with an array" do
|
21
|
-
it "passes if it is the first element of the array" do
|
22
|
-
expect([0, 1, 2]).to start_with 0
|
23
|
-
end
|
24
|
-
|
25
|
-
it "passes if the first elements of the array match" do
|
26
|
-
expect([0, 1, 2]).to start_with 0, 1
|
27
|
-
end
|
28
|
-
|
29
|
-
it "fails if it does not match the first element of the array" do
|
30
|
-
expect {
|
31
|
-
expect([0, 1, 2]).to start_with 2
|
32
|
-
}.to fail_with("expected [0, 1, 2] to start with 2")
|
33
|
-
end
|
34
|
-
|
35
|
-
it "fails if it the first elements of the array do not match" do
|
36
|
-
expect {
|
37
|
-
expect([0, 1, 2]).to start_with 1, 2
|
38
|
-
}.to fail_with("expected [0, 1, 2] to start with 1 and 2")
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context "with an object that does not respond to :[]" do
|
43
|
-
it "fails with a useful message" do
|
44
|
-
actual = Object.new
|
45
|
-
expect {
|
46
|
-
expect(actual).to start_with 0
|
47
|
-
}.to fail_with("expected #{actual.inspect} to start with 0, but it cannot be indexed using #[]")
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context "with a hash" do
|
52
|
-
it "fails with a useful error if trying to match more than one element" do
|
53
|
-
actual = { :a => 'b', :b => 'b', :c => 'c' }
|
54
|
-
expected = { :a => 'b', :b => 'b' }
|
55
|
-
expect{
|
56
|
-
expect(actual).to start_with(expected)
|
57
|
-
}.to fail_with("expected #{actual.inspect} to start with #{expected.inspect}, but it does not have ordered elements")
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "composing with other matchers" do
|
62
|
-
it 'passes if the start of an array matches two given matchers' do
|
63
|
-
expect([1.01, "food", 3]).to start_with(a_value_within(0.2).of(1), a_string_matching(/foo/))
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'passes if the start of an array matches one given matcher' do
|
67
|
-
expect([1.01, "food", 3]).to start_with(a_value_within(0.2).of(1))
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'provides a description' do
|
71
|
-
description = start_with(a_value_within(0.1).of(1), a_string_matching(/abc/)).description
|
72
|
-
expect(description).to eq("start with a value within 0.1 of 1 and a string matching /abc/")
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'fails with a clear error message when the matchers do not match' do
|
76
|
-
expect {
|
77
|
-
expect([2.01, "food", 3]).to start_with(a_value_within(0.2).of(1), a_string_matching(/foo/))
|
78
|
-
}.to fail_with('expected [2.01, "food", 3] to start with a value within 0.2 of 1 and a string matching /foo/')
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
describe "expect(...).not_to start_with" do
|
84
|
-
context "with a string" do
|
85
|
-
it "passes if it does not match the start of the actual string" do
|
86
|
-
expect("this string").not_to start_with "that str"
|
87
|
-
end
|
88
|
-
|
89
|
-
it "fails if it does match the start of the actual string" do
|
90
|
-
expect {
|
91
|
-
expect("this string").not_to start_with "this str"
|
92
|
-
}.to fail_with("expected \"this string\" not to start with \"this str\"")
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
context "with an array" do
|
97
|
-
it "passes if it is not the first element of the array" do
|
98
|
-
expect([0, 1, 2]).not_to start_with 2
|
99
|
-
end
|
100
|
-
|
101
|
-
it "passes if the first elements of the array do not match" do
|
102
|
-
expect([0, 1, 2]).not_to start_with 1, 2
|
103
|
-
end
|
104
|
-
|
105
|
-
it "fails if it matches the first element of the array" do
|
106
|
-
expect {
|
107
|
-
expect([0, 1, 2]).not_to start_with 0
|
108
|
-
}.to fail_with("expected [0, 1, 2] not to start with 0")
|
109
|
-
end
|
110
|
-
|
111
|
-
it "fails if it the first elements of the array match" do
|
112
|
-
expect {
|
113
|
-
expect([0, 1, 2]).not_to start_with 0, 1
|
114
|
-
}.to fail_with("expected [0, 1, 2] not to start with 0 and 1")
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
it 'can pass when composed with another matcher' do
|
119
|
-
expect(["a"]).not_to start_with(a_string_matching(/bar/))
|
120
|
-
end
|
121
|
-
|
122
|
-
it 'can fail when composed with another matcher' do
|
123
|
-
expect {
|
124
|
-
expect(["a"]).not_to start_with(a_string_matching(/a/))
|
125
|
-
}.to fail_with('expected ["a"] not to start with a string matching /a/')
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
describe "expect(...).to end_with" do
|
130
|
-
it_behaves_like "an RSpec matcher", :valid_value => "ab", :invalid_value => "bc" do
|
131
|
-
let(:matcher) { end_with("b") }
|
132
|
-
end
|
133
|
-
|
134
|
-
context "with a string" do
|
135
|
-
it "passes if it matches the end of the actual string" do
|
136
|
-
expect("this string").to end_with "is string"
|
137
|
-
end
|
138
|
-
|
139
|
-
it "fails if it does not match the end of the actual string" do
|
140
|
-
expect {
|
141
|
-
expect("this string").to end_with "is stringy"
|
142
|
-
}.to fail_with("expected \"this string\" to end with \"is stringy\"")
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
context "with an array" do
|
147
|
-
it "passes if it is the last element of the array" do
|
148
|
-
expect([0, 1, 2]).to end_with 2
|
149
|
-
end
|
150
|
-
|
151
|
-
it "passes if the last elements of the array match" do
|
152
|
-
expect([0, 1, 2]).to end_with [1, 2]
|
153
|
-
end
|
154
|
-
|
155
|
-
it "fails if it does not match the last element of the array" do
|
156
|
-
expect {
|
157
|
-
expect([0, 1, 2]).to end_with 1
|
158
|
-
}.to fail_with("expected [0, 1, 2] to end with 1")
|
159
|
-
end
|
160
|
-
|
161
|
-
it "fails if it the last elements of the array do not match" do
|
162
|
-
expect {
|
163
|
-
expect([0, 1, 2]).to end_with [0, 1]
|
164
|
-
}.to fail_with("expected [0, 1, 2] to end with 0 and 1")
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
context "with an object that does not respond to :[]" do
|
169
|
-
it "fails with a useful message" do
|
170
|
-
actual = Object.new
|
171
|
-
expect {
|
172
|
-
expect(actual).to end_with 0
|
173
|
-
}.to fail_with("expected #{actual.inspect} to end with 0, but it cannot be indexed using #[]")
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
context "with a hash" do
|
178
|
-
it "raises an ArgumentError if trying to match more than one element" do
|
179
|
-
actual = { :a => 'b', :b => 'b', :c => 'c' }
|
180
|
-
expected = { :a => 'b', :b => 'b' }
|
181
|
-
expect{
|
182
|
-
expect(actual).to end_with(expected)
|
183
|
-
}.to fail_with("expected #{actual.inspect} to end with #{expected.inspect}, but it does not have ordered elements")
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
describe "composing with other matchers" do
|
188
|
-
it 'passes if the end of an array matches two given matchers' do
|
189
|
-
expect([3, "food", 1.1]).to end_with(a_string_matching(/foo/), a_value_within(0.2).of(1))
|
190
|
-
end
|
191
|
-
|
192
|
-
it 'passes if the end of an array matches one given matcher' do
|
193
|
-
expect([3, "food", 1.1]).to end_with(a_value_within(0.2).of(1))
|
194
|
-
end
|
195
|
-
|
196
|
-
it 'provides a description' do
|
197
|
-
description = end_with(a_value_within(0.1).of(1), a_string_matching(/abc/)).description
|
198
|
-
expect(description).to eq("end with a value within 0.1 of 1 and a string matching /abc/")
|
199
|
-
end
|
200
|
-
|
201
|
-
it 'fails with a clear error message when the matchers do not match' do
|
202
|
-
expect {
|
203
|
-
expect([2.01, 3, "food"]).to end_with(a_value_within(0.2).of(1), a_string_matching(/foo/))
|
204
|
-
}.to fail_with('expected [2.01, 3, "food"] to end with a value within 0.2 of 1 and a string matching /foo/')
|
205
|
-
end
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
describe "expect(...).not_to end_with" do
|
210
|
-
context "with a sting" do
|
211
|
-
it "passes if it does not match the end of the actual string" do
|
212
|
-
expect("this string").not_to end_with "stringy"
|
213
|
-
end
|
214
|
-
|
215
|
-
it "fails if it matches the end of the actual string" do
|
216
|
-
expect {
|
217
|
-
expect("this string").not_to end_with "string"
|
218
|
-
}.to fail_with("expected \"this string\" not to end with \"string\"")
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
context "an array" do
|
223
|
-
it "passes if it is not the last element of the array" do
|
224
|
-
expect([0, 1, 2]).not_to end_with 1
|
225
|
-
end
|
226
|
-
|
227
|
-
it "passes if the last elements of the array do not match" do
|
228
|
-
expect([0, 1, 2]).not_to end_with [0, 1]
|
229
|
-
end
|
230
|
-
|
231
|
-
it "fails if it matches the last element of the array" do
|
232
|
-
expect {
|
233
|
-
expect([0, 1, 2]).not_to end_with 2
|
234
|
-
}.to fail_with("expected [0, 1, 2] not to end with 2")
|
235
|
-
end
|
236
|
-
|
237
|
-
it "fails if it the last elements of the array match" do
|
238
|
-
expect {
|
239
|
-
expect([0, 1, 2]).not_to end_with [1, 2]
|
240
|
-
}.to fail_with("expected [0, 1, 2] not to end with 1 and 2")
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
it 'can pass when composed with another matcher' do
|
245
|
-
expect(["a"]).not_to end_with(a_string_matching(/bar/))
|
246
|
-
end
|
247
|
-
|
248
|
-
it 'can fail when composed with another matcher' do
|
249
|
-
expect {
|
250
|
-
expect(["a"]).not_to end_with(a_string_matching(/a/))
|
251
|
-
}.to fail_with('expected ["a"] not to end with a string matching /a/')
|
252
|
-
end
|
253
|
-
end
|