Sha256: 4a1fb067dfdbde03673a7c4f85919911a37f7b46db635dd350128d7dfa94549e

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Relation, '.new' do
  subject { object.new(header, body) }

  let(:header) { Relation::Header.coerce([[:id, Integer]]) }
  let(:object) { described_class                           }
  let(:body)   { [[1]]                                     }

  context 'with no body' do
    subject { object.new(header) }

    it { should be_instance_of(Relation::Materialized) }

    it { should be_empty }
  end

  context 'with a body responding to #size' do
    it { should be_instance_of(Relation::Materialized) }

    it { should == body.dup }

    it 'does not freeze the body' do
      body.should_not be_frozen
      expect { subject }.to_not change(body, :frozen?)
    end
  end

  context 'with a body that returns nil for #size' do
    before do
      body.should_receive(:size).and_return(nil)
    end

    it { should be_instance_of(object) }

    it { should == body.dup }

    it 'does not freeze the body' do
      body.should_not be_frozen
      expect { subject }.to_not change(body, :frozen?)
    end
  end

  context 'with a body that returns Float::INFINITY for #size' do
    before do
      body.should_receive(:size).and_return(Float::INFINITY)
    end

    it { should be_instance_of(object) }

    it { should == body.dup }

    it 'does not freeze the body' do
      body.should_not be_frozen
      expect { subject }.to_not change(body, :frozen?)
    end
  end

  context 'with a body that does not respond to #size' do
    before do
      class << body
        undef_method(:size)
      end
    end

    it { should be_instance_of(object) }

    it { should == body.dup }

    it 'does not freeze the body' do
      body.should_not be_frozen
      expect { subject }.to_not change(body, :frozen?)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
axiom-0.1.1 spec/unit/axiom/relation/class_methods/new_spec.rb