diff --git a/lib/motion/stump_spec_helper.rb b/lib/motion/stump_spec_helper.rb index 6b1e94a..dbe7854 100644 --- a/lib/motion/stump_spec_helper.rb +++ b/lib/motion/stump_spec_helper.rb @@ -21,6 +21,7 @@ def verify_mocks def it_with_mock_verification(description, &block) @after << proc { verify_mocks } + @after << proc { Stump::Stubs.clear! } it_without_mock_verification(description, &block) end end diff --git a/lib/stump/stub.rb b/lib/stump/stub.rb index 720ad0a..194c607 100644 --- a/lib/stump/stub.rb +++ b/lib/stump/stub.rb @@ -11,6 +11,8 @@ class Object # my_string.retreat! # => "run away! run away!" # def stub!(method_name, options = {}, &stubbed) + Stump::Stubs.add(self, method_name) + behavior = (block_given? ? stubbed : lambda { return options[:return] }) safe_meta_def method_name, &behavior @@ -31,4 +33,4 @@ def stub(method, options = {}, &block) stub_object end -end \ No newline at end of file +end diff --git a/lib/stump/stubs.rb b/lib/stump/stubs.rb new file mode 100644 index 0000000..2a15637 --- /dev/null +++ b/lib/stump/stubs.rb @@ -0,0 +1,19 @@ +module Stump + class Stubs + class << self + def add(object, method) + stubs << [object, method] + end + + def stubs + @stubs ||= [] + end + + def clear! + stubs.each do |object, method| + object.reset(method) + end + end + end + end +end diff --git a/spec/main_spec.rb b/spec/main_spec.rb index 1174f92..eb7763e 100644 --- a/spec/main_spec.rb +++ b/spec/main_spec.rb @@ -209,5 +209,23 @@ def ignored_flunk(message) alias_method :flunk, :original_flunk end end + + describe "clear stubs" do + context "with stub" do + before do + Dog.stub!(:kind, return: 'Foo') + end + + it "runs with stubs" do + Dog.kind.should == 'Foo' + end + end + + context "without stub" do + it "runs without stubs" do + Dog.kind.should == 'Mammal' + end + end + end end end