pact-support 0.5.4 → 0.5.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 65b471492f7129b35b4d6c22ea34734b4236a064
4
- data.tar.gz: 731b9b98c849c17d19fae3efd98eec69bc953a0d
3
+ metadata.gz: 8302de9af32aa569443e49a502132233ecc0fbc6
4
+ data.tar.gz: d03296b6197757a59b1a8c197b375fb17e3be7d7
5
5
  SHA512:
6
- metadata.gz: 1a12e8a8345b77b732d66b356ff84d3ccb459011d40dbea405783b0c8aded30757615db3259fa97c226e44e58ce4a5402df8529d02abbbf92cae647b575bbd58
7
- data.tar.gz: a92b1568e2e590d163967b103617483d7510ec4cab06c033aa79ec5694bb906cca02441ed71d68b877bf28aea76a7d9e0a9a627f7916f630dd249d1eb704b0af
6
+ metadata.gz: db57a82df74f57807f6514abad63b30374ebbb81d6aadac107059e9dbef23978d2e94ef2b6a5c30095d5b870a464aea05269bea1ffa96aa030305a2d595c546a
7
+ data.tar.gz: 9918d2bd33d4986bfcf67e41ed2a52d1d216bff694df1035f666cef2a933fbaaef37e8d5f82b9d34c3f80b5fab3a6c6434db6e06c15fc01a982bac5bf6f435da
@@ -1,8 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
3
  - 2.0.0
5
- - 2.1.1
6
- - jruby-19mode
7
- - jruby-1.7.11
8
- - jruby-1.7.12
4
+ - 2.1.8
5
+ - 2.2.4
6
+ - 2.3.0
7
+ - jruby-9.0.5.0
@@ -1,6 +1,25 @@
1
1
  Do this to generate your change history
2
2
 
3
- git log --pretty=format:' * %h - %s (%an, %ad)'
3
+ git log --pretty=format:' * %h - %s (%an, %ad)' vX.Y.Z..HEAD
4
+
5
+
6
+ ### 0.5.5 (4 November 2015)
7
+ * e9aaff0 - Merge pull request #21 from TakatoshiMaeda/reify_support_nested_something_like (Sergei Matheson, Fri Apr 29 09:54:00 2016 +1000)
8
+ * eb9aa26 - Supporting nested Pact::SomethingLike reification (Takatoshi Maeda, Thu Apr 28 02:04:58 2016 +0900)
9
+ * 832790d - Merge pull request #20 from taiki45/dsl-without-block (Sergei Matheson, Thu Mar 24 09:36:22 2016 +1100)
10
+ * 9e924c8 - Object supporting DSL can be built without block (Taiki Ono, Wed Mar 23 16:38:27 2016 +0900)
11
+ * 57aa993 - Merge pull request #18 from taiki45/escape-query-string-component (Sergei Matheson, Tue Mar 15 09:24:36 2016 +1100)
12
+ * 2b0e7b4 - Escape query string components (Taiki Ono, Mon Mar 14 15:22:29 2016 +0900)
13
+ * a383368 - Fix indent (Taiki Ono, Mon Mar 14 15:18:26 2016 +0900)
14
+ * fae9a14 - Merge pull request #17 from taiki45/upgrade-jruby (Ronald Holshausen, Mon Mar 14 09:56:16 2016 +1100)
15
+ * dc54092 - Support latest jruby and drop supporting jruby 1.7 (Taiki Ono, Sun Mar 13 20:27:17 2016 +0900)
16
+ * 22651e8 - Merge pull request #16 from taiki45/drop-supporting-ruby1.9 (Beth Skurrie, Sat Mar 12 14:04:41 2016 +1100)
17
+ * 3dbaa38 - Merge pull request #15 from taiki45/suppress-rspec-warnings (Sergei Matheson, Fri Mar 11 09:29:26 2016 +1100)
18
+ * 656c98a - Merge pull request #14 from taiki45/nested-query (Sergei Matheson, Fri Mar 11 09:19:58 2016 +1100)
19
+ * 85fbb09 - Drop supporting ruby1.9 (Taiki Ono, Thu Mar 10 23:01:54 2016 +0900)
20
+ * 966fa3a - `raise_error` should be with specific error (Taiki Ono, Thu Mar 10 22:50:13 2016 +0900)
21
+ * 2861742 - Cosmetic change (Taiki Ono, Thu Mar 10 22:11:51 2016 +0900)
22
+ * c491682 - `QueryHash` accepts nested hash query (Taiki Ono, Thu Mar 10 21:24:41 2016 +0900)
4
23
 
5
24
  ### 0.5.4 (4 November 2015)
6
25
 
@@ -3,7 +3,7 @@
3
3
  1. Increment the version in `lib/pact/support/version.rb`
4
4
  2. Update the `CHANGELOG.md` using:
5
5
 
6
- $ git log --pretty=format:' * %h - %s (%an, %ad)'
6
+ $ git log --pretty=format:' * %h - %s (%an, %ad)' vX.Y.Z..HEAD
7
7
 
8
8
  3. Add files to git
9
9
 
@@ -9,27 +9,23 @@ module Pact
9
9
  include Pact::Matchers
10
10
  include SymbolizeKeys
11
11
 
12
- def initialize query
12
+ def initialize(query)
13
13
  @hash = query.nil? ? query : convert_to_hash_of_arrays(query)
14
14
  end
15
15
 
16
- def convert_to_hash_of_arrays query
17
- symbolize_keys(query).each_with_object({}) {|(k,v), hash| hash[k] = [*v] }
18
- end
19
-
20
- def as_json opts = {}
16
+ def as_json(opts = {})
21
17
  @hash
22
18
  end
23
19
 
24
- def to_json opts = {}
20
+ def to_json(opts = {})
25
21
  as_json(opts).to_json(opts)
26
22
  end
27
23
 
28
- def eql? other
24
+ def eql?(other)
29
25
  self == other
30
26
  end
31
27
 
32
- def == other
28
+ def ==(other)
33
29
  QueryHash === other && other.query == query
34
30
  end
35
31
 
@@ -51,5 +47,18 @@ module Pact
51
47
  @hash && @hash.empty?
52
48
  end
53
49
 
50
+ private
51
+
52
+ def convert_to_hash_of_arrays(query)
53
+ query.each_with_object({}) {|(k, v), hash| insert(hash, k, v) }
54
+ end
55
+
56
+ def insert(hash, k, v)
57
+ if Hash === v
58
+ v.each {|k2, v2| insert(hash, :"#{k}[#{k2}]", v2) }
59
+ else
60
+ hash[k.to_sym] = [*v]
61
+ end
62
+ end
54
63
  end
55
64
  end
@@ -8,7 +8,7 @@ module Pact
8
8
  def self.from_term(term)
9
9
  case term
10
10
  when Pact::Term, Regexp, Pact::SomethingLike, Pact::ArrayLike
11
- term.generate
11
+ from_term(term.generate)
12
12
  when Hash
13
13
  term.inject({}) do |mem, (key,term)|
14
14
  mem[key] = from_term(term)
@@ -20,19 +20,23 @@ module Pact
20
20
  from_term(term.to_hash)
21
21
  when Pact::QueryString
22
22
  from_term(term.query)
23
- when Pact::QueryHash
23
+ when Pact::QueryHash
24
24
  term.query.map { |k, v|
25
25
  if v.nil?
26
26
  k
27
27
  elsif v.is_a?(Array) #For cases where there are multiple instance of the same parameter
28
- v.map { |x| "#{k}=#{from_term(x)}"}.join('&')
28
+ v.map { |x| "#{k}=#{escape(from_term(x))}"}.join('&')
29
29
  else
30
- "#{k}=#{from_term(v)}"
30
+ "#{k}=#{escape(from_term(v))}"
31
31
  end
32
32
  }.join('&')
33
33
  else
34
34
  term
35
35
  end
36
36
  end
37
+
38
+ def self.escape(str)
39
+ URI.encode_www_form_component(str)
40
+ end
37
41
  end
38
42
  end
@@ -62,7 +62,7 @@ module Pact
62
62
  new_instance_of_delegation_target_class = self.new(*args)
63
63
  dsl_delegator_class = self.const_get('DSL_DELEGATOR_CLASS')
64
64
  dsl_delegator = dsl_delegator_class.new(new_instance_of_delegation_target_class)
65
- dsl_delegator.instance_eval_with_previous_context_available(&block)
65
+ dsl_delegator.instance_eval_with_previous_context_available(&block) if block
66
66
  new_instance_of_delegation_target_class.finalize
67
67
  new_instance_of_delegation_target_class
68
68
  end
@@ -73,4 +73,4 @@ module Pact
73
73
  end
74
74
 
75
75
  end
76
- end
76
+ end
@@ -1,5 +1,5 @@
1
1
  module Pact
2
2
  module Support
3
- VERSION = "0.5.4"
3
+ VERSION = "0.5.5"
4
4
  end
5
5
  end
@@ -34,6 +34,45 @@ module Pact
34
34
  expect(subject.difference(other)).to_not be_empty
35
35
  end
36
36
  end
