Created
December 2, 2010 13:03
-
-
Save floehopper/725248 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
commented
Dec 2, 2010
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment