我无法理解如何使用puts
测试输出。我需要知道我需要在我的RSPEC文件中做什么。rspec输出测试
这是我RSPEC文件:
require 'game_io'
require 'board'
describe GameIO do
before(:each) do
@gameio = GameIO.new
@board = Board.new
end
context 'welcome_message' do
it 'should display a welcome message' do
test_in = StringIO.new("some test input\n")
test_out = StringIO.new
test_io = GameIO.new(test_in, test_out)
test_io.welcome_message
test_io.game_output.string.should == "Hey, welcome to my game. Get ready to be defeated"
end
end
end
这是该文件是针对测试:
class GameIO
attr_reader :game_input, :game_output
def initialize(game_input = $stdin, game_output = $stdout)
@stdin = game_input
@stdout = game_output
end
def welcome_message
output "Hey, welcome to my game. Get ready to be defeated"
end
def output(msg)
@stdout.puts msg
end
def input
@stdin.gets
end
end
注:我更新了我的RSPEC代码,以反映我对给我的测试文件所做的更改在别处找到的建议为了完全解决这个问题,我使用了我的主文件中Chris Heald提出的修改。谢谢大家,谢谢克里斯。
以供将来参考:一旦你已经解决了这个问题,这是更好地把解决方案中的答案,而不是编辑你的问题。如果有人回到这个问题,很难看出原来的问题是什么。 :) – henrikhodne