rspec-expectations 2.0.0.beta.22 → 2.6.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.
- data/.gitignore +1 -1
- data/.travis.yml +7 -0
- data/Gemfile +35 -13
- data/Guardfile +5 -0
- data/License.txt +1 -1
- data/README.md +43 -0
- data/Rakefile +51 -9
- data/cucumber.yml +9 -2
- data/features/.nav +29 -0
- data/features/Changelog.md +101 -0
- data/features/README.markdown +45 -8
- data/features/built_in_matchers/README.md +71 -0
- data/features/built_in_matchers/be.feature +135 -0
- data/features/built_in_matchers/be_within.feature +43 -0
- data/features/built_in_matchers/cover.feature +45 -0
- data/features/{matchers → built_in_matchers}/equality.feature +16 -13
- data/features/built_in_matchers/exist.feature +43 -0
- data/features/built_in_matchers/expect_change.feature +59 -0
- data/features/built_in_matchers/expect_error.feature +105 -0
- data/features/built_in_matchers/have.feature +103 -0
- data/features/built_in_matchers/include.feature +121 -0
- data/features/built_in_matchers/match.feature +50 -0
- data/features/built_in_matchers/operators.feature +221 -0
- data/features/built_in_matchers/predicates.feature +128 -0
- data/features/built_in_matchers/respond_to.feature +78 -0
- data/features/built_in_matchers/satisfy.feature +31 -0
- data/features/built_in_matchers/throw_symbol.feature +85 -0
- data/features/built_in_matchers/types.feature +114 -0
- data/features/{matchers → custom_matchers}/access_running_example.feature +2 -2
- data/features/{matchers → custom_matchers}/define_diffable_matcher.feature +1 -1
- data/features/{matchers → custom_matchers}/define_matcher.feature +91 -9
- data/features/{matchers → custom_matchers}/define_matcher_outside_rspec.feature +1 -1
- data/features/{matchers → custom_matchers}/define_matcher_with_fluent_interface.feature +8 -11
- data/features/customized_message.feature +22 -0
- data/features/{expectations/diffing.feature → diffing.feature} +16 -16
- data/features/{expectations/implicit_docstrings.feature → implicit_docstrings.feature} +4 -4
- data/features/step_definitions/additional_cli_steps.rb +22 -0
- data/features/support/env.rb +5 -1
- data/features/test_frameworks/test_unit.feature +46 -0
- data/lib/rspec/expectations/backward_compatibility.rb +22 -1
- data/lib/rspec/expectations/deprecation.rb +36 -0
- data/lib/rspec/expectations/extensions.rb +0 -1
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/expectations.rb +2 -1
- data/lib/rspec/matchers/be.rb +4 -4
- data/lib/rspec/matchers/be_close.rb +2 -17
- data/lib/rspec/matchers/be_within.rb +40 -0
- data/lib/rspec/matchers/block_aliases.rb +19 -0
- data/lib/rspec/matchers/change.rb +74 -49
- data/lib/rspec/matchers/cover.rb +35 -0
- data/lib/rspec/matchers/exist.rb +13 -3
- data/lib/rspec/matchers/has.rb +15 -11
- data/lib/rspec/matchers/have.rb +5 -5
- data/lib/rspec/matchers/include.rb +14 -5
- data/lib/rspec/matchers/matcher.rb +39 -13
- data/lib/rspec/matchers/method_missing.rb +6 -3
- data/lib/rspec/matchers/operator_matcher.rb +12 -3
- data/lib/rspec/matchers/respond_to.rb +23 -9
- data/lib/rspec/matchers/satisfy.rb +4 -0
- data/lib/rspec/matchers/throw_symbol.rb +43 -26
- data/lib/rspec/matchers.rb +15 -3
- data/rspec-expectations.gemspec +2 -6
- data/spec/rspec/matchers/be_close_spec.rb +11 -39
- data/spec/rspec/matchers/be_spec.rb +8 -8
- data/spec/rspec/matchers/be_within_spec.rb +64 -0
- data/spec/rspec/matchers/change_spec.rb +88 -9
- data/spec/rspec/matchers/cover_spec.rb +65 -0
- data/spec/rspec/matchers/description_generation_spec.rb +41 -25
- data/spec/rspec/matchers/exist_spec.rb +90 -51
- data/spec/rspec/matchers/has_spec.rb +2 -2
- data/spec/rspec/matchers/have_spec.rb +291 -291
- data/spec/rspec/matchers/include_spec.rb +318 -65
- data/spec/rspec/matchers/matcher_spec.rb +91 -0
- data/spec/rspec/matchers/matchers_spec.rb +29 -0
- data/spec/rspec/matchers/method_missing_spec.rb +23 -0
- data/spec/rspec/matchers/operator_matcher_spec.rb +36 -10
- data/spec/rspec/matchers/respond_to_spec.rb +177 -1
- data/spec/rspec/matchers/satisfy_spec.rb +4 -0
- data/spec/rspec/matchers/throw_symbol_spec.rb +27 -10
- data/spec/spec_helper.rb +10 -35
- data/spec/support/classes.rb +1 -1
- data/spec/support/matchers.rb +22 -0
- data/spec/support/ruby_version.rb +10 -0
- metadata +95 -114
- data/History.md +0 -16
- data/README.markdown +0 -23
- data/features/expectations/attribute_of_subject.feature +0 -19
- data/features/expectations/customized_message.feature +0 -54
- data/features/matchers/expect_change.feature +0 -65
- data/features/matchers/expect_error.feature +0 -44
- data/lib/rspec/expectations/extensions/rspec/core/example_group.rb +0 -19
- data/spec/suite.rb +0 -1
- /data/{Upgrade.markdown → features/Upgrade.md} +0 -0
|
@@ -4,7 +4,7 @@ require 'stringio'
|
|
|
4
4
|
describe "have matcher" do
|
|
5
5
|
|
|
6
6
|
before(:each) do
|
|
7
|
-
if defined?(::ActiveSupport::Inflector)
|
|
7
|
+
if defined?(::ActiveSupport::Inflector) && ::ActiveSupport::Inflector.respond_to?(:pluralize)
|
|
8
8
|
@active_support_was_defined = true
|
|
9
9
|
else
|
|
10
10
|
@active_support_was_defined = false
|
|
@@ -27,191 +27,201 @@ describe "have matcher" do
|
|
|
27
27
|
owner
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
describe "should have(n).items" do
|
|
30
|
+
describe "should have(n).items" do
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
it "passes if target has a collection of items with n members" do
|
|
33
|
+
owner = create_collection_owner_with(3)
|
|
34
|
+
owner.should have(3).items_in_collection_with_length_method
|
|
35
|
+
owner.should have(3).items_in_collection_with_size_method
|
|
36
|
+
end
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
it "converts :no to 0" do
|
|
39
|
+
owner = create_collection_owner_with(0)
|
|
40
|
+
owner.should have(:no).items_in_collection_with_length_method
|
|
41
|
+
owner.should have(:no).items_in_collection_with_size_method
|
|
42
|
+
end
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
it "fails if target has a collection of items with > n members" do
|
|
55
|
-
owner = create_collection_owner_with(3)
|
|
56
|
-
lambda {
|
|
57
|
-
owner.should have(2).items_in_collection_with_length_method
|
|
58
|
-
}.should fail_with("expected 2 items_in_collection_with_length_method, got 3")
|
|
59
|
-
lambda {
|
|
60
|
-
owner.should have(2).items_in_collection_with_size_method
|
|
61
|
-
}.should fail_with("expected 2 items_in_collection_with_size_method, got 3")
|
|
62
|
-
end
|
|
63
|
-
end
|
|
44
|
+
it "fails if target has a collection of items with < n members" do
|
|
45
|
+
owner = create_collection_owner_with(3)
|
|
46
|
+
lambda {
|
|
47
|
+
owner.should have(4).items_in_collection_with_length_method
|
|
48
|
+
}.should fail_with("expected 4 items_in_collection_with_length_method, got 3")
|
|
49
|
+
lambda {
|
|
50
|
+
owner.should have(4).items_in_collection_with_size_method
|
|
51
|
+
}.should fail_with("expected 4 items_in_collection_with_size_method, got 3")
|
|
52
|
+
end
|
|
64
53
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
unless @active_support_was_defined
|
|
74
|
-
Object.__send__ :remove_const, :ActiveSupport
|
|
54
|
+
it "fails if target has a collection of items with > n members" do
|
|
55
|
+
owner = create_collection_owner_with(3)
|
|
56
|
+
lambda {
|
|
57
|
+
owner.should have(2).items_in_collection_with_length_method
|
|
58
|
+
}.should fail_with("expected 2 items_in_collection_with_length_method, got 3")
|
|
59
|
+
lambda {
|
|
60
|
+
owner.should have(2).items_in_collection_with_size_method
|
|
61
|
+
}.should fail_with("expected 2 items_in_collection_with_size_method, got 3")
|
|
75
62
|
end
|
|
76
63
|
end
|
|
77
|
-
end
|
|
78
64
|
|
|
79
|
-
describe 'should have(1).item when Inflector is defined' do
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
end
|
|
65
|
+
describe 'should have(1).item when ActiveSupport::Inflector is defined' do
|
|
66
|
+
|
|
67
|
+
it 'pluralizes the collection name' do
|
|
68
|
+
owner = create_collection_owner_with(1)
|
|
69
|
+
owner.should have(1).item
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
context "when ActiveSupport::Inflector is partially loaded without its inflectors" do
|
|
73
|
+
|
|
74
|
+
it "does not pluralize the collection name" do
|
|
75
|
+
(class << ::ActiveSupport::Inflector; self; end).send :undef_method, :pluralize
|
|
76
|
+
owner = create_collection_owner_with(1)
|
|
77
|
+
expect { owner.should have(1).item }.to raise_error(NoMethodError)
|
|
90
78
|
end
|
|
79
|
+
|
|
91
80
|
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
it 'pluralizes the collection name' do
|
|
95
|
-
owner = create_collection_owner_with(1)
|
|
96
|
-
owner.should have(1).item
|
|
97
|
-
end
|
|
98
81
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
82
|
+
after(:each) do
|
|
83
|
+
unless @active_support_was_defined
|
|
84
|
+
Object.__send__ :remove_const, :ActiveSupport
|
|
85
|
+
end
|
|
102
86
|
end
|
|
103
87
|
end
|
|
104
|
-
end
|
|
105
88
|
|
|
106
|
-
describe
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
89
|
+
describe 'should have(1).item when Inflector is defined' do
|
|
90
|
+
|
|
91
|
+
before(:each) do
|
|
92
|
+
if defined?(Inflector)
|
|
93
|
+
@inflector_was_defined = true
|
|
94
|
+
else
|
|
95
|
+
@inflector_was_defined = false
|
|
96
|
+
class ::Inflector
|
|
97
|
+
def self.pluralize(string)
|
|
98
|
+
string.to_s + 's'
|
|
99
|
+
end
|
|
100
|
+
end
|
|
111
101
|
end
|
|
112
|
-
end
|
|
113
|
-
lambda do
|
|
114
|
-
owner.should have(3).items
|
|
115
|
-
end.should raise_error("expected items to be a collection but it does not respond to #length or #size")
|
|
116
|
-
end
|
|
117
|
-
end
|
|
102
|
+
end
|
|
118
103
|
|
|
119
|
-
|
|
104
|
+
it 'pluralizes the collection name' do
|
|
105
|
+
owner = create_collection_owner_with(1)
|
|
106
|
+
owner.should have(1).item
|
|
107
|
+
end
|
|
120
108
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
it "passes if target has a collection of items with > n members" do
|
|
128
|
-
owner = create_collection_owner_with(3)
|
|
129
|
-
owner.should_not have(2).items_in_collection_with_length_method
|
|
130
|
-
owner.should_not have(2).items_in_collection_with_size_method
|
|
109
|
+
after(:each) do
|
|
110
|
+
unless @inflector_was_defined
|
|
111
|
+
Object.__send__ :remove_const, :Inflector
|
|
112
|
+
end
|
|
113
|
+
end
|
|
131
114
|
end
|
|
132
115
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
116
|
+
describe "should have(n).items where result responds to items but returns something other than a collection" do
|
|
117
|
+
it "provides a meaningful error" do
|
|
118
|
+
owner = Class.new do
|
|
119
|
+
def items
|
|
120
|
+
Object.new
|
|
121
|
+
end
|
|
122
|
+
end.new
|
|
123
|
+
lambda do
|
|
124
|
+
owner.should have(3).items
|
|
125
|
+
end.should raise_error("expected items to be a collection but it does not respond to #length or #size")
|
|
126
|
+
end
|
|
141
127
|
end
|
|
142
|
-
end
|
|
143
128
|
|
|
144
|
-
describe "
|
|
129
|
+
describe "should_not have(n).items" do
|
|
145
130
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
131
|
+
it "passes if target has a collection of items with < n members" do
|
|
132
|
+
owner = create_collection_owner_with(3)
|
|
133
|
+
owner.should_not have(4).items_in_collection_with_length_method
|
|
134
|
+
owner.should_not have(4).items_in_collection_with_size_method
|
|
135
|
+
end
|
|
151
136
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
137
|
+
it "passes if target has a collection of items with > n members" do
|
|
138
|
+
owner = create_collection_owner_with(3)
|
|
139
|
+
owner.should_not have(2).items_in_collection_with_length_method
|
|
140
|
+
owner.should_not have(2).items_in_collection_with_size_method
|
|
141
|
+
end
|
|
157
142
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
it "fails if target has a collection of items with > n members" do
|
|
169
|
-
owner = create_collection_owner_with(3)
|
|
170
|
-
lambda {
|
|
171
|
-
owner.should have_exactly(2).items_in_collection_with_length_method
|
|
172
|
-
}.should fail_with("expected 2 items_in_collection_with_length_method, got 3")
|
|
173
|
-
lambda {
|
|
174
|
-
owner.should have_exactly(2).items_in_collection_with_size_method
|
|
175
|
-
}.should fail_with("expected 2 items_in_collection_with_size_method, got 3")
|
|
143
|
+
it "fails if target has a collection of items with n members" do
|
|
144
|
+
owner = create_collection_owner_with(3)
|
|
145
|
+
lambda {
|
|
146
|
+
owner.should_not have(3).items_in_collection_with_length_method
|
|
147
|
+
}.should fail_with("expected target not to have 3 items_in_collection_with_length_method, got 3")
|
|
148
|
+
lambda {
|
|
149
|
+
owner.should_not have(3).items_in_collection_with_size_method
|
|
150
|
+
}.should fail_with("expected target not to have 3 items_in_collection_with_size_method, got 3")
|
|
151
|
+
end
|
|
176
152
|
end
|
|
177
|
-
end
|
|
178
153
|
|
|
179
|
-
describe "should
|
|
154
|
+
describe "should have_exactly(n).items" do
|
|
180
155
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
156
|
+
it "passes if target has a collection of items with n members" do
|
|
157
|
+
owner = create_collection_owner_with(3)
|
|
158
|
+
owner.should have_exactly(3).items_in_collection_with_length_method
|
|
159
|
+
owner.should have_exactly(3).items_in_collection_with_size_method
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it "converts :no to 0" do
|
|
163
|
+
owner = create_collection_owner_with(0)
|
|
164
|
+
owner.should have_exactly(:no).items_in_collection_with_length_method
|
|
165
|
+
owner.should have_exactly(:no).items_in_collection_with_size_method
|
|
166
|
+
end
|
|
192
167
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
168
|
+
it "fails if target has a collection of items with < n members" do
|
|
169
|
+
owner = create_collection_owner_with(3)
|
|
170
|
+
lambda {
|
|
171
|
+
owner.should have_exactly(4).items_in_collection_with_length_method
|
|
172
|
+
}.should fail_with("expected 4 items_in_collection_with_length_method, got 3")
|
|
173
|
+
lambda {
|
|
174
|
+
owner.should have_exactly(4).items_in_collection_with_size_method
|
|
175
|
+
}.should fail_with("expected 4 items_in_collection_with_size_method, got 3")
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
it "fails if target has a collection of items with > n members" do
|
|
179
|
+
owner = create_collection_owner_with(3)
|
|
180
|
+
lambda {
|
|
181
|
+
owner.should have_exactly(2).items_in_collection_with_length_method
|
|
182
|
+
}.should fail_with("expected 2 items_in_collection_with_length_method, got 3")
|
|
183
|
+
lambda {
|
|
184
|
+
owner.should have_exactly(2).items_in_collection_with_size_method
|
|
185
|
+
}.should fail_with("expected 2 items_in_collection_with_size_method, got 3")
|
|
186
|
+
end
|
|
201
187
|
end
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
188
|
+
|
|
189
|
+
describe "should have_at_least(n).items" do
|
|
190
|
+
|
|
191
|
+
it "passes if target has a collection of items with n members" do
|
|
192
|
+
owner = create_collection_owner_with(3)
|
|
193
|
+
owner.should have_at_least(3).items_in_collection_with_length_method
|
|
194
|
+
owner.should have_at_least(3).items_in_collection_with_size_method
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
it "passes if target has a collection of items with > n members" do
|
|
198
|
+
owner = create_collection_owner_with(3)
|
|
199
|
+
owner.should have_at_least(2).items_in_collection_with_length_method
|
|
200
|
+
owner.should have_at_least(2).items_in_collection_with_size_method
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
it "fails if target has a collection of items with < n members" do
|
|
204
|
+
owner = create_collection_owner_with(3)
|
|
205
|
+
lambda {
|
|
206
|
+
owner.should have_at_least(4).items_in_collection_with_length_method
|
|
207
|
+
}.should fail_with("expected at least 4 items_in_collection_with_length_method, got 3")
|
|
208
|
+
lambda {
|
|
209
|
+
owner.should have_at_least(4).items_in_collection_with_size_method
|
|
210
|
+
}.should fail_with("expected at least 4 items_in_collection_with_size_method, got 3")
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
it "provides educational negative failure messages" do
|
|
214
|
+
#given
|
|
215
|
+
owner = create_collection_owner_with(3)
|
|
216
|
+
length_matcher = have_at_least(3).items_in_collection_with_length_method
|
|
217
|
+
size_matcher = have_at_least(3).items_in_collection_with_size_method
|
|
218
|
+
|
|
219
|
+
#when
|
|
220
|
+
length_matcher.matches?(owner)
|
|
221
|
+
size_matcher.matches?(owner)
|
|
222
|
+
|
|
223
|
+
#then
|
|
224
|
+
length_matcher.failure_message_for_should_not.should == <<-EOF
|
|
215
225
|
Isn't life confusing enough?
|
|
216
226
|
Instead of having to figure out the meaning of this:
|
|
217
227
|
should_not have_at_least(3).items_in_collection_with_length_method
|
|
@@ -219,183 +229,173 @@ We recommend that you use this instead:
|
|
|
219
229
|
should have_at_most(2).items_in_collection_with_length_method
|
|
220
230
|
EOF
|
|
221
231
|
|
|
222
|
-
|
|
232
|
+
size_matcher.failure_message_for_should_not.should == <<-EOF
|
|
223
233
|
Isn't life confusing enough?
|
|
224
234
|
Instead of having to figure out the meaning of this:
|
|
225
235
|
should_not have_at_least(3).items_in_collection_with_size_method
|
|
226
236
|
We recommend that you use this instead:
|
|
227
237
|
should have_at_most(2).items_in_collection_with_size_method
|
|
228
238
|
EOF
|
|
239
|
+
end
|
|
229
240
|
end
|
|
230
|
-
end
|
|
231
241
|
|
|
232
|
-
describe "should have_at_most(n).items" do
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
242
|
+
describe "should have_at_most(n).items" do
|
|
243
|
+
it "passes if target has a collection of items with n members" do
|
|
244
|
+
owner = create_collection_owner_with(3)
|
|
245
|
+
owner.should have_at_most(3).items_in_collection_with_length_method
|
|
246
|
+
owner.should have_at_most(3).items_in_collection_with_size_method
|
|
247
|
+
end
|
|
238
248
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
249
|
+
it "fails if target has a collection of items with > n members" do
|
|
250
|
+
owner = create_collection_owner_with(3)
|
|
251
|
+
lambda {
|
|
252
|
+
owner.should have_at_most(2).items_in_collection_with_length_method
|
|
253
|
+
}.should fail_with("expected at most 2 items_in_collection_with_length_method, got 3")
|
|
254
|
+
lambda {
|
|
255
|
+
owner.should have_at_most(2).items_in_collection_with_size_method
|
|
256
|
+
}.should fail_with("expected at most 2 items_in_collection_with_size_method, got 3")
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
it "passes if target has a collection of items with < n members" do
|
|
260
|
+
owner = create_collection_owner_with(3)
|
|
261
|
+
owner.should have_at_most(4).items_in_collection_with_length_method
|
|
262
|
+
owner.should have_at_most(4).items_in_collection_with_size_method
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
it "provides educational negative failure messages" do
|
|
266
|
+
#given
|
|
267
|
+
owner = create_collection_owner_with(3)
|
|
268
|
+
length_matcher = have_at_most(3).items_in_collection_with_length_method
|
|
269
|
+
size_matcher = have_at_most(3).items_in_collection_with_size_method
|
|
254
270
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
#when
|
|
262
|
-
length_matcher.matches?(owner)
|
|
263
|
-
size_matcher.matches?(owner)
|
|
264
|
-
|
|
265
|
-
#then
|
|
266
|
-
length_matcher.failure_message_for_should_not.should == <<-EOF
|
|
271
|
+
#when
|
|
272
|
+
length_matcher.matches?(owner)
|
|
273
|
+
size_matcher.matches?(owner)
|
|
274
|
+
|
|
275
|
+
#then
|
|
276
|
+
length_matcher.failure_message_for_should_not.should == <<-EOF
|
|
267
277
|
Isn't life confusing enough?
|
|
268
278
|
Instead of having to figure out the meaning of this:
|
|
269
279
|
should_not have_at_most(3).items_in_collection_with_length_method
|
|
270
280
|
We recommend that you use this instead:
|
|
271
281
|
should have_at_least(4).items_in_collection_with_length_method
|
|
272
282
|
EOF
|
|
273
|
-
|
|
274
|
-
|
|
283
|
+
|
|
284
|
+
size_matcher.failure_message_for_should_not.should == <<-EOF
|
|
275
285
|
Isn't life confusing enough?
|
|
276
286
|
Instead of having to figure out the meaning of this:
|
|
277
287
|
should_not have_at_most(3).items_in_collection_with_size_method
|
|
278
288
|
We recommend that you use this instead:
|
|
279
289
|
should have_at_least(4).items_in_collection_with_size_method
|
|
280
290
|
EOF
|
|
291
|
+
end
|
|
281
292
|
end
|
|
282
|
-
end
|
|
283
293
|
|
|
284
|
-
describe "have(n).items(args, block)" do
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
294
|
+
describe "have(n).items(args, block)" do
|
|
295
|
+
it "passes args to target" do
|
|
296
|
+
target = mock("target")
|
|
297
|
+
target.should_receive(:items).with("arg1","arg2").and_return([1,2,3])
|
|
298
|
+
target.should have(3).items("arg1","arg2")
|
|
299
|
+
end
|
|
290
300
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
301
|
+
it "passes block to target" do
|
|
302
|
+
target = mock("target")
|
|
303
|
+
block = lambda { 5 }
|
|
304
|
+
target.should_receive(:items).with("arg1","arg2", block).and_return([1,2,3])
|
|
305
|
+
target.should have(3).items("arg1","arg2", block)
|
|
306
|
+
end
|
|
296
307
|
end
|
|
297
|
-
end
|
|
298
308
|
|
|
299
|
-
describe "have(n).items where target IS a collection" do
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
309
|
+
describe "have(n).items where target IS a collection" do
|
|
310
|
+
it "references the number of items IN the collection" do
|
|
311
|
+
[1,2,3].should have(3).items
|
|
312
|
+
end
|
|
303
313
|
|
|
304
|
-
|
|
305
|
-
|
|
314
|
+
it "fails when the number of items IN the collection is not as expected" do
|
|
315
|
+
lambda { [1,2,3].should have(7).items }.should fail_with("expected 7 items, got 3")
|
|
316
|
+
end
|
|
306
317
|
end
|
|
307
|
-
end
|
|
308
318
|
|
|
309
|
-
describe "have(n).characters where target IS a String" do
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
319
|
+
describe "have(n).characters where target IS a String" do
|
|
320
|
+
it "passes if the length is correct" do
|
|
321
|
+
"this string".should have(11).characters
|
|
322
|
+
end
|
|
313
323
|
|
|
314
|
-
|
|
315
|
-
|
|
324
|
+
it "fails if the length is incorrect" do
|
|
325
|
+
lambda { "this string".should have(12).characters }.should fail_with("expected 12 characters, got 11")
|
|
326
|
+
end
|
|
316
327
|
end
|
|
317
|
-
end
|
|
318
328
|
|
|
319
|
-
describe "have(n).things on an object which is not a collection nor contains one" do
|
|
320
|
-
|
|
321
|
-
|
|
329
|
+
describe "have(n).things on an object which is not a collection nor contains one" do
|
|
330
|
+
it "fails" do
|
|
331
|
+
lambda { Object.new.should have(2).things }.should raise_error(NoMethodError, /undefined method `things' for #<Object:/)
|
|
332
|
+
end
|
|
322
333
|
end
|
|
323
|
-
end
|
|
324
334
|
|
|
325
|
-
describe RSpec::Matchers::Have, "for a collection owner that implements #send" do
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
it "works in the straightforward case" do
|
|
333
|
-
lambda {
|
|
334
|
-
@collection.should have(2).floozles
|
|
335
|
-
}.should_not raise_error
|
|
336
|
-
end
|
|
335
|
+
describe RSpec::Matchers::Have, "for a collection owner that implements #send" do
|
|
336
|
+
before(:each) do
|
|
337
|
+
@collection = Object.new
|
|
338
|
+
def @collection.floozles; [1,2] end
|
|
339
|
+
def @collection.send(*args); raise "DOH! Library developers shouldn't use #send!" end
|
|
340
|
+
end
|
|
337
341
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
342
|
+
it "works in the straightforward case" do
|
|
343
|
+
lambda {
|
|
344
|
+
@collection.should have(2).floozles
|
|
345
|
+
}.should_not raise_error
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
it "works when doing automatic pluralization" do
|
|
349
|
+
lambda {
|
|
350
|
+
@collection.should have_at_least(1).floozle
|
|
351
|
+
}.should_not raise_error
|
|
352
|
+
end
|
|
343
353
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
354
|
+
it "blows up when the owner doesn't respond to that method" do
|
|
355
|
+
lambda {
|
|
356
|
+
@collection.should have(99).problems
|
|
357
|
+
}.should raise_error(NoMethodError, /problems/)
|
|
358
|
+
end
|
|
348
359
|
end
|
|
349
|
-
end
|
|
350
360
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
+
describe RSpec::Matchers::Have do
|
|
362
|
+
it "has method_missing as private" do
|
|
363
|
+
described_class.private_instance_methods.should include_method(:method_missing)
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
it "does not respond_to? method_missing (because it's private)" do
|
|
367
|
+
formatter = described_class.new({ }, StringIO.new)
|
|
368
|
+
formatter.should_not respond_to(:method_missing)
|
|
369
|
+
end
|
|
370
|
+
|
|
371
|
+
describe "respond_to?" do
|
|
372
|
+
before :each do
|
|
373
|
+
@have = described_class.new(:foo)
|
|
374
|
+
@a_method_which_have_defines = described_class.instance_methods.first
|
|
375
|
+
@a_method_which_object_defines = Object.instance_methods.first
|
|
361
376
|
end
|
|
362
377
|
|
|
363
|
-
it "
|
|
364
|
-
|
|
365
|
-
formatter.should_not respond_to(:method_missing)
|
|
378
|
+
it "is true for a method which Have defines" do
|
|
379
|
+
@have.should respond_to(@a_method_which_have_defines)
|
|
366
380
|
end
|
|
367
381
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
@have.should_not respond_to(:foo_bar_baz)
|
|
385
|
-
end
|
|
386
|
-
|
|
387
|
-
it "is false if the owner doesn't respond to the method" do
|
|
388
|
-
have = Have.new(99)
|
|
389
|
-
have.should_not respond_to(:problems)
|
|
390
|
-
end
|
|
391
|
-
|
|
392
|
-
it "is true if the owner responds to the method" do
|
|
393
|
-
have = Have.new(:a_symbol)
|
|
394
|
-
have.should respond_to(:to_sym)
|
|
395
|
-
end
|
|
382
|
+
it "is true for a method that it's superclass (Object) defines" do
|
|
383
|
+
@have.should respond_to(@a_method_which_object_defines)
|
|
384
|
+
end
|
|
385
|
+
|
|
386
|
+
it "is false for a method which neither Object nor nor Have defines" do
|
|
387
|
+
@have.should_not respond_to(:foo_bar_baz)
|
|
388
|
+
end
|
|
389
|
+
|
|
390
|
+
it "is false if the owner doesn't respond to the method" do
|
|
391
|
+
have = described_class.new(99)
|
|
392
|
+
have.should_not respond_to(:problems)
|
|
393
|
+
end
|
|
394
|
+
|
|
395
|
+
it "is true if the owner responds to the method" do
|
|
396
|
+
have = described_class.new(:a_symbol)
|
|
397
|
+
have.should respond_to(:to_sym)
|
|
396
398
|
end
|
|
397
399
|
end
|
|
398
400
|
end
|
|
399
401
|
end
|
|
400
|
-
|
|
401
|
-
end
|