Sha256: 8903bd983169be39e8058997fc6403f795fe70a1f6d7854fbd3818b5f98dc508

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 KB

Contents

#
# ActiveFacts tests: Parse all NORMA files and check the generated CQL.
# Copyright (c) 2008 Clifford Heath. Read the LICENSE file.
#
require 'rubygems'
require 'stringio'
require 'activefacts/vocabulary'
require 'activefacts/support'
require 'activefacts/input/orm'
require 'activefacts/generate/cql'

include ActiveFacts

describe "Norma Loader" do
  ORM_CQL_FAILURES = %w{
    OddIdentifier
    ServiceDirector
  }
  # Generate and return the CQL for the given vocabulary
  def cql(vocabulary)
    output = StringIO.new
    @dumper = ActiveFacts::Generate::CQL.new(vocabulary.constellation)
    @dumper.generate(output)
    output.rewind
    output.readlines
  end

  pattern = ENV["AFTESTS"] || "*"
  Dir["examples/norma/#{pattern}.orm"].each do |orm_file|
    expected_file = orm_file.sub(%r{/norma/(.*).orm\Z}, '/CQL/\1.cql')

    actual_file = orm_file.sub(%r{examples/norma/(.*).orm\Z}, 'spec/actual/\1.cql')

    it "should load #{orm_file} and dump CQL matching #{expected_file}" do
      pending if ORM_CQL_FAILURES.include? File.basename(orm_file, ".orm")
      vocabulary = ActiveFacts::Input::ORM.readfile(orm_file)

      cql = cql(vocabulary)
      # Save the actual file:
      File.open(actual_file, "w") { |f| f.write cql*"" }

      pending unless File.exists? expected_file
      cql.should == File.open(expected_file) {|f| f.readlines}
      File.delete(actual_file)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activefacts-0.7.3 spec/norma_cql_spec.rb