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,445 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'stringio'
|
|
3
|
-
|
|
4
|
-
describe "have matcher" do
|
|
5
|
-
let(:inflector) do
|
|
6
|
-
Class.new do
|
|
7
|
-
def self.pluralize(string)
|
|
8
|
-
string.to_s + 's'
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
before(:each) { stub_const("ActiveSupport::Inflector", inflector) }
|
|
14
|
-
|
|
15
|
-
def create_collection_owner_with(n)
|
|
16
|
-
owner = RSpec::Expectations::Helper::CollectionOwner.new
|
|
17
|
-
(1..n).each do |number|
|
|
18
|
-
owner.add_to_collection_with_length_method(number)
|
|
19
|
-
owner.add_to_collection_with_size_method(number)
|
|
20
|
-
owner.add_to_collection_with_count_method(number)
|
|
21
|
-
end
|
|
22
|
-
owner
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
describe "expect(...).to have(n).items" do
|
|
26
|
-
it_behaves_like "an RSpec matcher", :valid_value => [1, 2], :invalid_value => [1] do
|
|
27
|
-
let(:matcher) { have(2).items }
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it "passes if target has a collection of items with n members" do
|
|
31
|
-
owner = create_collection_owner_with(3)
|
|
32
|
-
expect(owner).to have(3).items_in_collection_with_length_method
|
|
33
|
-
expect(owner).to have(3).items_in_collection_with_size_method
|
|
34
|
-
expect(owner).to have(3).items_in_collection_with_count_method
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it "converts :no to 0" do
|
|
38
|
-
owner = create_collection_owner_with(0)
|
|
39
|
-
expect(owner).to have(:no).items_in_collection_with_length_method
|
|
40
|
-
expect(owner).to have(:no).items_in_collection_with_size_method
|
|
41
|
-
expect(owner).to have(:no).items_in_collection_with_count_method
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it "converts a String argument to Integer" do
|
|
45
|
-
owner = create_collection_owner_with(3)
|
|
46
|
-
expect(owner).to have('3').items_in_collection_with_length_method
|
|
47
|
-
expect(owner).to have('3').items_in_collection_with_size_method
|
|
48
|
-
expect(owner).to have('3').items_in_collection_with_count_method
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it "fails if target has a collection of items with < n members" do
|
|
52
|
-
owner = create_collection_owner_with(3)
|
|
53
|
-
expect {
|
|
54
|
-
expect(owner).to have(4).items_in_collection_with_length_method
|
|
55
|
-
}.to fail_with("expected 4 items_in_collection_with_length_method, got 3")
|
|
56
|
-
expect {
|
|
57
|
-
expect(owner).to have(4).items_in_collection_with_size_method
|
|
58
|
-
}.to fail_with("expected 4 items_in_collection_with_size_method, got 3")
|
|
59
|
-
expect {
|
|
60
|
-
expect(owner).to have(4).items_in_collection_with_count_method
|
|
61
|
-
}.to fail_with("expected 4 items_in_collection_with_count_method, got 3")
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it "fails if target has a collection of items with > n members" do
|
|
65
|
-
owner = create_collection_owner_with(3)
|
|
66
|
-
expect {
|
|
67
|
-
expect(owner).to have(2).items_in_collection_with_length_method
|
|
68
|
-
}.to fail_with("expected 2 items_in_collection_with_length_method, got 3")
|
|
69
|
-
expect {
|
|
70
|
-
expect(owner).to have(2).items_in_collection_with_size_method
|
|
71
|
-
}.to fail_with("expected 2 items_in_collection_with_size_method, got 3")
|
|
72
|
-
expect {
|
|
73
|
-
expect(owner).to have(2).items_in_collection_with_count_method
|
|
74
|
-
}.to fail_with("expected 2 items_in_collection_with_count_method, got 3")
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
describe 'expect(...).to have(1).item when ActiveSupport::Inflector is defined' do
|
|
79
|
-
|
|
80
|
-
it 'pluralizes the collection name' do
|
|
81
|
-
owner = create_collection_owner_with(1)
|
|
82
|
-
expect(owner).to have(1).item
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
context "when ActiveSupport::Inflector is partially loaded without its inflectors" do
|
|
86
|
-
|
|
87
|
-
it "does not pluralize the collection name" do
|
|
88
|
-
stub_const("ActiveSupport::Inflector", Module.new)
|
|
89
|
-
owner = create_collection_owner_with(1)
|
|
90
|
-
expect {
|
|
91
|
-
expect(owner).to have(1).item
|
|
92
|
-
}.to raise_error(NoMethodError)
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
describe 'expect(...).to have(1).item when Inflector is defined' do
|
|
99
|
-
before { stub_const("Inflector", inflector) }
|
|
100
|
-
|
|
101
|
-
it 'pluralizes the collection name' do
|
|
102
|
-
owner = create_collection_owner_with(1)
|
|
103
|
-
expect(owner).to have(1).item
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
describe "expect(...).to have(n).items where result responds to items but returns something other than a collection" do
|
|
108
|
-
it "provides a meaningful error" do
|
|
109
|
-
owner = Class.new do
|
|
110
|
-
def items
|
|
111
|
-
Object.new
|
|
112
|
-
end
|
|
113
|
-
end.new
|
|
114
|
-
expect do
|
|
115
|
-
expect(owner).to have(3).items
|
|
116
|
-
end.to raise_error("expected items to be a collection but it does not respond to #length, #size or #count")
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
describe "expect(...).not_to have(n).items" do
|
|
121
|
-
|
|
122
|
-
it "passes if target has a collection of items with < n members" do
|
|
123
|
-
owner = create_collection_owner_with(3)
|
|
124
|
-
expect(owner).not_to have(4).items_in_collection_with_length_method
|
|
125
|
-
expect(owner).not_to have(4).items_in_collection_with_size_method
|
|
126
|
-
expect(owner).not_to have(4).items_in_collection_with_count_method
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
it "passes if target has a collection of items with > n members" do
|
|
130
|
-
owner = create_collection_owner_with(3)
|
|
131
|
-
expect(owner).not_to have(2).items_in_collection_with_length_method
|
|
132
|
-
expect(owner).not_to have(2).items_in_collection_with_size_method
|
|
133
|
-
expect(owner).not_to have(2).items_in_collection_with_count_method
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
it "fails if target has a collection of items with n members" do
|
|
137
|
-
owner = create_collection_owner_with(3)
|
|
138
|
-
expect {
|
|
139
|
-
expect(owner).not_to have(3).items_in_collection_with_length_method
|
|
140
|
-
}.to fail_with("expected target not to have 3 items_in_collection_with_length_method, got 3")
|
|
141
|
-
expect {
|
|
142
|
-
expect(owner).not_to have(3).items_in_collection_with_size_method
|
|
143
|
-
}.to fail_with("expected target not to have 3 items_in_collection_with_size_method, got 3")
|
|
144
|
-
expect {
|
|
145
|
-
expect(owner).not_to have(3).items_in_collection_with_count_method
|
|
146
|
-
}.to fail_with("expected target not to have 3 items_in_collection_with_count_method, got 3")
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
describe "expect(...).to have_exactly(n).items" do
|
|
151
|
-
|
|
152
|
-
it "passes if target has a collection of items with n members" do
|
|
153
|
-
owner = create_collection_owner_with(3)
|
|
154
|
-
expect(owner).to have_exactly(3).items_in_collection_with_length_method
|
|
155
|
-
expect(owner).to have_exactly(3).items_in_collection_with_size_method
|
|
156
|
-
expect(owner).to have_exactly(3).items_in_collection_with_count_method
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
it "converts :no to 0" do
|
|
160
|
-
owner = create_collection_owner_with(0)
|
|
161
|
-
expect(owner).to have_exactly(:no).items_in_collection_with_length_method
|
|
162
|
-
expect(owner).to have_exactly(:no).items_in_collection_with_size_method
|
|
163
|
-
expect(owner).to have_exactly(:no).items_in_collection_with_count_method
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
it "fails if target has a collection of items with < n members" do
|
|
167
|
-
owner = create_collection_owner_with(3)
|
|
168
|
-
expect {
|
|
169
|
-
expect(owner).to have_exactly(4).items_in_collection_with_length_method
|
|
170
|
-
}.to fail_with("expected 4 items_in_collection_with_length_method, got 3")
|
|
171
|
-
expect {
|
|
172
|
-
expect(owner).to have_exactly(4).items_in_collection_with_size_method
|
|
173
|
-
}.to fail_with("expected 4 items_in_collection_with_size_method, got 3")
|
|
174
|
-
expect {
|
|
175
|
-
expect(owner).to have_exactly(4).items_in_collection_with_count_method
|
|
176
|
-
}.to fail_with("expected 4 items_in_collection_with_count_method, got 3")
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
it "fails if target has a collection of items with > n members" do
|
|
180
|
-
owner = create_collection_owner_with(3)
|
|
181
|
-
expect {
|
|
182
|
-
expect(owner).to have_exactly(2).items_in_collection_with_length_method
|
|
183
|
-
}.to fail_with("expected 2 items_in_collection_with_length_method, got 3")
|
|
184
|
-
expect {
|
|
185
|
-
expect(owner).to have_exactly(2).items_in_collection_with_size_method
|
|
186
|
-
}.to fail_with("expected 2 items_in_collection_with_size_method, got 3")
|
|
187
|
-
expect {
|
|
188
|
-
expect(owner).to have_exactly(2).items_in_collection_with_count_method
|
|
189
|
-
}.to fail_with("expected 2 items_in_collection_with_count_method, got 3")
|
|
190
|
-
end
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
describe "expect(...).to have_at_least(n).items" do
|
|
194
|
-
|
|
195
|
-
it "passes if target has a collection of items with n members" do
|
|
196
|
-
owner = create_collection_owner_with(3)
|
|
197
|
-
expect(owner).to have_at_least(3).items_in_collection_with_length_method
|
|
198
|
-
expect(owner).to have_at_least(3).items_in_collection_with_size_method
|
|
199
|
-
expect(owner).to have_at_least(3).items_in_collection_with_count_method
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
it "passes if target has a collection of items with > n members" do
|
|
203
|
-
owner = create_collection_owner_with(3)
|
|
204
|
-
expect(owner).to have_at_least(2).items_in_collection_with_length_method
|
|
205
|
-
expect(owner).to have_at_least(2).items_in_collection_with_size_method
|
|
206
|
-
expect(owner).to have_at_least(2).items_in_collection_with_count_method
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
it "fails if target has a collection of items with < n members" do
|
|
210
|
-
owner = create_collection_owner_with(3)
|
|
211
|
-
expect {
|
|
212
|
-
expect(owner).to have_at_least(4).items_in_collection_with_length_method
|
|
213
|
-
}.to fail_with("expected at least 4 items_in_collection_with_length_method, got 3")
|
|
214
|
-
expect {
|
|
215
|
-
expect(owner).to have_at_least(4).items_in_collection_with_size_method
|
|
216
|
-
}.to fail_with("expected at least 4 items_in_collection_with_size_method, got 3")
|
|
217
|
-
expect {
|
|
218
|
-
expect(owner).to have_at_least(4).items_in_collection_with_count_method
|
|
219
|
-
}.to fail_with("expected at least 4 items_in_collection_with_count_method, got 3")
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
it "provides educational negative failure messages" do
|
|
223
|
-
#given
|
|
224
|
-
owner = create_collection_owner_with(3)
|
|
225
|
-
length_matcher = have_at_least(3).items_in_collection_with_length_method
|
|
226
|
-
size_matcher = have_at_least(3).items_in_collection_with_size_method
|
|
227
|
-
count_matcher = have_at_least(3).items_in_collection_with_count_method
|
|
228
|
-
|
|
229
|
-
#when
|
|
230
|
-
length_matcher.matches?(owner)
|
|
231
|
-
size_matcher.matches?(owner)
|
|
232
|
-
count_matcher.matches?(owner)
|
|
233
|
-
|
|
234
|
-
#then
|
|
235
|
-
expect(length_matcher.failure_message_for_should_not).to eq <<-EOF
|
|
236
|
-
Isn't life confusing enough?
|
|
237
|
-
Instead of having to figure out the meaning of this:
|
|
238
|
-
expect(actual).not_to have_at_least(3).items_in_collection_with_length_method
|
|
239
|
-
We recommend that you use this instead:
|
|
240
|
-
expect(actual).to have_at_most(2).items_in_collection_with_length_method
|
|
241
|
-
EOF
|
|
242
|
-
|
|
243
|
-
expect(size_matcher.failure_message_for_should_not).to eq <<-EOF
|
|
244
|
-
Isn't life confusing enough?
|
|
245
|
-
Instead of having to figure out the meaning of this:
|
|
246
|
-
expect(actual).not_to have_at_least(3).items_in_collection_with_size_method
|
|
247
|
-
We recommend that you use this instead:
|
|
248
|
-
expect(actual).to have_at_most(2).items_in_collection_with_size_method
|
|
249
|
-
EOF
|
|
250
|
-
expect(count_matcher.failure_message_for_should_not).to eq <<-EOF
|
|
251
|
-
Isn't life confusing enough?
|
|
252
|
-
Instead of having to figure out the meaning of this:
|
|
253
|
-
expect(actual).not_to have_at_least(3).items_in_collection_with_count_method
|
|
254
|
-
We recommend that you use this instead:
|
|
255
|
-
expect(actual).to have_at_most(2).items_in_collection_with_count_method
|
|
256
|
-
EOF
|
|
257
|
-
end
|
|
258
|
-
end
|
|
259
|
-
|
|
260
|
-
describe "expect(...).to have_at_most(n).items" do
|
|
261
|
-
it "passes if target has a collection of items with n members" do
|
|
262
|
-
owner = create_collection_owner_with(3)
|
|
263
|
-
expect(owner).to have_at_most(3).items_in_collection_with_length_method
|
|
264
|
-
expect(owner).to have_at_most(3).items_in_collection_with_size_method
|
|
265
|
-
expect(owner).to have_at_most(3).items_in_collection_with_count_method
|
|
266
|
-
end
|
|
267
|
-
|
|
268
|
-
it "fails if target has a collection of items with > n members" do
|
|
269
|
-
owner = create_collection_owner_with(3)
|
|
270
|
-
expect {
|
|
271
|
-
expect(owner).to have_at_most(2).items_in_collection_with_length_method
|
|
272
|
-
}.to fail_with("expected at most 2 items_in_collection_with_length_method, got 3")
|
|
273
|
-
expect {
|
|
274
|
-
expect(owner).to have_at_most(2).items_in_collection_with_size_method
|
|
275
|
-
}.to fail_with("expected at most 2 items_in_collection_with_size_method, got 3")
|
|
276
|
-
expect {
|
|
277
|
-
expect(owner).to have_at_most(2).items_in_collection_with_count_method
|
|
278
|
-
}.to fail_with("expected at most 2 items_in_collection_with_count_method, got 3")
|
|
279
|
-
end
|
|
280
|
-
|
|
281
|
-
it "passes if target has a collection of items with < n members" do
|
|
282
|
-
owner = create_collection_owner_with(3)
|
|
283
|
-
expect(owner).to have_at_most(4).items_in_collection_with_length_method
|
|
284
|
-
expect(owner).to have_at_most(4).items_in_collection_with_size_method
|
|
285
|
-
expect(owner).to have_at_most(4).items_in_collection_with_count_method
|
|
286
|
-
end
|
|
287
|
-
|
|
288
|
-
it "provides educational negative failure messages" do
|
|
289
|
-
#given
|
|
290
|
-
owner = create_collection_owner_with(3)
|
|
291
|
-
length_matcher = have_at_most(3).items_in_collection_with_length_method
|
|
292
|
-
size_matcher = have_at_most(3).items_in_collection_with_size_method
|
|
293
|
-
count_matcher = have_at_most(3).items_in_collection_with_count_method
|
|
294
|
-
|
|
295
|
-
#when
|
|
296
|
-
length_matcher.matches?(owner)
|
|
297
|
-
size_matcher.matches?(owner)
|
|
298
|
-
count_matcher.matches?(owner)
|
|
299
|
-
|
|
300
|
-
#then
|
|
301
|
-
expect(length_matcher.failure_message_for_should_not).to eq <<-EOF
|
|
302
|
-
Isn't life confusing enough?
|
|
303
|
-
Instead of having to figure out the meaning of this:
|
|
304
|
-
expect(actual).not_to have_at_most(3).items_in_collection_with_length_method
|
|
305
|
-
We recommend that you use this instead:
|
|
306
|
-
expect(actual).to have_at_least(4).items_in_collection_with_length_method
|
|
307
|
-
EOF
|
|
308
|
-
|
|
309
|
-
expect(size_matcher.failure_message_for_should_not).to eq <<-EOF
|
|
310
|
-
Isn't life confusing enough?
|
|
311
|
-
Instead of having to figure out the meaning of this:
|
|
312
|
-
expect(actual).not_to have_at_most(3).items_in_collection_with_size_method
|
|
313
|
-
We recommend that you use this instead:
|
|
314
|
-
expect(actual).to have_at_least(4).items_in_collection_with_size_method
|
|
315
|
-
EOF
|
|
316
|
-
|
|
317
|
-
expect(count_matcher.failure_message_for_should_not).to eq <<-EOF
|
|
318
|
-
Isn't life confusing enough?
|
|
319
|
-
Instead of having to figure out the meaning of this:
|
|
320
|
-
expect(actual).not_to have_at_most(3).items_in_collection_with_count_method
|
|
321
|
-
We recommend that you use this instead:
|
|
322
|
-
expect(actual).to have_at_least(4).items_in_collection_with_count_method
|
|
323
|
-
EOF
|
|
324
|
-
end
|
|
325
|
-
end
|
|
326
|
-
|
|
327
|
-
describe "have(n).items(args, block)" do
|
|
328
|
-
it "passes args to target" do
|
|
329
|
-
target = mock("target")
|
|
330
|
-
target.should_receive(:items).with("arg1","arg2").and_return([1,2,3])
|
|
331
|
-
expect(target).to have(3).items("arg1","arg2")
|
|
332
|
-
end
|
|
333
|
-
|
|
334
|
-
it "passes block to target" do
|
|
335
|
-
target = mock("target")
|
|
336
|
-
block = lambda { 5 }
|
|
337
|
-
target.should_receive(:items).with("arg1","arg2", block).and_return([1,2,3])
|
|
338
|
-
expect(target).to have(3).items("arg1","arg2", block)
|
|
339
|
-
end
|
|
340
|
-
end
|
|
341
|
-
|
|
342
|
-
describe "have(n).items where target IS a collection" do
|
|
343
|
-
it "references the number of items IN the collection" do
|
|
344
|
-
expect([1,2,3]).to have(3).items
|
|
345
|
-
end
|
|
346
|
-
|
|
347
|
-
it "fails when the number of items IN the collection is not as expected" do
|
|
348
|
-
expect {
|
|
349
|
-
expect([1,2,3]).to have(7).items
|
|
350
|
-
}.to fail_with("expected 7 items, got 3")
|
|
351
|
-
end
|
|
352
|
-
end
|
|
353
|
-
|
|
354
|
-
describe "have(n).characters where target IS a String" do
|
|
355
|
-
it "passes if the length is correct" do
|
|
356
|
-
expect("this string").to have(11).characters
|
|
357
|
-
end
|
|
358
|
-
|
|
359
|
-
it "fails if the length is incorrect" do
|
|
360
|
-
expect {
|
|
361
|
-
expect("this string").to have(12).characters
|
|
362
|
-
}.to fail_with("expected 12 characters, got 11")
|
|
363
|
-
end
|
|
364
|
-
end
|
|
365
|
-
|
|
366
|
-
describe "have(n).things on an object which is not a collection nor contains one" do
|
|
367
|
-
it "fails" do
|
|
368
|
-
expect {
|
|
369
|
-
expect(Object.new).to have(2).things
|
|
370
|
-
}.to raise_error(NoMethodError) { |e|
|
|
371
|
-
expect(e.name).to eq :things
|
|
372
|
-
}
|
|
373
|
-
end
|
|
374
|
-
end
|
|
375
|
-
|
|
376
|
-
describe RSpec::Matchers::BuiltIn::Have, "for a collection owner that implements #send" do
|
|
377
|
-
before(:each) do
|
|
378
|
-
@collection = Object.new
|
|
379
|
-
def @collection.floozles; [1,2] end
|
|
380
|
-
def @collection.send; :sent; end
|
|
381
|
-
end
|
|
382
|
-
|
|
383
|
-
it "works in the straightforward case" do
|
|
384
|
-
expect(@collection).to have(2).floozles
|
|
385
|
-
end
|
|
386
|
-
|
|
387
|
-
it "works when doing automatic pluralization" do
|
|
388
|
-
expect(@collection).to have_at_least(1).floozle
|
|
389
|
-
end
|
|
390
|
-
|
|
391
|
-
it "blows up when the owner doesn't respond to that method" do
|
|
392
|
-
expect {
|
|
393
|
-
expect(@collection).to have(99).problems
|
|
394
|
-
}.to raise_error(NoMethodError, /problems/)
|
|
395
|
-
end
|
|
396
|
-
|
|
397
|
-
it 'works when #send is defined directly on an array' do
|
|
398
|
-
array = [1, 2]
|
|
399
|
-
def array.send; :sent; end
|
|
400
|
-
|
|
401
|
-
expect(array).to have(2).items
|
|
402
|
-
end
|
|
403
|
-
end
|
|
404
|
-
|
|
405
|
-
describe RSpec::Matchers::BuiltIn::Have do
|
|
406
|
-
it "has method_missing as private" do
|
|
407
|
-
expect(described_class.private_instance_methods).to include_method(:method_missing)
|
|
408
|
-
end
|
|
409
|
-
|
|
410
|
-
it "does not respond_to? method_missing (because it's private)" do
|
|
411
|
-
formatter = described_class.new(0, StringIO.new)
|
|
412
|
-
expect(formatter).not_to respond_to(:method_missing)
|
|
413
|
-
end
|
|
414
|
-
|
|
415
|
-
describe "respond_to?" do
|
|
416
|
-
before :each do
|
|
417
|
-
@have = described_class.new(:foo)
|
|
418
|
-
@a_method_which_have_defines = described_class.instance_methods.first
|
|
419
|
-
@a_method_which_object_defines = Object.instance_methods.first
|
|
420
|
-
end
|
|
421
|
-
|
|
422
|
-
it "is true for a method which Have defines" do
|
|
423
|
-
expect(@have).to respond_to(@a_method_which_have_defines)
|
|
424
|
-
end
|
|
425
|
-
|
|
426
|
-
it "is true for a method that it's superclass (Object) defines" do
|
|
427
|
-
expect(@have).to respond_to(@a_method_which_object_defines)
|
|
428
|
-
end
|
|
429
|
-
|
|
430
|
-
it "is false for a method which neither Object nor nor Have defines" do
|
|
431
|
-
expect(@have).not_to respond_to(:foo_bar_baz)
|
|
432
|
-
end
|
|
433
|
-
|
|
434
|
-
it "is false if the owner doesn't respond to the method" do
|
|
435
|
-
have = described_class.new(99)
|
|
436
|
-
expect(have).not_to respond_to(:problems)
|
|
437
|
-
end
|
|
438
|
-
|
|
439
|
-
it "is true if the owner responds to the method" do
|
|
440
|
-
have = described_class.new(:a_symbol)
|
|
441
|
-
expect(have).to respond_to(:to_sym)
|
|
442
|
-
end
|
|
443
|
-
end
|
|
444
|
-
end
|
|
445
|
-
end
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module RSpec
|
|
4
|
-
module Matchers
|
|
5
|
-
describe "include() interaction with built-in matchers" do
|
|
6
|
-
it "works with be_within(delta).of(expected)" do
|
|
7
|
-
expect([10, 20, 30]).to include( be_within(5).of(24) )
|
|
8
|
-
expect([10, 20, 30]).not_to include( be_within(3).of(24) )
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "works with be_instance_of(klass)" do
|
|
12
|
-
expect(["foo", 123, {:foo => "bar"}]).to include( be_instance_of(Hash) )
|
|
13
|
-
expect(["foo", 123, {:foo => "bar"}]).not_to include( be_instance_of(Range) )
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "works with be_kind_of(klass)" do
|
|
17
|
-
class StringSubclass < String; end
|
|
18
|
-
class NotHashSubclass; end
|
|
19
|
-
|
|
20
|
-
expect([StringSubclass.new("baz")]).to include( be_kind_of(String) )
|
|
21
|
-
expect([NotHashSubclass.new]).not_to include( be_kind_of(Hash) )
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it "works with be_[some predicate]" do
|
|
25
|
-
expect([stub("actual", :happy? => true)]).to include( be_happy )
|
|
26
|
-
expect([stub("actual", :happy? => false)]).not_to include( be_happy )
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|