spec/main_spec.rb in motion-stump-0.2.1 vs spec/main_spec.rb in motion-stump-0.3.0

- old
+ new

@@ -4,10 +4,14 @@ class Dog def self.create return Dog.new end + def self.kind + 'Mammal' + end + def bark "Woof!" end def eat(food) @@ -29,11 +33,11 @@ before do @dog = Dog.new end describe "#stub!" do - it "should stub a class method" do + it "should stub a class method" do Dog.stub!(:thing, return: :thing) Dog.should.not.be.nil Dog.thing.should == :thing end @@ -51,11 +55,11 @@ "#{a},#{b}" end my_obj.hello("foo", "bar").should.be == "foo,bar" end end - + describe "#stub" do it "should create a pure stub" do my_stub = stub(:thing, return: "dude, a thing!") my_stub.thing.should == "dude, a thing!" end @@ -106,11 +110,11 @@ end end end describe "#mock" do - it "should create pure mock" do + it "should create pure mock" do my_mock = mock(:hello, return: "hi") my_mock.hello.should == "hi" end end @@ -136,9 +140,66 @@ it "should raise an error with a class method" do Dog.should_not_call(:create) should.raise(Bacon::Error) do Dog.create + end + end + end + + describe "#reset" do + describe "stubbing" do + it "should restore original class method" do + Dog.stub!(:kind, return: 'Reptile') + Dog.kind.should == 'Reptile' + Dog.reset(:kind) + Dog.kind.should == 'Mammal' + end + + it "should restore original instance method" do + @dog.stub!(:bark, return: 'Meow!') + @dog.bark.should == 'Meow!' + @dog.reset(:bark) + @dog.bark.should == 'Woof!' + end + end + + describe "mocking" do + it "should restore original class method" do + Dog.mock!(:kind, return: 'Reptile') + Dog.kind.should == 'Reptile' + Dog.reset(:kind) + Dog.kind.should == 'Mammal' + end + + it "should restore original instance method" do + @dog.mock!(:bark, return: 'Meow!') + @dog.bark.should == 'Meow!' + @dog.reset(:bark) + @dog.bark.should == 'Woof!' + end + end + end + + describe "after each scenario" do + it "should verify mocks" do + Should.class_eval do + def ignored_flunk(message) + end + + alias_method :original_flunk, :flunk + alias_method :flunk, :ignored_flunk + end + + Dog.mock!(:kind, return: 'Reptile') + 1.should == 1 + end + + it "should have cleared mocks from the previous scenario" do + 1.should == 1 + + Should.class_eval do + alias_method :flunk, :original_flunk end end end end