Sha256: cde26202b212da5714a25e3012fd689cddc8cd510e52814cd483d92ba8408f12

Contents?: true

Size: 1.18 KB

Versions: 13

Compression:

Stored size: 1.18 KB

Contents

require_relative 'shared/a_predicate_ast_node'
class Predicate
  describe Factory, 'from_hash' do

    subject{ Factory.from_hash(h) }

    context "when the hash is empty" do
      let(:h){ {} }

      it{ should eq(Factory.tautology) }
    end

    context "when the hash is a singelton" do
      let(:h){ {:x => 12} }

      it_should_behave_like "a predicate AST node"
      it{ should be_a(Eq) }
      it{ should eq([:eq, [:identifier, :x], [:literal, 12]]) }
    end

    context "when the hash is not a singleton" do
      let(:h){ {:x => 12, :y => :z} }
      let(:expected){
        [:and,
          [:eq, [:identifier, :x], [:literal, 12]],
          [:eq, [:identifier, :y], [:identifier, :z]]]
      }

      it_should_behave_like "a predicate AST node"
      it{ should be_a(And) }
      it{ should eq(expected) }
    end

    context "when the hash has array values" do
      let(:h){ {:x => [12], :y => :z} }
      let(:expected){
        [:and,
          [:in, [:identifier, :x], [:literal, [12]]],
          [:eq, [:identifier, :y], [:identifier, :z]]]
      }

      it_should_behave_like "a predicate AST node"
      it{ should be_a(And) }
      it{ should eq(expected) }
    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
predicate-2.8.0 spec/factory/test_from_hash.rb
predicate-2.7.1 spec/factory/test_from_hash.rb
predicate-2.7.0 spec/factory/test_from_hash.rb
predicate-2.6.0 spec/factory/test_from_hash.rb
predicate-2.5.0 spec/factory/test_from_hash.rb
predicate-2.4.0 spec/factory/test_from_hash.rb
predicate-2.3.3 spec/factory/test_from_hash.rb
predicate-2.3.2 spec/factory/test_from_hash.rb
predicate-2.3.1 spec/factory/test_from_hash.rb
predicate-2.3.0 spec/factory/test_from_hash.rb
predicate-2.2.1 spec/factory/test_from_hash.rb
predicate-2.2.0 spec/factory/test_from_hash.rb
predicate-2.1.0 spec/factory/test_from_hash.rb