Sha256: 175d3f324f45a0f2aade5bf5bcc4994433cc38cc1c99d60336e86747335879fc

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

# encoding: utf-8

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')


describe Piglet::Relation::Split do

  before do
    @relation = mock('source')
    @expr1 = mock('expr1')
    @expr2 = mock('expr2')
    @relation.stub!(:alias).and_return('rel')
    @expr1.stub!(:to_s).and_return('expr1')
    @expr2.stub!(:to_s).and_return('expr2')
    @interpreter = mock('Interpreter')
    @interpreter.stub(:next_relation_alias).and_return(3)
    @split = Piglet::Relation::Split.new(@relation, @interpreter, [@expr1, @expr2])
  end

  describe '#to_s' do
    it 'outputs all x IF y expressions' do
      @split.to_s.should match(/SPLIT rel INTO \w+ IF expr[12], \w+ IF expr[12]/)
    end
    
    it 'contains the names of all the shard relations' do
      @shards = @split.shards
      @split.to_s.should include("#{@shards[0].alias} IF expr1")
      @split.to_s.should include("#{@shards[1].alias} IF expr2")
    end
  end
  
  describe '#shards' do
    it 'returns the same number of shards as there are expressions' do
      @split.shards.size.should == 2
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
piglet-0.3.0 spec/piglet/relation/split_spec.rb