我刚开始使用ruby测试,并不知道如何在测试中编写代码。 这里是测试文件的完整任务:如何使用Ruby测试?
require "temperature"
describe "temperature conversion functions" do
describe "#ftoc" do
it "converts freezing temperature" do
ftoc(32).should == 0
end
it "converts boiling temperature" do
ftoc(212).should == 100
end
it "converts body temperature" do
ftoc(98.6).should == 37
end
it "converts arbitrary temperature" do
ftoc(68).should == 20
end
end
describe "#ctof" do
it "converts freezing temperature" do
ctof(0).should == 32
end
it "converts boiling temperature" do
ctof(100).should == 212
end
it "converts arbitrary temperature" do
ctof(20).should == 68
end
end
end
在我的代码文件,我试试这个:
def ftoc(f)
(f - 32)/1.8
end
而且从rake命令从终端运行它。比耙说
temperature conversion functions
#ftoc
converts freezing temperature
converts boiling temperature
converts body temperature (FAILED - 1)
你指的是哪本书学习这个? –
控制台中的输出应该告诉你它预期会发现什么以及它实际发现了什么。这应该会给你提供进一步的线索。 – depa
好吧,我应该如何在代码中描述“#ftoc”? –