这是我需要通过的 rspec:
describe "adder" do
it "adds one to the value returned by the default block" do
adder do
5
end.should == 6
end
it "adds 3 to the value returned by the default block" do
adder(3) do
5
end.should == 8
end
end
这是我的代码
def adder(&block)
if block.call == 5
block.call + 1
else
block.call + 3
end
end
我的错误输出
加法器将默认块返回的值加 1 将默认块返回的值加 3 (FAILED - 1)
失败:
1) 一些愚蠢的块函数 adder 将默认块返回的值加 3 Failure/Error: adder(3) do ArgumentError: wrong number of arguments (1 for 0) # ./05_silly_blocks/silly_blocks.rb:5:in adder'
# ./05_silly_blocks/silly_blocks_spec.rb:37:in
block (3 级) 在 '