Sha256: b4f24615444ec5d3fa5cdefb9ab3795e059f5d87013d6397f7acdca2ca82ab22

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

require 'helper'

class Closed
end

class TestPeto < Test::Unit::TestCase
  context "Master instance" do
    setup do
      @peto = Peto::Master.new
    end

    context "loads contract yaml file" do
      setup do
        @peto.load("test/contracts/loading.yml")
      end
      context ".contract" do
        should "return loaded contract" do
          assert_equal({ "name" => "loading" }, @peto.contract)
        end
      end
    end

    context "parse procedures" do
      setup do
        @peto.load("test/contracts/generating.yml")
      end
      should "returns string by loaded contract" do
        assert_equal Hash, @peto.parse(:rb).class
        @peto.parse(:rb).each do |name, content|
          assert_equal String, name.class
          assert_equal String, content.class
        end
      end
    end
  end

  context "Generated ruby script" do
    setup do
      @peto = Peto::Master.new
      @peto.load("test/contracts/generating.yml")
      @generated = @peto.parse(:rb)
    end
    should "be readable as ruby" do
      @generated.each do |filepath, content|
        Closed.class_eval(content)
      end
      assert_equal({
        :procedure => "do_a",
        :args => {
          :a => 1,
          :b => "two",
          :c => {:foo=>"foo"},
        }
      }, Closed::Peto::Generating.do_a(1, "two", Closed::Peto::TypeB.new(:foo=>"foo")))
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
peto-0.2.7 test/test_peto.rb
peto-0.2.6 test/test_peto.rb