rspec-mocks 2.0.0.beta.4 → 2.0.0.beta.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/.autotest +3 -2
  2. data/VERSION +1 -1
  3. data/features/mocks/block_local_expectations.feature +0 -14
  4. data/features/mocks/mix_stubs_and_mocks.feature +2 -2
  5. data/features/mocks/warn_when_expectation_is_set_on_nil.feature +50 -0
  6. data/lib/rspec/mocks.rb +9 -9
  7. data/lib/rspec/mocks/argument_matchers.rb +1 -1
  8. data/lib/rspec/mocks/error_generator.rb +24 -8
  9. data/lib/rspec/mocks/framework.rb +1 -0
  10. data/lib/rspec/mocks/message_expectation.rb +1 -1
  11. data/lib/rspec/mocks/method_double.rb +156 -0
  12. data/lib/rspec/mocks/methods.rb +2 -2
  13. data/lib/rspec/mocks/mock.rb +17 -10
  14. data/lib/rspec/mocks/proxy.rb +71 -158
  15. data/lib/rspec/mocks/spec_methods.rb +19 -3
  16. data/rspec-mocks.gemspec +14 -10
  17. data/spec/rspec/mocks/any_number_of_times_spec.rb +1 -1
  18. data/spec/rspec/mocks/argument_expectation_spec.rb +2 -2
  19. data/spec/rspec/mocks/bug_report_10260_spec.rb +1 -1
  20. data/spec/rspec/mocks/bug_report_10263_spec.rb +8 -8
  21. data/spec/rspec/mocks/bug_report_15719_spec.rb +12 -12
  22. data/spec/rspec/mocks/bug_report_7611_spec.rb +1 -1
  23. data/spec/rspec/mocks/bug_report_7805_spec.rb +1 -1
  24. data/spec/rspec/mocks/bug_report_8165_spec.rb +1 -1
  25. data/spec/rspec/mocks/bug_report_957_spec.rb +1 -1
  26. data/spec/rspec/mocks/double_spec.rb +12 -0
  27. data/spec/rspec/mocks/failing_argument_matchers_spec.rb +7 -6
  28. data/spec/rspec/mocks/mock_ordering_spec.rb +54 -54
  29. data/spec/rspec/mocks/mock_space_spec.rb +4 -4
  30. data/spec/rspec/mocks/mock_spec.rb +55 -51
  31. data/spec/rspec/mocks/multiple_return_value_spec.rb +29 -7
  32. data/spec/rspec/mocks/nil_expectation_warning_spec.rb +8 -8
  33. data/spec/rspec/mocks/null_object_mock_spec.rb +2 -2
  34. data/spec/rspec/mocks/once_counts_spec.rb +1 -1
  35. data/spec/rspec/mocks/options_hash_spec.rb +1 -1
  36. data/spec/rspec/mocks/partial_mock_spec.rb +13 -7
  37. data/spec/rspec/mocks/passing_argument_matchers_spec.rb +1 -1
  38. data/spec/rspec/mocks/precise_counts_spec.rb +1 -1
  39. data/spec/rspec/mocks/record_messages_spec.rb +1 -1
  40. data/spec/rspec/mocks/stub_spec.rb +22 -22
  41. data/spec/rspec/mocks/stubbed_message_expectations_spec.rb +12 -12
  42. data/spec/rspec/mocks/twice_counts_spec.rb +1 -1
  43. metadata +13 -9
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe "An RSpec Mock" do
4
4
  it "should hide internals in its inspect representation" do
5
- m = mock('cup')
5
+ m = double('cup')
6
6
  m.inspect.should =~ /#<Rspec::Mocks::Mock:0x[a-f0-9.]+ @name="cup">/
7
7
  end
8
8
  end
@@ -1,26 +1,26 @@
1
1
  describe "Mock" do
2
2
  before do
3
- @mock = mock("test mock")
3
+ @double = double("test double")
4
4
  end
5
5
 
6
6
  specify "when one example has an expectation (non-mock) inside the block passed to the mock" do
7
- @mock.should_receive(:msg) do |b|
7
+ @double.should_receive(:msg) do |b|
8
8
  b.should be_true #this call exposes the problem
9
9
  end
10
10
  begin
11
- @mock.msg(false)
11
+ @double.msg(false)
12
12
  rescue Exception
13
13
  end
14
14
  end
15
15
 
16
16
  specify "then the next example should behave as expected instead of saying" do
17
- @mock.should_receive(:foobar)
18
- @mock.foobar
19
- @mock.rspec_verify
17
+ @double.should_receive(:foobar)
18
+ @double.foobar
19
+ @double.rspec_verify
20
20
  begin
21
- @mock.foobar
21
+ @double.foobar
22
22
  rescue Exception => e
23
- e.message.should == "Mock 'test mock' received unexpected message :foobar with (no args)"
23
+ e.message.should == "Double \"test double\" received unexpected message :foobar with (no args)"
24
24
  end
25
25
  end
26
26
  end
@@ -5,25 +5,25 @@ module Rspec
5
5
  describe "mock failure" do
6
6
 
7
7
  it "should tell you when it receives the right message with the wrong args" do
8
- m = mock("foo")
9
- m.should_receive(:bar).with("message")
8
+ double = double("foo")
9
+ double.should_receive(:bar).with("message")
10
10
  lambda {
11
- m.bar("different message")
12
- }.should raise_error(Rspec::Mocks::MockExpectationError, %Q{Mock 'foo' expected :bar with ("message") but received it with ("different message")})
13
- m.bar("message") # allows the spec to pass
11
+ double.bar("different message")
12
+ }.should raise_error(Rspec::Mocks::MockExpectationError, %Q{Double "foo" received :bar with unexpected arguments\n expected: ("message")\n got: ("different message")})
13
+ double.rspec_reset # so the example doesn't fail
14
14
  end
15
15
 
16
16
  pending "should tell you when it receives the right message with the wrong args if you stub the method (fix bug 15719)" do
17
17
  # NOTE - for whatever reason, if you use a the block style of pending here,
18
18
  # rcov gets unhappy. Don't know why yet.
19
- m = mock("foo")
20
- m.stub!(:bar)
21
- m.should_receive(:bar).with("message")
19
+ double = double("foo")
20
+ double.stub(:bar)
21
+ double.should_receive(:bar).with("message")
22
22
  lambda {
23
- m.bar("different message")
24
- }.should raise_error(Rspec::Mocks::MockExpectationError, %Q{Mock 'foo' expected :bar with ("message") but received it with ("different message")})
25
- m.bar("message") # allows the spec to pass
23
+ double.bar("different message")
24
+ }.should raise_error(Rspec::Mocks::MockExpectationError, %Q{Double 'foo' expected :bar with ("message") but received it with ("different message")})
25
+ double.rspec_reset # so the example doesn't fail
26
26
  end
27
27
  end
28
28
  end
29
- end
29
+ end
@@ -8,7 +8,7 @@ module Bug7611
8
8
  class Bar < Foo
9
9
  end
10
10
  it "should respect subclasses" do
11
- Foo.stub!(:new).and_return(Object.new)
11
+ Foo.stub(:new).and_return(Object.new)
12
12
  end
13
13
 
14
14
  it "should" do
@@ -5,7 +5,7 @@ module Bug7805
5
5
 
6
6
  describe "Stubs should correctly restore module methods" do
7
7
  it "1 - stub the open method" do
8
- File.stub!(:open).and_return("something")
8
+ File.stub(:open).and_return("something")
9
9
  File.open.should == "something"
10
10
  end
11
11
  it "2 - use File.open to create example.txt" do
@@ -21,7 +21,7 @@ describe "An object where respond_to? is true and does not have method" do
21
21
  end
22
22
 
23
23
  it "should not raise an exception for mock" do
24
- obj = mock("obj")
24
+ obj = double("obj")
25
25
  obj.should_receive(:respond_to?).with(:foobar).and_return(true)
26
26
  obj.should_receive(:foobar).and_return(:baz)
27
27
  obj.respond_to?(:foobar).should be_true
@@ -7,7 +7,7 @@ module Spec
7
7
  @base_class = Class.new
8
8
  @concrete_class = Class.new(@base_class)
9
9
 
10
- @base_class.stub!(:find).and_return "stubbed_value"
10
+ @base_class.stub(:find).and_return "stubbed_value"
11
11
  end
12
12
 
13
13
  it "should return the value for the stub on the base class" do
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe "double" do
4
+ it "is an alias for stub and mock" do
5
+ double().should be_a(Rspec::Mocks::Mock)
6
+ end
7
+
8
+ it "uses 'Double' in failure messages" do
9
+ double = double('name')
10
+ expect {double.foo}.to raise_error(/Double "name" received/)
11
+ end
12
+ end
@@ -4,7 +4,7 @@ module Rspec
4
4
  module Mocks
5
5
  describe "failing MockArgumentMatchers" do
6
6
  before(:each) do
7
- @mock = mock("test mock")
7
+ @mock = double("test double")
8
8
  @reporter = Rspec::Mocks::Mock.new("reporter", :null_object => true)
9
9
  end
10
10
 
@@ -52,35 +52,35 @@ module Rspec
52
52
  @mock.should_receive(:random_call).with(:a => "b", :c => "d")
53
53
  lambda do
54
54
  @mock.random_call(:a => "b", :c => "e")
55
- end.should raise_error(Rspec::Mocks::MockExpectationError, /Mock 'test mock' expected :random_call with \(\{(:a=>\"b\", :c=>\"d\"|:c=>\"d\", :a=>\"b\")\}\) but received it with \(\{(:a=>\"b\", :c=>\"e\"|:c=>\"e\", :a=>\"b\")\}\)/)
55
+ end.should raise_error(Rspec::Mocks::MockExpectationError, /Double "test double" received :random_call with unexpected arguments\n expected: \(\{(:a=>\"b\", :c=>\"d\"|:c=>\"d\", :a=>\"b\")\}\)\n got: \(\{(:a=>\"b\", :c=>\"e\"|:c=>\"e\", :a=>\"b\")\}\)/)
56
56
  end
57
57
 
58
58
  it "should fail for a hash w/ wrong keys" do
59
59
  @mock.should_receive(:random_call).with(:a => "b", :c => "d")
60
60
  lambda do
61
61
  @mock.random_call("a" => "b", "c" => "d")
62
- end.should raise_error(Rspec::Mocks::MockExpectationError, /Mock 'test mock' expected :random_call with \(\{(:a=>\"b\", :c=>\"d\"|:c=>\"d\", :a=>\"b\")\}\) but received it with \(\{(\"a\"=>\"b\", \"c\"=>\"d\"|\"c\"=>\"d\", \"a\"=>\"b\")\}\)/)
62
+ end.should raise_error(Rspec::Mocks::MockExpectationError, /Double "test double" received :random_call with unexpected arguments\n expected: \(\{(:a=>\"b\", :c=>\"d\"|:c=>\"d\", :a=>\"b\")\}\)\n got: \(\{(\"a\"=>\"b\", \"c\"=>\"d\"|\"c\"=>\"d\", \"a\"=>\"b\")\}\)/)
63
63
  end
64
64
 
65
65
  it "should match against a Matcher" do
66
66
  lambda do
67
67
  @mock.should_receive(:msg).with(equal(3))
68
68
  @mock.msg(37)
69
- end.should raise_error(Rspec::Mocks::MockExpectationError, "Mock 'test mock' expected :msg with (equal 3) but received it with (37)")
69
+ end.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" received :msg with unexpected arguments\n expected: (equal 3)\n got: (37)")
70
70
  end
71
71
 
72
72
  it "should fail no_args with one arg" do
73
73
  lambda do
74
74
  @mock.should_receive(:msg).with(no_args)
75
75
  @mock.msg(37)
76
- end.should raise_error(Rspec::Mocks::MockExpectationError, "Mock 'test mock' expected :msg with (no args) but received it with (37)")
76
+ end.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" received :msg with unexpected arguments\n expected: (no args)\n got: (37)")
77
77
  end
78
78
 
79
79
  it "should fail hash_including with missing key" do
80
80
  lambda do
81
81
  @mock.should_receive(:msg).with(hash_including(:a => 1))
82
82
  @mock.msg({})
83
- end.should raise_error(Rspec::Mocks::MockExpectationError, "Mock 'test mock' expected :msg with (hash_including(:a=>1)) but received it with ({})")
83
+ end.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" received :msg with unexpected arguments\n expected: (hash_including(:a=>1))\n got: ({})")
84
84
  end
85
85
 
86
86
  it "should fail with block matchers" do
@@ -93,3 +93,4 @@ module Rspec
93
93
  end
94
94
  end
95
95
  end
96
+
@@ -3,90 +3,90 @@ require 'spec_helper'
3
3
  module Rspec
4
4
  module Mocks
5
5
 
6
- describe "Mock ordering" do
6
+ describe "ordering" do
7
7
 
8
8
  before do
9
- @mock = mock("test mock")
9
+ @double = double("test double")
10
10
  end
11
11
 
12
12
  after do
13
- @mock.rspec_reset
13
+ @double.rspec_reset
14
14
  end
15
15
 
16
16
  it "should pass two calls in order" do
17
- @mock.should_receive(:one).ordered
18
- @mock.should_receive(:two).ordered
19
- @mock.one
20
- @mock.two
21
- @mock.rspec_verify
17
+ @double.should_receive(:one).ordered
18
+ @double.should_receive(:two).ordered
19
+ @double.one
20
+ @double.two
21
+ @double.rspec_verify
22
22
  end
23
23
 
24
24
  it "should pass three calls in order" do
25
- @mock.should_receive(:one).ordered
26
- @mock.should_receive(:two).ordered
27
- @mock.should_receive(:three).ordered
28
- @mock.one
29
- @mock.two
30
- @mock.three
31
- @mock.rspec_verify
25
+ @double.should_receive(:one).ordered
26
+ @double.should_receive(:two).ordered
27
+ @double.should_receive(:three).ordered
28
+ @double.one
29
+ @double.two
30
+ @double.three
31
+ @double.rspec_verify
32
32
  end
33
33
 
34
34
  it "should fail if second call comes first" do
35
- @mock.should_receive(:one).ordered
36
- @mock.should_receive(:two).ordered
35
+ @double.should_receive(:one).ordered
36
+ @double.should_receive(:two).ordered
37
37
  lambda do
38
- @mock.two
39
- end.should raise_error(Rspec::Mocks::MockExpectationError, "Mock 'test mock' received :two out of order")
38
+ @double.two
39
+ end.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" received :two out of order")
40
40
  end
41
41
 
42
42
  it "should fail if third call comes first" do
43
- @mock.should_receive(:one).ordered
44
- @mock.should_receive(:two).ordered
45
- @mock.should_receive(:three).ordered
46
- @mock.one
43
+ @double.should_receive(:one).ordered
44
+ @double.should_receive(:two).ordered
45
+ @double.should_receive(:three).ordered
46
+ @double.one
47
47
  lambda do
48
- @mock.three
49
- end.should raise_error(Rspec::Mocks::MockExpectationError, "Mock 'test mock' received :three out of order")
48
+ @double.three
49
+ end.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" received :three out of order")
50
50
  end
51
51
 
52
52
  it "should fail if third call comes second" do
53
- @mock.should_receive(:one).ordered
54
- @mock.should_receive(:two).ordered
55
- @mock.should_receive(:three).ordered
56
- @mock.one
53
+ @double.should_receive(:one).ordered
54
+ @double.should_receive(:two).ordered
55
+ @double.should_receive(:three).ordered
56
+ @double.one
57
57
  lambda do
58
- @mock.three
59
- end.should raise_error(Rspec::Mocks::MockExpectationError, "Mock 'test mock' received :three out of order")
58
+ @double.three
59
+ end.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" received :three out of order")
60
60
  end
61
61
 
62
62
  it "should ignore order of non ordered calls" do
63
- @mock.should_receive(:ignored_0)
64
- @mock.should_receive(:ordered_1).ordered
65
- @mock.should_receive(:ignored_1)
66
- @mock.should_receive(:ordered_2).ordered
67
- @mock.should_receive(:ignored_2)
68
- @mock.should_receive(:ignored_3)
69
- @mock.should_receive(:ordered_3).ordered
70
- @mock.should_receive(:ignored_4)
71
- @mock.ignored_3
72
- @mock.ordered_1
73
- @mock.ignored_0
74
- @mock.ordered_2
75
- @mock.ignored_4
76
- @mock.ignored_2
77
- @mock.ordered_3
78
- @mock.ignored_1
79
- @mock.rspec_verify
63
+ @double.should_receive(:ignored_0)
64
+ @double.should_receive(:ordered_1).ordered
65
+ @double.should_receive(:ignored_1)
66
+ @double.should_receive(:ordered_2).ordered
67
+ @double.should_receive(:ignored_2)
68
+ @double.should_receive(:ignored_3)
69
+ @double.should_receive(:ordered_3).ordered
70
+ @double.should_receive(:ignored_4)
71
+ @double.ignored_3
72
+ @double.ordered_1
73
+ @double.ignored_0
74
+ @double.ordered_2
75
+ @double.ignored_4
76
+ @double.ignored_2
77
+ @double.ordered_3
78
+ @double.ignored_1
79
+ @double.rspec_verify
80
80
  end
81
81
 
82
82
  it "should pass when duplicates exist" do
83
- @mock.should_receive(:a).ordered
84
- @mock.should_receive(:b).ordered
85
- @mock.should_receive(:a).ordered
83
+ @double.should_receive(:a).ordered
84
+ @double.should_receive(:b).ordered
85
+ @double.should_receive(:a).ordered
86
86
 
87
- @mock.a
88
- @mock.b
89
- @mock.a
87
+ @double.a
88
+ @double.b
89
+ @double.a
90
90
  end
91
91
 
92
92
  end
@@ -31,19 +31,19 @@ module Rspec
31
31
  @m2.should be_verified
32
32
  end
33
33
  it "should reset all mocks within" do
34
- @space.add(m1 = mock("mock1"))
35
- @space.add(m2 = mock("mock2"))
34
+ @space.add(m1 = double("mock1"))
35
+ @space.add(m2 = double("mock2"))
36
36
  m1.should_receive(:rspec_reset)
37
37
  m2.should_receive(:rspec_reset)
38
38
  @space.reset_all
39
39
  end
40
40
  it "should clear internal mocks on reset_all" do
41
- @space.add(m = mock("mock"))
41
+ @space.add(m = double("mock"))
42
42
  @space.reset_all
43
43
  @space.instance_eval { mocks.empty? }.should be_true
44
44
  end
45
45
  it "should only add an instance once" do
46
- @space.add(m1 = mock("mock1"))
46
+ @space.add(m1 = double("mock1"))
47
47
  @space.add(m1)
48
48
  m1.should_receive(:rspec_verify)
49
49
  @space.verify_all
@@ -6,7 +6,7 @@ module Rspec
6
6
  treats_method_missing_as_private :subject => Rspec::Mocks::Mock.new, :noop => false
7
7
 
8
8
  before(:each) do
9
- @mock = mock("test mock")
9
+ @mock = double("test double")
10
10
  end
11
11
 
12
12
  after(:each) do
@@ -25,7 +25,7 @@ module Rspec
25
25
  end
26
26
 
27
27
  it "should report line number of expectation of unreceived message after #should_receive after similar stub" do
28
- @mock.stub!(:wont_happen)
28
+ @mock.stub(:wont_happen)
29
29
  expected_error_line = __LINE__; @mock.should_receive(:wont_happen).with("x", 3)
30
30
  begin
31
31
  @mock.rspec_verify
@@ -50,18 +50,24 @@ module Rspec
50
50
 
51
51
  it "should fail when receiving message specified as not to be received" do
52
52
  @mock.should_not_receive(:not_expected)
53
- lambda {
53
+ expect {
54
54
  @mock.not_expected
55
55
  violated
56
- }.should raise_error(Rspec::Mocks::MockExpectationError, "Mock 'test mock' expected :not_expected with (no args) 0 times, but received it once")
56
+ }.to raise_error(
57
+ Rspec::Mocks::MockExpectationError,
58
+ %Q|(Double "test double").not_expected(no args)\n expected: 0 times\n received: 1 time|
59
+ )
57
60
  end
58
61
 
59
62
  it "should fail when receiving message specified as not to be received with args" do
60
63
  @mock.should_not_receive(:not_expected).with("unexpected text")
61
- lambda {
64
+ expect {
62
65
  @mock.not_expected("unexpected text")
63
66
  violated
64
- }.should raise_error(Rspec::Mocks::MockExpectationError, "Mock 'test mock' expected :not_expected with (\"unexpected text\") 0 times, but received it once")
67
+ }.to raise_error(
68
+ Rspec::Mocks::MockExpectationError,
69
+ %Q|(Double "test double").not_expected("unexpected text")\n expected: 0 times\n received: 1 time|
70
+ )
65
71
  end
66
72
 
67
73
  it "should pass when receiving message specified as not to be received with wrong args" do
@@ -93,32 +99,32 @@ module Rspec
93
99
  lambda {
94
100
  @mock.something("a","d","c")
95
101
  violated
96
- }.should raise_error(Rspec::Mocks::MockExpectationError, "Mock 'test mock' expected :something with (\"a\", \"b\", \"c\") but received it with (\"a\", \"d\", \"c\")")
102
+ }.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" received :something with unexpected arguments\n expected: (\"a\", \"b\", \"c\")\n got: (\"a\", \"d\", \"c\")")
97
103
  end
98
104
 
99
105
  it "should raise exception if args don't match when method called even when the method is stubbed" do
100
- @mock.stub!(:something)
106
+ @mock.stub(:something)
101
107
  @mock.should_receive(:something).with("a","b","c")
102
108
  lambda {
103
109
  @mock.something("a","d","c")
104
110
  @mock.rspec_verify
105
- }.should raise_error(Rspec::Mocks::MockExpectationError, "Mock 'test mock' expected :something with (\"a\", \"b\", \"c\") but received it with ([\"a\", \"d\", \"c\"])")
111
+ }.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" received :something with unexpected arguments\n expected: (\"a\", \"b\", \"c\")\n got: (\"a\", \"d\", \"c\")")
106
112
  end
107
113
 
108
114
  it "should raise exception if args don't match when method called even when using null_object" do
109
- @mock = mock("test mock", :null_object => true)
115
+ @mock = double("test double", :null_object => true)
110
116
  @mock.should_receive(:something).with("a","b","c")
111
117
  lambda {
112
118
  @mock.something("a","d","c")
113
119
  @mock.rspec_verify
114
- }.should raise_error(Rspec::Mocks::MockExpectationError, "Mock 'test mock' expected :something with (\"a\", \"b\", \"c\") but received it with ([\"a\", \"d\", \"c\"])")
120
+ }.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" received :something with unexpected arguments\n expected: (\"a\", \"b\", \"c\")\n got: (\"a\", \"d\", \"c\")")
115
121
  end
116
122
 
117
123
  it "should fail if unexpected method called" do
118
124
  lambda {
119
125
  @mock.something("a","b","c")
120
126
  violated
121
- }.should raise_error(Rspec::Mocks::MockExpectationError, "Mock 'test mock' received unexpected message :something with (\"a\", \"b\", \"c\")")
127
+ }.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" received unexpected message :something with (\"a\", \"b\", \"c\")")
122
128
  end
123
129
 
124
130
  it "should use block for expectation if provided" do
@@ -133,23 +139,25 @@ module Rspec
133
139
 
134
140
  it "should fail if expectation block fails" do
135
141
  @mock.should_receive(:something) {| bool | bool.should be_true}
136
- lambda {
142
+ expect {
137
143
  @mock.something false
138
- }.should raise_error(Rspec::Mocks::MockExpectationError, /Mock 'test mock' received :something but passed block failed with: expected false to be true/)
144
+ }.to raise_error(Rspec::Mocks::MockExpectationError, /Double \"test double\" received :something but passed block failed with: expected false to be true/)
139
145
  end
140
146
 
141
147
  it "should fail right away when method defined as never is received" do
142
148
  @mock.should_receive(:not_expected).never
143
- lambda {
144
- @mock.not_expected
145
- }.should raise_error(Rspec::Mocks::MockExpectationError, "Mock 'test mock' expected :not_expected with (no args) 0 times, but received it once")
149
+ expect { @mock.not_expected }.to raise_error(
150
+ Rspec::Mocks::MockExpectationError,
151
+ %Q|(Double "test double").not_expected(no args)\n expected: 0 times\n received: 1 time|
152
+ )
146
153
  end
147
154
 
148
155
  it "should eventually fail when method defined as never is received" do
149
156
  @mock.should_receive(:not_expected).never
150
- lambda {
151
- @mock.not_expected
152
- }.should raise_error(Rspec::Mocks::MockExpectationError, "Mock 'test mock' expected :not_expected with (no args) 0 times, but received it once")
157
+ expect { @mock.not_expected }.to raise_error(
158
+ Rspec::Mocks::MockExpectationError,
159
+ %Q|(Double "test double").not_expected(no args)\n expected: 0 times\n received: 1 time|
160
+ )
153
161
  end
154
162
 
155
163
  it "should raise when told to" do
@@ -209,18 +217,18 @@ module Rspec
209
217
  @mock.should_receive(:something).with(no_args())
210
218
  lambda {
211
219
  @mock.something 1
212
- }.should raise_error(Rspec::Mocks::MockExpectationError, "Mock 'test mock' expected :something with (no args) but received it with (1)")
220
+ }.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" received :something with unexpected arguments\n expected: (no args)\n got: (1)")
213
221
  end
214
222
 
215
223
  it "should fail when args are expected but none are received" do
216
224
  @mock.should_receive(:something).with(1)
217
225
  lambda {
218
226
  @mock.something
219
- }.should raise_error(Rspec::Mocks::MockExpectationError, "Mock 'test mock' expected :something with (1) but received it with (no args)")
227
+ }.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" received :something with unexpected arguments\n expected: (1)\n got: (no args)")
220
228
  end
221
229
 
222
230
  it "should return value from block by default" do
223
- @mock.stub!(:method_that_yields).and_yield
231
+ @mock.stub(:method_that_yields).and_yield
224
232
  @mock.method_that_yields { :returned_obj }.should == :returned_obj
225
233
  @mock.rspec_verify
226
234
  end
@@ -324,7 +332,7 @@ module Rspec
324
332
  @mock.should_receive(:yield_back).with(no_args()).once.and_yield('wha', 'zup')
325
333
  lambda {
326
334
  @mock.yield_back {|a|}
327
- }.should raise_error(Rspec::Mocks::MockExpectationError, "Mock 'test mock' yielded |\"wha\", \"zup\"| to block with arity of 1")
335
+ }.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" yielded |\"wha\", \"zup\"| to block with arity of 1")
328
336
  end
329
337
 
330
338
  it "should fail when calling yielding method consecutively with wrong arity" do
@@ -335,14 +343,14 @@ module Rspec
335
343
  a, b = nil
336
344
  c = []
337
345
  @mock.yield_back {|a,b| c << [a, b]}
338
- }.should raise_error(Rspec::Mocks::MockExpectationError, "Mock 'test mock' yielded |\"down\"| to block with arity of 2")
346
+ }.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" yielded |\"down\"| to block with arity of 2")
339
347
  end
