Sha256: ddddf1cef81efa30db60903c4383a083a39acd5c64ce672618807bcf07b6e9d9

Contents?: true

Size: 1.06 KB

Versions: 19

Compression:

Stored size: 1.06 KB

Contents

require 'spec_helper'
module Finitio
  describe Attribute, "fetch_on" do

    let(:attr){ Attribute.new(:red, intType) }

    subject{ attr.fetch_on(arg) }

    context 'with an object that does not support fetch' do
      let(:arg){ 12 }

      it 'should raise an error' do
        expect{
          subject
        }.to raise_error(ArgumentError, "Object responding to `fetch` expected")
      end
    end

    context 'with a hash with symbol keys' do
      let(:arg){ { red: 233 } }

      it{ should eq(233) }
    end

    context 'with a hash with string keys' do
      let(:arg){ { "red" => 233 } }

      it{ should eq(233) }
    end

    context 'when the key is missing and no block' do
      let(:arg){ { other: 123 } }

      it 'should raise an error' do
        expect{
          attr.fetch_on(arg)
        }.to raise_error(KeyError)
      end
    end

    context 'when the key is missing and a block' do
      let(:arg){ { other: 123 } }

      it 'should yield the block' do
        expect(attr.fetch_on(arg){ "none" }).to eq("none")
      end
    end

  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
finitio-0.12.0 spec/attribute/test_fetch_on.rb
finitio-0.11.4 spec/attribute/test_fetch_on.rb
finitio-0.11.3 spec/attribute/test_fetch_on.rb
finitio-0.11.2 spec/attribute/test_fetch_on.rb
finitio-0.11.1 spec/attribute/test_fetch_on.rb
finitio-0.10.0 spec/attribute/test_fetch_on.rb
finitio-0.9.1 spec/attribute/test_fetch_on.rb
finitio-0.9.0 spec/attribute/test_fetch_on.rb
finitio-0.8.0 spec/attribute/test_fetch_on.rb
finitio-0.7.0 spec/attribute/test_fetch_on.rb
finitio-0.7.0.pre.rc4 spec/attribute/test_fetch_on.rb
finitio-0.7.0.pre.rc3 spec/attribute/test_fetch_on.rb
finitio-0.7.0.pre.rc2 spec/attribute/test_fetch_on.rb
finitio-0.7.0.pre.rc1 spec/attribute/test_fetch_on.rb
finitio-0.6.1 spec/attribute/test_fetch_on.rb
finitio-0.6.0 spec/attribute/test_fetch_on.rb
finitio-0.5.2 spec/attribute/test_fetch_on.rb
finitio-0.5.1 spec/attribute/test_fetch_on.rb
finitio-0.5.0 spec/attribute/test_fetch_on.rb