Source

RubyCSharp / RSpec_samples / spec / calculator_spec.rb

Full commit
require './calculator'

#describe Calculator do
#
#  it "should sum two numbers" do
#    calculator = Calculator.new
#    result = calculator.sum(1, 1)
#    result.should == 3
#  end
#
#  it "should subtract two numbers" do
#    calculator = Calculator.new
#    result = calculator.subtract(5, 3)
#    result.should == 2
#  end
#end

#describe Calculator do
#  context "Given a calculator" do
#    before(:each) do
#      @calculator = Calculator.new
#    end
#
#    describe "when told to add 1 + 1" do
#
#      before { @calculator.sum(1, 1) }
#
#      it "should have two input values" do
#        @calculator.input_values.length.should == 2
#      end
#
#      it "should have last result of 2" do
#        @calculator.last_result.should == 2
#      end
#    end
#  end
#end

describe Calculator do
  context "Given a calculator" do
    subject { Calculator.new }

    describe "when told to add 1 + 1" do

      before { subject.sum(1, 1) }

      it { should have(2).input_values }
      its(:last_result) { should == 2 }
    end

    #describe "when told to subtract 5 - 3" do
    #
    #  before { @calculator.subtract(5, 3) }
    #
    #  it { should have(2).input_values }
    #  its(:last_result) { should == 2 }
    #end
  end
end