Created
July 31, 2010 16:43
-
-
Save shibason/502354 to your computer and use it in GitHub Desktop.
RSpec sample: Stubbing a Kernel method in a constructor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Stubbing a Kernel method in a constructor | |
class Sample | |
def initialize | |
puts 'Hello world!' | |
end | |
end | |
describe Sample do | |
it '#initialize call puts' do | |
Sample.module_eval do | |
alias :original_initialize :initialize | |
def initialize | |
self.should_receive(:puts).once.with('Hello world') | |
original_initialize | |
end | |
end | |
begin | |
Sample.new | |
ensure | |
Sample.module_eval do | |
alias :initialize :original_initialize | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment