spec/unit/axiom/algebra/restriction/methods/restrict_spec.rb in axiom-0.1.0 vs spec/unit/axiom/algebra/restriction/methods/restrict_spec.rb in axiom-0.1.1

- old
+ new

@@ -1,25 +1,25 @@ # encoding: utf-8 require 'spec_helper' describe Algebra::Restriction::Methods, '#restrict' do - let(:object) { described_class.new(header, body) } - let(:header) { [ [ :id, Integer ], [ :name, String ] ] } - let(:body) { LazyEnumerable.new([ [ 1, 'Dan Kubb' ], [ 2, 'Alex Kubb' ] ]) } - let(:described_class) { Relation } - let(:tautology) { Function::Proposition::Tautology.instance } + let(:object) { described_class.new(header, body) } + let(:header) { [[:id, Integer], [:name, String]] } + let(:body) { LazyEnumerable.new([[1, 'Dan Kubb'], [2, 'Alex Kubb']]) } + let(:described_class) { Relation } + let(:tautology) { Function::Proposition::Tautology.instance } context 'with a predicate' do subject { object.restrict(predicate) } let(:predicate) { object[:id].eq(1) } it { should be_instance_of(Algebra::Restriction) } it 'sets the predicate' do - subject.predicate.should equal(predicate) + subject.predicate.should be(predicate) end it 'behaves the same as Enumerable#select' do should == object.select { |tuple| tuple[:id] == 1 } end @@ -42,37 +42,34 @@ end context 'with a Hash' do subject { object.restrict(predicate) } - let(:predicate) { { :id => 1, :name => 'Dan Kubb' } } + let(:predicate) { { id: 1, name: 'Dan Kubb' } } it { should be_instance_of(Algebra::Restriction) } - # Hash order is not guaranteed except under 1.9+ - if RUBY_VERSION >= '1.9' - it 'sets the predicate' do - subject.predicate.should eql(tautology.and(object[:id].eq(1).and(object[:name].eq('Dan Kubb')))) - end + it 'sets the predicate' do + subject.predicate.should eql(tautology.and(object[:id].eq(1).and(object[:name].eq('Dan Kubb')))) end it 'behaves the same as Enumerable#select' do - should == object.select { |tuple| tuple[:id] == 1 and tuple[:name] == 'Dan Kubb' } + should == object.select { |tuple| tuple[:id] == 1 && tuple[:name] == 'Dan Kubb' } end end context 'with an Array' do subject { object.restrict(predicate) } - let(:predicate) { [ [ :id, 1 ], [ :name, 'Dan Kubb' ] ] } + let(:predicate) { [[:id, 1], [:name, 'Dan Kubb']] } it { should be_instance_of(Algebra::Restriction) } it 'sets the predicate' do subject.predicate.should eql(tautology.and(object[:id].eq(1).and(object[:name].eq('Dan Kubb')))) end it 'behaves the same as Enumerable#select' do - should == object.select { |tuple| tuple[:id] == 1 and tuple[:name] == 'Dan Kubb' } + should == object.select { |tuple| tuple[:id] == 1 && tuple[:name] == 'Dan Kubb' } end end end