rspec-mocks 2.9.0 → 2.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,52 +2,51 @@ require 'spec_helper'
2
2
 
3
3
  module RSpec
4
4
  module Mocks
5
- describe "OnceCounts" do
5
+ describe "#once" do
6
6
  before(:each) do
7
- @mock = double("test mock")
7
+ @double = double
8
8
  end
9
9
 
10
- it "once fails when called once with wrong args" do
11
- @mock.should_receive(:random_call).once.with("a", "b", "c")
10
+ it "passes when called once" do
11
+ @double.should_receive(:do_something).once
12
+ @double.do_something
13
+ @double.rspec_verify
14
+ end
15
+
16
+ it "passes when called once with specified args" do
17
+ @double.should_receive(:do_something).once.with("a", "b", "c")
18
+ @double.do_something("a", "b", "c")
19
+ @double.rspec_verify
20
+ end
21
+
22
+ it "passes when called once with unspecified args" do
23
+ @double.should_receive(:do_something).once
24
+ @double.do_something("a", "b", "c")
25
+ @double.rspec_verify
26
+ end
27
+
28
+ it "fails when called with wrong args" do
29
+ @double.should_receive(:do_something).once.with("a", "b", "c")
12
30
  lambda do
13
- @mock.random_call("d", "e", "f")
31
+ @double.do_something("d", "e", "f")
14
32
  end.should raise_error(RSpec::Mocks::MockExpectationError)
15
- @mock.rspec_reset
33
+ @double.rspec_reset
16
34
  end
17
35
 
18
- it "once fails when called twice" do
19
- @mock.should_receive(:random_call).once
20
- @mock.random_call
21
- @mock.random_call
36
+ it "fails fast when called twice" do
37
+ @double.should_receive(:do_something).once
38
+ @double.do_something
22
39
  lambda do
23
- @mock.rspec_verify
40
+ @double.do_something
24
41
  end.should raise_error(RSpec::Mocks::MockExpectationError)
25
42
  end
26
43
 
27
- it "once fails when not called" do
28
- @mock.should_receive(:random_call).once
44
+ it "fails when not called" do
45
+ @double.should_receive(:do_something).once
29
46
  lambda do
30
- @mock.rspec_verify
47
+ @double.rspec_verify
31
48
  end.should raise_error(RSpec::Mocks::MockExpectationError)
32
49
  end
33
-
34
- it "once passes when called once" do
35
- @mock.should_receive(:random_call).once
36
- @mock.random_call
37
- @mock.rspec_verify
38
- end
39
-
40
- it "once passes when called once with specified args" do
41
- @mock.should_receive(:random_call).once.with("a", "b", "c")
42
- @mock.random_call("a", "b", "c")
43
- @mock.rspec_verify
44
- end
45
-
46
- it "once passes when called once with unspecified args" do
47
- @mock.should_receive(:random_call).once
48
- @mock.random_call("a", "b", "c")
49
- @mock.rspec_verify
50
- end
51
50
  end
52
51
  end
53
52
  end
@@ -4,54 +4,64 @@ module RSpec
4
4
  module Mocks
5
5
  describe "PreciseCounts" do
6
6
  before(:each) do
7
- @mock = double("test mock")
7
+ @double = double("test double")
8
8
  end
9
9
 
10
10
  it "fails when exactly n times method is called less than n times" do
11
- @mock.should_receive(:random_call).exactly(3).times
12
- @mock.random_call
13
- @mock.random_call
11
+ @double.should_receive(:do_something).exactly(3).times
12
+ @double.do_something
13
+ @double.do_something
14
14
  lambda do
15
- @mock.rspec_verify
15
+ @double.rspec_verify
16
+ end.should raise_error(RSpec::Mocks::MockExpectationError)
17
+ end
18
+
19
+ it "fails fast when exactly n times method is called more than n times" do
20
+ @double.should_receive(:do_something).exactly(3).times
21
+ @double.do_something
22
+ @double.do_something
23
+ @double.do_something
24
+ lambda do
25
+ @double.do_something
16
26
  end.should raise_error(RSpec::Mocks::MockExpectationError)
17
27
  end
18
28
 
19
29
  it "fails when exactly n times method is never called" do
20
- @mock.should_receive(:random_call).exactly(3).times
30
+ @double.should_receive(:do_something).exactly(3).times
21
31
  lambda do
22
- @mock.rspec_verify
32
+ @double.rspec_verify
23
33
  end.should raise_error(RSpec::Mocks::MockExpectationError)
24
34
  end
25
35
 
26
36
  it "passes if exactly n times method is called exactly n times" do
27
- @mock.should_receive(:random_call).exactly(3).times
28
- @mock.random_call
29
- @mock.random_call
30
- @mock.random_call
31
- @mock.rspec_verify
37
+ @double.should_receive(:do_something).exactly(3).times
38
+ @double.do_something
39
+ @double.do_something
40
+ @double.do_something
41
+ @double.rspec_verify
32
42
  end
33
43
 
34
44
  it "returns the value given by a block when the exactly once method is called" do
35
- @mock.should_receive(:to_s).exactly(:once) { "testing" }
36
- @mock.to_s.should eq "testing"
37
- @mock.rspec_verify
45
+ @double.should_receive(:to_s).exactly(:once) { "testing" }
46
+ @double.to_s.should eq "testing"
47
+ @double.rspec_verify
38
48
  end
39
49
 
40
- it "passes multiple calls with different args and counts" do
41
- @mock.should_receive(:random_call).twice.with(1)
42
- @mock.should_receive(:random_call).once.with(2)
43
- @mock.random_call(1)
44
- @mock.random_call(2)
45
- @mock.random_call(1)
46
- @mock.rspec_verify
50
+ it "passes mutiple calls with different args" do
51
+ @double.should_receive(:do_something).once.with(1)
52
+ @double.should_receive(:do_something).once.with(2)
53
+ @double.do_something(1)
54
+ @double.do_something(2)
55
+ @double.rspec_verify
47
56
  end
48
57
 
49
- it "passes mutiple calls with different args" do
50
- @mock.should_receive(:random_call).once.with(1)
51
- @mock.should_receive(:random_call).once.with(2)
52
- @mock.random_call(1)
53
- @mock.random_call(2)
54
- @mock.rspec_verify
58
+ it "passes multiple calls with different args and counts" do
59
+ @double.should_receive(:do_something).twice.with(1)
60
+ @double.should_receive(:do_something).once.with(2)
61
+ @double.do_something(1)
62
+ @double.do_something(2)
63
+ @double.do_something(1)
64
+ @double.rspec_verify
55
65
  end
56
66
  end
57
67
  end
@@ -2,21 +2,22 @@ require 'spec_helper'
2
2
 
3
3
  module RSpec
4
4
  module Mocks
5
- class SerializableStruct < Struct.new(:foo, :bar); end
5
+ describe Serialization do
6
6
 
7
- class SerializableMockProxy
8
- attr_reader :mock_proxy
7
+ class SerializableObject < Struct.new(:foo, :bar); end
9
8
 
10
- def initialize(mock_proxy)
11
- @mock_proxy = mock_proxy
12
- end
9
+ class SerializableMockProxy
10
+ attr_reader :mock_proxy
11
+
12
+ def initialize(mock_proxy)
13
+ @mock_proxy = mock_proxy
14
+ end
13
15
 
14
- def ==(other)
15
- other.class == self.class && other.mock_proxy == mock_proxy
16
+ def ==(other)
17
+ other.class == self.class && other.mock_proxy == mock_proxy
18
+ end
16
19
  end
17
- end
18
20
 
19
- describe Serialization do
20
21
  def self.with_yaml_loaded(&block)
21
22
  context 'with YAML loaded' do
