2: Red

[~/local/src/ruby/LPP/rspec_examples/rpcalculator(1)]$ cat spec/math/rpcalc_spec.rb 
#require File.join(File.dirname(__FILE__), "/../spec_helper")
require "spec_helper"
module Math
  describe RPCalc do
    before :each do
      @c = Math::RPCalc.new
    end

    context "When an erroneous input is given" do
      it "must raise an exception" do
        expect { @c.calc('a') }.to raise_error(SyntaxError)
        expect { @c.calc('a') }.to raise_error("Error. found 'a'. Expected number or operator")
      end
    end
  end

[~/local/src/ruby/LPP/rspec_examples/rpcalculator(1)]$ rake spec
rspec -Ilib -Ispec spec/math/rpcalc_spec.rb

Math::RPCalc
  When an erroneous input is given
    must raise an exception (FAILED - 1)

Failures:

  1) Math::RPCalc When an erroneous input is given must raise an exception
     Failure/Error: expect { @c.calc('a') }.to raise_error(SyntaxError)
       expected SyntaxError, got #<NoMethodError: undefined method `calc' for #<Math::RPCalc:0x007fd4aabfb180>> with backtrace:
         # ./spec/math/rpcalc_spec.rb:11:in `block (4 levels) in <module:Math>'
         # ./spec/math/rpcalc_spec.rb:11:in `block (3 levels) in <module:Math>'
     # ./spec/math/rpcalc_spec.rb:11:in `block (3 levels) in <module:Math>'

Finished in 0.00196 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/math/rpcalc_spec.rb:10 # Math::RPCalc When an erroneous input is given must raise an exception

  1. expect
  2. raise_error


Casiano Rodriguez León 2015-01-07