Sha256: 3197f8d5c5f6fa2ae0241e7fa430406ea28e0f2226ae1f84249548b83876e4dd

Contents?: true

Size: 1.89 KB

Versions: 30

Compression:

Stored size: 1.89 KB

Contents

require 'spec_helper'
require 'pact/shared/dsl'
require 'support/dsl_spec_support'

module Pact
  describe DSL do

    class TestDSL
      extend DSL
      attr_accessor :thing, :blah, :global, :the_block, :another_block, :finalized

      dsl do
        def with_thing thing
          self.thing = thing
        end
        def with_blah blah
          self.blah = blah
        end
        def with_global global
          self.global = global
        end

        def with_block &the_block
          self.the_block = the_block
        end

        def with_another_block &the_block
          self.another_block = the_block
        end

      end

      def finalize
        @finalized = true
      end
    end

    describe "build" do
       before do
          def my_local_method
             'LA LA LA'
          end

          my_local_var = 123

          local_app = "I'm a local app"

          @test = TestDSL.build do
            with_thing my_local_method
            with_blah my_local_var
            with_global global_method
            with_block do
              global_app
            end
            with_another_block do
              local_app
            end
          end
       end

       it "supports using a local variable" do
          expect(@test.blah).to eq 123
       end

       it "supports using a local method" do
          expect(@test.thing).to eq 'LA LA LA'
       end

       it "supports using global methods from other files" do
         expect(@test.global).to eq "I'm global"
       end

       it "supports using a local method to provide the app" do
         expect(@test.another_block.call).to eq("I'm a local app")
       end

       it "should support using a global method to provide the app but it doesn't" do
         expect(@test.the_block.call).to eq("I'm a global app")
       end

       it "calls finalize" do
        expect(@test.finalized).to be_true
       end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
pact-1.1.0 spec/lib/pact/shared/dsl_spec.rb
pact-1.1.0.rc5 spec/lib/pact/shared/dsl_spec.rb
pact-1.1.0.rc4 spec/lib/pact/shared/dsl_spec.rb
pact-1.1.0.rc3 spec/lib/pact/shared/dsl_spec.rb
pact-1.0.39 spec/lib/pact/shared/dsl_spec.rb
pact-1.1.0.rc2 spec/lib/pact/shared/dsl_spec.rb
pact-1.0.38 spec/lib/pact/shared/dsl_spec.rb
pact-1.1.0.rc1 spec/lib/pact/shared/dsl_spec.rb
pact-1.0.37 spec/lib/pact/shared/dsl_spec.rb
pact-1.0.36 spec/lib/pact/shared/dsl_spec.rb
pact-1.0.35 spec/lib/pact/shared/dsl_spec.rb
pact-1.0.34 spec/lib/pact/shared/dsl_spec.rb
pact-1.0.33 spec/lib/pact/shared/dsl_spec.rb
pact-1.0.32 spec/lib/pact/shared/dsl_spec.rb
pact-1.0.31 spec/lib/pact/shared/dsl_spec.rb
pact-1.0.30 spec/lib/pact/shared/dsl_spec.rb
pact-1.0.29 spec/lib/pact/shared/dsl_spec.rb
pact-1.0.28 spec/lib/pact/shared/dsl_spec.rb
pact-1.0.27 spec/lib/pact/shared/dsl_spec.rb
pact-1.0.26 spec/lib/pact/shared/dsl_spec.rb