Sha256: 065cf9ec81494b9e61f3874a2445dcce7bea94bb986bc1bf5e68bfd59c4c864f

Contents?: true

Size: 1.66 KB

Versions: 4

Compression:

Stored size: 1.66 KB

Contents

require "#{File.dirname(__FILE__)}/spec_helper"


describe 'an object that uses the DSL' do


  let(:nodule) { CQL::Dsl }
  let(:dsl_enabled_object) { Object.new.extend(nodule) }


  describe 'invalid query structure' do

    it "will complain if no 'from' clause is specified" do
      gs = CQL::Repository.new("#{CQL_FEATURE_FIXTURES_DIRECTORY}/scenario/simple")

      expect {
        gs.query do
          select
          features
        end
      }.to raise_error(ArgumentError, "A query must specify a 'from' clause")
    end

    it "will complain if no 'select' clause is specified" do
      gs = CQL::Repository.new("#{CQL_FEATURE_FIXTURES_DIRECTORY}/scenario/simple")

      expect {
        gs.query do
          from features
        end
      }.to raise_error(ArgumentError, "A query must specify a 'select' clause")
    end

  end


  describe 'clause ordering' do

    it 'handles intermixed clauses' do
      # Clause ordering doesn't matter as long as any given type of clause is ordered correctly with respect to its multiple uses

      gs = CQL::Repository.new("#{CQL_FEATURE_FIXTURES_DIRECTORY}/scenario/simple")

      results = gs.query do
        with { |scenario| scenario.name =~ /slurping/ }
        as thing1
        transform :self => lambda { |thing1| 1 }
        select :self
        as thing2
        with scenarios => lambda { |scenario| scenario.name =~ /3/ }
        from scenarios
        select :self
        transform :self => lambda { |thing2| 2 }
        select name
      end

      expect(results.first).to eq('thing1' => 1, 'thing2' => 2, 'name' => 'Testing the slurping 3')
    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cql-1.7.0 testing/rspec/spec/dsl_spec.rb
cql-1.6.0 testing/rspec/spec/dsl_spec.rb
cql-1.5.1 testing/rspec/spec/dsl_spec.rb
cql-1.5.0 testing/rspec/spec/dsl_spec.rb