我刚开始使用 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)