rspec-expectations 2.13.0 → 3.0.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 +15 -0
- checksums.yaml.gz.sig +0 -0
- data/Changelog.md +413 -23
- data/License.txt +1 -0
- data/README.md +109 -80
- data/lib/rspec/{matchers → expectations}/configuration.rb +44 -14
- data/lib/rspec/expectations/expectation_target.rb +71 -38
- data/lib/rspec/expectations/fail_with.rb +12 -44
- data/lib/rspec/expectations/handler.rb +135 -35
- data/lib/rspec/expectations/minitest_integration.rb +16 -0
- data/lib/rspec/expectations/syntax.rb +60 -94
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/expectations.rb +46 -24
- data/lib/rspec/matchers/aliased_matcher.rb +41 -0
- data/lib/rspec/matchers/built_in/all.rb +78 -0
- data/lib/rspec/matchers/built_in/base_matcher.rb +63 -15
- data/lib/rspec/matchers/built_in/be.rb +170 -79
- data/lib/rspec/matchers/built_in/be_between.rb +77 -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 +40 -16
- data/lib/rspec/matchers/built_in/change.rb +275 -74
- data/lib/rspec/matchers/built_in/compound.rb +122 -0
- data/lib/rspec/matchers/built_in/contain_exactly.rb +256 -0
- data/lib/rspec/matchers/built_in/cover.rb +3 -0
- data/lib/rspec/matchers/built_in/eq.rb +60 -6
- data/lib/rspec/matchers/built_in/eql.rb +17 -5
- data/lib/rspec/matchers/built_in/equal.rb +55 -21
- data/lib/rspec/matchers/built_in/exist.rb +74 -10
- data/lib/rspec/matchers/built_in/has.rb +71 -15
- data/lib/rspec/matchers/built_in/include.rb +58 -29
- data/lib/rspec/matchers/built_in/match.rb +19 -1
- data/lib/rspec/matchers/built_in/operators.rb +119 -0
- data/lib/rspec/matchers/built_in/output.rb +150 -0
- data/lib/rspec/matchers/built_in/raise_error.rb +91 -33
- data/lib/rspec/matchers/built_in/respond_to.rb +42 -20
- data/lib/rspec/matchers/built_in/satisfy.rb +19 -3
- data/lib/rspec/matchers/built_in/start_and_end_with.rb +54 -18
- data/lib/rspec/matchers/built_in/throw_symbol.rb +38 -8
- data/lib/rspec/matchers/built_in/yield.rb +237 -55
- data/lib/rspec/matchers/built_in.rb +45 -33
- data/lib/rspec/matchers/composable.rb +179 -0
- data/lib/rspec/matchers/dsl.rb +362 -5
- data/lib/rspec/matchers/generated_descriptions.rb +13 -6
- data/lib/rspec/matchers/matcher_delegator.rb +37 -0
- data/lib/rspec/matchers/pretty.rb +33 -20
- data/lib/rspec/matchers.rb +450 -227
- data.tar.gz.sig +1 -0
- metadata +100 -215
- metadata.gz.sig +0 -0
- data/features/README.md +0 -49
- data/features/Upgrade.md +0 -53
- data/features/built_in_matchers/README.md +0 -90
- data/features/built_in_matchers/be.feature +0 -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 -146
- data/features/custom_matchers/access_running_example.feature +0 -53
- data/features/custom_matchers/define_diffable_matcher.feature +0 -27
- data/features/custom_matchers/define_matcher.feature +0 -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 -5
- data/features/syntax_configuration.feature +0 -68
- data/features/test_frameworks/test_unit.feature +0 -46
- data/lib/rspec/expectations/deprecation.rb +0 -38
- data/lib/rspec/expectations/differ.rb +0 -115
- data/lib/rspec/expectations/errors.rb +0 -9
- data/lib/rspec/expectations/extensions/array.rb +0 -9
- data/lib/rspec/expectations/extensions/object.rb +0 -39
- data/lib/rspec/expectations/extensions.rb +0 -2
- data/lib/rspec/matchers/be_close.rb +0 -9
- data/lib/rspec/matchers/built_in/have.rb +0 -108
- data/lib/rspec/matchers/built_in/match_array.rb +0 -51
- data/lib/rspec/matchers/compatibility.rb +0 -14
- 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-expectations.rb +0 -1
- data/spec/rspec/expectations/differ_spec.rb +0 -170
- data/spec/rspec/expectations/expectation_target_spec.rb +0 -75
- data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
- data/spec/rspec/expectations/fail_with_spec.rb +0 -95
- data/spec/rspec/expectations/handler_spec.rb +0 -206
- data/spec/rspec/expectations/syntax_spec.rb +0 -97
- 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 -129
- data/spec/rspec/matchers/change_spec.rb +0 -542
- data/spec/rspec/matchers/configuration_spec.rb +0 -238
- data/spec/rspec/matchers/cover_spec.rb +0 -69
- data/spec/rspec/matchers/description_generation_spec.rb +0 -176
- data/spec/rspec/matchers/dsl_spec.rb +0 -57
- data/spec/rspec/matchers/eq_spec.rb +0 -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 -445
- 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 -395
- 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 -437
- 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,516 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe "expect(...).to be_predicate" do
|
|
4
|
-
it "passes when actual returns true for :predicate?" do
|
|
5
|
-
actual = stub("actual", :happy? => true)
|
|
6
|
-
expect(actual).to be_happy
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
it "passes when actual returns true for :predicates? (present tense)" do
|
|
10
|
-
actual = stub("actual", :exists? => true, :exist? => true)
|
|
11
|
-
expect(actual).to be_exist
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "fails when actual returns false for :predicate?" do
|
|
15
|
-
actual = stub("actual", :happy? => false)
|
|
16
|
-
expect {
|
|
17
|
-
expect(actual).to be_happy
|
|
18
|
-
}.to fail_with("expected happy? to return true, got false")
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "fails when actual returns false for :predicate?" do
|
|
22
|
-
actual = stub("actual", :happy? => nil)
|
|
23
|
-
expect {
|
|
24
|
-
expect(actual).to be_happy
|
|
25
|
-
}.to fail_with("expected happy? to return true, got nil")
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it "fails when actual does not respond to :predicate?" do
|
|
29
|
-
expect {
|
|
30
|
-
expect(Object.new).to be_happy
|
|
31
|
-
}.to raise_error(NameError, /happy\?/)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it "fails on error other than NameError" do
|
|
35
|
-
actual = stub("actual")
|
|
36
|
-
actual.should_receive(:foo?).and_raise("aaaah")
|
|
37
|
-
expect {
|
|
38
|
-
expect(actual).to be_foo
|
|
39
|
-
}.to raise_error(/aaaah/)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it "fails on error other than NameError (with the present tense predicate)" do
|
|
43
|
-
actual = Object.new
|
|
44
|
-
actual.should_receive(:foos?).and_raise("aaaah")
|
|
45
|
-
expect {
|
|
46
|
-
expect(actual).to be_foo
|
|
47
|
-
}.to raise_error(/aaaah/)
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
describe "expect(...).not_to be_predicate" do
|
|
52
|
-
it "passes when actual returns false for :sym?" do
|
|
53
|
-
actual = stub("actual", :happy? => false)
|
|
54
|
-
expect(actual).not_to be_happy
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
it "passes when actual returns nil for :sym?" do
|
|
58
|
-
actual = stub("actual", :happy? => nil)
|
|
59
|
-
expect(actual).not_to be_happy
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
it "fails when actual returns true for :sym?" do
|
|
63
|
-
actual = stub("actual", :happy? => true)
|
|
64
|
-
expect {
|
|
65
|
-
expect(actual).not_to be_happy
|
|
66
|
-
}.to fail_with("expected happy? to return false, got true")
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it "fails when actual does not respond to :sym?" do
|
|
70
|
-
expect {
|
|
71
|
-
expect(Object.new).not_to be_happy
|
|
72
|
-
}.to raise_error(NameError)
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
describe "expect(...).to be_predicate(*args)" do
|
|
77
|
-
it "passes when actual returns true for :predicate?(*args)" do
|
|
78
|
-
actual = mock("actual")
|
|
79
|
-
actual.should_receive(:older_than?).with(3).and_return(true)
|
|
80
|
-
expect(actual).to be_older_than(3)
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
it "fails when actual returns false for :predicate?(*args)" do
|
|
84
|
-
actual = mock("actual")
|
|
85
|
-
actual.should_receive(:older_than?).with(3).and_return(false)
|
|
86
|
-
expect {
|
|
87
|
-
expect(actual).to be_older_than(3)
|
|
88
|
-
}.to fail_with("expected older_than?(3) to return true, got false")
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
it "fails when actual does not respond to :predicate?" do
|
|
92
|
-
expect {
|
|
93
|
-
expect(Object.new).to be_older_than(3)
|
|
94
|
-
}.to raise_error(NameError)
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
describe "expect(...).not_to be_predicate(*args)" do
|
|
99
|
-
it "passes when actual returns false for :predicate?(*args)" do
|
|
100
|
-
actual = mock("actual")
|
|
101
|
-
actual.should_receive(:older_than?).with(3).and_return(false)
|
|
102
|
-
expect(actual).not_to be_older_than(3)
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
it "fails when actual returns true for :predicate?(*args)" do
|
|
106
|
-
actual = mock("actual")
|
|
107
|
-
actual.should_receive(:older_than?).with(3).and_return(true)
|
|
108
|
-
expect {
|
|
109
|
-
expect(actual).not_to be_older_than(3)
|
|
110
|
-
}.to fail_with("expected older_than?(3) to return false, got true")
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
it "fails when actual does not respond to :predicate?" do
|
|
114
|
-
expect {
|
|
115
|
-
expect(Object.new).not_to be_older_than(3)
|
|
116
|
-
}.to raise_error(NameError)
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
describe "expect(...).to be_predicate(&block)" do
|
|
121
|
-
it "passes when actual returns true for :predicate?(&block)" do
|
|
122
|
-
actual = mock("actual")
|
|
123
|
-
delegate = mock("delegate")
|
|
124
|
-
actual.should_receive(:happy?).and_yield
|
|
125
|
-
delegate.should_receive(:check_happy).and_return(true)
|
|
126
|
-
expect(actual).to be_happy { delegate.check_happy }
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
it "fails when actual returns false for :predicate?(&block)" do
|
|
130
|
-
actual = mock("actual")
|
|
131
|
-
delegate = mock("delegate")
|
|
132
|
-
actual.should_receive(:happy?).and_yield
|
|
133
|
-
delegate.should_receive(:check_happy).and_return(false)
|
|
134
|
-
expect {
|
|
135
|
-
expect(actual).to be_happy { delegate.check_happy }
|
|
136
|
-
}.to fail_with("expected happy? to return true, got false")
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
it "fails when actual does not respond to :predicate?" do
|
|
140
|
-
delegate = mock("delegate", :check_happy => true)
|
|
141
|
-
expect {
|
|
142
|
-
expect(Object.new).to be_happy { delegate.check_happy }
|
|
143
|
-
}.to raise_error(NameError)
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
describe "expect(...).not_to be_predicate(&block)" do
|
|
148
|
-
it "passes when actual returns false for :predicate?(&block)" do
|
|
149
|
-
actual = mock("actual")
|
|
150
|
-
delegate = mock("delegate")
|
|
151
|
-
actual.should_receive(:happy?).and_yield
|
|
152
|
-
delegate.should_receive(:check_happy).and_return(false)
|
|
153
|
-
expect(actual).not_to be_happy { delegate.check_happy }
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
it "fails when actual returns true for :predicate?(&block)" do
|
|
157
|
-
actual = mock("actual")
|
|
158
|
-
delegate = mock("delegate")
|
|
159
|
-
actual.should_receive(:happy?).and_yield
|
|
160
|
-
delegate.should_receive(:check_happy).and_return(true)
|
|
161
|
-
expect {
|
|
162
|
-
expect(actual).not_to be_happy { delegate.check_happy }
|
|
163
|
-
}.to fail_with("expected happy? to return false, got true")
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
it "fails when actual does not respond to :predicate?" do
|
|
167
|
-
delegate = mock("delegate", :check_happy => true)
|
|
168
|
-
expect {
|
|
169
|
-
expect(Object.new).not_to be_happy { delegate.check_happy }
|
|
170
|
-
}.to raise_error(NameError)
|
|
171
|
-
end
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
describe "expect(...).to be_predicate(*args, &block)" do
|
|
175
|
-
it "passes when actual returns true for :predicate?(*args, &block)" do
|
|
176
|
-
actual = mock("actual")
|
|
177
|
-
delegate = mock("delegate")
|
|
178
|
-
actual.should_receive(:older_than?).with(3).and_yield(3)
|
|
179
|
-
delegate.should_receive(:check_older_than).with(3).and_return(true)
|
|
180
|
-
expect(actual).to be_older_than(3) { |age| delegate.check_older_than(age) }
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
it "fails when actual returns false for :predicate?(*args, &block)" do
|
|
184
|
-
actual = mock("actual")
|
|
185
|
-
delegate = mock("delegate")
|
|
186
|
-
actual.should_receive(:older_than?).with(3).and_yield(3)
|
|
187
|
-
delegate.should_receive(:check_older_than).with(3).and_return(false)
|
|
188
|
-
expect {
|
|
189
|
-
expect(actual).to be_older_than(3) { |age| delegate.check_older_than(age) }
|
|
190
|
-
}.to fail_with("expected older_than?(3) to return true, got false")
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
it "fails when actual does not respond to :predicate?" do
|
|
194
|
-
delegate = mock("delegate", :check_older_than => true)
|
|
195
|
-
expect {
|
|
196
|
-
expect(Object.new).to be_older_than(3) { |age| delegate.check_older_than(age) }
|
|
197
|
-
}.to raise_error(NameError)
|
|
198
|
-
end
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
describe "expect(...).not_to be_predicate(*args, &block)" do
|
|
202
|
-
it "passes when actual returns false for :predicate?(*args, &block)" do
|
|
203
|
-
actual = mock("actual")
|
|
204
|
-
delegate = mock("delegate")
|
|
205
|
-
actual.should_receive(:older_than?).with(3).and_yield(3)
|
|
206
|
-
delegate.should_receive(:check_older_than).with(3).and_return(false)
|
|
207
|
-
expect(actual).not_to be_older_than(3) { |age| delegate.check_older_than(age) }
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
it "fails when actual returns true for :predicate?(*args, &block)" do
|
|
211
|
-
actual = mock("actual")
|
|
212
|
-
delegate = mock("delegate")
|
|
213
|
-
actual.should_receive(:older_than?).with(3).and_yield(3)
|
|
214
|
-
delegate.should_receive(:check_older_than).with(3).and_return(true)
|
|
215
|
-
expect {
|
|
216
|
-
expect(actual).not_to be_older_than(3) { |age| delegate.check_older_than(age) }
|
|
217
|
-
}.to fail_with("expected older_than?(3) to return false, got true")
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
it "fails when actual does not respond to :predicate?" do
|
|
221
|
-
delegate = mock("delegate", :check_older_than => true)
|
|
222
|
-
expect {
|
|
223
|
-
expect(Object.new).not_to be_older_than(3) { |age| delegate.check_older_than(age) }
|
|
224
|
-
}.to raise_error(NameError)
|
|
225
|
-
end
|
|
226
|
-
end
|
|
227
|
-
|
|
228
|
-
describe "expect(...).to be_true" do
|
|
229
|
-
it "passes when actual equal?(true)" do
|
|
230
|
-
expect(true).to be_true
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
it "passes when actual is 1" do
|
|
234
|
-
expect(1).to be_true
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
it "fails when actual equal?(false)" do
|
|
238
|
-
expect {
|
|
239
|
-
expect(false).to be_true
|
|
240
|
-
}.to fail_with("expected: true value\n got: false")
|
|
241
|
-
end
|
|
242
|
-
end
|
|
243
|
-
|
|
244
|
-
describe "expect(...).to be_false" do
|
|
245
|
-
it "passes when actual equal?(false)" do
|
|
246
|
-
expect(false).to be_false
|
|
247
|
-
end
|
|
248
|
-
|
|
249
|
-
it "passes when actual equal?(nil)" do
|
|
250
|
-
expect(nil).to be_false
|
|
251
|
-
end
|
|
252
|
-
|
|
253
|
-
it "fails when actual equal?(true)" do
|
|
254
|
-
expect {
|
|
255
|
-
expect(true).to be_false
|
|
256
|
-
}.to fail_with("expected: false value\n got: true")
|
|
257
|
-
end
|
|
258
|
-
end
|
|
259
|
-
|
|
260
|
-
describe "expect(...).to be_nil" do
|
|
261
|
-
it "passes when actual is nil" do
|
|
262
|
-
expect(nil).to be_nil
|
|
263
|
-
end
|
|
264
|
-
|
|
265
|
-
it "fails when actual is not nil" do
|
|
266
|
-
expect {
|
|
267
|
-
expect(:not_nil).to be_nil
|
|
268
|
-
}.to fail_with(/^expected: nil/)
|
|
269
|
-
end
|
|
270
|
-
end
|
|
271
|
-
|
|
272
|
-
describe "expect(...).not_to be_nil" do
|
|
273
|
-
it "passes when actual is not nil" do
|
|
274
|
-
expect(:not_nil).not_to be_nil
|
|
275
|
-
end
|
|
276
|
-
|
|
277
|
-
it "fails when actual is nil" do
|
|
278
|
-
expect {
|
|
279
|
-
expect(nil).not_to be_nil
|
|
280
|
-
}.to fail_with(/^expected: not nil/)
|
|
281
|
-
end
|
|
282
|
-
end
|
|
283
|
-
|
|
284
|
-
describe "expect(...).to be <" do
|
|
285
|
-
it "passes when < operator returns true" do
|
|
286
|
-
expect(3).to be < 4
|
|
287
|
-
end
|
|
288
|
-
|
|
289
|
-
it "fails when < operator returns false" do
|
|
290
|
-
expect {
|
|
291
|
-
expect(3).to be < 3
|
|
292
|
-
}.to fail_with("expected: < 3\n got: 3")
|
|
293
|
-
end
|
|
294
|
-
|
|
295
|
-
it "describes itself" do
|
|
296
|
-
expect(be.<(4).description).to eq "be < 4"
|
|
297
|
-
end
|
|
298
|
-
end
|
|
299
|
-
|
|
300
|
-
describe "expect(...).to be <=" do
|
|
301
|
-
it "passes when <= operator returns true" do
|
|
302
|
-
expect(3).to be <= 4
|
|
303
|
-
expect(4).to be <= 4
|
|
304
|
-
end
|
|
305
|
-
|
|
306
|
-
it "fails when <= operator returns false" do
|
|
307
|
-
expect {
|
|
308
|
-
expect(3).to be <= 2
|
|
309
|
-
}.to fail_with("expected: <= 2\n got: 3")
|
|
310
|
-
end
|
|
311
|
-
end
|
|
312
|
-
|
|
313
|
-
describe "expect(...).to be >=" do
|
|
314
|
-
it "passes when >= operator returns true" do
|
|
315
|
-
expect(4).to be >= 4
|
|
316
|
-
expect(5).to be >= 4
|
|
317
|
-
end
|
|
318
|
-
|
|
319
|
-
it "fails when >= operator returns false" do
|
|
320
|
-
expect {
|
|
321
|
-
expect(3).to be >= 4
|
|
322
|
-
}.to fail_with("expected: >= 4\n got: 3")
|
|
323
|
-
end
|
|
324
|
-
end
|
|
325
|
-
|
|
326
|
-
describe "expect(...).to be >" do
|
|
327
|
-
it "passes when > operator returns true" do
|
|
328
|
-
expect(5).to be > 4
|
|
329
|
-
end
|
|
330
|
-
|
|
331
|
-
it "fails when > operator returns false" do
|
|
332
|
-
expect {
|
|
333
|
-
expect(3).to be > 4
|
|
334
|
-
}.to fail_with("expected: > 4\n got: 3")
|
|
335
|
-
end
|
|
336
|
-
end
|
|
337
|
-
|
|
338
|
-
describe "expect(...).to be ==" do
|
|
339
|
-
it "passes when == operator returns true" do
|
|
340
|
-
expect(5).to be == 5
|
|
341
|
-
end
|
|
342
|
-
|
|
343
|
-
it "fails when == operator returns false" do
|
|
344
|
-
expect {
|
|
345
|
-
expect(3).to be == 4
|
|
346
|
-
}.to fail_with("expected: == 4\n got: 3")
|
|
347
|
-
end
|
|
348
|
-
|
|
349
|
-
it 'works when the target overrides `#send`' do
|
|
350
|
-
klass = Struct.new(:message) do
|
|
351
|
-
def send
|
|
352
|
-
:message_sent
|
|
353
|
-
end
|
|
354
|
-
end
|
|
355
|
-
|
|
356
|
-
msg_1 = klass.new("hello")
|
|
357
|
-
msg_2 = klass.new("hello")
|
|
358
|
-
expect(msg_1).to be == msg_2
|
|
359
|
-
end
|
|
360
|
-
end
|
|
361
|
-
|
|
362
|
-
describe "expect(...).to be =~" do
|
|
363
|
-
it "passes when =~ operator returns true" do
|
|
364
|
-
expect("a string").to be =~ /str/
|
|
365
|
-
end
|
|
366
|
-
|
|
367
|
-
it "fails when =~ operator returns false" do
|
|
368
|
-
expect {
|
|
369
|
-
expect("a string").to be =~ /blah/
|
|
370
|
-
}.to fail_with(%Q|expected: =~ /blah/\n got: "a string"|)
|
|
371
|
-
end
|
|
372
|
-
end
|
|
373
|
-
|
|
374
|
-
describe "should be =~", :uses_should do
|
|
375
|
-
it "passes when =~ operator returns true" do
|
|
376
|
-
"a string".should be =~ /str/
|
|
377
|
-
end
|
|
378
|
-
|
|
379
|
-
it "fails when =~ operator returns false" do
|
|
380
|
-
expect {
|
|
381
|
-
"a string".should be =~ /blah/
|
|
382
|
-
}.to fail_with(%Q|expected: =~ /blah/\n got: "a string"|)
|
|
383
|
-
end
|
|
384
|
-
end
|
|
385
|
-
|
|
386
|
-
describe "expect(...).to be ===" do
|
|
387
|
-
it "passes when === operator returns true" do
|
|
388
|
-
expect(Hash).to be === Hash.new
|
|
389
|
-
end
|
|
390
|
-
|
|
391
|
-
it "fails when === operator returns false" do
|
|
392
|
-
expect {
|
|
393
|
-
expect(Hash).to be === "not a hash"
|
|
394
|
-
}.to fail_with(%[expected: === "not a hash"\n got: Hash])
|
|
395
|
-
end
|
|
396
|
-
end
|
|
397
|
-
|
|
398
|
-
describe "expect(...).not_to with operators" do
|
|
399
|
-
it "coaches user to stop using operators with expect().not_to" do
|
|
400
|
-
expect {
|
|
401
|
-
expect(5).not_to be < 6
|
|
402
|
-
}.to raise_error(/`expect\(actual\).not_to be < 6` not only FAILED,\nit is a bit confusing./m)
|
|
403
|
-
end
|
|
404
|
-
end
|
|
405
|
-
|
|
406
|
-
describe "should_not with operators", :uses_only_should do
|
|
407
|
-
it "coaches user to stop using operators with should_not" do
|
|
408
|
-
lambda {
|
|
409
|
-
5.should_not be < 6
|
|
410
|
-
}.should raise_error(/`actual.should_not be < 6` not only FAILED,\nit is a bit confusing./m)
|
|
411
|
-
end
|
|
412
|
-
end
|
|
413
|
-
|
|
414
|
-
describe "expect(...).to be" do
|
|
415
|
-
it "passes if actual is truthy" do
|
|
416
|
-
expect(true).to be
|
|
417
|
-
expect(1).to be
|
|
418
|
-
end
|
|
419
|
-
|
|
420
|
-
it "fails if actual is false" do
|
|
421
|
-
expect {
|
|
422
|
-
expect(false).to be
|
|
423
|
-
}.to fail_with("expected false to evaluate to true")
|
|
424
|
-
end
|
|
425
|
-
|
|
426
|
-
it "fails if actual is nil" do
|
|
427
|
-
expect {
|
|
428
|
-
expect(nil).to be
|
|
429
|
-
}.to fail_with("expected nil to evaluate to true")
|
|
430
|
-
end
|
|
431
|
-
|
|
432
|
-
it "describes itself" do
|
|
433
|
-
expect(be.description).to eq "be"
|
|
434
|
-
end
|
|
435
|
-
end
|
|
436
|
-
|
|
437
|
-
describe "expect(...).not_to be" do
|
|
438
|
-
it "passes if actual is falsy" do
|
|
439
|
-
expect(false).not_to be
|
|
440
|
-
expect(nil).not_to be
|
|
441
|
-
end
|
|
442
|
-
|
|
443
|
-
it "fails on true" do
|
|
444
|
-
expect {
|
|
445
|
-
expect(true).not_to be
|
|
446
|
-
}.to fail_with("expected true to evaluate to false")
|
|
447
|
-
end
|
|
448
|
-
end
|
|
449
|
-
|
|
450
|
-
describe "expect(...).to be(value)" do
|
|
451
|
-
it "delegates to equal" do
|
|
452
|
-
matcher = equal(5)
|
|
453
|
-
self.should_receive(:equal).with(5).and_return(matcher)
|
|
454
|
-
expect(5).to be(5)
|
|
455
|
-
end
|
|
456
|
-
end
|
|
457
|
-
|
|
458
|
-
describe "expect(...).not_to be(value)" do
|
|
459
|
-
it "delegates to equal" do
|
|
460
|
-
matcher = equal(4)
|
|
461
|
-
self.should_receive(:equal).with(4).and_return(matcher)
|
|
462
|
-
expect(5).not_to be(4)
|
|
463
|
-
end
|
|
464
|
-
end
|
|
465
|
-
|
|
466
|
-
describe "'expect(...).to be' with operator" do
|
|
467
|
-
it "includes 'be' in the description" do
|
|
468
|
-
expect((be > 6).description).to match /be > 6/
|
|
469
|
-
expect((be >= 6).description).to match /be >= 6/
|
|
470
|
-
expect((be <= 6).description).to match /be <= 6/
|
|
471
|
-
expect((be < 6).description).to match /be < 6/
|
|
472
|
-
end
|
|
473
|
-
end
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
describe "arbitrary predicate with DelegateClass" do
|
|
477
|
-
it "accesses methods defined in the delegating class (LH[#48])" do
|
|
478
|
-
require 'delegate'
|
|
479
|
-
class ArrayDelegate < DelegateClass(Array)
|
|
480
|
-
def initialize(array)
|
|
481
|
-
@internal_array = array
|
|
482
|
-
super(@internal_array)
|
|
483
|
-
end
|
|
484
|
-
|
|
485
|
-
def large?
|
|
486
|
-
@internal_array.size >= 5
|
|
487
|
-
end
|
|
488
|
-
end
|
|
489
|
-
|
|
490
|
-
delegate = ArrayDelegate.new([1,2,3,4,5,6])
|
|
491
|
-
expect(delegate).to be_large
|
|
492
|
-
end
|
|
493
|
-
end
|
|
494
|
-
|
|
495
|
-
describe "be_a, be_an" do
|
|
496
|
-
it "passes when class matches" do
|
|
497
|
-
expect("foobar").to be_a(String)
|
|
498
|
-
expect([1,2,3]).to be_an(Array)
|
|
499
|
-
end
|
|
500
|
-
|
|
501
|
-
it "fails when class does not match" do
|
|
502
|
-
expect("foobar").not_to be_a(Hash)
|
|
503
|
-
expect([1,2,3]).not_to be_an(Integer)
|
|
504
|
-
end
|
|
505
|
-
end
|
|
506
|
-
|
|
507
|
-
describe "be_an_instance_of" do
|
|
508
|
-
it "passes when direct class matches" do
|
|
509
|
-
expect(5).to be_an_instance_of(Fixnum)
|
|
510
|
-
end
|
|
511
|
-
|
|
512
|
-
it "fails when class is higher up hierarchy" do
|
|
513
|
-
expect(5).not_to be_an_instance_of(Numeric)
|
|
514
|
-
end
|
|
515
|
-
end
|
|
516
|
-
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module RSpec
|
|
4
|
-
module Matchers
|
|
5
|
-
describe "expect(actual).to be_within(delta).of(expected)" do
|
|
6
|
-
it_behaves_like "an RSpec matcher", :valid_value => 5, :invalid_value => -5 do
|
|
7
|
-
let(:matcher) { be_within(2).of(4.0) }
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
it "passes when actual == expected" do
|
|
11
|
-
expect(5.0).to be_within(0.5).of(5.0)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "passes when actual < (expected + delta)" do
|
|
15
|
-
expect(5.49).to be_within(0.5).of(5.0)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it "passes when actual > (expected - delta)" do
|
|
19
|
-
expect(4.51).to be_within(0.5).of(5.0)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it "passes when actual == (expected - delta)" do
|
|
23
|
-
expect(4.5).to be_within(0.5).of(5.0)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it "passes when actual == (expected + delta)" do
|
|
27
|
-
expect(5.5).to be_within(0.5).of(5.0)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it "fails when actual < (expected - delta)" do
|
|
31
|
-
expect {
|
|
32
|
-
expect(4.49).to be_within(0.5).of(5.0)
|
|
33
|
-
}.to fail_with("expected 4.49 to be within 0.5 of 5.0")
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it "fails when actual > (expected + delta)" do
|
|
37
|
-
expect {
|
|
38
|
-
expect(5.51).to be_within(0.5).of(5.0)
|
|
39
|
-
}.to fail_with("expected 5.51 to be within 0.5 of 5.0")
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it "works with Time" do
|
|
43
|
-
expect(Time.now).to be_within(0.1).of(Time.now)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it "provides a description" do
|
|
47
|
-
matcher = be_within(0.5).of(5.0)
|
|
48
|
-
matcher.matches?(5.1)
|
|
49
|
-
expect(matcher.description).to eq "be within 0.5 of 5.0"
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
it "raises an error if no expected value is given" do
|
|
53
|
-
expect {
|
|
54
|
-
expect(5.1).to be_within(0.5)
|
|
55
|
-
}.to raise_error(ArgumentError, /must set an expected value using #of/)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it "raises an error if the actual does not respond to :-" do
|
|
59
|
-
expect {
|
|
60
|
-
expect(nil).to be_within(0.1).of(0)
|
|
61
|
-
}.to raise_error(ArgumentError, /The actual value \(nil\) must respond to `-`/)
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
describe "expect(actual).to be_within(delta).percent_of(expected)" do
|
|
66
|
-
it "passes when actual is within the given percent variance" do
|
|
67
|
-
expect(9.0).to be_within(10).percent_of(10.0)
|
|
68
|
-
expect(10.0).to be_within(10).percent_of(10.0)
|
|
69
|
-
expect(11.0).to be_within(10).percent_of(10.0)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
it "fails when actual is outside the given percent variance" do
|
|
73
|
-
expect {
|
|
74
|
-
expect(8.9).to be_within(10).percent_of(10.0)
|
|
75
|
-
}.to fail_with("expected 8.9 to be within 10% of 10.0")
|
|
76
|
-
|
|
77
|
-
expect {
|
|
78
|
-
expect(11.1).to be_within(10).percent_of(10.0)
|
|
79
|
-
}.to fail_with("expected 11.1 to be within 10% of 10.0")
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
it "provides a description" do
|
|
83
|
-
matcher = be_within(0.5).percent_of(5.0)
|
|
84
|
-
matcher.matches?(5.1)
|
|
85
|
-
expect(matcher.description).to eq "be within 0.5% of 5.0"
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
describe "expect(actual).not_to be_within(delta).of(expected)" do
|
|
90
|
-
it "passes when actual < (expected - delta)" do
|
|
91
|
-
expect(4.49).not_to be_within(0.5).of(5.0)
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
it "passes when actual > (expected + delta)" do
|
|
95
|
-
expect(5.51).not_to be_within(0.5).of(5.0)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
it "fails when actual == expected" do
|
|
99
|
-
expect {
|
|
100
|
-
expect(5.0).not_to be_within(0.5).of(5.0)
|
|
101
|
-
}.to fail_with("expected 5.0 not to be within 0.5 of 5.0")
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
it "fails when actual < (expected + delta)" do
|
|
105
|
-
expect {
|
|
106
|
-
expect(5.49).not_to be_within(0.5).of(5.0)
|
|
107
|
-
}.to fail_with("expected 5.49 not to be within 0.5 of 5.0")
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
it "fails when actual > (expected - delta)" do
|
|
111
|
-
expect {
|
|
112
|
-
expect(4.51).not_to be_within(0.5).of(5.0)
|
|
113
|
-
}.to fail_with("expected 4.51 not to be within 0.5 of 5.0")
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
it "fails when actual == (expected - delta)" do
|
|
117
|
-
expect {
|
|
118
|
-
expect(4.5).not_to be_within(0.5).of(5.0)
|
|
119
|
-
}.to fail_with("expected 4.5 not to be within 0.5 of 5.0")
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
it "fails when actual == (expected + delta)" do
|
|
123
|
-
expect {
|
|
124
|
-
expect(5.5).not_to be_within(0.5).of(5.0)
|
|
125
|
-
}.to fail_with("expected 5.5 not to be within 0.5 of 5.0")
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
end
|