[~/local/src/ruby/LPP/rspec_examples/rpcalculator(master)]$ cat lib/math/rpcalc.rb module Math class RPCalc attr_accessor :stack def initialize() @stack = [] end def calc(expr) @stack = [] expr.split(/\s+/).each do |x| case x when '+', '*', '-', '/' # when /^-?\s*\d+(\.\d+)?([eE][+-]?\d+)?\s*$/ # else raise SyntaxError, "Error. found '#{x}'. Expected number or operator" end end end end # class RPCalc end # Math
[~/local/src/ruby/LPP/rspec_examples/rpcalculator(master)]$ rake spec rspec -Ilib -Ispec spec/math/rpcalc_spec.rb Math::RPCalc When an erroneous input is given must raise an exception Finished in 0.0018 seconds 1 example, 0 failures