Skip to content

Instantly share code, notes, and snippets.

@ono
Created October 22, 2009 22:58
Show Gist options
  • Save ono/216434 to your computer and use it in GitHub Desktop.
Save ono/216434 to your computer and use it in GitHub Desktop.
require File.dirname(__FILE__) + '/../spec_helper'
class Foo
def self.hello
"hello"
end
end
class FooBar < Foo
def self.konnichiwa
"konnichiwa"
end
end
describe '#mock' do
it "should be able to mock a class method" do
# ==== This succeeds.
mock(Foo).hello { "hello!" }
Foo.hello.should == "hello!"
end
it "should be able to mock a class method which will be executed by the subclass" do
# ==== This fails.
mock(Foo).hello { "hello!" }
FooBar.hello.should == "hello!"
end
it "should not affect from a previous example" do
# ==== This fails too. (remove '--reverse' from spec.opts and run after the above spec)
FooBar.hello.should == "hello"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment