Sha256: 5005c062693adccd86a50e1366a0deca013e02390f73a959392985fbbb29022c

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

require 'sham/config/attributes'

describe Sham::Config::Attributes do
  before(:all) do
    Object.send(:remove_const, :AttributesTester) if defined?(AttributesTester)
    class AttributesTester
      attr_accessor :id

      def initialize(options)
        self.id = options[:id]
      end
    end
  end

  let(:id){ stub }
  let(:options){ { :id => id } }
  let(:subject){ described_class.new(lambda{ options }) }
  let(:config){ subject.object(AttributesTester) }

  it 'passes default options' do
    AttributesTester.should_receive(:new).with(options)
    config.options.sham
  end

  it 'prioritizes passed options' do
    AttributesTester.should_receive(:new).with({ :id => 2 })
    config.options(:id => 2).sham
  end

  it 'merges passed options' do
    AttributesTester.should_receive(:new).with({ :id => id, :name => 'A' })
    config.options(:name => 'A').sham
  end

  it 'parses default options' do
    subject.should_receive(:parse!).with(id)
    config.options.sham
  end

  it 'does not parse passed options' do
    subject.should_receive(:parse!).with(2).never
    config.options(:id => 2).sham
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sham-1.1.0 spec/lib/sham/config/attributes_spec.rb
sham-1.0.3 spec/lib/sham/config/attributes_spec.rb