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,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,186 +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, 2]")
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context "with an object that does not respond to :[]" do
|
43
|
-
it "raises an ArgumentError" do
|
44
|
-
expect {
|
45
|
-
expect(Object.new).to start_with 0
|
46
|
-
}.to raise_error(ArgumentError, /does not respond to :\[\]/)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context "with a hash" do
|
51
|
-
it "raises an ArgumentError if trying to match more than one element" do
|
52
|
-
expect{
|
53
|
-
expect({:a => 'b', :b => 'b', :c => 'c'}).to start_with({:a => 'b', :b => 'b'})
|
54
|
-
}.to raise_error(ArgumentError, /does not have ordered elements/)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "expect(...).not_to start_with" do
|
60
|
-
context "with a string" do
|
61
|
-
it "passes if it does not match the start of the actual string" do
|
62
|
-
expect("this string").not_to start_with "that str"
|
63
|
-
end
|
64
|
-
|
65
|
-
it "fails if it does match the start of the actual string" do
|
66
|
-
expect {
|
67
|
-
expect("this string").not_to start_with "this str"
|
68
|
-
}.to fail_with("expected \"this string\" not to start with \"this str\"")
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context "with an array" do
|
73
|
-
it "passes if it is not the first element of the array" do
|
74
|
-
expect([0, 1, 2]).not_to start_with 2
|
75
|
-
end
|
76
|
-
|
77
|
-
it "passes if the first elements of the array do not match" do
|
78
|
-
expect([0, 1, 2]).not_to start_with 1, 2
|
79
|
-
end
|
80
|
-
|
81
|
-
it "fails if it matches the first element of the array" do
|
82
|
-
expect {
|
83
|
-
expect([0, 1, 2]).not_to start_with 0
|
84
|
-
}.to fail_with("expected [0, 1, 2] not to start with 0")
|
85
|
-
end
|
86
|
-
|
87
|
-
it "fails if it the first elements of the array match" do
|
88
|
-
expect {
|
89
|
-
expect([0, 1, 2]).not_to start_with 0, 1
|
90
|
-
}.to fail_with("expected [0, 1, 2] not to start with [0, 1]")
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
describe "expect(...).to end_with" do
|
96
|
-
it_behaves_like "an RSpec matcher", :valid_value => "ab", :invalid_value => "bc" do
|
97
|
-
let(:matcher) { end_with("b") }
|
98
|
-
end
|
99
|
-
|
100
|
-
context "with a string" do
|
101
|
-
it "passes if it matches the end of the actual string" do
|
102
|
-
expect("this string").to end_with "is string"
|
103
|
-
end
|
104
|
-
|
105
|
-
it "fails if it does not match the end of the actual string" do
|
106
|
-
expect {
|
107
|
-
expect("this string").to end_with "is stringy"
|
108
|
-
}.to fail_with("expected \"this string\" to end with \"is stringy\"")
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
context "with an array" do
|
113
|
-
it "passes if it is the last element of the array" do
|
114
|
-
expect([0, 1, 2]).to end_with 2
|
115
|
-
end
|
116
|
-
|
117
|
-
it "passes if the last elements of the array match" do
|
118
|
-
expect([0, 1, 2]).to end_with [1, 2]
|
119
|
-
end
|
120
|
-
|
121
|
-
it "fails if it does not match the last element of the array" do
|
122
|
-
expect {
|
123
|
-
expect([0, 1, 2]).to end_with 1
|
124
|
-
}.to fail_with("expected [0, 1, 2] to end with 1")
|
125
|
-
end
|
126
|
-
|
127
|
-
it "fails if it the last elements of the array do not match" do
|
128
|
-
expect {
|
129
|
-
expect([0, 1, 2]).to end_with [0, 1]
|
130
|
-
}.to fail_with("expected [0, 1, 2] to end with [0, 1]")
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
context "with an object that does not respond to :[]" do
|
135
|
-
it "raises an error if expected value can't be indexed'" do
|
136
|
-
expect {
|
137
|
-
expect(Object.new).to end_with 0
|
138
|
-
}.to raise_error(ArgumentError, /does not respond to :\[\]/)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
context "with a hash" do
|
143
|
-
it "raises an ArgumentError if trying to match more than one element" do
|
144
|
-
expect{
|
145
|
-
expect({:a => 'b', :b => 'b', :c => 'c'}).to end_with({:a => 'b', :b =>'b'})
|
146
|
-
}.to raise_error(ArgumentError, /does not have ordered elements/)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
end
|
151
|
-
|
152
|
-
describe "expect(...).not_to end_with" do
|
153
|
-
context "with a sting" do
|
154
|
-
it "passes if it does not match the end of the actual string" do
|
155
|
-
expect("this string").not_to end_with "stringy"
|
156
|
-
end
|
157
|
-
|
158
|
-
it "fails if it matches the end of the actual string" do
|
159
|
-
expect {
|
160
|
-
expect("this string").not_to end_with "string"
|
161
|
-
}.to fail_with("expected \"this string\" not to end with \"string\"")
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
context "an array" do
|
166
|
-
it "passes if it is not the last element of the array" do
|
167
|
-
expect([0, 1, 2]).not_to end_with 1
|
168
|
-
end
|
169
|
-
|
170
|
-
it "passes if the last elements of the array do not match" do
|
171
|
-
expect([0, 1, 2]).not_to end_with [0, 1]
|
172
|
-
end
|
173
|
-
|
174
|
-
it "fails if it matches the last element of the array" do
|
175
|
-
expect {
|
176
|
-
expect([0, 1, 2]).not_to end_with 2
|
177
|
-
}.to fail_with("expected [0, 1, 2] not to end with 2")
|
178
|
-
end
|
179
|
-
|
180
|
-
it "fails if it the last elements of the array match" do
|
181
|
-
expect {
|
182
|
-
expect([0, 1, 2]).not_to end_with [1, 2]
|
183
|
-
}.to fail_with("expected [0, 1, 2] not to end with [1, 2]")
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
@@ -1,116 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module RSpec::Matchers::BuiltIn
|
4
|
-
describe ThrowSymbol do
|
5
|
-
it_behaves_like("an RSpec matcher", :valid_value => lambda { throw :foo },
|
6
|
-
:invalid_value => lambda { }) do
|
7
|
-
let(:matcher) { throw_symbol(:foo) }
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "with no args" do
|
11
|
-
before(:each) { @matcher = throw_symbol }
|
12
|
-
|
13
|
-
it "matches if any Symbol is thrown" do
|
14
|
-
expect(@matcher.matches?(lambda{ throw :sym })).to be_true
|
15
|
-
end
|
16
|
-
it "matches if any Symbol is thrown with an arg" do
|
17
|
-
expect(@matcher.matches?(lambda{ throw :sym, "argument" })).to be_true
|
18
|
-
end
|
19
|
-
it "does not match if no Symbol is thrown" do
|
20
|
-
expect(@matcher.matches?(lambda{ })).to be_false
|
21
|
-
end
|
22
|
-
it "provides a failure message" do
|
23
|
-
@matcher.matches?(lambda{})
|
24
|
-
expect(@matcher.failure_message_for_should).to eq "expected a Symbol to be thrown, got nothing"
|
25
|
-
end
|
26
|
-
it "provides a negative failure message" do
|
27
|
-
@matcher.matches?(lambda{ throw :sym})
|
28
|
-
expect(@matcher.failure_message_for_should_not).to eq "expected no Symbol to be thrown, got :sym"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "with a symbol" do
|
33
|
-
before(:each) { @matcher = throw_symbol(:sym) }
|
34
|
-
|
35
|
-
it "matches if correct Symbol is thrown" do
|
36
|
-
expect(@matcher.matches?(lambda{ throw :sym })).to be_true
|
37
|
-
end
|
38
|
-
it "matches if correct Symbol is thrown with an arg" do
|
39
|
-
expect(@matcher.matches?(lambda{ throw :sym, "argument" })).to be_true
|
40
|
-
end
|
41
|
-
it "does not match if no Symbol is thrown" do
|
42
|
-
expect(@matcher.matches?(lambda{ })).to be_false
|
43
|
-
end
|
44
|
-
it "does not match if correct Symbol is thrown" do
|
45
|
-
expect(@matcher.matches?(lambda{ throw :other_sym })).to be_false
|
46
|
-
end
|
47
|
-
it "provides a failure message when no Symbol is thrown" do
|
48
|
-
@matcher.matches?(lambda{})
|
49
|
-
expect(@matcher.failure_message_for_should).to eq "expected :sym to be thrown, got nothing"
|
50
|
-
end
|
51
|
-
it "provides a failure message when wrong Symbol is thrown" do
|
52
|
-
@matcher.matches?(lambda{ throw :other_sym })
|
53
|
-
expect(@matcher.failure_message_for_should).to eq "expected :sym to be thrown, got :other_sym"
|
54
|
-
end
|
55
|
-
it "provides a negative failure message" do
|
56
|
-
@matcher.matches?(lambda{ throw :sym })
|
57
|
-
expect(@matcher.failure_message_for_should_not).to eq "expected :sym not to be thrown, got :sym"
|
58
|
-
end
|
59
|
-
it "only matches NameErrors raised by uncaught throws" do
|
60
|
-
expect {
|
61
|
-
expect(@matcher.matches?(lambda{ sym })).to be_false
|
62
|
-
}.to raise_error(NameError)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe "with a symbol and an arg" do
|
67
|
-
before(:each) { @matcher = throw_symbol(:sym, "a") }
|
68
|
-
|
69
|
-
it "matches if correct Symbol and args are thrown" do
|
70
|
-
expect(@matcher.matches?(lambda{ throw :sym, "a" })).to be_true
|
71
|
-
end
|
72
|
-
it "does not match if nothing is thrown" do
|
73
|
-
expect(@matcher.matches?(lambda{ })).to be_false
|
74
|
-
end
|
75
|
-
it "does not match if other Symbol is thrown" do
|
76
|
-
expect(@matcher.matches?(lambda{ throw :other_sym, "a" })).to be_false
|
77
|
-
end
|
78
|
-
it "does not match if no arg is thrown" do
|
79
|
-
expect(@matcher.matches?(lambda{ throw :sym })).to be_false
|
80
|
-
end
|
81
|
-
it "does not match if wrong arg is thrown" do
|
82
|
-
expect(@matcher.matches?(lambda{ throw :sym, "b" })).to be_false
|
83
|
-
end
|
84
|
-
it "provides a failure message when no Symbol is thrown" do
|
85
|
-
@matcher.matches?(lambda{})
|
86
|
-
expect(@matcher.failure_message_for_should).to eq %q[expected :sym with "a" to be thrown, got nothing]
|
87
|
-
end
|
88
|
-
it "provides a failure message when wrong Symbol is thrown" do
|
89
|
-
@matcher.matches?(lambda{ throw :other_sym })
|
90
|
-
expect(@matcher.failure_message_for_should).to eq %q[expected :sym with "a" to be thrown, got :other_sym]
|
91
|
-
end
|
92
|
-
it "provides a failure message when wrong arg is thrown" do
|
93
|
-
@matcher.matches?(lambda{ throw :sym, "b" })
|
94
|
-
expect(@matcher.failure_message_for_should).to eq %q[expected :sym with "a" to be thrown, got :sym with "b"]
|
95
|
-
end
|
96
|
-
it "provides a failure message when no arg is thrown" do
|
97
|
-
@matcher.matches?(lambda{ throw :sym })
|
98
|
-
expect(@matcher.failure_message_for_should).to eq %q[expected :sym with "a" to be thrown, got :sym with no argument]
|
99
|
-
end
|
100
|
-
it "provides a negative failure message" do
|
101
|
-
@matcher.matches?(lambda{ throw :sym })
|
102
|
-
expect(@matcher.failure_message_for_should_not).to eq %q[expected :sym with "a" not to be thrown, got :sym with no argument]
|
103
|
-
end
|
104
|
-
it "only matches NameErrors raised by uncaught throws" do
|
105
|
-
expect {
|
106
|
-
expect(@matcher.matches?(lambda{ sym })).to be_false
|
107
|
-
}.to raise_error(NameError)
|
108
|
-
end
|
109
|
-
it "raises other errors" do
|
110
|
-
expect {
|
111
|
-
@matcher.matches?(lambda { raise "Boom" })
|
112
|
-
}.to raise_error(/Boom/)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|