rspec-mocks 2.0.0.beta.8 → 2.0.0.beta.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/README.markdown +1 -1
  2. data/Rakefile +10 -10
  3. data/VERSION +1 -1
  4. data/features/mocks/block_local_expectations.feature +5 -5
  5. data/features/mocks/mix_stubs_and_mocks.feature +2 -2
  6. data/features/mocks/warn_when_expectation_is_set_on_nil.feature +6 -6
  7. data/features/stubs/stub_implementation.feature +2 -2
  8. data/lib/rspec/mocks.rb +112 -137
  9. data/lib/rspec/mocks/argument_expectation.rb +1 -1
  10. data/lib/rspec/mocks/argument_matchers.rb +1 -1
  11. data/lib/rspec/mocks/error_generator.rb +2 -2
  12. data/lib/rspec/mocks/errors.rb +1 -1
  13. data/lib/rspec/mocks/extensions/instance_exec.rb +2 -2
  14. data/lib/rspec/mocks/extensions/object.rb +1 -1
  15. data/lib/rspec/mocks/message_expectation.rb +3 -3
  16. data/lib/rspec/mocks/method_double.rb +3 -3
  17. data/lib/rspec/mocks/methods.rb +1 -1
  18. data/lib/rspec/mocks/mock.rb +9 -6
  19. data/lib/rspec/mocks/order_group.rb +1 -1
  20. data/lib/rspec/mocks/proxy.rb +9 -8
  21. data/lib/rspec/mocks/space.rb +1 -1
  22. data/lib/rspec/mocks/spec_methods.rb +13 -15
  23. data/lib/rspec/mocks/version.rb +1 -1
  24. data/rspec-mocks.gemspec +11 -11
  25. data/spec/rspec/mocks/and_yield_spec.rb +4 -4
  26. data/spec/rspec/mocks/any_number_of_times_spec.rb +2 -2
  27. data/spec/rspec/mocks/argument_expectation_spec.rb +3 -3
  28. data/spec/rspec/mocks/at_least_spec.rb +7 -7
  29. data/spec/rspec/mocks/at_most_spec.rb +5 -5
  30. data/spec/rspec/mocks/bug_report_10260_spec.rb +1 -1
  31. data/spec/rspec/mocks/bug_report_15719_spec.rb +3 -3
  32. data/spec/rspec/mocks/bug_report_830_spec.rb +2 -2
  33. data/spec/rspec/mocks/double_spec.rb +1 -1
  34. data/spec/rspec/mocks/failing_argument_matchers_spec.rb +14 -14
  35. data/spec/rspec/mocks/hash_including_matcher_spec.rb +1 -1
  36. data/spec/rspec/mocks/hash_not_including_matcher_spec.rb +1 -1
  37. data/spec/rspec/mocks/mock_ordering_spec.rb +4 -4
  38. data/spec/rspec/mocks/mock_space_spec.rb +2 -2
  39. data/spec/rspec/mocks/mock_spec.rb +32 -25
  40. data/spec/rspec/mocks/multiple_return_value_spec.rb +12 -12
  41. data/spec/rspec/mocks/nil_expectation_warning_spec.rb +3 -3
  42. data/spec/rspec/mocks/null_object_mock_spec.rb +3 -3
  43. data/spec/rspec/mocks/once_counts_spec.rb +4 -4
  44. data/spec/rspec/mocks/options_hash_spec.rb +4 -4
  45. data/spec/rspec/mocks/partial_mock_spec.rb +9 -9
  46. data/spec/rspec/mocks/partial_mock_using_mocks_directly_spec.rb +3 -3
  47. data/spec/rspec/mocks/passing_argument_matchers_spec.rb +3 -3
  48. data/spec/rspec/mocks/precise_counts_spec.rb +3 -3
  49. data/spec/rspec/mocks/record_messages_spec.rb +2 -2
  50. data/spec/rspec/mocks/stash_spec.rb +1 -1
  51. data/spec/rspec/mocks/stub_chain_spec.rb +1 -1
  52. data/spec/rspec/mocks/stub_implementation_spec.rb +1 -1
  53. data/spec/rspec/mocks/stub_spec.rb +1 -1
  54. data/spec/rspec/mocks/stubbed_message_expectations_spec.rb +2 -2
  55. data/spec/rspec/mocks/twice_counts_spec.rb +5 -5
  56. data/spec/spec_helper.rb +4 -4
  57. metadata +10 -10