37
+
38
+ context "with nested query" do
39
+ let(:query) { { param: { a: { aa: '11', bb: '22' }, b: '2' } } }
40
+
41
+ context "when the other is same" do
42
+ let(:other) { QueryString.new('param[b]=2&param[a][aa]=11&param[a][bb]=22') }
43
+
44
+ it 'returns an empty diff' do
45
+ expect(subject.difference(other)).to be_empty
46
+ end
47
+ end
48
+
49
+ context "when the other has extra param" do
50
+ let(:other) { QueryString.new('param[b]=2&param[c]=1') }
51
+
52
+ it 'returns the diff' do
53
+ expect(subject.difference(other)).not_to be_empty
54
+ expect(subject.difference(other).keys).to contain_exactly(:"param[a][aa]", :"param[a][bb]", :"param[c]")
55
+ end
56
+ end
57
+
58
+ context "when the other has different value with value difference" do
59
+ let(:other) { QueryString.new('param[b]=2&param[a][aa]=00&param[a][bb]=22') }
60
+
61
+ it 'returns the diff' do
62
+ expect(subject.difference(other)).not_to be_empty
63
+ expect(subject.difference(other).keys).to contain_exactly(:"param[a][aa]")
64
+ end
65
+ end
66
+
67
+ context "when the other has different value without structural difference" do
68
+ let(:other) { QueryString.new('param[b]=2&param[a]=11') }
69
+
70
+ it 'returns the diff' do
71
+ expect(subject.difference(other)).not_to be_empty
72
+ expect(subject.difference(other).keys).to contain_exactly(:"param[a]", :"param[a][aa]", :"param[a][bb]")
73
+ end
74
+ end
75
+ end
37
76
  end
38
77
 
39
78
  describe "#as_json" do
@@ -331,6 +331,15 @@ module Pact
331
331
  end
332
332
  end
333
333
 
334
+ context 'when the queries are defined by nested hashes' do
335
+ let(:expected_query) { { params: 'hello', nested: { a: { aa: '11', bb: '22' }, b: '2' }, params3: 'small' } }
336
+ let(:actual_query) { 'params3=small&nested[a][aa]=11&nested[a][bb]=22&nested[b]=2&params=hello' }
337
+
338
+ it "does match" do
339
+ expect(subject.matches? actual_request).to be true
340
+ end
341
+ end
342
+
334
343
  context 'when the queries are defined by hashes, order does not matter but content does' do
335
344
  let(:expected_query) { { params: 'hello', params2: 'world', params3: 'small' } }
336
345
  let(:actual_query) { 'params3=big&params2=world&params=hello' }
@@ -358,6 +367,15 @@ module Pact
358
367
  end
359
368
  end
360
369
 
370
+ context 'when the queries are defined by nested hashes holding Pact Terms, order does not matter but content does' do
371
+ let(:expected_query) { { params: { a: 'hello', b: Term.new(generate: 'world', matcher: /w\w+/) } } }
372
+ let(:actual_query) { 'params[a]=hello&params[b]=wroom'}
373
+
374
+ it "does match" do
375
+ expect(subject.matches? actual_request).to be true
376
+ end
377
+ end
378
+
361
379
  context 'when the queries are defined by hashes holding Pact Terms and the regex does not match' do
362
380
  let(:expected_query) { { params: 'hello', params2: Term.new(generate: 'world', matcher: /w\w+/), params3: 'small' } }
363
381
  let(:actual_query) { 'params3=small&params=hello&params2=bonjour'}
@@ -367,6 +385,15 @@ module Pact
367
385
  end
368
386
  end
369
387
 
388
+ context 'when the queries are defined by nested hashes holding Pact Terms and the regex does not match' do
389
+ let(:expected_query) { { params: { a: 'hello', b: Term.new(generate: 'world', matcher: /w\w+/) } } }
390
+ let(:actual_query) { 'params[a]=hello&params[b]=bonjour'}
391
+
392
+ it "does match" do
393
+ expect(subject.matches? actual_request).to be false
394
+ end
395
+ end
396
+
370
397
  context 'when the query is a hash containing arrays, to denote multiple parameters with the same name' do
371
398
  let(:expected_query) {
372
399
  { simple_param: "hi",
@@ -456,4 +483,4 @@ module Pact
456
483
  end
457
484
  end
458
485
  end
459
- end
486
+ end
@@ -63,6 +63,27 @@ module Pact
63
63
 
64
64
  end
65
65
 
66
+ context "when nested SomethingLike" do
67
+
68
+ let(:request) {
69
+ Pact::SomethingLike.new(
70
+ {
71
+ a: 'String',
72
+ b: Pact::SomethingLike.new(
73
+ c: 'NestedString'
74
+ )
75
+ }
76
+ )
77
+ }
78
+
79
+ subject { Reification.from_term(request)}
80
+
81
+ it "returns the contents of the SomethingLike" do
82
+ expect(subject).to eq({a: 'String', b: { c: 'NestedString' }})
83
+ end
84
+
85
+ end
86
+
66
87
  context "when ArrayLike" do
67
88
 
68
89
  let(:request) { Pact::ArrayLike.new({a: 'String'}, {min: 3})}
@@ -98,6 +119,17 @@ module Pact
98
119
  end
99
120
  end
100
121
 
122
+ context "when Hash Query with UTF-8 string" do
123
+
124
+ subject { Reification.from_term(query)}
125
+
126
+ let(:query) { QueryHash.new( {param: 'ILove', extra: '寿司'})}
127
+
128
+ it "returns the hash with escaping UTF-8 string" do
129
+ expect(subject).to eq("param=ILove&extra=%E5%AF%BF%E5%8F%B8")
130
+ end
131
+ end
132
+
101
133
  context "when Hash Query with embeded terms" do
102
134
 
103
135
  subject { Reification.from_term(query)}
@@ -9,6 +9,10 @@ module Pact
9
9
  extend DSL
10
10
  attr_accessor :thing, :blah, :global, :the_block, :another_block, :finalized
11
11
 
12
+ def initialize
13
+ @thing = 0
14
+ end
15
+
12
16
  dsl do
13
17
  def with_thing thing
14
18
  self.thing = thing
@@ -36,51 +40,61 @@ module Pact
36
40
  end
37
41
 
38
42
  describe "build" do
39
- before do
40
- def my_local_method
41
- 'LA LA LA'
42
- end
43
+ context "with block" do
44
+ before do
45
+ def my_local_method
46
+ 'LA LA LA'
47
+ end
43
48
 
44
- my_local_var = 123
49
+ my_local_var = 123
45
50
 
46
- local_app = "I'm a local app"
51
+ local_app = "I'm a local app"
47
52
 
48
- @test = TestDSL.build do
49
- with_thing my_local_method
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
53
+ @test = TestDSL.build do
54
+ with_thing my_local_method
55
+ with_blah my_local_var
56
+ with_global global_method
57
+ with_block do
58
+ global_app
59
+ end
60
+ with_another_block do
61
+ local_app
62
+ end
57
63
  end
58
- end
59
- end
64
+ end
65
+
66
+ it "supports using a local variable" do
67
+ expect(@test.blah).to eq 123
68
+ end
69
+
70
+ it "supports using a local method" do
71
+ expect(@test.thing).to eq 'LA LA LA'
72
+ end
60
73
 
61
- it "supports using a local variable" do
62
- expect(@test.blah).to eq 123
63
- end
74
+ it "supports using global methods from other files" do
75
+ expect(@test.global).to eq "I'm global"
76
+ end
64
77
 
65
- it "supports using a local method" do
66
- expect(@test.thing).to eq 'LA LA LA'
67
- end
78
+ it "supports using a local method to provide the app" do
79
+ expect(@test.another_block.call).to eq("I'm a local app")
80
+ end
68
81
 
69
- it "supports using global methods from other files" do
70
- expect(@test.global).to eq "I'm global"
71
- end
82
+ it "should support using a global method to provide the app but it doesn't" do
83
+ expect(@test.the_block.call).to eq("I'm a global app")
84
+ end
72
85
 
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
86
+ it "calls finalize" do
87
+ expect(@test.finalized).to be true
88
+ end
89
+ end
76
90
 
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
91
+ context "without block" do
92
+ let(:test) { TestDSL.build }
80
93
 
81
- it "calls finalize" do
82
- expect(@test.finalized).to be true
83
- end
94
+ it "initializes an instance" do
95
+ expect(test.thing).to eq(0)
96
+ end
97
+ end
84
98
  end
85
99
  end
86
100
  end
@@ -115,12 +115,12 @@ shared_examples "a request" do
115
115
 
116
116
  it "blows up if method is absent" do
117
117
  raw_request.delete 'method'
118
- expect { described_class.from_hash(raw_request) }.to raise_error
118
+ expect { described_class.from_hash(raw_request) }.to raise_error(KeyError)
119
119
  end
120
120
 
121
121
  it "blows up if path is absent" do
122
122
  raw_request.delete 'path'
123
- expect { described_class.from_hash(raw_request) }.to raise_error
123
+ expect { described_class.from_hash(raw_request) }.to raise_error(KeyError)
124
124
  end
125
125
 
126
126
  it "does not blow up if body is missing" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact-support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Fraser
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2015-11-09 00:00:00.000000000 Z
15
+ date: 2016-04-29 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: randexp