Skip to content

Commit

Permalink
Fix specs on ruby 2.0 with LazyEnumerable spec support lib
Browse files Browse the repository at this point in the history
  • Loading branch information
dkubb committed Dec 26, 2012
1 parent facdec0 commit 647b663
Show file tree
Hide file tree
Showing 131 changed files with 523 additions and 505 deletions.
10 changes: 5 additions & 5 deletions spec/integration/veritas/algebra/difference/optimize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
subject { object.optimize }

let(:header) { [ [ :id, Integer ] ] }
let(:left_body) { [ [ 1 ] ].each }
let(:right_body) { [ [ 2 ] ].each }
let(:left_body) { LazyEnumerable.new([ [ 1 ] ]) }
let(:right_body) { LazyEnumerable.new([ [ 2 ] ]) }
let(:original_left) { Relation.new(header, left_body) }
let(:original_right) { Relation.new(header, right_body) }
let(:object) { described_class.new(left, right) }
Expand Down Expand Up @@ -102,9 +102,9 @@

unless defined?(JRUBY_VERSION) && JRUBY_VERSION < '1.6'
context 'left and right are equivalent relations' do
let(:right_body) { left_body.dup }
let(:left) { original_left }
let(:right) { original_right }
let(:right_body) { LazyEnumerable.new([ [ 1 ] ]) }
let(:left) { original_left }
let(:right) { original_right }

it { should eql(Relation::Empty.new(header)) }

Expand Down
10 changes: 5 additions & 5 deletions spec/integration/veritas/algebra/intersection/optimize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
subject { object.optimize }

let(:header) { [ [ :id, Integer ] ] }
let(:left_body) { [ [ 1 ] ].each }
let(:right_body) { [ [ 2 ] ].each }
let(:left_body) { LazyEnumerable.new([ [ 1 ] ]) }
let(:right_body) { LazyEnumerable.new([ [ 2 ] ]) }
let(:original_left) { Relation.new(header, left_body) }
let(:original_right) { Relation.new(header, right_body) }
let(:object) { described_class.new(left, right) }
Expand Down Expand Up @@ -102,9 +102,9 @@

unless defined?(JRUBY_VERSION) && JRUBY_VERSION < '1.6'
context 'left and right are equivalent relations' do
let(:right_body) { left_body.dup }
let(:left) { original_left }
let(:right) { original_right }
let(:right_body) { LazyEnumerable.new([ [ 1 ] ]) }
let(:left) { original_left }
let(:right) { original_right }

it { should equal(left) }

Expand Down
4 changes: 2 additions & 2 deletions spec/integration/veritas/algebra/join/optimize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
describe Algebra::Join, '#optimize' do
subject { object.optimize }

let(:left_body) { [ [ 1 ], [ 2 ] ].each }
let(:right_body) { [ [ 2, 'Dan Kubb' ] ].each }
let(:left_body) { LazyEnumerable.new([ [ 1 ], [ 2 ] ]) }
let(:right_body) { LazyEnumerable.new([ [ 2, 'Dan Kubb' ] ]) }
let(:original_left) { Relation.new([ [ :id, Integer ] ], left_body) }
let(:original_right) { Relation.new([ [ :id, Integer ], [ :name, String ] ], right_body) }
let(:left) { original_left }
Expand Down
4 changes: 2 additions & 2 deletions spec/integration/veritas/algebra/product/optimize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
describe Algebra::Product, '#optimize' do
subject { object.optimize }

let(:left_body) { [ [ 1 ] ].each }
let(:right_body) { [ [ 'Dan Kubb' ] ].each }
let(:left_body) { LazyEnumerable.new([ [ 1 ] ]) }
let(:right_body) { LazyEnumerable.new([ [ 'Dan Kubb' ] ]) }
let(:left) { Relation.new([ [ :id, Integer ] ], left_body) }
let(:right) { Relation.new([ [ :name, String ] ], right_body) }
let(:object) { described_class.new(left, right) }
Expand Down
14 changes: 7 additions & 7 deletions spec/integration/veritas/algebra/projection/optimize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
subject { object.optimize }