340
348
 
341
349
  it "should fail when calling yielding method without block" do
342
350
  @mock.should_receive(:yield_back).with(no_args()).once.and_yield('wha', 'zup')
343
351
  lambda {
344
352
  @mock.yield_back
345
- }.should raise_error(Rspec::Mocks::MockExpectationError, "Mock 'test mock' asked to yield |[\"wha\", \"zup\"]| but no block was passed")
353
+ }.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" asked to yield |[\"wha\", \"zup\"]| but no block was passed")
346
354
  end
347
355
 
348
356
  it "should be able to mock send" do
@@ -369,11 +377,11 @@ module Rspec
369
377
  @mock.rspec_verify
370
378
  lambda {
371
379
  @mock.foobar
372
- }.should raise_error(Rspec::Mocks::MockExpectationError, "Mock 'test mock' received unexpected message :foobar with (no args)")
380
+ }.should raise_error(Rspec::Mocks::MockExpectationError, %q|Double "test double" received unexpected message :foobar with (no args)|)
373
381
  end
374
382
 
375
383
  it "should restore objects to their original state on rspec_reset" do
376
- mock = mock("this is a mock")
384
+ mock = double("this is a mock")
377
385
  mock.should_receive(:blah)
378
386
  mock.rspec_reset
379
387
  mock.rspec_verify #should throw if reset didn't work
@@ -409,7 +417,7 @@ module Rspec
409
417
  end
410
418
 
411
419
  it "should temporarily replace a method stub on a mock" do
412
- @mock.stub!(:msg).and_return(:stub_value)
420
+ @mock.stub(:msg).and_return(:stub_value)
413
421
  @mock.should_receive(:msg).with(:arg).and_return(:mock_value)
414
422
  @mock.msg(:arg).should equal(:mock_value)
415
423
  @mock.msg.should equal(:stub_value)
@@ -418,7 +426,7 @@ module Rspec
418
426
  end
419
427
 
420
428
  it "should not require a different signature to replace a method stub" do
421
- @mock.stub!(:msg).and_return(:stub_value)
429
+ @mock.stub(:msg).and_return(:stub_value)
422
430
  @mock.should_receive(:msg).and_return(:mock_value)
423
431
  @mock.msg(:arg).should equal(:mock_value)
424
432
  @mock.msg.should equal(:stub_value)
@@ -427,14 +435,14 @@ module Rspec
427
435
  end
428
436
 
429
437
  it "should raise an error when a previously stubbed method has a negative expectation" do
430
- @mock.stub!(:msg).and_return(:stub_value)
438
+ @mock.stub(:msg).and_return(:stub_value)
431
439
  @mock.should_not_receive(:msg).and_return(:mock_value)
432
440
  lambda {@mock.msg(:arg)}.should raise_error(Rspec::Mocks::MockExpectationError)
433
441
  end
434
442
 
435
443
  it "should temporarily replace a method stub on a non-mock" do
436
444
  non_mock = Object.new
437
- non_mock.stub!(:msg).and_return(:stub_value)
445
+ non_mock.stub(:msg).and_return(:stub_value)
438
446
  non_mock.should_receive(:msg).with(:arg).and_return(:mock_value)
439
447
  non_mock.msg(:arg).should equal(:mock_value)
440
448
  non_mock.msg.should equal(:stub_value)
@@ -443,14 +451,14 @@ module Rspec
443
451
  end
444
452
 
445
453
  it "should return the stubbed value when no new value specified" do
446
- @mock.stub!(:msg).and_return(:stub_value)
454
+ @mock.stub(:msg).and_return(:stub_value)
447
455
  @mock.should_receive(:msg)
448
456
  @mock.msg.should equal(:stub_value)
449
457
  @mock.rspec_verify
450
458
  end
451
459
 
452
460
  it "should not mess with the stub's yielded values when also mocked" do
453
- @mock.stub!(:yield_back).and_yield(:stub_value)
461
+ @mock.stub(:yield_back).and_yield(:stub_value)
454
462
  @mock.should_receive(:yield_back).and_yield(:mock_value)
