rspec-expectations 2.8.0.rc2 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,15 +15,15 @@ module RSpec
15
15
  output = ""
16
16
  diffs = Diff::LCS.diff(data_old, data_new)
17
17
  return output if diffs.empty?
18
- oldhunk = hunk = nil
18
+ oldhunk = hunk = nil
19
19
  file_length_difference = 0
20
20
  diffs.each do |piece|
21
21
  begin
22
22
  hunk = Diff::LCS::Hunk.new(
23
23
  data_old, data_new, piece, context_lines, file_length_difference
24
24
  )
25
- file_length_difference = hunk.file_length_difference
26
- next unless oldhunk
25
+ file_length_difference = hunk.file_length_difference
26
+ next unless oldhunk
27
27
  # Hunks may overlap, which is why we need to be careful when our
28
28
  # diff includes lines of context. Otherwise, we might print
29
29
  # redundant lines.
@@ -36,14 +36,14 @@ module RSpec
36
36
  oldhunk = hunk
37
37
  output << "\n"
38
38
  end
39
- end
39
+ end
40
40
  #Handle the last remaining hunk
41
41
  output << oldhunk.diff(format) << "\n"
42
- end
42
+ end
43
43
 
44
44
  def diff_as_object(actual,expected)
45
- actual = String === actual ? actual : PP.pp(actual,"")
46
- expected = String === expected ? expected : PP.pp(expected,"")
45
+ actual = object_to_string(actual)
46
+ expected = object_to_string(expected)
47
47
  diff_as_string(actual, expected)
48
48
  end
49
49
 
@@ -56,7 +56,21 @@ module RSpec
56
56
  def context_lines
57
57
  3
58
58
  end
59
+
60
+ def object_to_string(object)
61
+ case object
62
+ when Hash
63
+ object.keys.sort_by { |k| k.to_s }.map do |k|
64
+ %(#{PP.singleline_pp(k, "")} => #{PP.singleline_pp(object[k], "")})
65
+ end.join(",\n")
66
+ when String
67
+ object =~ /\n/ ? object : object.inspect
68
+ else
69
+ PP.pp(object,"")
70
+ end
71
+ end
59
72
  end
60
73
 
61
74
  end
62
75
  end
76
+
@@ -2,7 +2,7 @@ module RSpec
2
2
  module Expectations
3
3
  # @private
4
4
  module Version
5
- STRING = '2.8.0.rc2'
5
+ STRING = '2.8.0'
6
6
  end
7
7
  end
8
8
  end
@@ -7,7 +7,7 @@ module RSpec
7
7
  matcher = RSpec::Matchers::Matcher.new(name, &declarations)
8
8
  define_method name do |*expected|
9
9
  $matcher_execution_context = self
10
- matcher.for_expected *expected
10
+ matcher.for_expected(*expected)
11
11
  end
12
12
  end
13
13
 
@@ -20,6 +20,10 @@ module RSpec
20
20
  "include#{expected_to_sentence}"
21
21
  end
22
22
 
23
+ def diffable?
24
+ true
25
+ end
26
+
23
27
  private
24
28
 
25
29
  def perform_match(predicate, hash_predicate, actuals, expecteds)
@@ -56,7 +56,7 @@ EOD
56
56
  expected = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'charlie', :width, 'quite wide' ]
57
57
  actual = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'tango' , :width, 'very wide' ]
58
58
 
59
- expected_diff = <<'EOD'
59
+ expected_diff = <<EOD
60
60
 
61
61
 
62
62
  @@ -5,7 +5,7 @@
@@ -70,7 +70,6 @@ EOD
70
70
  + "quite wide"]
71
71
  EOD
72
72
 
73
-
74
73
  diff = @differ.diff_as_object(expected,actual)
75
74
  diff.should == expected_diff
76
75
  end
@@ -93,4 +92,53 @@ EOD
93
92
  diff.should == expected_diff
94
93
  end
95
94
 
