Skip to content

Instantly share code, notes, and snippets.

@sgerrand
Created November 12, 2013 11:25
Show Gist options
  • Save sgerrand/7429380 to your computer and use it in GitHub Desktop.
Save sgerrand/7429380 to your computer and use it in GitHub Desktop.
An example using Minitest::Mock, using the version (4.7) available in the Ruby standard library.
class Roro
def initialize(host, speakers = [])
@host = host
@speakers = speakers
end
def start
@host.speak
end
end
require 'minitest/autorun'
require 'minitest/pride'
require_relative 'roro'
class TestRoro < MiniTest::Unit::TestCase
def setup
@mock = MiniTest::Mock.new
@mock.expect :speak, 'Welcome to roro!'
end
def test_start_returns_welcome_message
@roro = Roro.new(@mock)
assert_equal 'Welcome to roro!', @roro.start
@mock.verify
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment