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 |
Author
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
If I comment out line #21 i.e. the call to Red#second_method from within Red#first_method, I get the test failure I would expect :-