-1
我是新來測試,我需要在代碼文件中添加代碼到類中,以便在規範文件中創建的測試通過。RSpec的測試驅動開發
我已經在代碼文件中寫了一條評論,我認爲應該寫這些測試,但是如何編寫它們以便它們通過?
我的規格代碼如下所示:
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
你能給我一個啓動功能的例子嗎? – samgbelton
首先,你沒有正確寫出'RSpec'測試,你應該將'start'函數的輸出響應與建議的輸出相匹配。當你爲這個功能的所有可能的輸出做了測試時,你可以開始執行它。 我會推薦你閱讀這個[鏈接](http://code.tutsplus.com/tutorials/ruby-for-newbies-testing-with-rspec-net-21297),這將有助於你理解這些概念。 – Saurabh