In the below part, you passed only 1 argument instead 2.
describe "repeat" do
it "should repeat" do
repeat("hello").should == "hello hello"
# ^ why only 1 argument ?
end
As per your code, it should be repeat("hello", 2).should == "hello hello"
.
As per commented hints, you can write also :-
def repeat(x, y = 2)
y.times { print x + ‘ ‘ }
end
Now, the test code you wrote, will work without error, with above modified method definition.
require simon_says
describe "repeat" do
it "should repeat" do
# here you are not passsing the second argument. But *repeat* method has `2`
# as its default value of the second argument. So no issue will be here.
repeat("hello").should == "hello hello"
end
it "should repeat a number of times" do
repeat("hello", 3).should == "hello hello hello"
end
end
Read this default argument to know, how default argument works in Ruby.