@@ -3,6 +3,6 @@ require 'spec_helper'
3
3
  describe "An RSpec Mock" do
4
4
  it "should hide internals in its inspect representation" do
5
5
  m = double('cup')
6
- m.inspect.should =~ /#<Rspec::Mocks::Mock:0x[a-f0-9.]+ @name="cup">/
6
+ m.inspect.should =~ /#<RSpec::Mocks::Mock:0x[a-f0-9.]+ @name="cup">/
7
7
  end
8
8
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- module Rspec
3
+ module RSpec
4
4
  module Mocks
5
5
  describe "mock failure" do
6
6
 
@@ -9,7 +9,7 @@ module Rspec
9
9
  double.should_receive(:bar).with("message")
10
10
  lambda {
11
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")})
12
+ }.should raise_error(RSpec::Mocks::MockExpectationError, %Q{Double "foo" received :bar with unexpected arguments\n expected: ("message")\n got: ("different message")})
13
13
  double.rspec_reset # so the example doesn't fail
14
14
  end
15
15
 
@@ -21,7 +21,7 @@ module Rspec
21
21
  double.should_receive(:bar).with("message")
22
22
  lambda {
23
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")})
24
+ }.should raise_error(RSpec::Mocks::MockExpectationError, %Q{Double 'foo' expected :bar with ("message") but received it with ("different message")})
25
25
  double.rspec_reset # so the example doesn't fail
26
26
  end
27
27
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- module Rspec
3
+ module RSpec
4
4
  module Mocks
5
5
  describe 'Calling a method that catches StandardError' do
6
6
  class Foo
@@ -14,7 +14,7 @@ module Rspec
14
14
  Foo.should_not_receive :bar
15
15
  lambda do
16
16
  Foo.foo
17
- end.should raise_error(Rspec::Mocks::MockExpectationError)
17
+ end.should raise_error(RSpec::Mocks::MockExpectationError)
18
18
  end
19
19
  end
20
20
  end
@@ -2,7 +2,7 @@ require "spec_helper"
2
2
 
3
3
  describe "double" do
4
4
  it "is an alias for stub and mock" do
5
- double().should be_a(Rspec::Mocks::Mock)
5
+ double().should be_a(RSpec::Mocks::Mock)
6
6
  end
7
7
 
8
8
  it "uses 'Double' in failure messages" do
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
- module Rspec
3
+ module RSpec
4
4
  module Mocks
5
5
  describe "failing MockArgumentMatchers" do
6
6
  before(:each) do
7
7
  @mock = double("test double")
8
- @reporter = Rspec::Mocks::Mock.new("reporter", :null_object => true)
8
+ @reporter = RSpec::Mocks::Mock.new("reporter").as_null_object
9
9
  end
10
10
 
11
11
  after(:each) do
@@ -16,78 +16,78 @@ module Rspec
16
16
  @mock.should_receive(:random_call).with(boolean())
17
17
  lambda do
18
18
  @mock.random_call("false")
19
- end.should raise_error(Rspec::Mocks::MockExpectationError)
19
+ end.should raise_error(RSpec::Mocks::MockExpectationError)
20
20
  end
21
21
 
22
22
  it "should reject non numeric" do
23
23
  @mock.should_receive(:random_call).with(an_instance_of(Numeric))
24
24
  lambda do
25
25
  @mock.random_call("1")
26
- end.should raise_error(Rspec::Mocks::MockExpectationError)
26
+ end.should raise_error(RSpec::Mocks::MockExpectationError)
27
27
  end
28
28
 
29
29
  it "should reject non string" do
30
30
  @mock.should_receive(:random_call).with(an_instance_of(String))
31
31
  lambda do
32
32
  @mock.random_call(123)
33
- end.should raise_error(Rspec::Mocks::MockExpectationError)
33
+ end.should raise_error(RSpec::Mocks::MockExpectationError)
34
34
  end
35
35
 
36
36
  it "should reject goose when expecting a duck" do
37
37
  @mock.should_receive(:random_call).with(duck_type(:abs, :div))
38
- lambda { @mock.random_call("I don't respond to :abs or :div") }.should raise_error(Rspec::Mocks::MockExpectationError)
38
+ lambda { @mock.random_call("I don't respond to :abs or :div") }.should raise_error(RSpec::Mocks::MockExpectationError)
39
39
  end
40
40
 
41
41
  it "should fail if regexp does not match submitted string" do
42
42
  @mock.should_receive(:random_call).with(/bcd/)
43
- lambda { @mock.random_call("abc") }.should raise_error(Rspec::Mocks::MockExpectationError)
43
+ lambda { @mock.random_call("abc") }.should raise_error(RSpec::Mocks::MockExpectationError)
44
44
  end
45
45
 
46
46
  it "should fail if regexp does not match submitted regexp" do
47
47
  @mock.should_receive(:random_call).with(/bcd/)
48
- lambda { @mock.random_call(/bcde/) }.should raise_error(Rspec::Mocks::MockExpectationError)
48
+ lambda { @mock.random_call(/bcde/) }.should raise_error(RSpec::Mocks::MockExpectationError)
49
49
  end
50
50
 
51
51
  it "should fail for a hash w/ wrong values" do
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, /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\")\}\)/)
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, /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\")\}\)/)
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, "Double \"test double\" received :msg with unexpected arguments\n expected: (equal 3)\n got: (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, "Double \"test double\" received :msg with unexpected arguments\n expected: (no args)\n got: (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, "Double \"test double\" received :msg with unexpected arguments\n expected: (hash_including(:a=>1))\n got: ({})")
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
87
87
  lambda do
88
88
  @mock.should_receive(:msg).with {|arg| arg.should == :received }
89
89
  @mock.msg :no_msg_for_you
90
- end.should raise_error(Rspec::Expectations::ExpectationNotMetError, /expected: :received.*\s*.*got: :no_msg_for_you/)
90
+ end.should raise_error(RSpec::Expectations::ExpectationNotMetError, /expected: :received.*\s*.*got: :no_msg_for_you/)
91
91
  end
92
92
 
93
93
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- module Rspec
3
+ module RSpec
4
4
  module Mocks
5
5
  module ArgumentMatchers
6
6
  describe HashIncludingMatcher do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- module Rspec
3
+ module RSpec
4
4
  module Mocks
5
5
  module ArgumentMatchers
6
6
  describe HashNotIncludingMatcher do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- module Rspec
3
+ module RSpec
4
4
  module Mocks
5
5
 
6
6
  describe "ordering" do
@@ -36,7 +36,7 @@ module Rspec
36
36
  @double.should_receive(:two).ordered
37
37
  lambda do
38
38
  @double.two
39
- end.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" received :two out of order")
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
@@ -46,7 +46,7 @@ module Rspec
46
46
  @double.one
47
47
  lambda do
48
48
  @double.three
49
- end.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" received :three out of order")
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
@@ -56,7 +56,7 @@ module Rspec
56
56
  @double.one
57
57
  lambda do
58
58
  @double.three
59
- end.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" received :three out of order")
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
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
2
  require 'rspec/mocks'
3
3
 
4
- module Rspec
4
+ module RSpec
5
5
  module Mocks
6
6
  describe Space do
7
7
  before :each do
8
- @space = Rspec::Mocks::Space.new
8
+ @space = RSpec::Mocks::Space.new
9
9
  klazz = Class.new do
10
10
  def rspec_verify
11
11
  @verified = true
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
- module Rspec
3
+ module RSpec
4
4
  module Mocks
5
5
  describe Mock do
6
- treats_method_missing_as_private :subject => Rspec::Mocks::Mock.new, :noop => false
6
+ treats_method_missing_as_private :subject => RSpec::Mocks::Mock.new, :noop => false
7
7
 
8
8
  before(:each) do
9
9
  @mock = double("test double")
@@ -18,7 +18,7 @@ module Rspec
18
18
  begin
19
19
  @mock.rspec_verify
20
20
  violated
21
- rescue Rspec::Mocks::MockExpectationError => e
21
+ rescue RSpec::Mocks::MockExpectationError => e
22
22
  # NOTE - this regexp ended w/ $, but jruby adds extra info at the end of the line