22
23
  module_eval(&block)
@@ -25,7 +26,7 @@ module RSpec
25
26
 
26
27
  def self.without_yaml_loaded(&block)
27
28
  context 'without YAML loaded' do
28
- before(:each) do
29
+ before do
29
30
  # We can't really unload yaml, but we can fake it here...
30
31
  @orig_yaml_constant = Object.send(:remove_const, :YAML)
31
32
  Struct.class_eval do
@@ -36,7 +37,7 @@ module RSpec
36
37
 
37
38
  module_eval(&block)
38
39
 
39
- after(:each) do
40
+ after do
40
41
  Object.const_set(:YAML, @orig_yaml_constant)
41
42
  Struct.class_eval do
42
43
  alias to_yaml __old_to_yaml
@@ -46,19 +47,19 @@ module RSpec
46
47
  end
47
48
  end
48
49
 
49
- subject { RSpec::Mocks::SerializableStruct.new(7, "something") }
50
+ let(:serializable_object) { RSpec::Mocks::SerializableObject.new(7, "something") }
50
51
 
51
52
  def set_stub
52
- subject.stub(:bazz => 5)
53
+ serializable_object.stub(:bazz => 5)
53
54
  end
54
55
 
55
56
  shared_examples_for 'normal YAML serialization' do
56
57
  it 'serializes to yaml the same with and without stubbing, using #to_yaml' do
57
- expect { set_stub }.to_not change { subject.to_yaml }
58
+ expect { set_stub }.to_not change { serializable_object.to_yaml }
58
59
  end
59
60
 
60
61
  it 'serializes to yaml the same with and without stubbing, using YAML.dump' do
61
- expect { set_stub }.to_not change { YAML.dump(subject) }
62
+ expect { set_stub }.to_not change { YAML.dump(serializable_object) }
62
63
  end
63
64
  end
64
65
 
@@ -87,22 +88,22 @@ module RSpec
87
88
 
88
89
  without_yaml_loaded do
89
90
  it 'does not add #to_yaml to the stubbed object' do
90
- subject.should_not respond_to(:to_yaml)
91
+ serializable_object.should_not respond_to(:to_yaml)
91
92
  set_stub
92
- subject.should_not respond_to(:to_yaml)
93
+ serializable_object.should_not respond_to(:to_yaml)
93
94
  end
94
95
  end
95
96
 
96
97
  it 'marshals the same with and without stubbing' do
97
- expect { set_stub }.to_not change { Marshal.dump(subject) }
98
+ expect { set_stub }.to_not change { Marshal.dump(serializable_object) }
98
99
  end
99
100
 
100
101
  describe "an object that has its own mock_proxy instance variable" do
101
- subject { RSpec::Mocks::SerializableMockProxy.new(:my_mock_proxy) }
102
+ let(:serializable_object) { RSpec::Mocks::SerializableMockProxy.new(:my_mock_proxy) }
102
103
 
103
104
  it 'does not interfere with its marshalling' do
104
- marshalled_copy = Marshal.load(Marshal.dump(subject))
105
- marshalled_copy.should eq subject
105
+ marshalled_copy = Marshal.load(Marshal.dump(serializable_object))
106
+ marshalled_copy.should eq serializable_object
106
107
  end
107
108
  end
108
109
  end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ module RSpec
4
+ module Mocks
5
+ describe TestDouble do
6
+ before(:all) do
7
+ Module.class_eval do
8
+ private
9
+ def use; end
10
+ end
11
+ end
12
+
13
+ after(:all) do
14
+ Module.class_eval do
15
+ undef use
16
+ end
17
+ end
18
+
19
+ it 'can be extended onto a module to make it a pure test double that can mock private methods' do
20
+ double = Module.new
21
+ double.stub(:use)
22
+ expect { double.use }.to raise_error(/private method `use' called/)
23
+
24
+ double = Module.new { TestDouble.extend_onto(self) }
25
+ double.should_receive(:use).and_return(:ok)
26
+ double.use.should be(:ok)
27
+ end
28
+
29
+ it 'sets the test double name when a name is passed' do
30
+ double = Module.new { TestDouble.extend_onto(self, "MyDouble") }
31
+ expect { double.foo }.to raise_error(/Mock "MyDouble" received/)
32
+ end
33
+
34
+ it 'stubs the methods passed in the stubs hash' do
35
+ double = Module.new do
36
+ TestDouble.extend_onto(self, "MyDouble", :a => 5, :b => 10)
37
+ end
38
+
39
+ double.a.should eq(5)
40
+ double.b.should eq(10)
41
+ end
42
+
43
+ it 'indicates what type of test double it is in error messages' do
44
+ double = Module.new do
45
+ TestDouble.extend_onto(self, "A", :__declared_as => "ModuleMock")
46
+ end
47
+ expect { double.foo }.to raise_error(/ModuleMock "A"/)
48
+ end
49
+
50
+ it 'is declared as a mock by default' do
51
+ double = Module.new { TestDouble.extend_onto(self) }
52
+ expect { double.foo }.to raise_error(/Mock received/)
53
+ end
54
+ end
55
+ end
56
+ end
57
+
@@ -2,65 +2,64 @@ require 'spec_helper'
2
2
 
3
3
  module RSpec
4
4
  module Mocks
5
- describe "TwiceCounts" do
5
+ describe "#twice" do
6
6
  before(:each) do
7
- @mock = double("test mock")
7
+ @double = double("test double")
8
8
  end
9
9
 
10
- it "twice should fail when call count is higher than expected" do
11
- @mock.should_receive(:random_call).twice
12
- @mock.random_call
13
- @mock.random_call
14
- @mock.random_call
10
+ it "passes when called twice" do
11
+ @double.should_receive(:do_something).twice
12
+ @double.do_something
13
+ @double.do_something
14
+ @double.rspec_verify
15
+ end
16
+
17
+ it "passes when called twice with specified args" do
18
+ @double.should_receive(:do_something).twice.with("1", 1)
19
+ @double.do_something("1", 1)
20
+ @double.do_something("1", 1)
21
+ @double.rspec_verify
22
+ end
23
+
24
+ it "passes when called twice with unspecified args" do
25
+ @double.should_receive(:do_something).twice
26
+ @double.do_something("1")
27
+ @double.do_something(1)
28
+ @double.rspec_verify
29
+ end
30
+
31
+ it "fails fast when call count is higher than expected" do
32
+ @double.should_receive(:do_something).twice
33
+ @double.do_something
34
+ @double.do_something
15
35
  lambda do
16
- @mock.rspec_verify
36
+ @double.do_something
17
37
  end.should raise_error(RSpec::Mocks::MockExpectationError)
18
38
  end
19
-
20
- it "twice should fail when call count is lower than expected" do
21
- @mock.should_receive(:random_call).twice
22
- @mock.random_call
39
+
40
+ it "fails when call count is lower than expected" do
41
+ @double.should_receive(:do_something).twice
42
+ @double.do_something
23
43
  lambda do
24
- @mock.rspec_verify
44
+ @double.rspec_verify
25
45
  end.should raise_error(RSpec::Mocks::MockExpectationError)
26
46
  end
27
-
28
- it "twice should fail when called twice with wrong args on the first call" do
29
- @mock.should_receive(:random_call).twice.with("1", 1)
47
+
48
+ it "fails when called wrong args on the first call" do
49
+ @double.should_receive(:do_something).twice.with("1", 1)
30
50
  lambda do
31
- @mock.random_call(1, "1")
51
+ @double.do_something(1, "1")
32
52
  end.should raise_error(RSpec::Mocks::MockExpectationError)
33
- @mock.rspec_reset
53
+ @double.rspec_reset
34
54
  end
35
-
36
- it "twice should fail when called twice with wrong args on the second call" do
37
- @mock.should_receive(:random_call).twice.with("1", 1)
38
- @mock.random_call("1", 1)
55
+
56
+ it "fails when called with wrong args on the second call" do
57
+ @double.should_receive(:do_something).twice.with("1", 1)
58
+ @double.do_something("1", 1)
39
59
  lambda do
40
- @mock.random_call(1, "1")
60
+ @double.do_something(1, "1")
41
61
  end.should raise_error(RSpec::Mocks::MockExpectationError)
42
- @mock.rspec_reset
43
- end
44
-
45
- it "twice should pass when called twice" do
46
- @mock.should_receive(:random_call).twice
47
- @mock.random_call
48
- @mock.random_call
49
- @mock.rspec_verify
50
- end
51
-
52
- it "twice should pass when called twice with specified args" do
53
- @mock.should_receive(:random_call).twice.with("1", 1)
54
- @mock.random_call("1", 1)
55
- @mock.random_call("1", 1)
56
- @mock.rspec_verify
57
- end
58
-
59
- it "twice should pass when called twice with unspecified args" do
60
- @mock.should_receive(:random_call).twice
61
- @mock.random_call("1")
62
- @mock.random_call(1)
63
- @mock.rspec_verify
62
+ @double.rspec_reset
64
63
  end
65
64
  end
66
65
  end
metadata CHANGED
@@ -1,80 +1,71 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rspec-mocks
3
- version: !ruby/object:Gem::Version
4
- hash: 43
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.10.0
5
5
  prerelease:
6
- segments:
7
- - 2
8
- - 9
9
- - 0
10
- version: 2.9.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Steven Baker
14
9
  - David Chelimsky
15
10
  autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
-
19
- date: 2012-03-17 00:00:00 Z
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- version_requirements: &id001 !ruby/object:Gem::Requirement
13
+ date: 2012-05-04 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ requirement: !ruby/object:Gem::Requirement
23
18
  none: false
24
- requirements:
19
+ requirements:
25
20
  - - ~>
26
- - !ruby/object:Gem::Version
27
- hash: 63
28
- segments:
29
- - 0
30
- - 9
31
- - 2
21
+ - !ruby/object:Gem::Version
32
22
  version: 0.9.2
33
- prerelease: false
34
- requirement: *id001
35
- name: rake
36
23
  type: :development
37
- - !ruby/object:Gem::Dependency
38
- version_requirements: &id002 !ruby/object:Gem::Requirement
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
39
26
  none: false
40
- requirements:
27
+ requirements:
41
28
  - - ~>
42
- - !ruby/object:Gem::Version
43
- hash: 1
44
- segments:
45
- - 1
46
- - 1
47
- - 9
48
- version: 1.1.9
49
- prerelease: false
50
- requirement: *id002
29
+ - !ruby/object:Gem::Version
30
+ version: 0.9.2
31
+ - !ruby/object:Gem::Dependency
51
32
  name: cucumber
52
- type: :development
53
- - !ruby/object:Gem::Dependency
54
- version_requirements: &id003 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
55
34
  none: false
56
- requirements:
35
+ requirements:
57
36
  - - ~>
58
- - !ruby/object:Gem::Version
59
- hash: 25
60
- segments:
61
- - 0
62
- - 4
63
- - 11
64
- version: 0.4.11
37
+ - !ruby/object:Gem::Version
38
+ version: 1.1.9
39
+ type: :development
65
40
  prerelease: false
66
- requirement: *id003
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 1.1.9
47
+ - !ruby/object:Gem::Dependency
67
48
  name: aruba
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.4.11
68
55
  type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 0.4.11
69
63
  description: RSpec's 'test double' framework, with support for stubbing and mocking
70
64
  email: rspec-users@rubyforge.org
71
65
  executables: []
72
-
73
66
  extensions: []
74
-
75
67
  extra_rdoc_files: []
76
-
77
- files:
68
+ files:
78
69
  - lib/rspec/mocks.rb
79
70
  - lib/rspec/mocks/any_instance.rb
80
71
  - lib/rspec/mocks/any_instance/chain.rb
@@ -98,6 +89,7 @@ files:
98
89
  - lib/rspec/mocks/serialization.rb
99
90
  - lib/rspec/mocks/space.rb
100
91
  - lib/rspec/mocks/standalone.rb
92
+ - lib/rspec/mocks/test_double.rb
101
93
  - lib/rspec/mocks/version.rb
102
94
  - lib/spec/mocks.rb
103
95
  - README.md
@@ -105,7 +97,7 @@ files:
105
97
  - Changelog.md
106
98
  - .yardopts
107
99
  - .document
108
- - features/README.markdown
100
+ - features/README.md
109
101
  - features/Scope.md
110
102
  - features/Upgrade.md
111
103
  - features/argument_matchers/README.md
@@ -169,45 +161,45 @@ files:
169
161
  - spec/rspec/mocks/stub_implementation_spec.rb
170
162
  - spec/rspec/mocks/stub_spec.rb
171
163
  - spec/rspec/mocks/stubbed_message_expectations_spec.rb
164
+ - spec/rspec/mocks/test_double_spec.rb
172
165
  - spec/rspec/mocks/to_ary_spec.rb
173
166
  - spec/rspec/mocks/twice_counts_spec.rb
174
167
  - spec/rspec/mocks_spec.rb
175
168
  - spec/spec_helper.rb
176
169
  homepage: http://github.com/rspec/rspec-mocks
177
- licenses:
170
+ licenses:
178
171
  - MIT
179
172
  post_install_message:
180
- rdoc_options:
173
+ rdoc_options:
181
174
  - --charset=UTF-8
182
- require_paths:
175
+ require_paths:
183
176
  - lib
184
- required_ruby_version: !ruby/object:Gem::Requirement
177
+ required_ruby_version: !ruby/object:Gem::Requirement
185
178
  none: false
186
- requirements:
187
- - - ">="
188
- - !ruby/object:Gem::Version
189
- hash: 3
190
- segments:
179
+ requirements:
180
+ - - ! '>='
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ segments:
191
184
  - 0
192
- version: "0"
193
- required_rubygems_version: !ruby/object:Gem::Requirement
185
+ hash: -3514585856622943193
186
+ required_rubygems_version: !ruby/object:Gem::Requirement
194
187
  none: false
195
- requirements:
196
- - - ">="
197
- - !ruby/object:Gem::Version
198
- hash: 3
199
- segments:
188
+ requirements:
189
+ - - ! '>='
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ segments:
200
193
  - 0
201
- version: "0"
194
+ hash: -3514585856622943193
202
195
  requirements: []
203
-
204
196
  rubyforge_project: rspec
205
- rubygems_version: 1.8.15
197
+ rubygems_version: 1.8.24
206
198
  signing_key:
207
199
  specification_version: 3
208
- summary: rspec-mocks-2.9.0
209
- test_files:
210
- - features/README.markdown
200
+ summary: rspec-mocks-2.10.0
201
+ test_files:
202
+ - features/README.md
211
203
  - features/Scope.md
212
204
  - features/Upgrade.md
213
205
  - features/argument_matchers/README.md
@@ -271,6 +263,7 @@ test_files:
271
263
  - spec/rspec/mocks/stub_implementation_spec.rb
272
264
  - spec/rspec/mocks/stub_spec.rb
273
265
  - spec/rspec/mocks/stubbed_message_expectations_spec.rb
266
+ - spec/rspec/mocks/test_double_spec.rb
274
267
  - spec/rspec/mocks/to_ary_spec.rb
275
268
  - spec/rspec/mocks/twice_counts_spec.rb
276
269
  - spec/rspec/mocks_spec.rb