Sha256: 14fbcaf8a5ed3c3e3cd57bd33963e95652eef4124ba33b16fd16d47166848842

Contents?: true

Size: 1.57 KB

Versions: 4

Compression:

Stored size: 1.57 KB

Contents

#
# ActiveFacts tests: Parse all CQL files and check the generated Ruby.
# 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/ruby'

include ActiveFacts

class String
  def strip_comments()
    c_comment = %r{/\*((?!\*/).)*\*/}m
    gsub(c_comment, '').gsub(%r{\n\n+},"\n")
  end
end

describe "NORMA Loader with Ruby output" do
  # Generate and return the Ruby for the given vocabulary
  def ruby(vocabulary)
    output = StringIO.new
    @dumper = ActiveFacts::Generate::RUBY.new(vocabulary.constellation)
    @dumper.generate(output)
    output.rewind
    output.read
  end

  #Dir["examples/norma/Bl*.orm"].each do |orm_file|
  #Dir["examples/norma/Meta*.orm"].each do |orm_file|
  #Dir["examples/norma/[ACG]*.orm"].each do |orm_file|
  Dir["examples/norma/*.orm"].each do |orm_file|
    expected_file = orm_file.sub(%r{examples/norma/(.*).orm\Z}, 'examples/ruby/\1.rb')
    actual_file = orm_file.sub(%r{examples/norma/(.*).orm\Z}, 'spec/actual/\1.rb')

    it "should load #{orm_file} and dump Ruby matching #{expected_file}" do
      vocabulary = ActiveFacts::Input::ORM.readfile(orm_file)

      # Build and save the actual file:
      ruby_text = ruby(vocabulary)
      File.open(actual_file, "w") { |f| f.write ruby_text }

      pending unless File.exists? expected_file
      ruby_text.should == File.open(expected_file) {|f| f.read }
      File.delete(actual_file)  # It succeeded, we don't need the file.
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
activefacts-0.6.0 spec/norma_ruby_spec.rb
activefacts-0.7.0 spec/norma_ruby_spec.rb
activefacts-0.7.1 spec/norma_ruby_spec.rb
activefacts-0.7.2 spec/norma_ruby_spec.rb