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
@@ -19,42 +19,45 @@ module RSpec
19
19
  throw :proc_did_not_throw_anything, :nothing_thrown
20
20
  end
21
21
  end
22
- @caught_symbol = @expected_symbol unless @caught_arg == :nothing_thrown
22
+
23
+ if @caught_arg == :nothing_thrown
24
+ @caught_arg = nil
25
+ else
26
+ @caught_symbol = @expected_symbol
27
+ end
23
28
  end
24
29
 
25
30
  # Ruby 1.8 uses NameError with `symbol'
26
31
  # Ruby 1.9 uses ArgumentError with :symbol
27
32
  rescue NameError, ArgumentError => e
28
- raise e unless e.message =~ /uncaught throw (`|\:)([a-zA-Z0-9_]*)(')?/
33
+ unless e.message =~ /uncaught throw (`|\:)([a-zA-Z0-9_]*)(')?/
34
+ other_exception = e
35
+ raise
36
+ end
29
37
  @caught_symbol = $2.to_sym
30
-
38
+ rescue => other_exception
39
+ raise
31
40
  ensure
32
- if @expected_symbol.nil?
33
- return !@caught_symbol.nil?
34
- else
35
- if @expected_arg.nil?
36
- return @caught_symbol == @expected_symbol
41
+ unless other_exception
42
+ if @expected_symbol.nil?
43
+ return !@caught_symbol.nil?
37
44
  else
38
- return (@caught_symbol == @expected_symbol) & (@caught_arg == @expected_arg)
45
+ if @expected_arg.nil?
46
+ return @caught_symbol == @expected_symbol
47
+ else
48
+ return (@caught_symbol == @expected_symbol) & (@caught_arg == @expected_arg)
49
+ end
39
50
  end
40
51
  end
41
52
  end
42
53
  end
43
54
 
44
55
  def failure_message_for_should
45
- if @caught_symbol
46
- "expected #{expected}, got #{@caught_symbol.inspect}"
47
- else
48
- "expected #{expected} but nothing was thrown"
49
- end
56
+ "expected #{expected} to be thrown, got #{caught}"
50
57
  end
51
58
 
52
59
  def failure_message_for_should_not
53
- if @expected_symbol
54
- "expected #{expected} not to be thrown"
55
- else
56
- "expected no Symbol, got :#{@caught_symbol}"
57
- end
60
+ "expected #{expected('no Symbol')}#{' not' if @expected_symbol} to be thrown, got #{caught}"
58
61
  end
59
62
 
60
63
  def description
@@ -62,15 +65,29 @@ module RSpec
62
65
  end
63
66
 
64
67
  private
65
-
66
- def expected
67
- @expected_symbol.nil? ? "a Symbol" : "#{@expected_symbol.inspect}#{args}"
68
+
69
+ def expected(symbol_desc = 'a Symbol')
70
+ throw_description(@expected_symbol || symbol_desc, @expected_arg)
68
71
  end
69
-
70
- def args
71
- @expected_arg.nil? ? "" : " with #{@expected_arg.inspect}"
72
+
73
+ def caught
74
+ throw_description(@caught_symbol || 'nothing', @caught_arg)
72
75
  end
73
-
76
+
77
+ def throw_description(symbol, arg)
78
+ symbol_description = symbol.is_a?(String) ? symbol : symbol.inspect
79
+
80
+ arg_description = if arg
81
+ " with #{arg.inspect}"
82
+ elsif @expected_arg && @caught_symbol == @expected_symbol
83
+ " with no argument"
84
+ else
85
+ ""
86
+ end
87
+
88
+ symbol_description + arg_description
89
+ end
90
+
74
91
  end
75
92
 
76
93
  # :call-seq:
@@ -16,7 +16,7 @@ module RSpec
16
16
  #
17
17
  # In addition to those Expression Matchers that are defined explicitly, RSpec will
18
18
  # create custom Matchers on the fly for any arbitrary predicate, giving your specs
19
- # a much more natural language feel.
19
+ # a much more natural language feel.
20
20
  #
21
21
  # A Ruby predicate is a method that ends with a "?" and returns true or false.
22
22
  # Common examples are +empty?+, +nil?+, and +instance_of?+.
@@ -155,8 +155,17 @@ module RSpec
155
155
  # end
156
156
  #
157
157
  module Matchers
158
- if RSpec.respond_to?(:configure)
159
- RSpec.configure {|c| c.include self}
158
+ # Include Matchers for other test frameworks.
159
+ # Note that MiniTest _must_ come before TU because on ruby 1.9,
160
+ # T::U::TC is a subclass of MT::U::TC and a 1.9 bug can lead
161
+ # to infinite recursion from the `super` call in our method_missing
162
+ # hook. See this gist for more info:
163
+ # https://gist.github.com/845896
164
+ if defined?(MiniTest::Unit::TestCase)
165
+ MiniTest::Unit::TestCase.send(:include, self)
166
+ end
167
+ if defined?(Test::Unit::TestCase)
168
+ Test::Unit::TestCase.send(:include, self)
160
169
  end
161
170
  end
162
171
  end
@@ -169,7 +178,10 @@ require 'rspec/matchers/be'
169
178
  require 'rspec/matchers/be_close'
170
179
  require 'rspec/matchers/be_instance_of'
171
180
  require 'rspec/matchers/be_kind_of'
181
+ require 'rspec/matchers/be_within'
182
+ require 'rspec/matchers/block_aliases'
172
183
  require 'rspec/matchers/change'
184
+ require 'rspec/matchers/cover' if (1..2).respond_to? :cover?
173
185
  require 'rspec/matchers/eq'
174
186
  require 'rspec/matchers/eql'
175
187
  require 'rspec/matchers/equal'
@@ -18,14 +18,10 @@ Gem::Specification.new do |s|
18
18
  s.files = `git ls-files`.split("\n")
19
19
  s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
20
20
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
- s.extra_rdoc_files = [ "README.markdown" ]
21
+ s.extra_rdoc_files = [ "README.md" ]
22
22
  s.rdoc_options = ["--charset=UTF-8"]
23
23
  s.require_path = "lib"
24
24
 
25
- s.add_runtime_dependency 'diff-lcs', '>= 1.1.2'
26
- s.add_development_dependency 'cucumber', ">= 0.6.2"
27
- s.add_development_dependency 'aruba', ">= 0.1.1"
28
- s.add_development_dependency 'rspec-core', ">= #{RSpec::Expectations::Version::STRING}"
29
- s.add_development_dependency 'rspec-mocks', ">= #{RSpec::Expectations::Version::STRING}"
25
+ s.add_runtime_dependency 'diff-lcs', '~> 1.1.2'
30
26
  end
31
27
 
@@ -1,49 +1,21 @@
1
1
  require 'spec_helper'
2
+
2
3
  module RSpec
3
4
  module Matchers
4
5
  describe "[actual.should] be_close(expected, delta)" do
5
- it "matches when actual == expected" do
6
- be_close(5.0, 0.5).matches?(5.0).should be_true
7
- end
8
- it "matches when actual < (expected + delta)" do
9
- be_close(5.0, 0.5).matches?(5.49).should be_true
10
- end
11
- it "matches when actual > (expected - delta)" do
12
- be_close(5.0, 0.5).matches?(4.51).should be_true
13
- end
14
- it "does not match when actual == (expected - delta)" do
15
- be_close(5.0, 0.5).matches?(4.5).should be_false
16
- end
17
- it "does not match when actual < (expected - delta)" do
18
- be_close(5.0, 0.5).matches?(4.49).should be_false
19
- end
20
- it "does not match when actual == (expected + delta)" do
21
- be_close(5.0, 0.5).matches?(5.5).should be_false
22
- end
23
- it "does not match when actual > (expected + delta)" do
24
- be_close(5.0, 0.5).matches?(5.51).should be_false
25
- end
26
- it "provides a failure message for should" do
27
- #given
28
- matcher = be_close(5.0, 0.5)
29
- #when
30
- matcher.matches?(5.51)
31
- #then
32
- matcher.failure_message_for_should.should == "expected 5.0 +/- (< 0.5), got 5.51"
6
+ before(:each) do
7
+ RSpec.stub(:warn)
33
8
  end
34
9
 
35
- it "provides a failure message for should tno" do
36
- #given
37
- matcher = be_close(5.0, 0.5)
38
- #when
39
- matcher.matches?(5.49)
40
- #then
41
- matcher.failure_message_for_should_not.should == "expected 5.0 +/- (< 0.5), got 5.49"
10
+ it "delegates to be_within(delta).of(expected)" do
11
+ should_receive(:be_within).with(0.5).and_return( be_within_matcher = stub )
12
+ be_within_matcher.should_receive(:of).with(3.0)
13
+ be_close(3.0, 0.5)
42
14
  end
43
- it "provides a description" do
44
- matcher = be_close(5.0, 0.5)
45
- matcher.matches?(5.1)
46
- matcher.description.should == "be close to 5.0 (within +- 0.5)"
15
+
16
+ it "prints a deprecation warning" do
17
+ RSpec.should_receive(:warn).with(/please use be_within.*instead/)
18
+ be_close(3.0, 0.5)
47
19
  end
48
20
  end
49
21
  end
@@ -265,7 +265,7 @@ describe "should be_nil" do
265
265
  it "fails when actual is not nil" do
266
266
  lambda {
267
267
  :not_nil.should be_nil
268
- }.should fail_with("expected nil, got :not_nil")
268
+ }.should fail_with(/^expected: nil/)
269
269
  end