95
+ it "outputs unified diff message of two hashes" do
96
+ expected = { :foo => 'bar', :baz => 'quux', :metasyntactic => 'variable', :delta => 'charlie', :width =>'quite wide' }
97
+ actual = { :foo => 'bar', :metasyntactic => 'variable', :delta => 'charlotte', :width =>'quite wide' }
98
+
99
+ expected_diff = <<'EOD'
100
+
101
+ @@ -1,4 +1,5 @@
102
+ -:delta => "charlotte",
103
+ +:baz => "quux",
104
+ +:delta => "charlie",
105
+ :foo => "bar",
106
+ :metasyntactic => "variable",
107
+ :width => "quite wide"
108
+ EOD
109
+
110
+ diff = @differ.diff_as_object(expected,actual)
111
+ diff.should == expected_diff
112
+ end
113
+
114
+ it "outputs unified diff of single line strings" do
115
+ expected = "this is one string"
116
+ actual = "this is another string"
117
+
118
+ expected_diff = <<EOD
119
+
120
+ @@ -1,2 +1,2 @@
121
+ -"this is another string"
122
+ +"this is one string"
123
+ EOD
124
+
125
+ diff = @differ.diff_as_object(expected,actual)
126
+ diff.should == expected_diff
127
+ end
128
+
129
+ it "outputs unified diff of multi line strings" do
130
+ expected = "this is:\n one string"
131
+ actual = "this is:\n another string"
132
+
133
+ expected_diff = <<EOD
134
+
135
+ @@ -1,3 +1,3 @@
136
+ this is:
137
+ - another string
138
+ + one string
139
+ EOD
140
+
141
+ diff = @differ.diff_as_object(expected,actual)
142
+ diff.should == expected_diff
143
+ end
96
144
  end
@@ -1,345 +1,351 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "should include(expected)" do
4
- context "for a string target" do
5
- it "passes if target includes expected" do
6
- "abc".should include("a")
7
- end
8
-
9
- it "fails if target does not include expected" do
10
- lambda {
11
- "abc".should include("d")
12
- }.should fail_with("expected \"abc\" to include \"d\"")
13
- end
14
- end
15
-
16
- context "for an array target" do
17
- it "passes if target includes expected" do
18
- [1,2,3].should include(3)
19
- end
20
-
21
- it "fails if target does not include expected" do
22
- lambda {
23
- [1,2,3].should include(4)
24
- }.should fail_with("expected [1, 2, 3] to include 4")
25
- end
3
+ describe "#include matcher" do
4
+ it "is diffable" do
5
+ include("a").should be_diffable
26
6
  end
27
7
 
28
- context "for a hash target" do
29
- it 'passes if target has the expected as a key' do
30
- {:key => 'value'}.should include(:key)
31
- end
8
+ describe "should include(with_one_arg)" do
9
+ context "for a string target" do
10
+ it "passes if target includes expected" do
11
+ "abc".should include("a")
12
+ end
32
13
 
33
- it "fails if target does not include expected" do
34
- lambda {
35
- {:key => 'value'}.should include(:other)
36
- }.should fail_matching(%Q|expected {:key=>"value"} to include :other|)
14
+ it "fails if target does not include expected" do
15
+ lambda {
16
+ "abc".should include("d")
17
+ }.should fail_matching("expected \"abc\" to include \"d\"")
18
+ end
37
19
  end
38
- end
39
- end
40
20
 
41
- describe "should include(with, multiple, args)" do
42
- it "has a description" do
43
- matcher = include("a")
44
- matcher.description.should eq("include \"a\"")
45
- end
46
- context "for a string target" do
47
- it "passes if target includes all items" do
48
- "a string".should include("str", "a")
49
- end
21
+ context "for an array target" do
22
+ it "passes if target includes expected" do
23
+ [1,2,3].should include(3)
24
+ end
50
25
 
51
- it "fails if target does not include any one of the items" do
52
- lambda {
53
- "a string".should include("str", "a", "foo")
54
- }.should fail_with(%Q{expected "a string" to include "str", "a", and "foo"})
26
+ it "fails if target does not include expected" do
27
+ lambda {
28
+ [1,2,3].should include(4)
29
+ }.should fail_matching("expected [1, 2, 3] to include 4")
30
+ end
55
31
  end
56
- end
57
32
 
58
- context "for an array target" do
59
- it "passes if target includes all items" do
60
- [1,2,3].should include(1,2,3)
61
- end
33
+ context "for a hash target" do
34
+ it 'passes if target has the expected as a key' do
35
+ {:key => 'value'}.should include(:key)
36
+ end
62
37
 
63
- it "fails if target does not include any one of the items" do
64
- lambda {
65
- [1,2,3].should include(1,2,4)
66
- }.should fail_with("expected [1, 2, 3] to include 1, 2, and 4")
38
+ it "fails if target does not include expected" do
39
+ lambda {
40
+ {:key => 'value'}.should include(:other)
41
+ }.should fail_matching(%Q|expected {:key=>"value"} to include :other|)
42
+ end
67
43
  end
68
44
  end
69
45
 
70
- context "for a hash target" do
71
- it 'passes if target includes all items as keys' do
72
- {:key => 'value', :other => 'value'}.should include(:key, :other)
46
+ describe "should include(with, multiple, args)" do
47
+ it "has a description" do
48
+ matcher = include("a")
49
+ matcher.description.should eq("include \"a\"")
73
50
  end
51
+ context "for a string target" do
52
+ it "passes if target includes all items" do
53
+ "a string".should include("str", "a")
54
+ end
74
55
 
75
- it 'fails if target is missing any item as a key' do
76
- lambda {
77
- {:key => 'value'}.should include(:key, :other)
78
- }.should fail_matching(%Q|expected {:key=>"value"} to include :key and :other|)
56
+ it "fails if target does not include any one of the items" do
57
+ lambda {
58
+ "a string".should include("str", "a", "foo")
59
+ }.should fail_matching(%Q{expected "a string" to include "str", "a", and "foo"})
60
+ end
79
61
  end
80
- end
81
- end
82
62
 
83
- describe "should_not include(expected)" do
84
- context "for a string target" do
85
- it "passes if target does not include expected" do
86
- "abc".should_not include("d")
87
- end
88
-
89
- it "fails if target includes expected" do
90
- lambda {
91
- "abc".should_not include("c")
92
- }.should fail_with("expected \"abc\" not to include \"c\"")
93
- end
94
- end
95
-
96
- context "for an array target" do
97
- it "passes if target does not include expected" do
98
- [1,2,3].should_not include(4)
99
- end
100
-
101
- it "fails if target includes expected" do
102
- lambda {
103
- [1,2,3].should_not include(3)
104
- }.should fail_with("expected [1, 2, 3] not to include 3")
105
- end
106
- end
107
-
108
- context "for a hash target" do
109
- it 'passes if target does not have the expected as a key' do
110
- {:other => 'value'}.should_not include(:key)
111
- end
112
-
113
- it "fails if target includes expected key" do
114
- lambda {
115
- {:key => 'value'}.should_not include(:key)
116
- }.should fail_matching(%Q|expected {:key=>"value"} not to include :key|)
117
- end
118
- end
119
-
120
- end
121
-
122
- describe "should_not include(with, multiple, args)" do
123
- context "for a string target" do
124
- it "passes if the target does not include any of the expected" do
125
- "abc".should_not include("d", "e", "f")
126
- end
127
-
128
- it "fails if the target includes all of the expected" do
129
- expect {
130
- "abc".should_not include("c", "a")
131
- }.to fail_with(%q{expected "abc" not to include "c" and "a"})
132
- end
133
-
134
- it "fails if the target includes some (but not all) of the expected" do
135
- expect {
136
- "abc".should_not include("d", "a")
137
- }.to fail_with(%q{expected "abc" not to include "d" and "a"})
138
- end
139
- end
63
+ context "for an array target" do
64
+ it "passes if target includes all items" do
65
+ [1,2,3].should include(1,2,3)
66
+ end
140
67
 
141
- context "for a hash target" do
142
- it "passes if it does not include any of the expected keys" do
143
- { :a => 1, :b => 2 }.should_not include(:c, :d)
68
+ it "fails if target does not include any one of the items" do
69
+ lambda {
70
+ [1,2,3].should include(1,2,4)
71
+ }.should fail_matching("expected [1, 2, 3] to include 1, 2, and 4")
72
+ end
144
73
  end
145
74
 
146
- it "fails if the target includes all of the expected keys" do
147
- expect {
148
- { :a => 1, :b => 2 }.should_not include(:a, :b)
149
- }.to fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} not to include :a and :b|)
150
- end
75
+ context "for a hash target" do
76
+ it 'passes if target includes all items as keys' do
77
+ {:key => 'value', :other => 'value'}.should include(:key, :other)
78
+ end
151
79
 
152
- it "fails if the target includes some (but not all) of the expected keys" do
153
- expect {
154
- { :a => 1, :b => 2 }.should_not include(:d, :b)
155
- }.to fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} not to include :d and :b|)
80
+ it 'fails if target is missing any item as a key' do
81
+ lambda {
82
+ {:key => 'value'}.should include(:key, :other)
83
+ }.should fail_matching(%Q|expected {:key=>"value"} to include :key and :other|)
84
+ end
156
85
  end
157
86
  end
158
87
 
159
- context "for an array target" do
160
- it "passes if the target does not include any of the expected" do
161
- [1, 2, 3].should_not include(4, 5, 6)
162
- end
88
+ describe "should_not include(expected)" do
89
+ context "for a string target" do
90
+ it "passes if target does not include expected" do
91
+ "abc".should_not include("d")
92
+ end
163
93
 
164
- it "fails if the target includes all of the expected" do
165
- expect {
166
- [1, 2, 3].should_not include(3, 1)
167
- }.to fail_with(%q{expected [1, 2, 3] not to include 3 and 1})
94
+ it "fails if target includes expected" do
95
+ lambda {
96
+ "abc".should_not include("c")
97
+ }.should fail_with("expected \"abc\" not to include \"c\"")
98
+ end
168
99
  end
169
100
 
170
- it "fails if the target includes some (but not all) of the expected" do
171
- expect {
172
- [1, 2, 3].should_not include(4, 1)
173
- }.to fail_with(%q{expected [1, 2, 3] not to include 4 and 1})
174
- end
175
- end
176
- end
101
+ context "for an array target" do
102
+ it "passes if target does not include expected" do
103
+ [1,2,3].should_not include(4)
104
+ end
177
105
 
178
- describe "should include(:key => value)" do
179
- context 'for a hash target' do
180
- it "passes if target includes the key/value pair" do
181
- {:key => 'value'}.should include(:key => 'value')
106
+ it "fails if target includes expected" do
107
+ lambda {
108
+ [1,2,3].should_not include(3)
109
+ }.should fail_with("expected [1, 2, 3] not to include 3")
110
+ end
182
111
  end
183
112
 
184
- it "passes if target includes the key/value pair among others" do
185
- {:key => 'value', :other => 'different'}.should include(:key => 'value')
186
- end
113
+ context "for a hash target" do
114
+ it 'passes if target does not have the expected as a key' do
115
+ {:other => 'value'}.should_not include(:key)
116
+ end
187
117
 
188
- it "fails if target has a different value for key" do
189
- lambda {
190
- {:key => 'different'}.should include(:key => 'value')
191
- }.should fail_matching(%Q|expected {:key=>"different"} to include {:key=>"value"}|)
118
+ it "fails if target includes expected key" do
119
+ lambda {
120
+ {:key => 'value'}.should_not include(:key)
121
+ }.should fail_matching(%Q|expected {:key=>"value"} not to include :key|)
122
+ end
192
123
  end
193
124
 
194
- it "fails if target has a different key" do
195
- lambda {
196
- {:other => 'value'}.should include(:key => 'value')
197
- }.should fail_matching(%Q|expected {:other=>"value"} to include {:key=>"value"}|)
198
- end
199
125
  end
200
126
 
201
- context 'for a non-hash target' do
202
- it "fails if the target does not contain the given hash" do
203
- lambda {
204
- ['a', 'b'].should include(:key => 'value')
205
- }.should fail_matching(%q|expected ["a", "b"] to include {:key=>"value"}|)
206
- end
207
-
208
- it "passes if the target contains the given hash" do
209
- ['a', { :key => 'value' } ].should include(:key => 'value')
127
+ describe "should_not include(with, multiple, args)" do
128
+ context "for a string target" do
129
+ it "passes if the target does not include any of the expected" do
130
+ "abc".should_not include("d", "e", "f")
131
+ end
132
+
133
+ it "fails if the target includes all of the expected" do
134
+ expect {
135
+ "abc".should_not include("c", "a")
136
+ }.to fail_with(%q{expected "abc" not to include "c" and "a"})
137
+ end
138
+
139
+ it "fails if the target includes some (but not all) of the expected" do
140
+ expect {
141
+ "abc".should_not include("d", "a")
142
+ }.to fail_with(%q{expected "abc" not to include "d" and "a"})
143
+ end
144
+ end
145
+
146
+ context "for a hash target" do
147
+ it "passes if it does not include any of the expected keys" do
148
+ { :a => 1, :b => 2 }.should_not include(:c, :d)
149
+ end
150
+
151
+ it "fails if the target includes all of the expected keys" do
152
+ expect {
153
+ { :a => 1, :b => 2 }.should_not include(:a, :b)
154
+ }.to fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} not to include :a and :b|)
155
+ end
156
+
157
+ it "fails if the target includes some (but not all) of the expected keys" do
158
+ expect {
159
+ { :a => 1, :b => 2 }.should_not include(:d, :b)
160
+ }.to fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} not to include :d and :b|)
161
+ end
162
+ end
163
+
164
+ context "for an array target" do
165
+ it "passes if the target does not include any of the expected" do
166
+ [1, 2, 3].should_not include(4, 5, 6)
167
+ end
168
+
169
+ it "fails if the target includes all of the expected" do
170
+ expect {
171
+ [1, 2, 3].should_not include(3, 1)
172
+ }.to fail_with(%q{expected [1, 2, 3] not to include 3 and 1})
173
+ end
174
+
175
+ it "fails if the target includes some (but not all) of the expected" do
176
+ expect {
177
+ [1, 2, 3].should_not include(4, 1)
178
+ }.to fail_with(%q{expected [1, 2, 3] not to include 4 and 1})
179
+ end
210
180
  end
211
181
  end
212
- end
213
182
 
214
- describe "should_not include(:key => value)" do
215
- context 'for a hash target' do
216
- it "fails if target includes the key/value pair" do
217
- lambda {
218
- {:key => 'value'}.should_not include(:key => 'value')
219
- }.should fail_matching(%Q|expected {:key=>"value"} not to include {:key=>"value"}|)
220
- end
183
+ describe "should include(:key => value)" do
184
+ context 'for a hash target' do
185
+ it "passes if target includes the key/value pair" do
186
+ {:key => 'value'}.should include(:key => 'value')
187
+ end
221
188
 
