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.
Files changed (93) hide show
  1. data/.gitignore +1 -1
  2. data/.travis.yml +7 -0
  3. data/Gemfile +35 -13
  4. data/Guardfile +5 -0
  5. data/License.txt +1 -1
  6. data/README.md +43 -0
  7. data/Rakefile +51 -9
  8. data/cucumber.yml +9 -2
  9. data/features/.nav +29 -0
  10. data/features/Changelog.md +101 -0
  11. data/features/README.markdown +45 -8
  12. data/features/built_in_matchers/README.md +71 -0
  13. data/features/built_in_matchers/be.feature +135 -0
  14. data/features/built_in_matchers/be_within.feature +43 -0
  15. data/features/built_in_matchers/cover.feature +45 -0
  16. data/features/{matchers → built_in_matchers}/equality.feature +16 -13
  17. data/features/built_in_matchers/exist.feature +43 -0
  18. data/features/built_in_matchers/expect_change.feature +59 -0
  19. data/features/built_in_matchers/expect_error.feature +105 -0
  20. data/features/built_in_matchers/have.feature +103 -0
  21. data/features/built_in_matchers/include.feature +121 -0
  22. data/features/built_in_matchers/match.feature +50 -0
  23. data/features/built_in_matchers/operators.feature +221 -0
  24. data/features/built_in_matchers/predicates.feature +128 -0
  25. data/features/built_in_matchers/respond_to.feature +78 -0
  26. data/features/built_in_matchers/satisfy.feature +31 -0
  27. data/features/built_in_matchers/throw_symbol.feature +85 -0
  28. data/features/built_in_matchers/types.feature +114 -0
  29. data/features/{matchers → custom_matchers}/access_running_example.feature +2 -2
  30. data/features/{matchers → custom_matchers}/define_diffable_matcher.feature +1 -1
  31. data/features/{matchers → custom_matchers}/define_matcher.feature +91 -9
  32. data/features/{matchers → custom_matchers}/define_matcher_outside_rspec.feature +1 -1
  33. data/features/{matchers → custom_matchers}/define_matcher_with_fluent_interface.feature +8 -11
  34. data/features/customized_message.feature +22 -0
  35. data/features/{expectations/diffing.feature → diffing.feature} +16 -16
  36. data/features/{expectations/implicit_docstrings.feature → implicit_docstrings.feature} +4 -4
  37. data/features/step_definitions/additional_cli_steps.rb +22 -0
  38. data/features/support/env.rb +5 -1
  39. data/features/test_frameworks/test_unit.feature +46 -0
  40. data/lib/rspec/expectations/backward_compatibility.rb +22 -1
  41. data/lib/rspec/expectations/deprecation.rb +36 -0
  42. data/lib/rspec/expectations/extensions.rb +0 -1
  43. data/lib/rspec/expectations/version.rb +1 -1
  44. data/lib/rspec/expectations.rb +2 -1
  45. data/lib/rspec/matchers/be.rb +4 -4
  46. data/lib/rspec/matchers/be_close.rb +2 -17
  47. data/lib/rspec/matchers/be_within.rb +40 -0
  48. data/lib/rspec/matchers/block_aliases.rb +19 -0
  49. data/lib/rspec/matchers/change.rb +74 -49
  50. data/lib/rspec/matchers/cover.rb +35 -0
  51. data/lib/rspec/matchers/exist.rb +13 -3
  52. data/lib/rspec/matchers/has.rb +15 -11
  53. data/lib/rspec/matchers/have.rb +5 -5
  54. data/lib/rspec/matchers/include.rb +14 -5
  55. data/lib/rspec/matchers/matcher.rb +39 -13
  56. data/lib/rspec/matchers/method_missing.rb +6 -3
  57. data/lib/rspec/matchers/operator_matcher.rb +12 -3
  58. data/lib/rspec/matchers/respond_to.rb +23 -9
  59. data/lib/rspec/matchers/satisfy.rb +4 -0
  60. data/lib/rspec/matchers/throw_symbol.rb +43 -26
  61. data/lib/rspec/matchers.rb +15 -3
  62. data/rspec-expectations.gemspec +2 -6
  63. data/spec/rspec/matchers/be_close_spec.rb +11 -39
  64. data/spec/rspec/matchers/be_spec.rb +8 -8
  65. data/spec/rspec/matchers/be_within_spec.rb +64 -0
  66. data/spec/rspec/matchers/change_spec.rb +88 -9
  67. data/spec/rspec/matchers/cover_spec.rb +65 -0
  68. data/spec/rspec/matchers/description_generation_spec.rb +41 -25
  69. data/spec/rspec/matchers/exist_spec.rb +90 -51
  70. data/spec/rspec/matchers/has_spec.rb +2 -2
  71. data/spec/rspec/matchers/have_spec.rb +291 -291
  72. data/spec/rspec/matchers/include_spec.rb +318 -65
  73. data/spec/rspec/matchers/matcher_spec.rb +91 -0
  74. data/spec/rspec/matchers/matchers_spec.rb +29 -0
  75. data/spec/rspec/matchers/method_missing_spec.rb +23 -0
  76. data/spec/rspec/matchers/operator_matcher_spec.rb +36 -10
  77. data/spec/rspec/matchers/respond_to_spec.rb +177 -1
  78. data/spec/rspec/matchers/satisfy_spec.rb +4 -0
  79. data/spec/rspec/matchers/throw_symbol_spec.rb +27 -10
  80. data/spec/spec_helper.rb +10 -35
  81. data/spec/support/classes.rb +1 -1
  82. data/spec/support/matchers.rb +22 -0
  83. data/spec/support/ruby_version.rb +10 -0
  84. metadata +95 -114
  85. data/History.md +0 -16
  86. data/README.markdown +0 -23
  87. data/features/expectations/attribute_of_subject.feature +0 -19
  88. data/features/expectations/customized_message.feature +0 -54
  89. data/features/matchers/expect_change.feature +0 -65
  90. data/features/matchers/expect_error.feature +0 -44
  91. data/lib/rspec/expectations/extensions/rspec/core/example_group.rb +0 -19
  92. data/spec/suite.rb +0 -1
  93. /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
