rspec-expectations 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,21 +1,38 @@
1
1
  source "http://rubygems.org"
2
2
 
3
+ ### rspec libs
3
4
  %w[rspec-core rspec-expectations rspec-mocks].each do |lib|
4
- gem lib, :path => File.expand_path("../../#{lib}", __FILE__)
5
+ library_path = File.expand_path("../../#{lib}", __FILE__)
6
+ if File.exist?(library_path)
7
+ gem lib, :path => library_path
8
+ else
9
+ gem lib
10
+ end
5
11
  end
6
12
 
7
- gem "rake"
13
+ ### dev dependencies
14
+ gem "rake", "0.8.7"
8
15
  gem "cucumber", "0.9.4"
9
16
  gem "aruba", "0.2.2"
10
- gem "autotest"
11
- gem "diff-lcs"
12
- gem "watchr"
13
- gem "rcov"
14
- gem "relish"
17
+ gem "rcov", "0.9.9"
18
+ gem "relish", "0.2.0"
19
+ gem "guard-rspec", "0.1.9"
20
+ gem "growl", "1.0.3"
21
+ gem "ZenTest", "~> 4.4.2"
15
22
 
16
- case RUBY_VERSION
17
- when '1.9.2'
18
- gem 'ruby-debug19'
19
- when /^1\.8/
20
- gem 'ruby-debug'
23
+ if RUBY_PLATFORM =~ /darwin/
24
+ gem "autotest-fsevent", "~> 0.2.4"
25
+ gem "autotest-growl", "~> 0.2.9"
26
+ end
27
+
28
+ gem "ruby-debug", :platforms => :ruby_18
29
+ gem "ruby-debug19", "~> 0.11.6", :platforms => :ruby_19
30
+
31
+ platforms :ruby_18, :ruby_19 do
32
+ gem "rb-fsevent", "~> 0.3.9"
33
+ gem "ruby-prof", "~> 0.9.2"
34
+ end
35
+
36
+ platforms :jruby do
37
+ gem "jruby-openssl"
21
38
  end
@@ -1,5 +1,12 @@
1
1
  ## rspec-expectations release history (incomplete)
2
2
 
3
+ ### 2.3.0 / 2010-12-12
4
+
5
+ [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.2.1...v2.3.0)
6
+
7
+ * Enhancements
8
+ * diff strings when include matcher fails (Mike Sassak)
9
+
3
10
  ### 2.2.0 / 2010-11-28
4
11
 
5
12
  [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.1.0...v2.2.0)
data/README.md CHANGED
@@ -5,10 +5,10 @@ RSpec::Matchers, a library of standard matchers.
5
5
 
6
6
  ## Documentation
7
7
 
8
- The [Cucumber features](http://relishapp.com/rspec/rspec-expectations/v/2-1)
8
+ The [Cucumber features](http://relishapp.com/rspec/rspec-expectations)
9
9
  are the most comprehensive and up-to-date docs for end-users.
10
10
 
11
- The [RDoc](http://rubydoc.info/gems/rspec-expectations/2.1/frames) provides
11
+ The [RDoc](http://rubydoc.info/gems/rspec-expectations/2.3.0/frames) provides
12
12
  additional information for contributors and/or extenders.
13
13
 
14
14
  All of the documentation is open source and a work in progress. If you find it
@@ -131,6 +131,5 @@ Feature: include matcher
131
131
  | expected {:a=>7, :b=>5} to include {:a=>5, :b=>7} |
132
132
  | expected {:a=>7, :b=>5} to include :a and :d |
133
133
  | expected {:a=>7, :b=>5} not to include :a and :d |
134
- | expected {:a=>7, :b=>5} to include {:a=>7, :d=>3} |
135
- | expected {:a=>7, :b=>5} not to include {:a=>7, :d=>3} |
136
-
134
+ And the output should match /expected \{:a=>7, :b=>5\} to include \{(?::a=>7, :d=>3)|(?::d=>3, :a=>7)\}/
135
+ And the output should match /expected \{:a=>7, :b=>5\} not to include \{(?::a=>7, :d=>3)|(?::d=>3, :a=>7)\}/
@@ -1,7 +1,7 @@
1
1
  module RSpec # :nodoc:
2
2
  module Expectations # :nodoc:
3
3
  module Version # :nodoc:
4
- STRING = '2.2.0'
4
+ STRING = '2.3.0'
5
5
  end
6
6
  end
7
7
  end
@@ -18,6 +18,9 @@ module RSpec
18
18
  # "spread".should_not include("red")
19
19
  def include(*expected)
20
20
  Matcher.new :include, *expected do |*_expected|
21
+
22
+ diffable
23
+
21
24
  match_for_should do |actual|
22
25
  perform_match(:all?, :all?, actual, _expected)
23
26
  end
@@ -27,201 +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
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
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
43
37
 
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
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
64
43
 
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
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
70
63
  end
71
64
 
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
65
+ describe 'should have(1).item when ActiveSupport::Inflector is defined' do
66
+
67
+ it 'pluralizes the collection name' do
76
68
  owner = create_collection_owner_with(1)
77
- expect { owner.should have(1).item }.to raise_error(NoMethodError)
69
+ owner.should have(1).item
78
70
  end
79
71
 
80
- end
81
-
82
- after(:each) do
83
- unless @active_support_was_defined
84
- Object.__send__ :remove_const, :ActiveSupport
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)
78
+ end
79
+
80
+ end
81
+
82
+ after(:each) do
83
+ unless @active_support_was_defined
84
+ Object.__send__ :remove_const, :ActiveSupport
85
+ end
85
86
  end
86
87
  end
87
- end
88
88
 
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'
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
99
100
  end
100
101
  end
101
102
  end
102
- end
103
-
104
- it 'pluralizes the collection name' do
105
- owner = create_collection_owner_with(1)
106
- owner.should have(1).item
107
- end
108
-
109
- after(:each) do
110
- unless @inflector_was_defined
111
- Object.__send__ :remove_const, :Inflector
103
+
104
+ it 'pluralizes the collection name' do
105
+ owner = create_collection_owner_with(1)
106
+ owner.should have(1).item
112
107
  end
113
- end
114
- end
115
108
 
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
109
+ after(:each) do
110
+ unless @inflector_was_defined
111
+ Object.__send__ :remove_const, :Inflector
121
112
  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")
113
+ end
126
114
  end
127
- end
128
115
 
129
- describe "should_not have(n).items" do
130
-
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
136
-
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
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
128
 
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
152
- end
129
+ describe "should_not have(n).items" do
153
130
 
154
- describe "should have_exactly(n).items" do
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
136
+
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
155
142
 
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
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
160
152
  end
161
153
 
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
154
+ describe "should have_exactly(n).items" do
167
155
 
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
187
- 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
188
161
 
189
- describe "should have_at_least(n).items" do
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
190
167
 
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
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
188
 
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
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
218
196
 
219
- #when
220
- length_matcher.matches?(owner)
221
- size_matcher.matches?(owner)
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
222
212
 
223
- #then
224
- length_matcher.failure_message_for_should_not.should == <<-EOF
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
225
225
  Isn't life confusing enough?
226
226
  Instead of having to figure out the meaning of this:
227
227
  should_not have_at_least(3).items_in_collection_with_length_method
@@ -229,183 +229,173 @@ We recommend that you use this instead:
229
229
  should have_at_most(2).items_in_collection_with_length_method
230
230
  EOF
231
231
 
232
- size_matcher.failure_message_for_should_not.should == <<-EOF
232
+ size_matcher.failure_message_for_should_not.should == <<-EOF
233
233
  Isn't life confusing enough?
234
234
  Instead of having to figure out the meaning of this:
235
235
  should_not have_at_least(3).items_in_collection_with_size_method
236
236
  We recommend that you use this instead:
237
237
  should have_at_most(2).items_in_collection_with_size_method
238
238
  EOF
239
- end
240
- end
241
-
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
239
+ end
247
240
  end
248
241
 
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
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
264
248
 
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
270
-
271
- #when
272
- length_matcher.matches?(owner)
273
- size_matcher.matches?(owner)
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
274
258
 
275
- #then
276
- length_matcher.failure_message_for_should_not.should == <<-EOF
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
270
+
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
277
277
  Isn't life confusing enough?
278
278
  Instead of having to figure out the meaning of this:
279
279
  should_not have_at_most(3).items_in_collection_with_length_method
280
280
  We recommend that you use this instead:
281
281
  should have_at_least(4).items_in_collection_with_length_method
282
282
  EOF
283
-
284
- size_matcher.failure_message_for_should_not.should == <<-EOF
283
+
284
+ size_matcher.failure_message_for_should_not.should == <<-EOF
285
285
  Isn't life confusing enough?
286
286
  Instead of having to figure out the meaning of this:
287
287
  should_not have_at_most(3).items_in_collection_with_size_method
288
288
  We recommend that you use this instead:
289
289
  should have_at_least(4).items_in_collection_with_size_method
290
290
  EOF
291
+ end
291
292
  end
292
- end
293
293
 
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
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
300
300
 
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)
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
306
307
  end
307
- end
308
308
 
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
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
313
313
 
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")
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
316
317
  end
317
- end
318
318
 
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
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
323
323
 
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")
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
326
327
  end
327
- end
328
328
 
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:/)
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
332
333
  end
333
- end
334
334
 
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
341
-
342
- it "works in the straightforward case" do
343
- lambda {
344
- @collection.should have(2).floozles
345
- }.should_not raise_error
346
- 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
341
+
342
+ it "works in the straightforward case" do
343
+ lambda {
344
+ @collection.should have(2).floozles
345
+ }.should_not raise_error
346
+ end
347
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
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
353
353
 
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/)
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
358
359
  end