222
- it "fails if target includes the key/value pair among others" do
223
- lambda {
224
- {:key => 'value', :other => 'different'}.should_not include(:key => 'value')
225
- }.should fail_matching(%Q|expected #{{:key=>"value", :other=>"different"}.inspect} not to include {:key=>"value"}|)
226
- end
189
+ it "passes if target includes the key/value pair among others" do
190
+ {:key => 'value', :other => 'different'}.should include(:key => 'value')
191
+ end
227
192
 
228
- it "passes if target has a different value for key" do
229
- {:key => 'different'}.should_not include(:key => 'value')
230
- end
193
+ it "fails if target has a different value for key" do
194
+ lambda {
195
+ {:key => 'different'}.should include(:key => 'value')
196
+ }.should fail_matching(%Q|expected {:key=>"different"} to include {:key=>"value"}|)
197
+ end
231
198
 
232
- it "passes if target has a different key" do
233
- {:other => 'value'}.should_not include(:key => 'value')
199
+ it "fails if target has a different key" do
200
+ lambda {
201
+ {:other => 'value'}.should include(:key => 'value')
202
+ }.should fail_matching(%Q|expected {:other=>"value"} to include {:key=>"value"}|)
203
+ end
234
204
  end
235
- end
236
205
 
237
- context "for a non-hash target" do
238
- it "passes if the target does not contain the given hash" do
239
- ['a', 'b'].should_not include(:key => 'value')
240
- end
206
+ context 'for a non-hash target' do
207
+ it "fails if the target does not contain the given hash" do
208
+ lambda {
209
+ ['a', 'b'].should include(:key => 'value')
210
+ }.should fail_matching(%q|expected ["a", "b"] to include {:key=>"value"}|)
211
+ end
241
212
 
242
- it "fails if the target contains the given hash" do
243
- lambda {
244
- ['a', { :key => 'value' } ].should_not include(:key => 'value')
245
- }.should fail_matching(%Q|expected ["a", {:key=>"value"}] not to include {:key=>"value"}|)
213
+ it "passes if the target contains the given hash" do
214
+ ['a', { :key => 'value' } ].should include(:key => 'value')
215
+ end
246
216
  end
247
217
  end
248
- end
249
218
 
250
- describe "should include(:key1 => value1, :key2 => value2)" do
251
- context 'for a hash target' do
252
- it "passes if target includes the key/value pairs" do
253
- {:a => 1, :b => 2}.should include(:b => 2, :a => 1)
254
- end
219
+ describe "should_not include(:key => value)" do
220
+ context 'for a hash target' do
221
+ it "fails if target includes the key/value pair" do
222
+ lambda {
223
+ {:key => 'value'}.should_not include(:key => 'value')
224
+ }.should fail_matching(%Q|expected {:key=>"value"} not to include {:key=>"value"}|)
225
+ end
255
226
 
256
- it "passes if target includes the key/value pairs among others" do
257
- {:a => 1, :c => 3, :b => 2}.should include(:b => 2, :a => 1)
258
- end
227
+ it "fails if target includes the key/value pair among others" do
228
+ lambda {
229
+ {:key => 'value', :other => 'different'}.should_not include(:key => 'value')
230
+ }.should fail_matching(%Q|expected #{{:key=>"value", :other=>"different"}.inspect} not to include {:key=>"value"}|)
231
+ end
259
232
 
260
- it "fails if target has a different value for one of the keys" do
261
- lambda {
262
- {:a => 1, :b => 2}.should include(:a => 2, :b => 2)
263
- }.should fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} to include #{{:a=>2, :b=>2}.inspect}|)
264
- end
233
+ it "passes if target has a different value for key" do
234
+ {:key => 'different'}.should_not include(:key => 'value')
235
+ end
265
236
 
266
- it "fails if target has a different value for both of the keys" do
267
- lambda {
268
- {:a => 1, :b => 1}.should include(:a => 2, :b => 2)
269
- }.should fail_matching(%Q|expected #{{:a=>1, :b=>1}.inspect} to include #{{:a=>2, :b=>2}.inspect}|)
237
+ it "passes if target has a different key" do
238
+ {:other => 'value'}.should_not include(:key => 'value')
239
+ end
270
240
  end
271
241
 
272
- it "fails if target lacks one of the keys" do
273
- lambda {
274
- {:a => 1, :b => 1}.should include(:a => 1, :c => 1)
275
- }.should fail_matching(%Q|expected #{{:a=>1, :b=>1}.inspect} to include #{{:a=>1, :c=>1}.inspect}|)
276
- end
242
+ context "for a non-hash target" do
243
+ it "passes if the target does not contain the given hash" do
244
+ ['a', 'b'].should_not include(:key => 'value')
245
+ end
277
246
 
278
- it "fails if target lacks both of the keys" do
279
- lambda {
280
- {:a => 1, :b => 1}.should include(:c => 1, :d => 1)
281
- }.should fail_matching(%Q|expected #{{:a=>1, :b=>1}.inspect} to include #{{:c=>1, :d=>1}.inspect}|)
247
+ it "fails if the target contains the given hash" do
248
+ lambda {
249
+ ['a', { :key => 'value' } ].should_not include(:key => 'value')
250
+ }.should fail_matching(%Q|expected ["a", {:key=>"value"}] not to include {:key=>"value"}|)
251
+ end
282
252
  end
283
253
  end
284
254
 
285
- context 'for a non-hash target' do
286
- it "fails if the target does not contain the given hash" do
287
- lambda {
288
- ['a', 'b'].should include(:a => 1, :b => 1)
289
- }.should fail_matching(%Q|expected ["a", "b"] to include #{{:a=>1, :b=>1}.inspect}|)
290
- end
291
-
292
- it "passes if the target contains the given hash" do
293
- ['a', { :a => 1, :b => 2 } ].should include(:a => 1, :b => 2)
255
+ describe "should include(:key1 => value1, :key2 => value2)" do
256
+ context 'for a hash target' do
257
+ it "passes if target includes the key/value pairs" do
258
+ {:a => 1, :b => 2}.should include(:b => 2, :a => 1)
259
+ end
260
+
261
+ it "passes if target includes the key/value pairs among others" do
262
+ {:a => 1, :c => 3, :b => 2}.should include(:b => 2, :a => 1)
263
+ end
264
+
265
+ it "fails if target has a different value for one of the keys" do
266
+ lambda {
267
+ {:a => 1, :b => 2}.should include(:a => 2, :b => 2)
268
+ }.should fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} to include #{{:a=>2, :b=>2}.inspect}|)
269
+ end
270
+
271
+ it "fails if target has a different value for both of the keys" do
272
+ lambda {
273
+ {:a => 1, :b => 1}.should include(:a => 2, :b => 2)
274
+ }.should fail_matching(%Q|expected #{{:a=>1, :b=>1}.inspect} to include #{{:a=>2, :b=>2}.inspect}|)
275
+ end
276
+
277
+ it "fails if target lacks one of the keys" do
278
+ lambda {
279
+ {:a => 1, :b => 1}.should include(:a => 1, :c => 1)
280
+ }.should fail_matching(%Q|expected #{{:a=>1, :b=>1}.inspect} to include #{{:a=>1, :c=>1}.inspect}|)
281
+ end
282
+
283
+ it "fails if target lacks both of the keys" do
284
+ lambda {
285
+ {:a => 1, :b => 1}.should include(:c => 1, :d => 1)
286
+ }.should fail_matching(%Q|expected #{{:a=>1, :b=>1}.inspect} to include #{{:c=>1, :d=>1}.inspect}|)
287
+ end
288
+ end
289
+
290
+ context 'for a non-hash target' do
291
+ it "fails if the target does not contain the given hash" do
292
+ lambda {
293
+ ['a', 'b'].should include(:a => 1, :b => 1)
294
+ }.should fail_matching(%Q|expected ["a", "b"] to include #{{:a=>1, :b=>1}.inspect}|)
295
+ end
296
+
297
+ it "passes if the target contains the given hash" do
298
+ ['a', { :a => 1, :b => 2 } ].should include(:a => 1, :b => 2)
299
+ end
294
300
  end
295
301
  end
296
- end
297
-
298
- describe "should_not include(:key1 => value1, :key2 => value2)" do
299
- context 'for a hash target' do
300
- it "fails if target includes the key/value pairs" do
301
- lambda {
302
- {:a => 1, :b => 2}.should_not include(:a => 1, :b => 2)
303
- }.should fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} not to include #{{:a=>1, :b=>2}.inspect}|)
304
- end
305
-
306
- it "fails if target includes the key/value pairs among others" do
307
- hash = {:a => 1, :b => 2, :c => 3}
308
- lambda {
309
- hash.should_not include(:a => 1, :b => 2)
310
- }.should fail_matching(%Q|expected #{hash.inspect} not to include #{{:a=>1, :b=>2}.inspect}|)
311
- end
312
-
313
- it "fails if target has a different value for one of the keys" do
314
- lambda {
315
- {:a => 1, :b => 2}.should_not include(:a => 2, :b => 2)
316
- }.should fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} not to include #{{:a=>2, :b=>2}.inspect}|)
317
- end
318
-
319
- it "passes if target has a different value for both of the keys" do
320
- {:a => 1, :b => 1}.should_not include(:a => 2, :b => 2)
321
- end
322
-
323
- it "fails if target lacks one of the keys" do
324
- lambda {
325
- {:a => 1, :b => 1}.should_not include(:a => 1, :c => 1)
326
- }.should fail_matching(%Q|expected #{{:a=>1, :b=>1}.inspect} not to include #{{:a=>1, :c=>1}.inspect}|)
327
- end
328
-
329
- it "passes if target lacks both of the keys" do
330
- {:a => 1, :b => 1}.should_not include(:c => 1, :d => 1)
331
- end
332
- end
333
-
334
- context 'for a non-hash target' do
335
- it "passes if the target does not contain the given hash" do
336
- ['a', 'b'].should_not include(:a => 1, :b => 1)
337
- end
338
302
 
339
- it "fails if the target contains the given hash" do
340
- lambda {
341
- ['a', { :a => 1, :b => 2 } ].should_not include(:a => 1, :b => 2)
342
- }.should fail_matching(%Q|expected #{["a", {:a=>1, :b=>2}].inspect} not to include #{{:a=>1, :b=>2}.inspect}|)
303
+ describe "should_not include(:key1 => value1, :key2 => value2)" do
304
+ context 'for a hash target' do
305
+ it "fails if target includes the key/value pairs" do
306
+ lambda {
307
+ {:a => 1, :b => 2}.should_not include(:a => 1, :b => 2)
308
+ }.should fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} not to include #{{:a=>1, :b=>2}.inspect}|)
309
+ end
310
+
311
+ it "fails if target includes the key/value pairs among others" do
312
+ hash = {:a => 1, :b => 2, :c => 3}
313
+ lambda {
314
+ hash.should_not include(:a => 1, :b => 2)
315
+ }.should fail_matching(%Q|expected #{hash.inspect} not to include #{{:a=>1, :b=>2}.inspect}|)
316
+ end
317
+
318
+ it "fails if target has a different value for one of the keys" do
319
+ lambda {
320
+ {:a => 1, :b => 2}.should_not include(:a => 2, :b => 2)
321
+ }.should fail_matching(%Q|expected #{{:a=>1, :b=>2}.inspect} not to include #{{:a=>2, :b=>2}.inspect}|)
322
+ end
323
+
324
+ it "passes if target has a different value for both of the keys" do
325
+ {:a => 1, :b => 1}.should_not include(:a => 2, :b => 2)
326
+ end
327
+
328
+ it "fails if target lacks one of the keys" do
329
+ lambda {
330
+ {:a => 1, :b => 1}.should_not include(:a => 1, :c => 1)
331
+ }.should fail_matching(%Q|expected #{{:a=>1, :b=>1}.inspect} not to include #{{:a=>1, :c=>1}.inspect}|)
332
+ end
333
+
334
+ it "passes if target lacks both of the keys" do
335
+ {:a => 1, :b => 1}.should_not include(:c => 1, :d => 1)
336
+ end
337
+ end
338
+
339
+ context 'for a non-hash target' do
340
+ it "passes if the target does not contain the given hash" do
341
+ ['a', 'b'].should_not include(:a => 1, :b => 1)
342
+ end
343
+
344
+ it "fails if the target contains the given hash" do
345
+ lambda {
346
+ ['a', { :a => 1, :b => 2 } ].should_not include(:a => 1, :b => 2)
347
+ }.should fail_matching(%Q|expected #{["a", {:a=>1, :b=>2}].inspect} not to include #{{:a=>1, :b=>2}.inspect}|)
348
+ end
343
349
  end
344
350
  end
345
351
  end
metadata CHANGED
@@ -1,15 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-expectations
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15424209
5
- prerelease: 6
4
+ hash: 47
5
+ prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 8
9
9
  - 0
10
- - rc
11
- - 2
12
- version: 2.8.0.rc2
10
+ version: 2.8.0
13
11
  platform: ruby
14
12
  authors:
15
13
  - Steven Baker
@@ -18,7 +16,7 @@ autorequire:
18
16
  bindir: bin
19
17
  cert_chain: []
20
18
 
21
- date: 2011-12-20 00:00:00 Z
19
+ date: 2012-01-05 00:00:00 Z
22
20
  dependencies:
23
21
  - !ruby/object:Gem::Dependency
24
22
  version_requirements: &id001 !ruby/object:Gem::Requirement
@@ -178,21 +176,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
178
176
  required_rubygems_version: !ruby/object:Gem::Requirement
179
177
  none: false
180
178
  requirements:
181
- - - ">"
179
+ - - ">="
182
180
  - !ruby/object:Gem::Version
183
- hash: 25
181
+ hash: 3
184
182
  segments:
185
- - 1
186
- - 3
187
- - 1
188
- version: 1.3.1
183
+ - 0
184
+ version: "0"
189
185
  requirements: []
190
186
 
191
187
  rubyforge_project: rspec
192
188
  rubygems_version: 1.8.11
193
189
  signing_key:
194
190
  specification_version: 3
195
- summary: rspec-expectations-2.8.0.rc2
191
+ summary: rspec-expectations-2.8.0
196
192
  test_files:
197
193
  - features/README.markdown
198
194
  - features/Upgrade.md