23
23
  e.backtrace[0].should match(/#{File.basename(__FILE__)}:#{expected_error_line}/)
24
24
  end
@@ -30,7 +30,7 @@ module Rspec
30
30
  begin
31
31
  @mock.rspec_verify
32
32
  violated
33
- rescue Rspec::Mocks::MockExpectationError => e
33
+ rescue RSpec::Mocks::MockExpectationError => e
34
34
  # NOTE - this regexp ended w/ $, but jruby adds extra info at the end of the line
35
35
  e.backtrace[0].should match(/#{File.basename(__FILE__)}:#{expected_error_line}/)
36
36
  end
@@ -54,7 +54,7 @@ module Rspec
54
54
  @mock.not_expected
55
55
  violated
56
56
  }.to raise_error(
57
- Rspec::Mocks::MockExpectationError,
57
+ RSpec::Mocks::MockExpectationError,
58
58
  %Q|(Double "test double").not_expected(no args)\n expected: 0 times\n received: 1 time|
59
59
  )
60
60
  end
@@ -65,7 +65,7 @@ module Rspec
65
65
  @mock.not_expected("unexpected text")
66
66
  violated
67
67
  }.to raise_error(
68
- Rspec::Mocks::MockExpectationError,
68
+ RSpec::Mocks::MockExpectationError,
69
69
  %Q|(Double "test double").not_expected("unexpected text")\n expected: 0 times\n received: 1 time|
70
70
  )
71
71
  end
@@ -99,7 +99,7 @@ module Rspec
99
99
  lambda {
100
100
  @mock.something("a","d","c")
101
101
  violated
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\")")
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\")")
103
103
  end
104
104
 
105
105
  it "should raise exception if args don't match when method called even when the method is stubbed" do
@@ -108,23 +108,23 @@ module Rspec
108
108
  lambda {
109
109
  @mock.something("a","d","c")
110
110
  @mock.rspec_verify
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\")")
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\")")
112
112
  end
113
113
 
114
114
  it "should raise exception if args don't match when method called even when using null_object" do
115
- @mock = double("test double", :null_object => true)
115
+ @mock = double("test double").as_null_object
116
116
  @mock.should_receive(:something).with("a","b","c")
117
117
  lambda {
118
118
  @mock.something("a","d","c")
119
119
  @mock.rspec_verify
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\")")
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\")")
121
121
  end
122
122
 
123
123
  it "should fail if unexpected method called" do
124
124
  lambda {
125
125
  @mock.something("a","b","c")
126
126
  violated
127
- }.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" 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\")")
128
128
  end
129
129
 
130
130
  it "should use block for expectation if provided" do
@@ -141,13 +141,13 @@ module Rspec
141
141
  @mock.should_receive(:something) {| bool | bool.should be_true}
142
142
  expect {
143
143
  @mock.something false
144
- }.to raise_error(Rspec::Mocks::MockExpectationError, /Double \"test double\" 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/)
145
145
  end
146
146
 
147
147
  it "should fail right away when method defined as never is received" do
148
148
  @mock.should_receive(:not_expected).never
149
149
  expect { @mock.not_expected }.to raise_error(
150
- Rspec::Mocks::MockExpectationError,
150
+ RSpec::Mocks::MockExpectationError,
151
151
  %Q|(Double "test double").not_expected(no args)\n expected: 0 times\n received: 1 time|
152
152
  )
153
153
  end
@@ -155,7 +155,7 @@ module Rspec
155
155
  it "should eventually fail when method defined as never is received" do
156
156
  @mock.should_receive(:not_expected).never
157
157
  expect { @mock.not_expected }.to raise_error(
158
- Rspec::Mocks::MockExpectationError,
158
+ RSpec::Mocks::MockExpectationError,
159
159
  %Q|(Double "test double").not_expected(no args)\n expected: 0 times\n received: 1 time|
160
160
  )
161
161
  end
@@ -186,7 +186,7 @@ module Rspec
186
186
  @mock.should_receive(:something).with(2).and_raise(RuntimeError)
187
187
  lambda {
188
188
  @mock.something 1
189
- }.should raise_error(Rspec::Mocks::MockExpectationError)
189
+ }.should raise_error(RSpec::Mocks::MockExpectationError)
190
190
  end
191
191
 
192
192
  it "should throw when told to" do
@@ -201,7 +201,7 @@ module Rspec
201
201
  @mock.should_receive(:fruit) do |colour|
202
202
  :strawberry
203
203
  end.and_return :apple
204
- }.should raise_error(Rspec::Mocks::AmbiguousReturnError)
204
+ }.should raise_error(RSpec::Mocks::AmbiguousReturnError)
205
205
  end
206
206
 
207
207
  it "should ignore args on any args" do
@@ -217,14 +217,14 @@ module Rspec
217
217
  @mock.should_receive(:something).with(no_args())
218
218
  lambda {
219
219
  @mock.something 1
220
- }.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" received :something with unexpected arguments\n expected: (no args)\n got: (1)")
220
+ }.should raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :something with unexpected arguments\n expected: (no args)\n got: (1)")
221
221
  end
222
222
 
223
223
  it "should fail when args are expected but none are received" do
224
224
  @mock.should_receive(:something).with(1)
225
225
  lambda {
226
226
  @mock.something
227
- }.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" received :something with unexpected arguments\n expected: (1)\n got: (no args)")
227
+ }.should raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :something with unexpected arguments\n expected: (1)\n got: (no args)")
228
228
  end
229
229
 
230
230
  it "should return value from block by default" do
@@ -332,7 +332,7 @@ module Rspec
332
332
  @mock.should_receive(:yield_back).with(no_args()).once.and_yield('wha', 'zup')
333
333
  lambda {
334
334
  @mock.yield_back {|a|}
335
- }.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" 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")
336
336
  end
337
337
 
338
338
  it "should fail when calling yielding method consecutively with wrong arity" do
@@ -343,14 +343,14 @@ module Rspec
343
343
  a, b = nil
344
344
  c = []
345
345
  @mock.yield_back {|a,b| c << [a, b]}
346
- }.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" 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")
347
347
  end
348
348
 
349
349
  it "should fail when calling yielding method without block" do
350
350
  @mock.should_receive(:yield_back).with(no_args()).once.and_yield('wha', 'zup')
351
351
  lambda {
352
352
  @mock.yield_back
353
- }.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" 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")
354
354
  end
355
355
 
356
356
  it "should be able to mock send" do
@@ -377,7 +377,7 @@ module Rspec
377
377
  @mock.rspec_verify
378
378
  lambda {
379
379
  @mock.foobar
380
- }.should raise_error(Rspec::Mocks::MockExpectationError, %q|Double "test double" 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)|)
381
381
  end
382
382
 
383
383
  it "should restore objects to their original state on rspec_reset" do
@@ -413,7 +413,7 @@ module Rspec
413
413
  @mock.rspec_verify
414
414
 
415
415
  lambda { @mock.foobar }.should_not raise_error(NameError)
416
- lambda { @mock.foobar }.should raise_error(Rspec::Mocks::MockExpectationError)
416
+ lambda { @mock.foobar }.should raise_error(RSpec::Mocks::MockExpectationError)
417
417
  end
418
418
 
419
419
  it "should temporarily replace a method stub on a mock" do
@@ -437,7 +437,7 @@ module Rspec
437
437
  it "should raise an error when a previously stubbed method has a negative expectation" do
438
438
  @mock.stub(:msg).and_return(:stub_value)
439
439
  @mock.should_not_receive(:msg).and_return(:mock_value)
440
- lambda {@mock.msg(:arg)}.should raise_error(Rspec::Mocks::MockExpectationError)
440
+ lambda {@mock.msg(:arg)}.should raise_error(RSpec::Mocks::MockExpectationError)
441
441
  end
442
442
 
443
443
  it "should temporarily replace a method stub on a non-mock" do
@@ -476,7 +476,7 @@ module Rspec
476
476
  end
477
477
 
478
478
  it "should assign stub return values" do
479
- mock = Rspec::Mocks::Mock.new('name', :message => :response)
479
+ mock = RSpec::Mocks::Mock.new('name', :message => :response)
480
480
  mock.message.should == :response
481
481
  end
482
482
 
@@ -561,6 +561,13 @@ module Rspec
561
561
  end
562
562
  end
563
563
 
564
+ describe "string representation generated by #to_str" do
565
+ it "looks the same as #to_s" do
566
+ double = double("Foo")
567
+ double.to_str.should == double.to_s
568
+ end
569
+ end
570
+
564
571
  describe "mock created with no name" do
565
572
  it "should not use a name in a failure message" do
566
573
  mock = double()
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- module Rspec
3
+ module RSpec
4
4
  module Mocks
5
5
  describe "a Mock expectation with multiple return values and no specified count" do
6
6
  before(:each) do
7
- @mock = Rspec::Mocks::Mock.new("mock")
7
+ @mock = RSpec::Mocks::Mock.new("mock")
8
8
  @return_values = ["1",2,Object.new]
9
9
  @mock.should_receive(:message).and_return(@return_values[0],@return_values[1],@return_values[2])
10
10
  end
@@ -21,7 +21,7 @@ module Rspec
21
21
  @mock.message.should == @return_values[0]
22
22
  @mock.message.should == @return_values[1]
23
23
  expect { @mock.rspec_verify }.to raise_error(
24
- Rspec::Mocks::MockExpectationError,
24
+ RSpec::Mocks::MockExpectationError,
25
25
  %Q|(Mock "mock").message(any args)\n expected: 3 times\n received: 2 times|
26
26
  )