359
- end
360
360
 
361
- module RSpec
362
- module Matchers
363
- describe Have do
364
- it "has method_missing as private" do
365
- with_ruby 1.8 do
366
- described_class.private_instance_methods.should include("method_missing")
367
- end
368
- with_ruby 1.9 do
369
- described_class.private_instance_methods.should include(:method_missing)
370
- end
371
- 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
372
365
 
373
- it "does not respond_to? method_missing (because it's private)" do
374
- formatter = described_class.new({ }, StringIO.new)
375
- formatter.should_not respond_to(:method_missing)
376
- end
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
377
370
 
378
- describe "respond_to?" do
379
- before :each do
380
- @have = Have.new(:foo)
381
- @a_method_which_have_defines = Have.instance_methods.first
382
- @a_method_which_object_defines = Object.instance_methods.first
383
- end
384
-
385
- it "is true for a method which Have defines" do
386
- @have.should respond_to(@a_method_which_have_defines)
387
- end
388
-
389
- it "is true for a method that it's superclass (Object) defines" do
390
- @have.should respond_to(@a_method_which_object_defines)
391
- end
392
-
393
- it "is false for a method which neither Object nor nor Have defines" do
394
- @have.should_not respond_to(:foo_bar_baz)
395
- end
396
-
397
- it "is false if the owner doesn't respond to the method" do
398
- have = Have.new(99)
399
- have.should_not respond_to(:problems)
400
- end
401
-
402
- it "is true if the owner responds to the method" do
403
- have = Have.new(:a_symbol)
404
- have.should respond_to(:to_sym)
405
- end
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
376
+ end
377
+
378
+ it "is true for a method which Have defines" do
379
+ @have.should respond_to(@a_method_which_have_defines)
380
+ end
381
+
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)
406
398
  end
407
399
  end
408
400
  end
409
401
  end
410
-
411
- end
@@ -33,7 +33,7 @@ describe "should include(expected)" do
33
33
  it "fails if target does not include expected" do
34
34
  lambda {
35
35
  {:key => 'value'}.should include(:other)
36
- }.should fail_with(%Q|expected {:key=>"value"} to include :other|)
36
+ }.should fail_matching(%Q|expected {:key=>"value"} to include :other|)
37
37
  end
38
38
  end
39
39
  end
@@ -71,7 +71,7 @@ describe "should include(with, multiple, args)" do
71
71
  it 'fails if target is missing any item as a key' do
72
72
  lambda {
73
73
  {:key => 'value'}.should include(:key, :other)
74
- }.should fail_with(%Q|expected {:key=>"value"} to include :key and :other|)
74
+ }.should fail_matching(%Q|expected {:key=>"value"} to include :key and :other|)
75
75
  end
76
76
  end
77
77
  end
@@ -109,7 +109,7 @@ describe "should_not include(expected)" do
109
109
  it "fails if target includes expected key" do
110
110
  lambda {
111
111
  {:key => 'value'}.should_not include(:key)
112
- }.should fail_with(%Q|expected {:key=>"value"} not to include :key|)
112
+ }.should fail_matching(%Q|expected {:key=>"value"} not to include :key|)
113
113
  end
114
114
  end
115
115
 
@@ -142,13 +142,13 @@ describe "should_not include(with, multiple, args)" do
142
142
  it "fails if the target includes all of the expected keys" do
143
143
  expect {
144
144
  { :a => 1, :b => 2 }.should_not include(:a, :b)
145
- }.to fail_with(%q|expected {:a=>1, :b=>2} not to include :a and :b|)
145
+ }.to fail_matching(%Q|expected {:a=>1, :b=>2} not to include :a and :b|)
146
146
  end
147
147
 
148
148
  it "fails if the target includes some (but not all) of the expected keys" do
149
149
  expect {
150
150
  { :a => 1, :b => 2 }.should_not include(:d, :b)
151
- }.to fail_with(%q|expected {:a=>1, :b=>2} not to include :d and :b|)
151
+ }.to fail_matching(%Q|expected {:a=>1, :b=>2} not to include :d and :b|)
152
152
  end
153
153
  end
154
154
 
@@ -184,13 +184,13 @@ describe "should include(:key => value)" do
184
184
  it "fails if target has a different value for key" do
185
185
  lambda {
186
186
  {:key => 'different'}.should include(:key => 'value')
187
- }.should fail_with(%Q|expected {:key=>"different"} to include {:key=>"value"}|)
187
+ }.should fail_matching(%Q|expected {:key=>"different"} to include {:key=>"value"}|)
188
188
  end
189
189
 
190
190
  it "fails if target has a different key" do
191
191
  lambda {
192
192
  {:other => 'value'}.should include(:key => 'value')
193
- }.should fail_with(%Q|expected {:other=>"value"} to include {:key=>"value"}|)
193
+ }.should fail_matching(%Q|expected {:other=>"value"} to include {:key=>"value"}|)
194
194
  end
195
195
  end
196
196
 
@@ -198,7 +198,7 @@ describe "should include(:key => value)" do
198
198
  it "fails if the target does not contain the given hash" do
199
199
  lambda {
200
200
  ['a', 'b'].should include(:key => 'value')
201
- }.should fail_with(%q|expected ["a", "b"] to include {:key=>"value"}|)
201
+ }.should fail_matching(%q|expected ["a", "b"] to include {:key=>"value"}|)
202
202
  end
203
203
 
204
204
  it "passes if the target contains the given hash" do
@@ -212,13 +212,13 @@ describe "should_not include(:key => value)" do
212
212
  it "fails if target includes the key/value pair" do
213
213
  lambda {
214
214
  {:key => 'value'}.should_not include(:key => 'value')
215
- }.should fail_with(%Q|expected {:key=>"value"} not to include {:key=>"value"}|)
215
+ }.should fail_matching(%Q|expected {:key=>"value"} not to include {:key=>"value"}|)
216
216
  end
217
217
 
218
218
  it "fails if target includes the key/value pair among others" do
