ruby - undefined function error in rspec -
i having trouble running rspec file, provided part of exercise, , not sure going on.
here code in silly_blocks.rb:
def reverser(num = 1) result = [] if yield == integer yield + num else yield.split.each{|word| result << word.reverse} result.join(' ') end end
here rspec file:
require "05_silly_blocks" describe "some silly block functions" describe "reverser" "reverses string returned default block" result = reverser "hello" end result.should == "olleh" end "reverses each word in string returned default block" result = reverser "hello dolly" end result.should == "olleh yllod" end end describe "adder" "adds 1 value returned default block" adder 5 end.should == 6 end "adds 3 value returned default block" adder(3) 5 end.should == 8 end end describe "repeater" "executes default block" block_was_executed = false repeater block_was_executed = true end block_was_executed.should == true end "executes default block 3 times" n = 0 repeater(3) n += 1 end n.should == 3 end "executes default block 10 times" n = 0 repeater(10) n += 1 end n.should == 10 end end end
i error when hits third test 'adder':
failures: 1) silly block functions adder adds 1 value returned default block failure/error: adder nomethoderror: undefined method `adder' #<rspec::examplegroups::somesillyblockfunctions::adder:0x007f334345b460> # ./p.rb:30:in `block (3 levels) in <top (required)>'
it seems adder defined in exact same way previous methods in rspec, not sure going on. have check various other posts haven't found me, or @ least understand enough me.
the function under test (adder
) isn't defined yet, spec failure tells. defining part of exercise. define it, add
def adder end
in 05_silly_blocks.rb
, either before or after current code.
(more needed third example pass, got first 2 examples passing, you'll know there.)