pact 1.0.12 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 1.0.13 (10 October 2013)
2
+
3
+ * Fixed bug deserialising Pact::SomethingLike [Beth Skurrie]
4
+
1
5
  ### 1.0.12 (9 October 2013)
2
6
 
3
7
  * Changing default pactfile_write_mode to :overwrite, and adding :smart option to dynamically determine whether rake is running. [Beth Skurrie]
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pact (1.0.12)
4
+ pact (1.0.13)
5
5
  awesome_print (~> 1.1.0)
6
6
  find_a_port (~> 1.0.1)
7
7
  json
@@ -1,34 +1,56 @@
1
- require 'delegate'
2
-
3
1
  module Pact
4
2
 
5
- class DslDelegator < SimpleDelegator
6
- def instance_eval_with_previous_context_available(*args, &b)
3
+ class DslDelegator
4
+
5
+ def initialize delegation_target
6
+ @delegation_target = delegation_target
7
+ end
8
+
9
+ def instance_eval_with_previous_context_available(*args, &block)
10
+ with_previous_context_available(block.binding) do
11
+ bind_block_as_instance_method_on_self(&block).call(*args)
12
+ end
13
+ end
14
+
15
+ protected
16
+
17
+ def method_missing(method, *args, &block)
18
+ if delegation_target_responds_to? method
19
+ delegation_target.send(method, *args, &block)
20
+ else
21
+ previous_context.send(method, *args, &block)
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ attr_accessor :delegation_target, :previous_context
28
+
29
+ def bind_block_as_instance_method_on_self(&block)
30
+ create_instance_method_from_block(&block).bind(self)
31
+ end
32
+
33
+
34
+ def create_instance_method_from_block &block
7
35
  meth = self.class.class_eval do
8
- define_method :cloaker_, &b
9
- meth = instance_method :cloaker_
10
- remove_method :cloaker_
36
+ define_method :block_as_instance_method_, &block
37
+ meth = instance_method :block_as_instance_method_
38
+ remove_method :block_as_instance_method_
11
39
  meth
12
40
  end
13
- with_previous_context(b.binding) {meth.bind(self).call(*args)}
14
41
  end
15
42
 
16
- def with_previous_context(binding, &block)
43
+ def with_previous_context_available(binding, &block)
17
44
  @previous_context = binding.eval('self')
18
45
  result = block.call
19
46
  @previous_context = nil
20
47
  result
21
48
  end
22
49
 
23
- def method_missing(method, *args, &block)
24
- if __getobj__().respond_to? method
25
- super
26
- elsif @previous_context
27
- @previous_context.send(method, *args, &block)
28
- else
29
- super
30
- end
50
+ def delegation_target_responds_to?(method)
51
+ delegation_target.respond_to? method
31
52
  end
53
+
32
54
  end
33
55
 
34
56
 
@@ -37,17 +59,18 @@ module Pact
37
59
  # to access variables and methods defined in the calling scope.
38
60
  module DSL
39
61
  def build(*args, &block)
40
- base = self.new(*args)
41
- delegator_klass = self.const_get('DSL_DELEGATOR')
42
- delegator = delegator_klass.new(base)
43
- delegator.instance_eval_with_previous_context_available(&block)
44
- base.finalize
45
- base
62
+ new_instance_of_delegation_target_class = self.new(*args)
63
+ dsl_delegator_class = self.const_get('DSL_DELEGATOR_CLASS')
64
+ dsl_delegator = dsl_delegator_class.new(new_instance_of_delegation_target_class)
65
+ dsl_delegator.instance_eval_with_previous_context_available(&block)
66
+ new_instance_of_delegation_target_class.finalize
67
+ new_instance_of_delegation_target_class
46
68
  end
47
69
 
48
70
  def dsl(&block)
49
- delegator_klass = Class.new(DslDelegator, &block)
50
- self.const_set('DSL_DELEGATOR', delegator_klass)
71
+ dsl_delegator_class = Class.new(DslDelegator, &block)
72
+ self.const_set('DSL_DELEGATOR_CLASS', dsl_delegator_class)
51
73
  end
74
+
52
75
  end
53
76
  end
@@ -25,7 +25,15 @@ module Pact
25
25
  end
26
26
 
27
27
  def self.json_create hash
28
- new(symbolize_keys(hash))
28
+ new(symbolize_keys(hash)[:contents])
29
+ end
30
+
31
+ def eq other
32
+ self == other
33
+ end
34
+
35
+ def == other
36
+ other.is_a?(SomethingLike) && other.contents == self.contents
29
37
  end
30
38
 
31
39
  def generate
data/lib/pact/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pact
2
- VERSION = "1.0.12"
2
+ VERSION = "1.0.13"
3
3
  end
@@ -1,12 +1,13 @@
1
1
  require 'spec_helper'
2
2
  require 'pact/shared/dsl'
3
+ require 'support/dsl_spec_support'
3
4
 
4
5
  module Pact
5
6
  describe DSL do
6
7
 
7
8
  class TestDSL
8
9
  extend DSL
9
- attr_accessor :thing, :blah, :finally
10
+ attr_accessor :thing, :blah, :global, :the_block, :another_block, :finalized
10
11
 
11
12
  dsl do
12
13
  def with_thing thing
@@ -15,29 +16,70 @@ module Pact
15
16
  def with_blah blah
16
17
  self.blah = blah
17
18
  end
19
+ def with_global global
20
+ self.global = global
21
+ end
22
+
23
+ def with_block &the_block
24
+ self.the_block = the_block
25
+ end
26
+
27
+ def with_another_block &the_block
28
+ self.another_block = the_block
29
+ end
30
+
18
31
  end
19
32
 
20
33
  def finalize
21
- @finally = 'yay'
34
+ @finalized = true
22
35
  end
23
36
  end
24
37
 
25
38
  describe "build" do
26
- it "should support calling other variables and methods in scope" do
27
- def my_method
39
+ before do
40
+ def my_local_method
28
41
  'LA LA LA'
29
42
  end
30
43
 
31
44
  my_local_var = 123
32
45
 
33
- test = TestDSL.build do
34
- with_thing my_method
46
+ local_app = "I'm a local app"
47
+
48
+ @test = TestDSL.build do
49
+ with_thing my_local_method
35
50
  with_blah my_local_var
51
+ with_global global_method
52
+ with_block do
53
+ global_app
54
+ end
55
+ with_another_block do
56
+ local_app
57
+ end
36
58
  end
59
+ end
60
+
61
+ it "supports using a local variable" do
62
+ expect(@test.blah).to eq 123
63
+ end
64
+
65
+ it "supports using a local method" do
66
+ expect(@test.thing).to eq 'LA LA LA'
67
+ end
68
+
69
+ it "supports using global methods from other files" do
70
+ expect(@test.global).to eq "I'm global"
71
+ end
72
+
73
+ it "supports using a local method to provide the app" do
74
+ expect(@test.another_block.call).to eq("I'm a local app")
75
+ end
76
+
77
+ it "should support using a global method to provide the app but it doesn't" do
78
+ expect(@test.the_block.call).to eq("I'm a global app")
79
+ end
37
80
 
38
- expect(test.thing).to eq my_method
39
- expect(test.blah).to eq my_local_var
40
- expect(test.finally).to eq 'yay'
81
+ it "calls finalize" do
82
+ expect(@test.finalized).to be_true
41
83
  end
42
84
  end
43
85
  end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ module Pact
4
+ describe SomethingLike do
5
+ describe 'json_create' do
6
+ let(:json) do
7
+ '
8
+ {
9
+ "json_class": "Pact::SomethingLike",
10
+ "contents" : { "thing" : "blah" }
11
+ }
12
+ '
13
+ end
14
+ subject { SomethingLike.json_create(JSON.parse(json)) }
15
+ it "creates a SomethingLike object from json" do
16
+ expect(subject).to eq(SomethingLike.new({"thing" => "blah"}))
17
+ end
18
+ end
19
+ end
20
+
21
+ end
@@ -0,0 +1,7 @@
1
+ def global_method
2
+ "I'm global"
3
+ end
4
+
5
+ def global_app
6
+ "I'm a global app"
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.12
4
+ version: 1.0.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2013-10-10 00:00:00.000000000 Z
16
+ date: 2013-10-21 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: randexp
@@ -385,12 +385,14 @@ files:
385
385
  - spec/lib/pact/provider/test_methods_spec.rb
386
386
  - spec/lib/pact/reification_spec.rb
387
387
  - spec/lib/pact/shared/dsl_spec.rb
388
+ - spec/lib/pact/something_like_spec.rb
388
389
  - spec/lib/pact/term_spec.rb
389
390
  - spec/lib/pact/verification_task_spec.rb
390
391
  - spec/spec_helper.rb
391
392
  - spec/support/a_consumer-a_producer.json
392
393
  - spec/support/a_consumer-a_provider.json
393
394
  - spec/support/consumer_contract_template.json
395
+ - spec/support/dsl_spec_support.rb
394
396
  - spec/support/factories.rb
395
397
  - spec/support/pact_helper.rb
396
398
  - spec/support/shared_examples_for_request.rb
@@ -410,12 +412,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
410
412
  - - ! '>='
411
413
  - !ruby/object:Gem::Version
412
414
  version: '0'
415
+ segments:
416
+ - 0
417
+ hash: -1516639792059640389
413
418
  required_rubygems_version: !ruby/object:Gem::Requirement
414
419
  none: false
415
420
  requirements:
416
421
  - - ! '>='
417
422
  - !ruby/object:Gem::Version
418
423
  version: '0'
424
+ segments:
425
+ - 0
426
+ hash: -1516639792059640389
419
427
  requirements: []
420
428
  rubyforge_project:
421
429
  rubygems_version: 1.8.25
@@ -453,12 +461,14 @@ test_files:
453
461
  - spec/lib/pact/provider/test_methods_spec.rb
454
462
  - spec/lib/pact/reification_spec.rb
455
463
  - spec/lib/pact/shared/dsl_spec.rb
464
+ - spec/lib/pact/something_like_spec.rb
456
465
  - spec/lib/pact/term_spec.rb
457
466
  - spec/lib/pact/verification_task_spec.rb
458
467
  - spec/spec_helper.rb
459
468
  - spec/support/a_consumer-a_producer.json
460
469
  - spec/support/a_consumer-a_provider.json
461
470
  - spec/support/consumer_contract_template.json
471
+ - spec/support/dsl_spec_support.rb
462
472
  - spec/support/factories.rb
463
473
  - spec/support/pact_helper.rb
464
474
  - spec/support/shared_examples_for_request.rb