Skip to content

Instantly share code, notes, and snippets.

@blowmage
Last active December 22, 2015 17:19
Show Gist options
  • Save blowmage/98ab11f9171761612fd6 to your computer and use it in GitHub Desktop.
Save blowmage/98ab11f9171761612fd6 to your computer and use it in GitHub Desktop.
Test with a mock and a stub
require "minitest/autorun"
class RestClient
def self.get action
end
end
class MyClass
def do_it!
RestClient.get :index
end
end
class TestMyClass < Minitest::Test
def test_mock_and_stub
mock = Minitest::Mock.new
mock.expect :does_something, "return value"
RestClient.stub :get, :index do
mock.does_something
end
MyClass.new.do_it!
mock.verify
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment