Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 33 lines (26 sloc) 0.978 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
require 'spec_helper'

describe Virtus::Attribute::Hash, '.merge_options' do
  subject { described_class.merge_options(type, options) }

  let(:type) { { String => Integer } }
  let(:options) { { :opt => 'val' } }

  context 'when `type` responds to `size`' do
    context 'when size is == 1' do
      specify { subject[:opt].should == 'val' }
      specify { subject[:key_type].should == String }
      specify { subject[:value_type].should == Integer }
    end

    context 'when size is > 1' do
      let(:type) { { :opt1 => 'val1', :opt2 => 'val2' } }

      it 'should raise ArgumentError' do
        message = "more than one [key => value] pair in `#{type.inspect}`"
        expect { subject }.to raise_error(ArgumentError, message)
      end
    end
  end

  context 'when `type` does not respond to `size`' do
    before do
      type.should_receive(:respond_to?).with(:size).and_return(false)
    end

    it { should be_eql(options) }
  end
end
Something went wrong with that request. Please try again.