Sha256: be66554d376f5704d9bd8abdaaa5885f10bb63437c0a22ef8bdfeba126d42c2a

Contents?: true

Size: 1.26 KB

Versions: 3

Compression:

Stored size: 1.26 KB

Contents

require 'spec_helper'
require 'dottie/ext'

describe Hash do
  
  describe 'Dottie extensions' do
    before :each do
      @hash = { 'a' => 'b', 'c' => { 'd' => 'e' } }
    end
    
    context 'untouched' do
      it "should not have Dottie's behavior" do
        expect(@hash['a.b']).to be_nil
      end
    end
    
    context 'wrapped' do
      let(:freckle) { @hash.dottie }
      
      it 'is no longer a Hash' do
        expect(freckle).to_not be_a Hash
      end
      it 'wraps a Hash in a Dottie::Freckle' do
        expect(freckle).to be_a Dottie::Freckle
      end
      it 'acts like a regular Hash for standard keys' do
        expect(freckle['a']).to eq 'b'
      end
      it "has Dottie's behavior" do
        expect(freckle['c.d']).to eq 'e'
      end
      it "does not add Dottie's behavior to the original Hash" do
        expect(@hash['a.b']).to be_nil
      end
    end
    
    context 'mixed in' do
      before :each do
        @hash.dottie!
      end
      
      it 'is still a Hash' do
        expect(@hash).to be_a Hash
      end
      it 'acts like a regular Hash for standard keys' do
        expect(@hash['a']).to eq 'b'
      end
      it "adds Dottie's behavior to a Hash" do
        expect(@hash['c.d']).to eq 'e'
      end
    end
    
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dottie-0.0.3 spec/hash_spec.rb
dottie-0.0.2 spec/hash_spec.rb
dottie-0.0.1 spec/hash_spec.rb