219
219
  lambda {
220
220
  {:key => 'value', :other => 'different'}.should_not include(:key => 'value')
221
- }.should fail_with(%Q|expected {:key=>"value", :other=>"different"} not to include {:key=>"value"}|)
221
+ }.should fail_matching(%Q|expected {:key=>"value", :other=>"different"} not to include {:key=>"value"}|)
222
222
  end
223
223
 
224
224
  it "passes if target has a different value for key" do
@@ -238,7 +238,7 @@ describe "should_not include(:key => value)" do
238
238
  it "fails if the target contains the given hash" do
239
239
  lambda {
240
240
  ['a', { :key => 'value' } ].should_not include(:key => 'value')
241
- }.should fail_with(%Q|expected ["a", {:key=>"value"}] not to include {:key=>"value"}|)
241
+ }.should fail_matching(%Q|expected ["a", {:key=>"value"}] not to include {:key=>"value"}|)
242
242
  end
243
243
  end
244
244
  end
@@ -256,25 +256,31 @@ describe "should include(:key1 => value1, :key2 => value2)" do
256
256
  it "fails if target has a different value for one of the keys" do
257
257
  lambda {
258
258
  {:a => 1, :b => 2}.should include(:a => 2, :b => 2)
259
- }.should fail_with(%Q|expected {:a=>1, :b=>2} to include {:a=>2, :b=>2}|)
259
+ }.should fail_matching(%Q|expected {:a=>1, :b=>2} to include {:a=>2, :b=>2}|)
260
260
  end
261
261
 
262
262
  it "fails if target has a different value for both of the keys" do
263
263
  lambda {
264
264
  {:a => 1, :b => 1}.should include(:a => 2, :b => 2)
265
- }.should fail_with(%Q|expected {:a=>1, :b=>1} to include {:a=>2, :b=>2}|)
265
+ }.should fail_matching(%Q|expected {:a=>1, :b=>1} to include {:a=>2, :b=>2}|)
266
266
  end
267
267
 
268
268
  it "fails if target lacks one of the keys" do
269
269
  lambda {
270
270
  {:a => 1, :b => 1}.should include(:a => 1, :c => 1)
271
- }.should fail_with(%Q|expected {:a=>1, :b=>1} to include {:a=>1, :c=>1}|)
271
+ }.should fail_matching(%Q|expected {:a=>1, :b=>1} to include {:a=>1, :c=>1}|)
272
272
  end
273
273
 
274
274
  it "fails if target lacks both of the keys" do
275
- lambda {
275
+ begin
276
276
  {:a => 1, :b => 1}.should include(:c => 1, :d => 1)
277
- }.should fail_with(%Q|expected {:a=>1, :b=>1} to include {:c=>1, :d=>1}|)
277
+ rescue Exception => e
278
+ ensure
279
+ e.message.should match(/expected \{:a=>1, :b=>1\} to include/)
280
+ e.message.match(/include (.*)$/) do |m|
281
+ eval(m[1]).should eq({:c=>1,:d=>1})
282
+ end
283
+ end
278
284
  end
279
285
  end
280
286
 
@@ -282,7 +288,7 @@ describe "should include(:key1 => value1, :key2 => value2)" do
282
288
  it "fails if the target does not contain the given hash" do
283
289
  lambda {
284
290
  ['a', 'b'].should include(:a => 1, :b => 1)
285
- }.should fail_with(%q|expected ["a", "b"] to include {:a=>1, :b=>1}|)
291
+ }.should fail_matching(%Q|expected ["a", "b"] to include {:a=>1, :b=>1}|)
286
292
  end
287
293
 
288
294
  it "passes if the target contains the given hash" do
@@ -296,20 +302,20 @@ describe "should_not include(:key1 => value1, :key2 => value2)" do
296
302
  it "fails if target includes the key/value pairs" do
297
303
  lambda {
298
304
  {:a => 1, :b => 2}.should_not include(:a => 1, :b => 2)
299
- }.should fail_with(%Q|expected {:a=>1, :b=>2} not to include {:a=>1, :b=>2}|)
305
+ }.should fail_matching(%Q|expected {:a=>1, :b=>2} not to include {:a=>1, :b=>2}|)
300
306
  end