- 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
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
- 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
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
- 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
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
- 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
- after(:each) do
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
- before(:each) do
82
- if defined?(Inflector)
83
- @inflector_was_defined = true
84
- else
85
- @inflector_was_defined = false
86
- class ::Inflector
87
- def self.pluralize(string)
88
- string.to_s + 's'
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
- after(:each) do
100
- unless @inflector_was_defined
101
- Object.__send__ :remove_const, :Inflector
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 "should have(n).items where result responds to items but returns something other than a collection" do
107
- it "provides a meaningful error" do
108
- owner = Class.new do
109
- def items
110
- Object.new
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.new
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
- describe "should_not have(n).items" do
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
- it "passes if target has a collection of items with < n members" do
122
- owner = create_collection_owner_with(3)
123
- owner.should_not have(4).items_in_collection_with_length_method
124
- owner.should_not have(4).items_in_collection_with_size_method
125
- end
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
- it "fails if target has a collection of items with n members" do
134
- owner = create_collection_owner_with(3)
135
- lambda {
136
- owner.should_not have(3).items_in_collection_with_length_method
137
- }.should fail_with("expected target not to have 3 items_in_collection_with_length_method, got 3")
138
- lambda {
139
- owner.should_not have(3).items_in_collection_with_size_method
140
- }.should fail_with("expected target not to have 3 items_in_collection_with_size_method, got 3")
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 "should have_exactly(n).items" do
129
+ describe "should_not have(n).items" do
145
130
 
146
- it "passes if target has a collection of items with n members" do
147
- owner = create_collection_owner_with(3)
148
- owner.should have_exactly(3).items_in_collection_with_length_method
149
- owner.should have_exactly(3).items_in_collection_with_size_method
150
- end
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
- it "converts :no to 0" do
153
- owner = create_collection_owner_with(0)
154
- owner.should have_exactly(:no).items_in_collection_with_length_method
155
- owner.should have_exactly(:no).items_in_collection_with_size_method
156
- end
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
- it "fails if target has a collection of items with < n members" do
159
- owner = create_collection_owner_with(3)
160
- lambda {
161
- owner.should have_exactly(4).items_in_collection_with_length_method
162
- }.should fail_with("expected 4 items_in_collection_with_length_method, got 3")
163
- lambda {
164
- owner.should have_exactly(4).items_in_collection_with_size_method
165
- }.should fail_with("expected 4 items_in_collection_with_size_method, got 3")
166
- end
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 have_at_least(n).items" do
154
+ describe "should have_exactly(n).items" do
180
155
 
