您好,请查看我的代码并告诉我出了什么问题,因为它未能通过 rspec 但适用于 repl.it。我不明白来自 rspec 的反馈。失败/错误:n.should == 3 Expect: 3 Got: 0 (using==)
我的代码:
def repeater(x=0)
if x == 0
return yield
else
x.times do |n|
n += 1
end
end
end
它通过了以下的第一个测试:
describe "repeater" do
it "executes the default block" do
block_was_executed = false
repeater do
block_was_executed = true
end
block_was_executed.should == true
end
it "executes the default block 3 times" do
n = 0
repeater(3) do
n += 1
end
n.should == 3
end
it "executes the default block 10 times" do
n = 0
repeater(10) do
n += 1
end
n.should == 10
end
end
谢谢大家的帮助。