270
270
  end
271
271
 
@@ -277,7 +277,7 @@ describe "should_not be_nil" do
277
277
  it "fails when actual is nil" do
278
278
  lambda {
279
279
  nil.should_not be_nil
280
- }.should fail_with("expected not nil, got nil")
280
+ }.should fail_with(/^expected: not nil/)
281
281
  end
282
282
  end
283
283
 
@@ -287,7 +287,7 @@ describe "should be <" do
287
287
  end
288
288
 
289
289
  it "fails when < operator returns false" do
290
- lambda { 3.should be < 3 }.should fail_with("expected < 3, got 3")
290
+ lambda { 3.should be < 3 }.should fail_with("expected: < 3\n got: 3")
291
291
  end
292
292
 
293
293
  it "describes itself" do
@@ -302,7 +302,7 @@ describe "should be <=" do
302
302
  end
303
303
 
304
304
  it "fails when <= operator returns false" do
305
- lambda { 3.should be <= 2 }.should fail_with("expected <= 2, got 3")
305
+ lambda { 3.should be <= 2 }.should fail_with("expected: <= 2\n got: 3")
306
306
  end
307
307
  end
308
308
 
@@ -313,7 +313,7 @@ describe "should be >=" do
313
313
  end
314
314
 
315
315
  it "fails when >= operator returns false" do
316
- lambda { 3.should be >= 4 }.should fail_with("expected >= 4, got 3")
316
+ lambda { 3.should be >= 4 }.should fail_with("expected: >= 4\n got: 3")
317
317
  end
318
318
  end
319
319
 
@@ -323,7 +323,7 @@ describe "should be >" do
323
323
  end
324
324
 
325
325
  it "fails when > operator returns false" do
326
- lambda { 3.should be > 4 }.should fail_with("expected > 4, got 3")
326
+ lambda { 3.should be > 4 }.should fail_with("expected: > 4\n got: 3")
327
327
  end
328
328
  end
329
329
 
@@ -333,7 +333,7 @@ describe "should be ==" do
333
333
  end
334
334
 
335
335
  it "fails when == operator returns false" do
336
- lambda { 3.should be == 4 }.should fail_with("expected == 4, got 3")
336
+ lambda { 3.should be == 4 }.should fail_with("expected: == 4\n got: 3")
337
337
  end
338
338
  end
339
339
 
@@ -343,7 +343,7 @@ describe "should be ===" do
343
343
  end
344
344
 
345
345
  it "fails when === operator returns false" do
346
- lambda { Hash.should be === "not a hash" }.should fail_with(%[expected === not a hash, got Hash])
346
+ lambda { Hash.should be === "not a hash" }.should fail_with(%[expected: === "not a hash"\n got: Hash])
347
347
  end
