spec/lib/pact/shared/dsl_spec.rb in pact-1.0.12 vs spec/lib/pact/shared/dsl_spec.rb in pact-1.0.13
- old
+ new
@@ -1,44 +1,86 @@
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, :finally
+ 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
- @finally = 'yay'
+ @finalized = true
end
end
describe "build" do
- it "should support calling other variables and methods in scope" do
- def my_method
+ before do
+ def my_local_method
'LA LA LA'
end
my_local_var = 123
- test = TestDSL.build do
- with_thing my_method
+ 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
- expect(test.thing).to eq my_method
- expect(test.blah).to eq my_local_var
- expect(test.finally).to eq 'yay'
+ 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