Sha256: 0021bc21911ff27653810453b527fe86b816f1d77e6883f8fff60013a5eb9e5e

Contents?: true

Size: 1.88 KB

Versions: 1

Compression:

Stored size: 1.88 KB

Contents

require 'spec_helper'

require 'mspire/mass/mass_provider'

module MockModule
  extend Mspire::Mass::MassProvider
end

describe Mspire::Mass::MassProvider do
  subject do
    { :C => 3, :E => 5 }
  end
  it 'can prepare hashes' do
    new_hash = MockModule.prepare_hash(subject) 
    new_hash.should == {:C=>3, :E=>5}
  end

  it 'can prepare hashes with downcase keys' do
    new_hash = MockModule.prepare_hash(subject, case: :down) 
    new_hash.should == {:c=>3, :e=>5}
  end

  it 'can prepare hashes with upcase keys' do
    new_hash = MockModule.prepare_hash(subject, case: :up) 
    new_hash.should == {:C=>3, :E=>5}
  end

  it 'can prepare hashes with either case keys' do
    new_hash = MockModule.prepare_hash(subject, case: :both) 
    new_hash.sort.should == {:c=>3, :e=>5, :C=>3, :E=>5}.sort
  end

  it 'can prepare hashes with symbol keys' do
    new_hash = MockModule.prepare_hash(subject, by: :symbol) 
    new_hash.should == {:C=>3, :E=>5}
  end

  it 'can prepare hashes with symbol keys even if string keys were used' do
    yikes = subject.map {|k,v| [k.to_s, v]}.to_h
    yikes.should == {"C"=>3, "E"=>5}
    new_hash = MockModule.prepare_hash(yikes, by: :symbol) 
    new_hash.should == {:C=>3, :E=>5}
  end

  it 'can prepare hashes with string keys' do
    new_hash = MockModule.prepare_hash(subject, by: :string) 
    new_hash.should == {'C'=>3, 'E'=>5}
  end

  it 'can prepare hashes with both string and symbol keys' do
    new_hash = MockModule.prepare_hash(subject, by: :both) 
    # could fail if sort order is done differently
    new_hash.should == {:C=>3, :E=>5, 'C'=>3, 'E'=>5}
  end

  it 'can prepare hashes with both string and symbol keys and upper and lower case' do
    new_hash = MockModule.prepare_hash(subject, by: :both, case: :both) 
    # could fail if sort order is done differently
    new_hash.should == {:C=>3, :c=>3, "C"=>3, "c"=>3, :E=>5, :e=>5, "E"=>5, "e"=>5}
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mspire-mass-0.1.0 spec/mspire/mass/mass_provider_spec.rb