455
463
  @mock.yield_back{|v| v.should == :mock_value }
456
464
  @mock.yield_back{|v| v.should == :stub_value }
@@ -458,7 +466,7 @@ module Rspec
458
466
  end
459
467
 
460
468
  it "should yield multiple values after a similar stub" do
461
- File.stub!(:open).and_yield(:stub_value)
469
+ File.stub(:open).and_yield(:stub_value)
462
470
  File.should_receive(:open).and_yield(:first_call).and_yield(:second_call)
463
471
  yielded_args = []
464
472
  File.open {|v| yielded_args << v }
@@ -476,7 +484,7 @@ module Rspec
476
484
 
477
485
  describe "a mock message receiving a block" do
478
486
  before(:each) do
479
- @mock = mock("mock")
487
+ @mock = double("mock")
480
488
  @calls = 0
481
489
  end
482
490
 
@@ -493,7 +501,7 @@ module Rspec
493
501
  end
494
502
 
495
503
  it "should call the block after #should_receive after a similar stub" do
496
- @mock.stub!(:foo).and_return(:bar)
504
+ @mock.stub(:foo).and_return(:bar)
497
505
  @mock.should_receive(:foo) { add_call }
498
506
 
499
507
  @mock.foo
@@ -547,33 +555,29 @@ module Rspec
547
555
 
548
556
  describe 'string representation generated by #to_s' do
549
557
  it 'should not contain < because that might lead to invalid HTML in some situations' do
550
- mock = mock("Dog")
558
+ mock = double("Dog")
551
559
  valid_html_str = "#{mock}"
552
560
  valid_html_str.should_not include('<')
553
561
  end
554
562
  end
555
563
 
556
564
  describe "mock created with no name" do
557
- it "should name itself 'mock'" do
558
- mock.to_s.should include('mock')
559
- end
560
-
561
- it "should name itself after initially stubbed methods" do
562
- string = mock(:foo => "woo", :bar => "car").to_s
563
- string.should include('foo: \"woo\"', 'bar: \"car\"')
565
+ it "should not use a name in a failure message" do
566
+ mock = double()
567
+ expect {mock.foo}.to raise_error(/Double received/)
564
568
  end
565
-
569
+
566
570
  it "should respond to initially stubbed methods" do
567
- mock = mock(:foo => "woo", :bar => "car")
568
- mock.foo.should == "woo"
569
- mock.bar.should == "car"
571
+ double = double(:foo => "woo", :bar => "car")
572
+ double.foo.should == "woo"
573
+ double.bar.should == "car"
570
574
  end
571
575
  end
572
576
 
573
577
  describe "==" do
574
578
  it "sends '== self' to the comparison object" do
575
- first = mock('first')
576
- second = mock('second')
579
+ first = double('first')
580
+ second = double('second')
577
581
 
578
582
  first.should_receive(:==).with(second)
579
583
  second == first