Skip to content

Commit

Permalink
Added example for overriding a pre-existing stub and got it to pass.
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Apr 9, 2010
1 parent cf0bc51 commit 92e9741
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/rspec/mocks/method_double.rb
Expand Up @@ -127,14 +127,14 @@ def add_expectation(error_generator, expectation_ordering, expected_from, opts,
def add_negative_expectation(error_generator, expectation_ordering, expected_from, &implementation)
configure_method
expectation = NegativeMessageExpectation.new(error_generator, expectation_ordering, expected_from, @method_name, implementation)
expectations << expectation
expectations.unshift expectation
expectation
end

def add_stub(error_generator, expectation_ordering, expected_from, opts={}, &implementation)
configure_method
stub = MessageExpectation.new(error_generator, expectation_ordering, expected_from, @method_name, nil, :any, opts, &implementation)
stubs << stub
stubs.unshift stub
stub
end

Expand Down
2 changes: 1 addition & 1 deletion rspec-mocks.gemspec
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |s|

s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["David Chelimsky", "Chad Humphries"]
s.date = %q{2010-04-04}
s.date = %q{2010-04-09}
s.description = %q{Rspec's 'test double' framework, with support for stubbing and mocking}
s.email = %q{dchelimsky@gmail.com;chad.humphries@gmail.com}
s.extra_rdoc_files = [
Expand Down
10 changes: 8 additions & 2 deletions spec/rspec/mocks/stub_spec.rb
Expand Up @@ -67,7 +67,7 @@ def existing_instance_method

it "should return values in order to consecutive calls" do
return_values = ["1",2,Object.new]
@instance.stub(:msg).and_return(return_values[0],return_values[1],return_values[2])
@instance.stub(:msg).and_return(*return_values)
@instance.msg.should == return_values[0]
@instance.msg.should == return_values[1]
@instance.msg.should == return_values[2]
Expand Down Expand Up @@ -130,10 +130,16 @@ def existing_instance_method
end.should throw_symbol(:up)
end

it "should override a pre-existing stub" do
it "should override a pre-existing method" do
@stub.stub(:existing_instance_method).and_return(:updated_stub_value)
@stub.existing_instance_method.should == :updated_stub_value
end

it "should override a pre-existing stub" do
@stub.stub(:foo) { 'bar' }
@stub.stub(:foo) { 'baz' }
@stub.foo.should == 'baz'
end

it "should limit " do
@stub.stub(:foo).with("bar")
Expand Down

0 comments on commit 92e9741

Please sign in to comment.