I’m trying to polish up my Ruby by re writing Kent Beck’s xUnit Python example from ‘Test Driven Development: By Example’. I’ve got quite far but now I get the following error when I run which I don’t grok.
C:\Documents and Settings\aharmel\My Documents\My Workspace\TDD_Book\TDDBook_xUnit_RubyVersion\lib\main.rb:21:in `test_running': wrong number of arguments (0 for 2) (ArgumentError) from C:\Documents and Settings\aharmel\My Documents\My Workspace\TDD_Book\TDDBook_xUnit_RubyVersion\lib\main.rb:21:in `run' from C:\Documents and Settings\aharmel\My Documents\My Workspace\TDD_Book\TDDBook_xUnit_RubyVersion\lib\main.rb:85
My code looks like this:
class TestCase def initialize(name) puts '1. inside TestCase.initialise: @name: #{name}' @name = name end def set_up # No implementation (but present to be overridden in WasRun) end def run self.set_up self.send @name # <<<<<<<<<<<<<<<<<<<<<<<<<= ERROR HERE!!!!!! end end class WasRun < TestCase attr_accessor :wasRun attr_accessor :wasSetUp def initialize(name) super(name) end def set_up @wasRun = false @wasSetUp = true end def test_method @wasRun = true end end class TestCaseTest < TestCase def set_up @test = WasRun.new('test_method') end def test_running @test.run puts 'test was run? (true expected): #{test.wasRun}' end def test_set_up @test.run puts 'test was set up? (true expected): #{test.wasSetUp}' end end TestCaseTest.new('test_running').run
Can anyone point out my obvious mistake?
It’s your print statement:
should be
without the ‘@’ you are calling Kernel#test, which expects 2 variables.