let(:header) { [ [ :id, Integer ], [ :name, String ], [ :age, Integer ] ] }
let(:body) { [ [ 1, 'Dan Kubb', 35 ] ].each }
let(:body) { LazyEnumerable.new([ [ 1, 'Dan Kubb', 35 ] ]) }
let(:relation) { Relation.new(header, body) }
let(:operand) { relation }
let(:object) { described_class.new(operand, attributes) }
Expand Down Expand Up @@ -141,10 +141,10 @@
end

context 'containing a set operation' do
let(:left) { Relation.new([ [ :id, Integer ], [ :name, String ] ], [ [ 1, 'Dan Kubb' ] ].each) }
let(:right) { Relation.new([ [ :id, Integer ], [ :name, String ] ], [ [ 2, 'Dan Kubb' ] ].each) }
let(:operand) { left.union(right) }
let(:attributes) { [ :name ] }
let(:left) { Relation.new([ [ :id, Integer ], [ :name, String ] ], LazyEnumerable.new([ [ 1, 'Dan Kubb' ] ])) }
let(:right) { Relation.new([ [ :id, Integer ], [ :name, String ] ], LazyEnumerable.new([ [ 2, 'Dan Kubb' ] ])) }
let(:operand) { left.union(right) }
let(:attributes) { [ :name ] }

it 'pushes the object to each relation' do
should eql(Algebra::Union.new(
Expand All @@ -166,8 +166,8 @@
end

context 'containing a set operation containing a projection of relations' do
let(:left_body) { [ [ 1, 'Dan Kubb', 35 ] ].each }
let(:right_body) { [ [ 2, 'Dan Kubb', 35 ] ].each }
let(:left_body) { LazyEnumerable.new([ [ 1, 'Dan Kubb', 35 ] ]) }
let(:right_body) { LazyEnumerable.new([ [ 2, 'Dan Kubb', 35 ] ]) }
let(:left) { Relation.new(header, left_body) }
let(:right) { Relation.new(header, right_body) }
let(:operand) { left.project([ :id, :name ]).union(right.project([ :id, :name ])) }
Expand Down
16 changes: 8 additions & 8 deletions spec/integration/veritas/algebra/rename/optimize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
describe Algebra::Rename, '#optimize' do
subject { object.optimize }

let(:body) { [ [ 1, 'Dan Kubb' ] ].each }
let(:body) { LazyEnumerable.new([ [ 1, 'Dan Kubb' ] ]) }
let(:relation) { Relation.new([ [ :id, Integer ], [ :name, String ] ], body) }
let(:operand) { relation }
let(:aliases) { { :id => :other_id } }
Expand Down Expand Up @@ -224,9 +224,9 @@
end

context 'containing a set operation' do
let(:left) { Relation.new([ [ :id, Integer ], [ :name, String ] ], [ [ 1, 'Dan Kubb' ] ].each) }
let(:right) { Relation.new([ [ :id, Integer ], [ :name, String ] ], [ [ 2, 'Dan Kubb' ] ].each) }
let(:operand) { left.union(right) }
let(:left) { Relation.new([ [ :id, Integer ], [ :name, String ] ], LazyEnumerable.new([ [ 1, 'Dan Kubb' ] ])) }
let(:right) { Relation.new([ [ :id, Integer ], [ :name, String ] ], LazyEnumerable.new([ [ 2, 'Dan Kubb' ] ])) }
let(:operand) { left.union(right) }

it 'pushes the object to each relation' do
should eql(left.rename(aliases).union(right.rename(aliases)))
Expand All @@ -245,10 +245,10 @@
end

context 'containing a set operation, containing a object that cancels out' do
let(:left) { Relation.new([ [ :id, Integer ], [ :name, String ] ], [ [ 1, 'Dan Kubb' ] ].each) }
let(:right) { Relation.new([ [ :id, Integer ], [ :name, String ] ], [ [ 2, 'Dan Kubb' ] ].each) }
let(:operand) { left.rename(:id => :other_id).union(right.rename(:id => :other_id)) }
let(:aliases) { { :other_id => :id } }
let(:left) { Relation.new([ [ :id, Integer ], [ :name, String ] ], LazyEnumerable.new([ [ 1, 'Dan Kubb' ] ])) }
let(:right) { Relation.new([ [ :id, Integer ], [ :name, String ] ], LazyEnumerable.new([ [ 2, 'Dan Kubb' ] ])) }
let(:operand) { left.rename(:id => :other_id).union(right.rename(:id => :other_id)) }
let(:aliases) { { :other_id => :id } }

it 'pushes the object to each relation, then cancel it out' do
should eql(left.union(right))
Expand Down
10 changes: 5 additions & 5 deletions spec/integration/veritas/algebra/restriction/optimize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
describe Algebra::Restriction, '#optimize' do
subject { object.optimize }

let(:body) { [ [ 1 ] ].each }
let(:body) { LazyEnumerable.new([ [ 1 ] ]) }
let(:relation) { Relation.new([ [ :id, Integer ] ], body) }
let(:operand) { relation }
let(:object) { described_class.new(operand, predicate) }
Expand Down Expand Up @@ -162,10 +162,10 @@
end

context 'with a set operation' do
let(:left) { Relation.new([ [ :id, Integer ] ], [ [ 1 ] ].each) }
let(:right) { Relation.new([ [ :id, Integer ] ], [ [ 2 ] ].each) }
let(:operand) { left.union(right) }
let(:predicate) { operand[:id].gte(1) }
let(:left) { Relation.new([ [ :id, Integer ] ], LazyEnumerable.new([ [ 1 ] ])) }
let(:right) { Relation.new([ [ :id, Integer ] ], LazyEnumerable.new([ [ 2 ] ])) }
let(:operand) { left.union(right) }
let(:predicate) { operand[:id].gte(1) }

it 'pushes the object to each relation' do
should eql(left.restrict { |r| r.id.gte(1) }.union(right.restrict { |r| r.id.gte(1) }))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
subject { object.optimize }

let(:header) { [ [ :id, Integer ], [ :name, String ], [ :age, Integer ] ] }
let(:body) { [ [ 1, 'Dan Kubb', 35 ], [ 2, 'Jane Doe', 24 ] ].each }
let(:body) { LazyEnumerable.new([ [ 1, 'Dan Kubb', 35 ], [ 2, 'Jane Doe', 24 ] ]) }
let(:relation) { Relation.new(header, body) }
let(:operand) { relation }
let(:summarize_per) { relation.project([ :id ]) }
Expand Down
12 changes: 6 additions & 6 deletions spec/integration/veritas/algebra/union/optimize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
subject { object.optimize }

let(:header) { [ [ :id, Integer ] ] }
let(:left_body) { [ [ 1 ] ].each }
let(:right_body) { [ [ 2 ] ].each }
let(:left_body) { LazyEnumerable.new([ [ 1 ] ]) }
let(:right_body) { LazyEnumerable.new([ [ 2 ] ]) }
let(:original_left) { Relation.new(header, left_body) }
let(:original_right) { Relation.new(header, right_body) }
let(:object) { described_class.new(left, right) }
Expand Down Expand Up @@ -111,10 +111,10 @@
end

context 'left and right are equivalent relations' do
let(:left_body) { [ [ 1 ] ].each }
let(:right_body) { [ [ 1 ] ].each }
let(:left) { original_left }
let(:right) { original_right }
let(:left_body) { LazyEnumerable.new([ [ 1 ] ]) }
let(:right_body) { LazyEnumerable.new([ [ 1 ] ]) }
let(:left) { original_left }
let(:right) { original_right }

it { should equal(left) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
describe Relation::Operation::Limit, '#optimize' do
subject { object.optimize }

let(:body) { [ [ 1 ], [ 2 ], [ 3 ] ].each }
let(:relation) { Relation.new([ [ :id, Integer ] ], body) }
let(:directions) { [ relation[:id] ] }
let(:order) { relation.sort_by { directions } }
let(:operand) { order }
let(:limit) { 1 }
let(:object) { described_class.new(operand, limit) }
let(:body) { LazyEnumerable.new([ [ 1 ], [ 2 ], [ 3 ] ]) }
let(:relation) { Relation.new([ [ :id, Integer ] ], body) }
let(:directions) { [ relation[:id] ] }
let(:order) { relation.sort_by { directions } }
let(:operand) { order }
let(:limit) { 1 }
let(:object) { described_class.new(operand, limit) }

context 'when the limit is 0' do
let(:limit) { 0 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
describe Relation::Operation::Offset, '#optimize' do
subject { object.optimize }

let(:body) { [ [ 1 ], [ 2 ], [ 3 ] ].each }
let(:relation) { Relation.new([ [ :id, Integer ] ], body) }
let(:directions) { [ relation[:id] ] }
let(:order) { relation.sort_by { directions } }
let(:operand) { order }
let(:offset) { 1 }
let(:object) { described_class.new(operand, offset) }
let(:body) { LazyEnumerable.new([ [ 1 ], [ 2 ], [ 3 ] ]) }
let(:relation) { Relation.new([ [ :id, Integer ] ], body) }
let(:directions) { [ relation[:id] ] }
let(:order) { relation.sort_by { directions } }
let(:operand) { order }
let(:offset) { 1 }
let(:object) { described_class.new(operand, offset) }

context 'with an object of 0' do
let(:offset) { 0 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
describe Relation::Operation::Order, '#optimize' do
subject { object.optimize }

let(:body) { [ [ 1 ], [ 2 ], [ 3 ] ].each }
let(:relation) { Relation.new([ [ :id, Integer ] ], body) }
let(:operand) { relation }
let(:directions) { [ relation[:id] ] }
let(:object) { described_class.new(operand, directions) }
let(:body) { LazyEnumerable.new([ [ 1 ], [ 2 ], [ 3 ] ]) }
let(:relation) { Relation.new([ [ :id, Integer ] ], body) }
let(:operand) { relation }
let(:directions) { [ relation[:id] ] }
let(:object) { described_class.new(operand, directions) }

context 'containing a relation' do
it { should equal(object) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
describe Relation::Operation::Reverse, '#optimize' do
subject { object.optimize }

let(:body) { [ [ 1 ], [ 2 ], [ 3 ] ].each }
let(:relation) { Relation.new([ [ :id, Integer ] ], body) }
let(:order) { relation.sort_by { |r| r.id } }
let(:operand) { order }
let(:object) { described_class.new(operand) }
let(:body) { LazyEnumerable.new([ [ 1 ], [ 2 ], [ 3 ] ]) }
let(:relation) { Relation.new([ [ :id, Integer ] ], body) }
let(:order) { relation.sort_by { |r| r.id } }
let(:operand) { order }
let(:object) { described_class.new(operand) }

context 'with a object operation' do
let(:limit) { order.take(2) }
Expand Down
6 changes: 3 additions & 3 deletions spec/integration/veritas/relation/optimize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
describe Relation, '#optimize' do
subject { object.optimize(*args) }

let(:object) { described_class.new([ [ :id, Integer ] ], [ [ 1 ] ].each) }
let(:object) { described_class.new([ [ :id, Integer ] ], LazyEnumerable.new([ [ 1 ] ])) }

before do
object.should be_instance_of(described_class)
Expand All @@ -25,8 +25,8 @@
end

context 'with an optimizer' do
let(:optimized) { described_class.new([ [ :id, Integer ] ], [ [ 1 ] ].each) }
let(:args) { [ lambda { |relation| optimized } ] }
let(:optimized) { described_class.new([ [ :id, Integer ] ], LazyEnumerable.new([ [ 1 ] ])) }
let(:args) { [ lambda { |relation| optimized } ] }

it { should equal(optimized) }

Expand Down
18 changes: 18 additions & 0 deletions spec/support/lazy_enumerable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# encoding: utf-8

class LazyEnumerable < BasicObject
def initialize(enumerable = [])
@enumerable = enumerable
end

def size
nil
end

private

def method_missing(*args, &block)
@enumerable.__send__(*args, &block)
end

end
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
describe Optimizer::Algebra::Difference::EmptyLeft, '#optimize' do
subject { object.optimize }

let(:header) { Relation::Header.coerce([ [ :id, Integer ] ]) }
let(:left) { Relation::Empty.new(header) }
let(:right) { Relation.new(header, [ [ 1 ] ].each) }
let(:relation) { left.difference(right) }
let(:object) { described_class.new(relation) }
let(:header) { Relation::Header.coerce([ [ :id, Integer ] ]) }
let(:left) { Relation::Empty.new(header) }
let(:right) { Relation.new(header, LazyEnumerable.new([ [ 1 ] ])) }
let(:relation) { left.difference(right) }
let(:object) { described_class.new(relation) }

before do
object.should be_optimizable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
describe Optimizer::Algebra::Difference::EmptyRight, '#optimize' do
subject { object.optimize }

let(:header) { Relation::Header.coerce([ [ :id, Integer ] ]) }
let(:left) { Relation.new(header, [ [ 1 ] ].each) }
let(:right) { Relation::Empty.new(header) }
let(:relation) { left.difference(right) }
let(:object) { described_class.new(relation) }
let(:header) { Relation::Header.coerce([ [ :id, Integer ] ]) }
let(:left) { Relation.new(header, LazyEnumerable.new([ [ 1 ] ])) }
let(:right) { Relation::Empty.new(header) }
let(:relation) { left.difference(right) }
let(:object) { described_class.new(relation) }

before do
object.should be_optimizable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
describe Optimizer::Algebra::Difference::EqualOperands, '#optimize' do
subject { object.optimize }

let(:header) { Relation::Header.coerce([ [ :id, Integer ] ]) }
let(:left) { Relation.new(header, [ [ 1 ] ].each) }
let(:right) { Relation.new(header, [ [ 1 ] ].each) }
let(:relation) { left.difference(right) }
let(:object) { described_class.new(relation) }
let(:header) { Relation::Header.coerce([ [ :id, Integer ] ]) }
let(:left) { Relation.new(header, LazyEnumerable.new([ [ 1 ] ])) }
let(:right) { Relation.new(header, LazyEnumerable.new([ [ 1 ] ])) }
let(:relation) { left.difference(right) }
let(:object) { described_class.new(relation) }

before do
object.should be_optimizable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
describe Optimizer::Algebra::Extension::OrderOperand, '#optimizable?' do
subject { object.optimizable? }

let(:base) { Relation.new([ [ :id, Integer ] ], [].each) }
let(:relation) { operand.extend {} }
let(:object) { described_class.new(relation) }
let(:base) { Relation.new([ [ :id, Integer ] ], LazyEnumerable.new) }
let(:relation) { operand.extend {} }
let(:object) { described_class.new(relation) }

context 'when operand is an order' do
let(:operand) { base.sort_by { |r| r.id } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
describe Optimizer::Algebra::Extension::OrderOperand, '#optimize' do
subject { object.optimize }

let(:base) { Relation.new([ [ :id, Integer ] ], [].each) }
let(:operand) { base.sort_by { |r| r.id } }
let(:relation) { operand.extend {} }
let(:object) { described_class.new(relation) }
let(:base) { Relation.new([ [ :id, Integer ] ], LazyEnumerable.new) }
let(:operand) { base.sort_by { |r| r.id } }
let(:relation) { operand.extend {} }
let(:object) { described_class.new(relation) }

before do
object.should be_optimizable
Expand Down
Loading

0 comments on commit 647b663

Please sign in to comment.