Answering rspec to raise_error in Ruby -


basically i'm trying answer series of rspec instructions. 1 of instructions this:

it "fails informatively when there's not enough values stacked away"   expect {      calculator.plus   }.to raise_error("calculator empty") end 

so learned raise_error , how answer it, me create sort of error/exception.

def plus   @array_nums.length >= 2 ? @array_nums << @array_nums.pop + @array_nums.pop : raise {"calculator empty"}   @value = @array_nums[-1] 

to clear there end on bottom text editor wasn't processing it. i'm raising error, i've tried raise argumenterror , that, keep getting response rspec:

failure/error:    expect {      calculator.plus    }.to raise_error("calculator empty")     expected exception "calculator empty", got runtimeerror backtrace:      # ./lib/12_rpn_calculator.rb:16:in `plus'      # ./spec/12_rpn_calculator_spec.rb:119:in `block (3 levels) in <top (required)>'      # ./spec/12_rpn_calculator_spec.rb:118:in `block (2 levels) in <top (required)>'  # ./spec/12_rpn_calculator_spec.rb:118:in `block (2 levels) in <top (required)>' 

any other raised errors try don't work, , i'm struggling find right direction take this. maybe i'm looking in wrong place? appreciated, thank you!

try instead:

  @array_nums.length >= 2 ? @array_nums << @array_nums.pop + @array_nums.pop : raise standarderror, 'calculator empty' 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -