Sha256: 15e14fec27cacdb162b8cc69ea27af2c6e0d842739daf55003a44b1097261e70

Contents?: true

Size: 697 Bytes

Versions: 8

Compression:

Stored size: 697 Bytes

Contents

require 'spec_helper'

unless Enumerable.method_defined? :sum
  describe 'Enumerable#sum' do
    it 'sums up the numbers of an enum' do
      expect((1..3).sum).to eq(6)
    end

    it 'returns zero when invoked on an empty collection' do
      expect([].sum).to be_zero
    end

    it 'returns the initial value when invoked on an empty collection' do
      expect([].sum('')).to be_empty
    end

    it 'prepends the initial value to the sum' do
      expect(['b', 'c'].sum('a')).to eq('abc')
    end

    it 'concatenates strings' do
      expect(['a', 'b', 'c'].sum).to eq('abc')
    end

    it 'concatenates arrays' do
      expect([[1], [2], [3]].sum).to eq([1, 2, 3])
    end
  end
end

Version data entries

8 entries across 6 versions & 4 rubygems

Version Path
powerpack-0.1.3 spec/powerpack/enumerable/sum_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.2/spec/powerpack/enumerable/sum_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.2/spec/powerpack/enumerable/sum_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.2/spec/powerpack/enumerable/sum_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.2/spec/powerpack/enumerable/sum_spec.rb
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.2/spec/powerpack/enumerable/sum_spec.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/powerpack-0.1.2/spec/powerpack/enumerable/sum_spec.rb
powerpack-0.1.2 spec/powerpack/enumerable/sum_spec.rb