27
27
  end
@@ -33,7 +33,7 @@ module Rspec
33
33
  @mock.message.should == @return_values[2]
34
34
  @mock.message.should == @return_values[2]
35
35
  expect { @mock.rspec_verify }.to raise_error(
36
- Rspec::Mocks::MockExpectationError,
36
+ RSpec::Mocks::MockExpectationError,
37
37
  %Q|(Mock "mock").message(any args)\n expected: 3 times\n received: 4 times|
38
38
  )
39
39
  end
@@ -41,7 +41,7 @@ module Rspec
41
41
 
42
42
  describe "a Mock expectation with multiple return values with a specified count equal to the number of values" do
43
43
  before(:each) do
44
- @mock = Rspec::Mocks::Mock.new("mock")
44
+ @mock = RSpec::Mocks::Mock.new("mock")
45
45
  @return_values = ["1",2,Object.new]
46
46
  @mock.should_receive(:message).exactly(3).times.and_return(@return_values[0],@return_values[1],@return_values[2])
47
47
  end
@@ -58,7 +58,7 @@ module Rspec
58
58
  @mock.message.should == @return_values[0]
59
59
  @mock.message.should == @return_values[1]
60
60
  expect { @mock.rspec_verify }.to raise_error(
61
- Rspec::Mocks::MockExpectationError,
61
+ RSpec::Mocks::MockExpectationError,
62
62
  %Q|(Mock "mock").message(any args)\n expected: 3 times\n received: 2 times|
63
63
  )
64
64
  end
@@ -70,7 +70,7 @@ module Rspec
70
70
  @mock.message.should == @return_values[2]
71
71
  @mock.message.should == @return_values[2]
72
72
  expect { @mock.rspec_verify }.to raise_error(
73
- Rspec::Mocks::MockExpectationError,
73
+ RSpec::Mocks::MockExpectationError,
74
74
  %Q|(Mock "mock").message(any args)\n expected: 3 times\n received: 4 times|
75
75
  )
76
76
  end
@@ -78,7 +78,7 @@ module Rspec
78
78
 
79
79
  describe "a Mock expectation with multiple return values specifying at_least less than the number of values" do
80
80
  before(:each) do
81
- @mock = Rspec::Mocks::Mock.new("mock")
81
+ @mock = RSpec::Mocks::Mock.new("mock")
82
82
  @mock.should_receive(:message).at_least(:twice).with(no_args).and_return(11, 22)
83
83
  end
84
84
 
@@ -92,7 +92,7 @@ module Rspec
92
92
  it "should fail when called less than the specified number" do
93
93
  @mock.message.should equal(11)
94
94
  expect { @mock.rspec_verify }.to raise_error(
95
- Rspec::Mocks::MockExpectationError,
95
+ RSpec::Mocks::MockExpectationError,
96
96
  %Q|(Mock "mock").message(no args)\n expected: 2 times\n received: 1 time|
97
97
  )
98
98
  end
@@ -100,7 +100,7 @@ module Rspec
100
100
 
101
101
  describe "a Mock expectation with multiple return values with a specified count larger than the number of values" do
102
102
  before(:each) do
103
- @mock = Rspec::Mocks::Mock.new("mock")
103
+ @mock = RSpec::Mocks::Mock.new("mock")
104
104
  @mock.should_receive(:message).exactly(3).times.and_return(11, 22)
105
105
  end
106
106
 
@@ -114,7 +114,7 @@ module Rspec
114
114
  it "should fail when called less than the specified number" do
115
115
  @mock.message.should equal(11)
116
116
  expect { @mock.rspec_verify }.to raise_error(
117
- Rspec::Mocks::MockExpectationError,
117
+ RSpec::Mocks::MockExpectationError,
118
118
  %Q|(Mock "mock").message(any args)\n expected: 3 times\n received: 1 time|
119
119
  )
120
120
  end
@@ -125,7 +125,7 @@ module Rspec
125
125
  @mock.message.should equal(22)
126
126
  @mock.message.should equal(22)
127
127
  expect { @mock.rspec_verify }.to raise_error(
128
- Rspec::Mocks::MockExpectationError,
128
+ RSpec::Mocks::MockExpectationError,
129
129
  %Q|(Mock "mock").message(any args)\n expected: 3 times\n received: 4 times|
130
130
  )
131
131
  end