Mocha example
I thought I’d put the examples from the RDoc README up here if only for the syntax highlighting.
class Enterprise
def initialize(dilithium) @dilithium = dilithium end
def go(warp_factor) warp_factor.times { @dilithium.nuke(:anti_matter) } end
end
require 'rubygems' require 'mocha' require 'test/unit'
class EnterpriseTest < Test::Unit::TestCase
include Mocha
def test_should_boldly_go dilithium = Mock.new dilithium.expects(:nuke).with(:anti_matter).at_least_once enterprise = Enterprise.new(dilithium) enterprise.go(2) dilithium.verify end
end