【发布时间】:2014-04-22 12:08:25
【问题描述】:
我是测试新手,我需要将代码添加到代码文件中的类中,以便规范文件中创建的测试通过。
我在我认为应该编写测试的代码文件中写了一条注释,但我该如何编写它们才能通过?
我的规范代码如下所示:
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
【问题讨论】: