Sha256: 4bdfa7f46d9f4fa816183d38a9abf04ff024b5a82f9407abb294842dd2246ddd

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe Addy do
  describe "#sum" do
    before(:all) do
      class NotInjectable
        include ::Addy
      end
    end
    
    context "when sum is called with a parameter" do
      before(:all) do
        class ::Object
          include ::Addy
        end
      end
    
      it "should calculate the sum of the values passed in when no block is given" do
        sum(1..5).should == 15
      end
    
      it "should calculate the sum of the results of the block for the values passed in when a block is given" do
        sum(1..3) {|i| i**i }.should == 32
      end
      
      it "should raise an exception when self does not respond to inject" do
        lambda {sum NotInjectable.new}.should raise_error "NotInjectable does not implement inject."
      end
    end
    
    context "when sum is called without a parameter" do
      before(:all) do
        class ::Range
          include ::Addy
        end
      end
      
      it "should calculate the sum of the values of self when no block is given" do
        (1..5).sum.should == 15
      end
            
      it "should calculate the sum of the results of the block for each value of self when a block is given" do
        (1..3).sum {|i| i**i }.should == 32
      end
      
      it "should raise an exception when self does not respond to inject" do
        lambda {NotInjectable.new.sum}.should raise_error "NotInjectable does not implement inject."
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
addy-1.1.0 spec/addy_spec.rb