Sha256: ac60a0b96f64d16a22eea6a2b5d18d42f2056e99174497fe82b769ebff18eb4e

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

require 'spec_helper'
class Predicate
  describe Predicate, ".coerce" do

    subject{ Predicate.coerce(arg) }

    describe "from Predicate" do
      let(:arg){ Predicate.new(Factory.tautology) }

      it{ should be(arg) }
    end

    describe "from true" do
      let(:arg){ true }

      specify{
        subject.expr.should be_a(Tautology)
      }
    end

    describe "from false" do
      let(:arg){ false }

      specify{
        subject.expr.should be_a(Contradiction)
      }
    end

    describe "from Symbol" do
      let(:arg){ :status }

      specify{
        subject.expr.should be_a(Identifier)
        subject.expr.name.should eq(arg)
      }
    end

    describe "from Proc" do
      let(:arg){ lambda{ status == 10 } }

      specify{
        subject.expr.should be_a(Native)
        subject.to_proc.should be(arg)
      }
    end

    describe "from String" do
      let(:arg){ "status == 10" }

      it 'raises an error' do
        lambda{
          subject
        }.should raise_error(ArgumentError)
      end
    end

    describe "from Hash (single)" do
      let(:arg){ {status: 10} }

      specify{
        subject.expr.should be_a(Eq)
        subject.expr.should eq([:eq, [:identifier, :status], [:literal, 10]])
      }
    end

    describe "from Hash (multiple)" do
      let(:arg){ {status: 10, name: "Jones"} }

      specify{
        subject.should eq(Predicate.eq(status: 10) & Predicate.eq(name: "Jones"))
      }
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
predicate-1.0.0 spec/predicate/test_coerce.rb