301
307
 
302
308
  it "fails if target includes the key/value pairs among others" do
303
309
  hash = {:a => 1, :b => 2, :c => 3}
304
310
  lambda {
305
311
  hash.should_not include(:a => 1, :b => 2)
306
- }.should fail_with(%Q|expected #{hash.inspect} not to include {:a=>1, :b=>2}|)
312
+ }.should fail_matching(%Q|expected #{hash.inspect} not to include {:a=>1, :b=>2}|)
307
313
  end
308
314
 
309
315
  it "fails if target has a different value for one of the keys" do
310
316
  lambda {
311
317
  {:a => 1, :b => 2}.should_not include(:a => 2, :b => 2)
312
- }.should fail_with(%Q|expected {:a=>1, :b=>2} not to include {:a=>2, :b=>2}|)
318
+ }.should fail_matching(%Q|expected {:a=>1, :b=>2} not to include {:a=>2, :b=>2}|)
313
319
  end
314
320
 
315
321
  it "passes if target has a different value for both of the keys" do
@@ -319,7 +325,7 @@ describe "should_not include(:key1 => value1, :key2 => value2)" do
319
325
  it "fails if target lacks one of the keys" do
320
326
  lambda {
321
327
  {:a => 1, :b => 1}.should_not include(:a => 1, :c => 1)
322
- }.should fail_with(%Q|expected {:a=>1, :b=>1} not to include {:a=>1, :c=>1}|)
328
+ }.should fail_matching(%Q|expected {:a=>1, :b=>1} not to include {:a=>1, :c=>1}|)
323
329
  end
324
330
 
325
331
  it "passes if target lacks both of the keys" do
@@ -335,7 +341,7 @@ describe "should_not include(:key1 => value1, :key2 => value2)" do
335
341
  it "fails if the target contains the given hash" do
336
342
  lambda {
337
343
  ['a', { :a => 1, :b => 2 } ].should_not include(:a => 1, :b => 2)
338
- }.should fail_with(%Q|expected ["a", {:a=>1, :b=>2}] not to include {:a=>1, :b=>2}|)
344
+ }.should fail_matching(%Q|expected ["a", {:a=>1, :b=>2}] not to include {:a=>1, :b=>2}|)
339
345
  end
340
346
  end
341
347
  end
@@ -21,7 +21,7 @@ describe "should ==" do
21
21
 
22
22
  end
23
23
 
24
- describe "unsupported operators", :ruby => '1.9' do
24
+ describe "unsupported operators", :if => RUBY_VERSION.to_f == 1.9 do
25
25
  it "raises an appropriate error for should != expected" do
26
26
  expect {
27
27
  "apple".should != "pear"
@@ -15,52 +15,10 @@ require 'rspec/expectations'
15
15
  require 'rspec/core'
16
16
  require 'rspec/mocks'
17
17
 
18
- Dir['./spec/support/**/*'].each do |f|
19
- require f
20
- end
21
-
22
- def with_ruby(version)
23
- yield if RUBY_PLATFORM =~ Regexp.compile("^#{version}")
24
- end
25
-
26
- module RSpec
27
- module Ruby
28
- class << self
29
- def version
30
- RUBY_VERSION
31
- end
32
- end
33
- end
34
- end
35
-
36
- module RSpec
37
- module Matchers
38
- def fail
39
- raise_error(RSpec::Expectations::ExpectationNotMetError)
40
- end
41
-
42
- def fail_with(message)
43
- raise_error(RSpec::Expectations::ExpectationNotMetError, message)
44
- end
45
- end
46
- end
18
+ Dir['./spec/support/**/*'].each {|f| require f}
47
19
 
48
20
  RSpec::configure do |config|
49
- config.mock_with(:rspec)
50
- config.include RSpec::Mocks::Methods
51
21
  config.color_enabled = true
52
22
  config.filter_run :focused => true
53
-
54
- config.filter_run_excluding :ruby => lambda {|version|
55
- case version.to_s
56
- when "!jruby"
57
- RUBY_ENGINE != "jruby"
58
- when /^> (.*)/
59
- !(RUBY_VERSION.to_s > $1)
60
- else
61
- !(RUBY_VERSION.to_s =~ /^#{version.to_s}/)
62
- end
63
- }
64
-
65
23
  config.run_all_when_everything_filtered = true
66
24
  end
@@ -1,4 +1,4 @@
1
- # This file contains various classes used by the specs.
1
+ # various classes used by the specs
2
2
  module RSpec
3
3
  module Expectations
4
4
  module Helper
@@ -0,0 +1,22 @@
1
+ RSpec::Matchers.define :include_method do |expected|
2
+ match do |actual|
3
+ actual.map { |m| m.to_s }.include?(expected.to_s)
4
+ end
5
+ end
6
+
7
+ module RSpec
8
+ module Matchers
9
+ def fail
10
+ raise_error(RSpec::Expectations::ExpectationNotMetError)
11
+ end
12
+
13
+ def fail_with(message)
14
+ raise_error(RSpec::Expectations::ExpectationNotMetError, message)
15
+ end
16
+
17
+ def fail_matching(message)
18
+ raise_error(RSpec::Expectations::ExpectationNotMetError, /#{Regexp.escape(message)}/)
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,10 @@
1
+ module RSpec
2
+ module Ruby
3
+ class << self
4
+ def version
5
+ RUBY_VERSION
6
+ end
7
+ end
8
+ end
9
+ end
10
+
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-expectations
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 3
4
5
  prerelease: false
5
6
  segments:
6
7
  - 2
7
- - 2
8
+ - 3
8
9
  - 0
9
- version: 2.2.0
10
+ version: 2.3.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - David Chelimsky
@@ -15,22 +16,23 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-11-28 00:00:00 -06:00
19
+ date: 2010-12-12 00:00:00 -06:00
19
20
  default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
22
- name: diff-lcs
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
26
  - - ~>
27
27
  - !ruby/object:Gem::Version
28
+ hash: 23
28
29
  segments:
29
30
  - 1
30
31
  - 1
31
32
  - 2
32
33
  version: 1.1.2
33
34
  type: :runtime
35
+ name: diff-lcs
34
36
  prerelease: false
35
37
  version_requirements: *id001
36
38
  description: rspec expectations (should[_not] and matchers)
@@ -154,6 +156,8 @@ files:
154
156
  - spec/spec_helper.rb
155
157
  - spec/suite.rb
156
158
  - spec/support/classes.rb
159
+ - spec/support/matchers.rb
160
+ - spec/support/ruby_version.rb
157
161
  - specs.watchr
158
162
  has_rdoc: true
159
163
  homepage: http://github.com/rspec/rspec-expectations
@@ -169,7 +173,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
169
173
  requirements:
170
174
  - - ">="
171
175
  - !ruby/object:Gem::Version
172
- hash: -833655942959929431
176
+ hash: 3
173
177
  segments:
174
178
  - 0
175
179
  version: "0"
@@ -178,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
182
  requirements:
179
183
  - - ">="
180
184
  - !ruby/object:Gem::Version
181
- hash: -833655942959929431
185
+ hash: 3
182
186
  segments:
183
187
  - 0
184
188
  version: "0"
@@ -188,7 +192,7 @@ rubyforge_project: rspec
188
192
  rubygems_version: 1.3.7
189
193
  signing_key:
190
194
  specification_version: 3
191
- summary: rspec-expectations-2.2.0
195
+ summary: rspec-expectations-2.3.0
192
196
  test_files:
193
197
  - features/README.markdown
194
198
  - features/expectations/attribute_of_subject.feature
@@ -250,3 +254,5 @@ test_files:
250
254
  - spec/spec_helper.rb
251
255
  - spec/suite.rb
252
256
  - spec/support/classes.rb
257
+ - spec/support/matchers.rb
258
+ - spec/support/ruby_version.rb