Skip to content

Instantly share code, notes, and snippets.

@shibason
Created July 31, 2010 16:43
Show Gist options
  • Save shibason/502354 to your computer and use it in GitHub Desktop.
Save shibason/502354 to your computer and use it in GitHub Desktop.
RSpec sample: Stubbing a Kernel method in a constructor
# 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