rspec-mocks 2.0.0.beta.12 → 2.0.0.beta.13

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.
data/.gitignore CHANGED
@@ -6,3 +6,4 @@ pkg
6
6
  doc
7
7
  tmp
8
8
  rerun.txt
9
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ gem "rake"
2
+ gem "jeweler"
3
+ gem "cucumber"
4
+ gem "aruba"
5
+ gem "autotest"
6
+ gem "rspec-mocks", :path => "."
7
+ gem "rspec-core", :path => "../rspec-core"
8
+ gem "rspec-expectations", :path => "../rspec-expectations"
9
+ gem "ruby-debug"
data/Rakefile CHANGED
@@ -1,4 +1,6 @@
1
- $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
1
+ require "bundler"
2
+ Bundler.setup
3
+
2
4
  require 'rake'
3
5
  require 'rspec/mocks/version'
4
6
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0.beta.12
1
+ 2.0.0.beta.13
@@ -1,2 +1,21 @@
1
+ require 'bundler'
2
+ Bundler.setup
3
+
1
4
  require 'aruba'
2
5
  require 'rspec/expectations'
6
+
7
+ module ArubaOverrides
8
+ def detect_ruby_script(cmd)
9
+ if cmd =~ /^rspec /
10
+ "bundle exec ../../../rspec-core/bin/#{cmd}"
11
+ elsif cmd =~ /^ruby /
12
+ "bundle exec #{cmd}"
13
+ else
14
+ super(cmd)
15
+ end
16
+ end
17
+ end
18
+
19
+ World(ArubaOverrides)
20
+
21
+
@@ -6,7 +6,7 @@ module RSpec
6
6
 
7
7
  def initialize(args, &block)
8
8
  @args = args
9
- @matchers_block = block
9
+ @matchers_block = block if args.empty?
10
10
  @match_any_args = false
11
11
  @matchers = nil
12
12
 
@@ -68,7 +68,7 @@ module RSpec
68
68
  stashed = stashed_method_name
69
69
  orig = @method_name
70
70
  object_singleton_class.class_eval do
71
- alias_method(stashed, orig) if method_defined?(orig)
71
+ alias_method(stashed, orig) if method_defined?(orig) || private_method_defined?(orig)
72
72
  end
73
73
  @stashed = true
74
74
  end
@@ -91,7 +91,7 @@ module RSpec
91
91
  stashed_method_name = self.stashed_method_name
92
92
  object_singleton_class.instance_eval do
93
93
  remove_method method_name
94
- if method_defined?(stashed_method_name)
94
+ if method_defined?(stashed_method_name) || private_method_defined?(stashed_method_name)
95
95
  alias_method method_name, stashed_method_name
96
96
  remove_method stashed_method_name
97
97
  end
@@ -139,6 +139,11 @@ module RSpec
139
139
  stubs.unshift stub
140
140
  stub
141
141
  end
142
+
143
+ def remove_stub
144
+ raise_method_not_stubbed_error if stubs.empty?
145
+ expectations.empty? ? reset : stubs.clear
146
+ end
142
147
 
143
148
  def proxy_for_nil_class?
144
149
  @object.nil?
@@ -149,6 +154,10 @@ module RSpec
149
154
  Kernel.warn("An expectation of :#{@method_name} was set on nil. Called from #{caller[4]}. Use allow_message_expectations_on_nil to disable warnings.")
150
155
  end
151
156
  end
157
+
158
+ def raise_method_not_stubbed_error
159
+ raise MockExpectationError, "The method `#{method_name}` was not stubbed or was already unstubbed"
160
+ end
152
161
 
153
162
  def reset_nil_expectations_warning
154
163
  RSpec::Mocks::Proxy.warn_about_expectations_on_nil = true if proxy_for_nil_class?
@@ -17,7 +17,12 @@ module RSpec
17
17
  end
18
18
  end
19
19
 
20
+ def unstub(sym)
21
+ __mock_proxy.remove_stub(sym)
22
+ end
23
+
20
24
  alias_method :stub!, :stub
25
+ alias_method :unstub!, :unstub
21
26
 
22
27
  def stub_chain(*methods)
23
28
  if methods.length > 1
@@ -65,6 +65,10 @@ module RSpec
65
65
  method_double[method_name].add_stub @error_generator, @expectation_ordering, location, opts, &implementation
66
66
  end
67
67
 
68
+ def remove_stub(method_name)
69
+ method_double[method_name].remove_stub
70
+ end
71
+
68
72
  def verify #:nodoc:
69
73
  method_doubles.each {|d| d.verify}
70
74
  ensure
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rspec-mocks}
8
- s.version = "2.0.0.beta.12"
8
+ s.version = "2.0.0.beta.13"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David Chelimsky", "Chad Humphries"]
12
- s.date = %q{2010-06-14}
12
+ s.date = %q{2010-06-23}
13
13
  s.description = %q{RSpec's 'test double' framework, with support for stubbing and mocking}
14
14
  s.email = %q{dchelimsky@gmail.com;chad.humphries@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  ".autotest",
20
20
  ".document",
21
21
  ".gitignore",
22
+ "Gemfile",
22
23
  "License.txt",
23
24
  "README.markdown",
24
25
  "Rakefile",
@@ -98,7 +99,7 @@ Gem::Specification.new do |s|
98
99
  s.homepage = %q{http://github.com/rspec/mocks}
99
100
  s.post_install_message = %q{**************************************************
100
101
 
101
- Thank you for installing rspec-mocks-2.0.0.beta.12
102
+ Thank you for installing rspec-mocks-2.0.0.beta.13
102
103
 
103
104
  **************************************************
104
105
  }
@@ -106,7 +107,7 @@ Gem::Specification.new do |s|
106
107
  s.require_paths = ["lib"]
107
108
  s.rubyforge_project = %q{rspec}
108
109
  s.rubygems_version = %q{1.3.6}
109
- s.summary = %q{rspec-mocks-2.0.0.beta.12}
110
+ s.summary = %q{rspec-mocks-2.0.0.beta.13}
110
111
  s.test_files = [
111
112
  "spec/rspec/mocks/and_yield_spec.rb",
112
113
  "spec/rspec/mocks/any_number_of_times_spec.rb",
@@ -158,15 +159,15 @@ Gem::Specification.new do |s|
158
159
  s.specification_version = 3
159
160
 
160
161
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
161
- s.add_development_dependency(%q<rspec-core>, ["= 2.0.0.beta.12"])
162
- s.add_development_dependency(%q<rspec-expectations>, ["= 2.0.0.beta.12"])
162
+ s.add_development_dependency(%q<rspec-core>, ["= 2.0.0.beta.13"])
163
+ s.add_development_dependency(%q<rspec-expectations>, ["= 2.0.0.beta.13"])
163
164
  else
164
- s.add_dependency(%q<rspec-core>, ["= 2.0.0.beta.12"])
165
- s.add_dependency(%q<rspec-expectations>, ["= 2.0.0.beta.12"])
165
+ s.add_dependency(%q<rspec-core>, ["= 2.0.0.beta.13"])
166
+ s.add_dependency(%q<rspec-expectations>, ["= 2.0.0.beta.13"])
166
167
  end
167
168
  else
168
- s.add_dependency(%q<rspec-core>, ["= 2.0.0.beta.12"])
169
- s.add_dependency(%q<rspec-expectations>, ["= 2.0.0.beta.12"])
169
+ s.add_dependency(%q<rspec-core>, ["= 2.0.0.beta.13"])
170
+ s.add_dependency(%q<rspec-expectations>, ["= 2.0.0.beta.13"])
170
171
  end
171
172
  end
172
173
 
@@ -3,12 +3,12 @@ require 'spec_helper'
3
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
7
-
8
6
  before(:each) do
9
7
  @mock = double("test double")
10
8
  end
11
9
 
10
+ treats_method_missing_as_private :subject => RSpec::Mocks::Mock.new, :noop => false
11
+
12
12
  after(:each) do
13
13
  @mock.rspec_reset
14
14
  end
@@ -597,5 +597,47 @@ module RSpec
597
597
  second == first
598
598
  end
599
599
  end
600
+
601
+ describe "with" do
602
+ before { @mock = double('double') }
603
+ context "with args" do
604
+ context "with matching args" do
605
+ it "passes" do
606
+ @mock.should_receive(:foo).with('bar')
607
+ @mock.foo('bar')
608
+ end
609
+ end
610
+
611
+ context "with non-matching args" do
612
+ it "fails" do
613
+ @mock.should_receive(:foo).with('bar')
614
+ expect do
615
+ @mock.foo('baz')
616
+ end.to raise_error
617
+ @mock.rspec_reset
618
+ end
619
+ end
620
+ end
621
+
622
+ context "with a block" do
623
+ context "with matching args" do
624
+ it "returns the result of the block" do
625
+ @mock.should_receive(:foo).with('bar') { 'baz' }
626
+ @mock.foo('bar').should eq('baz')
627
+ end
628
+ end
629
+
630
+ context "with non-matching args" do
631
+ it "fails" do
632
+ @mock.should_receive(:foo).with('bar') { 'baz' }
633
+ expect do
634
+ @mock.foo('wrong').should eq('baz')
635
+ end.to raise_error(/received :foo with unexpected arguments/)
636
+ @mock.rspec_reset
637
+ end
638
+ end
639
+ end
640
+ end
641
+
600
642
  end
601
643
  end
@@ -24,7 +24,44 @@ module RSpec
24
24
  obj = stub()
25
25
  obj.stub(:foo) {|*given| given.first}
26
26
  obj.foo(:bar).should == :bar
27
- end
27
+ end
28
+ end
29
+ end
30
+
31
+
32
+ describe "unstub implementation" do
33
+ it "should replace the stubbed method with the original method" do
34
+ obj = Object.new
35
+ def obj.foo; :original; end
36
+ obj.stub(:foo)
37
+ obj.unstub(:foo)
38
+ obj.foo.should == :original
39
+ end
40
+
41
+ it "should remove all stubs with the supplied method name" do
42
+ obj = Object.new
43
+ def obj.foo; :original; end
44
+ obj.stub(:foo).with(1)
45
+ obj.stub(:foo).with(2)
46
+ obj.unstub(:foo)
47
+ obj.foo.should == :original
48
+ end
49
+
50
+ it "should not remove any expectations with the same method name" do
51
+ obj = Object.new
52
+ def obj.foo; :original; end
53
+ obj.should_receive(:foo).with(3).and_return(:three)
54
+ obj.stub(:foo).with(1)
55
+ obj.stub(:foo).with(2)
56
+ obj.unstub(:foo)
57
+ obj.foo(3).should == :three
58
+ end
59
+
60
+ it "should raise a MockExpectationError if the method has not been stubbed" do
61
+ obj = Object.new
62
+ lambda do
63
+ obj.unstub(:foo)
64
+ end.should raise_error(MockExpectationError)
28
65
  end
29
66
  end
30
67
  end
@@ -5,11 +5,23 @@ module RSpec
5
5
  describe "A method stub" do
6
6
  before(:each) do
7
7
  @class = Class.new do
8
- def self.existing_class_method
9
- :original_value
8
+ class << self
9
+ def existing_class_method
10
+ existing_private_class_method
11
+ end
12
+
13
+ private
14
+ def existing_private_class_method
15
+ :original_value
16
+ end
10
17
  end
11
18
 
12
19
  def existing_instance_method
20
+ existing_private_instance_method
21
+ end
22
+
23
+ private
24
+ def existing_private_instance_method
13
25
  :original_value
14
26
  end
15
27
  end
@@ -90,7 +102,15 @@ module RSpec
90
102
  @instance.rspec_verify
91
103
  @instance.existing_instance_method.should equal(:original_value)
92
104
  end
93
-
105
+
106
+ it "should revert to original private instance method if there is one" do
107
+ @instance.existing_instance_method.should equal(:original_value)
108
+ @instance.stub(:existing_private_instance_method).and_return(:mock_value)
109
+ @instance.existing_instance_method.should equal(:mock_value)
110
+ @instance.rspec_verify
111
+ @instance.existing_instance_method.should equal(:original_value)
112
+ end
113
+
94
114
  it "should revert to original class method if there is one" do
95
115
  @class.existing_class_method.should equal(:original_value)
96
116
  @class.stub(:existing_class_method).and_return(:mock_value)
@@ -99,6 +119,14 @@ module RSpec
99
119
  @class.existing_class_method.should equal(:original_value)
100
120
  end
101
121
 
122
+ it "should revert to original private class method if there is one" do
123
+ @class.existing_class_method.should equal(:original_value)
124
+ @class.stub(:existing_private_class_method).and_return(:mock_value)
125
+ @class.existing_class_method.should equal(:mock_value)
126
+ @class.rspec_verify
127
+ @class.existing_class_method.should equal(:original_value)
128
+ end
129
+
102
130
  it "should yield a specified object" do
103
131
  @instance.stub(:method_that_yields).and_yield(:yielded_obj)
104
132
  current_value = :value_before
@@ -1,6 +1,6 @@
1
- $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
2
- $LOAD_PATH << File.expand_path('../../../rspec-core/lib', __FILE__)
3
- $LOAD_PATH << File.expand_path('../../../rspec-expectations/lib', __FILE__)
1
+ require 'bundler'
2
+ Bundler.setup
3
+
4
4
  require 'rspec/core'
5
5
  require 'rspec/mocks'
6
6
  require 'rspec/expectations'
metadata CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
7
7
  - 0
8
8
  - 0
9
9
  - beta
10
- - 12
11
- version: 2.0.0.beta.12
10
+ - 13
11
+ version: 2.0.0.beta.13
12
12
  platform: ruby
13
13
  authors:
14
14
  - David Chelimsky
@@ -17,13 +17,13 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-06-14 00:00:00 -05:00
20
+ date: 2010-06-23 00:00:00 -05:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
24
+ type: :development
24
25
  name: rspec-core
25
- prerelease: false
26
- requirement: &id001 !ruby/object:Gem::Requirement
26
+ version_requirements: &id001 !ruby/object:Gem::Requirement
27
27
  requirements:
28
28
  - - "="
29
29
  - !ruby/object:Gem::Version
@@ -32,14 +32,14 @@ dependencies:
32
32
  - 0
33
33
  - 0
34
34
  - beta
35
- - 12
36
- version: 2.0.0.beta.12
37
- type: :development
38
- version_requirements: *id001
35
+ - 13
36
+ version: 2.0.0.beta.13
37
+ requirement: *id001
38
+ prerelease: false
39
39
  - !ruby/object:Gem::Dependency
40
+ type: :development
40
41
  name: rspec-expectations
41
- prerelease: false
42
- requirement: &id002 !ruby/object:Gem::Requirement
42
+ version_requirements: &id002 !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "="
45
45
  - !ruby/object:Gem::Version
@@ -48,10 +48,10 @@ dependencies:
48
48
  - 0
49
49
  - 0
50
50
  - beta
51
- - 12
52
- version: 2.0.0.beta.12
53
- type: :development
54
- version_requirements: *id002
51
+ - 13
52
+ version: 2.0.0.beta.13
53
+ requirement: *id002
54
+ prerelease: false
55
55
  description: RSpec's 'test double' framework, with support for stubbing and mocking
56
56
  email: dchelimsky@gmail.com;chad.humphries@gmail.com
57
57
  executables: []
@@ -64,6 +64,7 @@ files:
64
64
  - .autotest
65
65
  - .document
66
66
  - .gitignore
67
+ - Gemfile
67
68
  - License.txt
68
69
  - README.markdown
69
70
  - Rakefile
@@ -146,7 +147,7 @@ licenses: []
146
147
  post_install_message: |
147
148
  **************************************************
148
149
 
149
- Thank you for installing rspec-mocks-2.0.0.beta.12
150
+ Thank you for installing rspec-mocks-2.0.0.beta.13
150
151
 
151
152
  **************************************************
152
153
 
@@ -176,7 +177,7 @@ rubyforge_project: rspec
176
177
  rubygems_version: 1.3.6
177
178
  signing_key:
178
179
  specification_version: 3
179
- summary: rspec-mocks-2.0.0.beta.12
180
+ summary: rspec-mocks-2.0.0.beta.13
180
181
  test_files:
181
182
  - spec/rspec/mocks/and_yield_spec.rb
182
183
  - spec/rspec/mocks/any_number_of_times_spec.rb