181
- it "passes if target has a collection of items with n members" do
182
- owner = create_collection_owner_with(3)
183
- owner.should have_at_least(3).items_in_collection_with_length_method
184
- owner.should have_at_least(3).items_in_collection_with_size_method
185
- end
186
-
187
- it "passes if target has a collection of items with > n members" do
188
- owner = create_collection_owner_with(3)
189
- owner.should have_at_least(2).items_in_collection_with_length_method
190
- owner.should have_at_least(2).items_in_collection_with_size_method
191
- end
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
- it "fails if target has a collection of items with < n members" do
194
- owner = create_collection_owner_with(3)
195
- lambda {
196
- owner.should have_at_least(4).items_in_collection_with_length_method
197
- }.should fail_with("expected at least 4 items_in_collection_with_length_method, got 3")
198
- lambda {
199
- owner.should have_at_least(4).items_in_collection_with_size_method
200
- }.should fail_with("expected at least 4 items_in_collection_with_size_method, got 3")
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
- it "provides educational negative failure messages" do
204
- #given
205
- owner = create_collection_owner_with(3)
206
- length_matcher = have_at_least(3).items_in_collection_with_length_method
207
- size_matcher = have_at_least(3).items_in_collection_with_size_method
208
-
209
- #when
210
- length_matcher.matches?(owner)
211
- size_matcher.matches?(owner)
212
-
213
- #then
214
- length_matcher.failure_message_for_should_not.should == <<-EOF
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
- size_matcher.failure_message_for_should_not.should == <<-EOF
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
- it "passes if target has a collection of items with n members" do
234
- owner = create_collection_owner_with(3)
235
- owner.should have_at_most(3).items_in_collection_with_length_method
236
- owner.should have_at_most(3).items_in_collection_with_size_method
237
- end
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
- it "fails if target has a collection of items with > n members" do
240
- owner = create_collection_owner_with(3)
241
- lambda {
242
- owner.should have_at_most(2).items_in_collection_with_length_method
243
- }.should fail_with("expected at most 2 items_in_collection_with_length_method, got 3")
244
- lambda {
245
- owner.should have_at_most(2).items_in_collection_with_size_method
246
- }.should fail_with("expected at most 2 items_in_collection_with_size_method, got 3")
247
- end
248
-
249
- it "passes if target has a collection of items with < n members" do
250
- owner = create_collection_owner_with(3)
251
- owner.should have_at_most(4).items_in_collection_with_length_method
252
- owner.should have_at_most(4).items_in_collection_with_size_method
253
- end
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
- it "provides educational negative failure messages" do
256
- #given
257
- owner = create_collection_owner_with(3)
258
- length_matcher = have_at_most(3).items_in_collection_with_length_method
259
- size_matcher = have_at_most(3).items_in_collection_with_size_method
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
- size_matcher.failure_message_for_should_not.should == <<-EOF
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
- it "passes args to target" do
286
- target = mock("target")
287
- target.should_receive(:items).with("arg1","arg2").and_return([1,2,3])
288
- target.should have(3).items("arg1","arg2")
289
- end
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
- it "passes block to target" do
292
- target = mock("target")
293
- block = lambda { 5 }
294
- target.should_receive(:items).with("arg1","arg2", block).and_return([1,2,3])
295
- target.should have(3).items("arg1","arg2", block)
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
- it "references the number of items IN the collection" do
301
- [1,2,3].should have(3).items
302
- end
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
- it "fails when the number of items IN the collection is not as expected" do
305
- lambda { [1,2,3].should have(7).items }.should fail_with("expected 7 items, got 3")
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
- it "passes if the length is correct" do
311
- "this string".should have(11).characters
312
- end
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
- it "fails if the length is incorrect" do
315
- lambda { "this string".should have(12).characters }.should fail_with("expected 12 characters, got 11")
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
- it "fails" do
321
- lambda { Object.new.should have(2).things }.should raise_error(NoMethodError, /undefined method `things' for #<Object:/)
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
- before(:each) do
327
- @collection = Object.new
328
- def @collection.floozles; [1,2] end
329
- def @collection.send(*args); raise "DOH! Library developers shouldn't use #send!" end
330
- end
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
- it "works when doing automatic pluralization" do
339
- lambda {
340
- @collection.should have_at_least(1).floozle
341
- }.should_not raise_error
342
- end
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
- it "blows up when the owner doesn't respond to that method" do
345
- lambda {
346
- @collection.should have(99).problems
347
- }.should raise_error(NoMethodError, /problems/)
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
- module RSpec
352
- module Matchers
353
- describe Have do
354
- it "has method_missing as private" do
355
- with_ruby 1.8 do
356
- described_class.private_instance_methods.should include("method_missing")
357
- end
358
- with_ruby 1.9 do
359
- described_class.private_instance_methods.should include(:method_missing)
360
- end
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 "does not respond_to? method_missing (because it's private)" do
364
- formatter = described_class.new({ }, StringIO.new)
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
- describe "respond_to?" do
369
- before :each do
370
- @have = Have.new(:foo)
371
- @a_method_which_have_defines = Have.instance_methods.first
372
- @a_method_which_object_defines = Object.instance_methods.first
373
- end
374
-
375
- it "is true for a method which Have defines" do
376
- @have.should respond_to(@a_method_which_have_defines)
377
- end
378
-
379
- it "is true for a method that it's superclass (Object) defines" do
380
- @have.should respond_to(@a_method_which_object_defines)
381
- end
382
-
383
- it "is false for a method which neither Object nor nor Have defines" do
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