348
348
  end
349
349
 
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ module RSpec
4
+ module Matchers
5
+ describe "[actual.should] be_within(delta).of(expected)" do
6
+ it "matches when actual == expected" do
7
+ be_within(0.5).of(5.0).matches?(5.0).should be_true
8
+ end
9
+
10
+ it "matches when actual < (expected + delta)" do
11
+ be_within(0.5).of(5.0).matches?(5.49).should be_true
12
+ end
13
+
14
+ it "matches when actual > (expected - delta)" do
15
+ be_within(0.5).of(5.0).matches?(4.51).should be_true
16
+ end
17
+
18
+ it "does not match when actual == (expected - delta)" do
19
+ be_within(0.5).of(5.0).matches?(4.5).should be_false
20
+ end
21
+
22
+ it "does not match when actual < (expected - delta)" do
23
+ be_within(0.5).of(5.0).matches?(4.49).should be_false
24
+ end
25
+
26
+ it "does not match when actual == (expected + delta)" do
27
+ be_within(0.5).of(5.0).matches?(5.5).should be_false
28
+ end
29
+
30
+ it "does not match when actual > (expected + delta)" do
31
+ be_within(0.5).of(5.0).matches?(5.51).should be_false
32
+ end
33
+
34
+ it "provides a failure message for should" do
35
+ #given
36
+ matcher = be_within(0.5).of(5.0)
37
+ #when
38
+ matcher.matches?(5.51)
39
+ #then
40
+ matcher.failure_message_for_should.should == "expected 5.51 to be within 0.5 of 5.0"
41
+ end
42
+
43
+ it "provides a failure message for should not" do
44
+ #given
45
+ matcher = be_within(0.5).of(5.0)
46
+ #when
47
+ matcher.matches?(5.49)
48
+ #then
49
+ matcher.failure_message_for_should_not.should == "expected 5.49 not to be within 0.5 of 5.0"
50
+ end
51
+
52
+ it "provides a description" do
53
+ matcher = be_within(0.5).of(5.0)
54
+ matcher.matches?(5.1)
55
+ matcher.description.should == "be within 0.5 of 5.0"
56
+ end
57
+
58
+ it "raises an error if no expected value is given" do
59
+ matcher = be_within(0.5)
60
+ expect { matcher.matches?(5.1) }.to raise_error(ArgumentError, /must set an expected value using #of/)
61
+ end
62
+ end
63
+ end
64
+ end
@@ -14,7 +14,7 @@ describe "should change(actual, message)" do
14
14
  end
15
15
 
16
16
  it "passes when actual is modified by the block" do
17
- expect {@instance.some_value = 6}.to change(@instance, :some_value)
17
+ expect {@instance.some_value = 6.0}.to change(@instance, :some_value)
18
18
  end
19
19
 
20
20
  it "fails when actual is not modified by the block" do
@@ -44,6 +44,57 @@ describe "should change(actual, message)" do
44
44
  end.to fail_with("some_value should have changed, but is still true")
45
45
  end
46
46
  end
47
+
48
+ context "with nil value" do
49
+ before(:each) do
50
+ @instance = SomethingExpected.new
51
+ @instance.some_value = nil
52
+ end
53
+
54
+ it "passes when actual is modified by the block" do
55
+ expect {@instance.some_value = false}.to change(@instance, :some_value)
56
+ end
57
+
58
+ it "fails when actual is not modified by the block" do
59
+ expect do
60
+ expect {}.to change(@instance, :some_value)
61
+ end.to fail_with("some_value should have changed, but is still nil")
62
+ end
63
+ end
64
+
65
+ context "with an array" do
66
+ before(:each) do
67
+ @instance = SomethingExpected.new
68
+ @instance.some_value = []
69
+ end
70
+
71
+ it "passes when actual is modified by the block" do
72
+ expect {@instance.some_value << 1}.to change(@instance, :some_value)
73
+ end
74
+
75
+ it "fails when actual is not modified by the block" do
76
+ expect do
77
+ expect {}.to change(@instance, :some_value)
78
+ end.to fail_with("some_value should have changed, but is still []")
79
+ end
80
+ end
81
+
82
+ context "with a hash" do
83
+ before(:each) do
84
+ @instance = SomethingExpected.new
85
+ @instance.some_value = {:a => 'a'}
86
+ end
87
+
88
+ it "passes when actual is modified by the block" do
89
+ expect {@instance.some_value[:a] = 'A'}.to change(@instance, :some_value)
90
+ end
91
+
92
+ it "fails when actual is not modified by the block" do
93
+ expect do
94
+ expect {}.to change(@instance, :some_value)
95
+ end.to fail
96
+ end
97
+ end
47
98
  end
48
99
 
49
100
  describe "should_not change(actual, message)" do
@@ -123,6 +174,10 @@ describe "should change(actual, message).by(expected)" do
123
174
  expect { @instance.some_value += 1 }.to change(@instance, :some_value).by(1)
124
175
  end
125
176
 
177
+ it "passes when attribute is not changed and expected amount is 0" do
178
+ expect { @instance.some_value += 0 }.to change(@instance, :some_value).by(0)
179
+ end
180
+
126
181
  it "fails when the attribute is changed by unexpected amount" do
127
182
  expect do
128
183
  expect { @instance.some_value += 2 }.to change(@instance, :some_value).by(1)
@@ -269,11 +324,17 @@ describe "should change(actual, message).from(old)" do
269
324
  @instance.some_value = 'string'
270
325
  end
271
326
 
272
- it "passes when attribute is == to expected value before executing block" do
327
+ it "passes when attribute is === to expected value before executing block" do
273
328
  expect { @instance.some_value = "astring" }.to change(@instance, :some_value).from("string")
274
329
  end
275
330
 
276
- it "fails when attribute is not == to expected value before executing block" do
331
+ it "compares the expected and actual values with ===" do
332
+ expected = "string"
333
+ expected.should_receive(:===).and_return true
334
+ expect { @instance.some_value = "astring" }.to change(@instance, :some_value).from(expected)
335
+ end
336
+
337
+ it "fails when attribute is not === to expected value before executing block" do
277
338
  expect do
278
339
  expect { @instance.some_value = "knot" }.to change(@instance, :some_value).from("cat")
279
340
  end.to fail_with("some_value should have initially been \"cat\", but was \"string\"")
@@ -287,11 +348,17 @@ describe "should change{ block }.from(old)" do
287
348
  @instance.some_value = 'string'
288
349
  end
289
350
 
290
- it "passes when attribute is == to expected value before executing block" do
351
+ it "passes when attribute is === to expected value before executing block" do
291
352
  expect { @instance.some_value = "astring" }.to change{@instance.some_value}.from("string")
292
353
  end
293
354
 
294
- it "fails when attribute is not == to expected value before executing block" do
355
+ it "compares the expected and actual values with ===" do
356
+ expected = "string"
357
+ expected.should_receive(:===).and_return true
358
+ expect { @instance.some_value = "astring" }.to change{@instance.some_value}.from(expected)
359
+ end
360
+
361
+ it "fails when attribute is not === to expected value before executing block" do
295
362
  expect do
296
363
  expect { @instance.some_value = "knot" }.to change{@instance.some_value}.from("cat")
297
364
  end.to fail_with("result should have initially been \"cat\", but was \"string\"")
@@ -321,11 +388,17 @@ describe "should change(actual, message).to(new)" do
321
388
  @instance.some_value = 'string'
322
389
  end
323
390
 
324
- it "passes when attribute is == to expected value after executing block" do
391
+ it "passes when attribute is === to expected value after executing block" do
325
392
  expect { @instance.some_value = "cat" }.to change(@instance, :some_value).to("cat")
326
393
  end
327
394
 
328
- it "fails when attribute is not == to expected value after executing block" do
395
+ it "compares the expected and actual values with ===" do
396
+ expected = "cat"
397
+ expected.should_receive(:===).and_return true
398
+ expect { @instance.some_value = "cat" }.to change(@instance, :some_value).to(expected)
399
+ end
400
+
401
+ it "fails when attribute is not === to expected value after executing block" do
329
402
  expect do
330
403
  expect { @instance.some_value = "cat" }.to change(@instance, :some_value).from("string").to("dog")
331
404
  end.to fail_with("some_value should have been changed to \"dog\", but is now \"cat\"")
@@ -339,11 +412,17 @@ describe "should change{ block }.to(new)" do
339
412
  @instance.some_value = 'string'
340
413
  end
341
414
 
342
- it "passes when attribute is == to expected value after executing block" do
415
+ it "passes when attribute is === to expected value after executing block" do
343
416
  expect { @instance.some_value = "cat" }.to change{@instance.some_value}.to("cat")
344
417
  end
345
418
 
346
- it "fails when attribute is not == to expected value after executing block" do
419
+ it "compares the expected and actual values with ===" do
420
+ expected = "cat"
421
+ expected.should_receive(:===).and_return true
422
+ expect { @instance.some_value = "cat" }.to change{@instance.some_value}.to(expected)
423
+ end
424
+
425
+ it "fails when attribute is not === to expected value after executing block" do
347
426
  expect do
348
427
  expect { @instance.some_value = "cat" }.to change{@instance.some_value}.from("string").to("dog")
349
428
  end.to fail_with("result should have been changed to \"dog\", but is now \"cat\"")
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe "should cover(expected)", :if => RSpec::Matchers.respond_to?(:cover) do
4
+ context "for a range target" do
5
+ it "passes if target covers expected" do
6
+ (1..10).should cover(5)
7
+ end
8
+
9
+ it "fails if target does not cover expected" do
10
+ lambda {
11
+ (1..10).should cover(11)
12
+ }.should fail_with("expected 1..10 to cover 11")
13
+ end
14
+ end
15
+ end
16
+
17
+ describe "should cover(with, multiple, args)", :if => RSpec::Matchers.respond_to?(:cover) do
18
+ context "for a range target" do
19
+ it "passes if target covers all items" do
20
+ (1..10).should cover(4, 6)
21
+ end
22
+
23
+ it "fails if target does not cover any one of the items" do
24
+ lambda {
25
+ (1..10).should cover(4, 6, 11)
26
+ }.should fail_with("expected 1..10 to cover 4, 6, and 11")
27
+ end
28
+ end
29
+ end
30
+
31
+ describe "should_not cover(expected)", :if => RSpec::Matchers.respond_to?(:cover) do
32
+ context "for a range target" do
33
+ it "passes if target does not cover expected" do
34
+ (1..10).should_not cover(11)
35
+ end
36
+
37
+ it "fails if target covers expected" do
38
+ lambda {
39
+ (1..10).should_not cover(5)
40
+ }.should fail_with("expected 1..10 not to cover 5")
41
+ end
42
+ end
43
+ end
44
+
45
+ describe "should_not cover(with, multiple, args)", :if => RSpec::Matchers.respond_to?(:cover) do
46
+ context "for a range target" do
47
+ it "passes if the target does not cover any of the expected" do
48
+ (1..10).should_not include(11, 12, 13)
49
+ end
50
+
51
+ it "fails if the target covers all of the expected" do
52
+ expect {
53
+ (1..10).should_not include(4, 6)
54
+ }.to fail_with("expected 1..10 not to include 4 and 6")
55
+ end
56
+
57
+ it "fails if the target covers some (but not all) of the expected" do
58
+ expect {
59
+ (1..10).should_not include(5, 11)
60
+ }.to fail_with("expected 1..10 not to include 5 and 11")
61
+ end
62
+ end
63
+ end
64
+
65
+