Skip to content

Instantly share code, notes, and snippets.

@floehopper
Created December 2, 2010 13:03
Show Gist options
  • Select an option

  • Save floehopper/725248 to your computer and use it in GitHub Desktop.

Select an option

Save floehopper/725248 to your computer and use it in GitHub Desktop.
require "test/unit"
require "rubygems"
require "shoulda"
require "mocha"
class Red
def gets(*args)
@input.gets(*args)
end
def puts(*args)
@output.puts(*args)
end
def initialize
@input = $stdin
@output = $stdout
end
private
def first_method
input = gets.chomp
if input == "test"
second_method(input)
end
end
def second_method(value)
puts value
# second_method(value) # this would result in infinite recursion
end
end
class FooTest < Test::Unit::TestCase
context "foo" do
setup do
@project = Red.new
@project.instance_variable_set(:@input, StringIO.new("test\n"))
@project.stubs(:second_method)
end
should "pass input value to second_method" do
@project.expects(:second_method).with("test").once
@project.instance_eval {first_method}
end
end
end
@floehopper

Copy link
Copy Markdown
Author
$ ruby -v
ruby 1.8.7 (2010-04-19 patchlevel 253) [i686-darwin10.4.0], MBARI 0x6770, Ruby Enterprise Edition 2010.02
$ gem -v
1.3.7
$ gem list mocha

*** LOCAL GEMS ***

mocha (0.9.10)
$ gem list shoulda

*** LOCAL GEMS ***

shoulda (2.11.3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment