Skip to content

Instantly share code, notes, and snippets.

@cfcosta
Created April 17, 2012 17:33
Show Gist options
  • Save cfcosta/2407670 to your computer and use it in GitHub Desktop.
Save cfcosta/2407670 to your computer and use it in GitHub Desktop.
>> require "minitest/mock"
=> true
>> mock = MiniTest::Mock.new
=> #<MiniTest::Mock:0x007fc48ca57d70 @expected_calls={}, @actual_calls={}>
>> mock.respond_to? :abc
=> false
>> mock.expect(:abc, "123")
=> #<MiniTest::Mock:0x007fc48ca57d70 @expected_calls={:abc=>{:retval=>"123", :args=>[]}}, @actual_calls={}>
>> mock.respond_to? :abc
=> true
>> mock.abc
=> "123"
>> mock2 = MiniTest::Mock.new
=> #<MiniTest::Mock:0x007fc48ca61f78 @expected_calls={}, @actual_calls={}>
>> mock2.respond_to? :abc
=> false
>> mock2.abc
NoMethodError: unmocked method :abc, expected one of []
from /Users/cfcosta/.rbenv/versions/1.9.3-p125-perf/lib/ruby/1.9.1/minitest/mock.rb:82:in `method_missing'
from (irb):9
from /Users/cfcosta/.rbenv/versions/1.9.3-p125-perf/bin/irb:12:in `<main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment