我是测试的新手,我需要在代码文件中向类中添加代码,以便在规范文件中创建的测试通过。
我在代码文件中写了一条评论,我认为应该编写测试,但是如何编写它们以便它们通过?
我的规范代码如下:
require "wad_TIM_00_gen"
module ImpossibleMachine
# Input and output constants processed by subprocesses
DOWN_ARROW = 1
UP_ARROW = 2
RIGHT_ARROW = 3
REPEAT_ARROW = 4
END_PROCESS = 5
START_CURRENT = 6
# RSpec Tests
describe Game do
describe "#start The impossible machine game" do
before(:each) do
@process = []
@output = double('output').as_null_object
@game = Game.new(@output)
end
it "sends a welcome message" do
@output.should_receive(:puts).with('Welcome to the Impossible Machine!')
@game.start
end
it "sends a starting message" do
@output.should_receive(:puts).with('Starting game...')
@game.start
end
end
end
我的代码文件如下所示:
# Main class module
module ImpossibleMachine
# Input and output constants processed by subprocesses. MUST NOT change.
DOWN_ARROW = 1
UP_ARROW = 2
RIGHT_ARROW = 3
REPEAT_ARROW = 4
END_PROCESS = 5
START_CURRENT = 6
class Game
attr_reader :process, :output
attr_writer :process, :output
def initialize(output)
@output = output
puts "[#{@output}]"
end
# I think the tests should be written here
end
end