我无法理解如何使用puts
. 我需要知道我需要在我的 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 建议的更改。谢谢大家,谢谢克里斯。