pact-support 0.1.0 → 0.1.1

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: 96c37218ffea4538adf60f7a93d1c494723d14c1
4
- data.tar.gz: a54ca9babda872a3aec4412e2d3f2456dc915d72
3
+ metadata.gz: df14a80c6fb9e36924a13bdf658aaae7f244183f
4
+ data.tar.gz: c84bef17499b45fb3a1ba67fcf4152dc81a2ef63
5
5
  SHA512:
6
- metadata.gz: f92a57c9ab90f83c059d23a17434dc4e9cb96424a9ef50953a750ec38bd994adc716b05b7495c76dc1ce1cb9e044ecae5e91517296d400d620b2bcb6eb2598a7
7
- data.tar.gz: 0740b78cb0f67a31ef808efcd85e7c00274928247ae1dfa4d7becb401860eeb2c3d8757697de6213258b032770a3771b3f12a59fbfeba90007d50da88eb5ae4e
6
+ metadata.gz: 2dc586e4103e8596c17e370b8a3c384745c92abfb5a64f39413b5a0a43fce9324ddd1d3591c8bd87d4a6914f67a492c50382aac952180f8bb0d0ba21bdee5972
7
+ data.tar.gz: 6acab79c481d452bca05ae0d90a30b353efac77ef529154630bb3779aa3817fa2829be944bbfaf7bc13d0b2ad4f9dbc95d58f3c79934058d66ac30a4285c019f
data/.gitignore CHANGED
@@ -27,3 +27,4 @@ spec/pacts
27
27
  log
28
28
  .idea
29
29
  reports
30
+ Gemfile.lock
@@ -2,6 +2,10 @@ Do this to generate your change history
2
2
 
3
3
  git log --pretty=format:' * %h - %s (%an, %ad)'
4
4
 
5
+ ### 0.1.1 (22 October 2014)
6
+
7
+ * ff6a01d - Disallowing unexpected params in the query (bethesque, Wed Oct 22 14:42:41 2014 +1100)
8
+
5
9
  ### 0.1.0 (22 October 2014)
6
10
 
7
11
  * fa7e03f - Removed JSON serialisation code from models. It has been moved to decorators in pact_mock-service. (bethesque, Wed Oct 22 12:53:21 2014 +1100)
@@ -14,7 +14,7 @@ module Pact
14
14
  end
15
15
 
16
16
  def convert_to_hash_of_arrays query
17
- symbolize_keys(query).inject({}) {|h,(k,v)| h[k] = v.is_a?(Array) ? v : [v] ; h }
17
+ symbolize_keys(query).each_with_object({}) {|(k,v), hash| hash[k] = [*v] }
18
18
  end
19
19
 
20
20
  def as_json opts = {}
@@ -36,7 +36,7 @@ module Pact
36
36
  # other will always be a QueryString, not a QueryHash, as it will have ben created
37
37
  # from the actual query string.
38
38
  def difference(other)
39
- diff(query, symbolize_keys(CGI::parse(other.query)))
39
+ diff(query, symbolize_keys(CGI::parse(other.query)), allow_unexpected_keys: false)
40
40
  end
41
41
 
42
42
  def query
@@ -52,4 +52,4 @@ module Pact
52
52
  end
53
53
 
54
54
  end
55
- end
55
+ end
@@ -43,10 +43,14 @@ module Pact
43
43
  end
44
44
 
45
45
  def content_type
46
- return nil if headers.is_a? self.class.key_not_found.class
46
+ return nil unless specified?(:headers)
47
47
  headers['Content-Type']
48
48
  end
49
49
 
50
+ def content_type? content_type
51
+ self.content_type == content_type
52
+ end
53
+
50
54
  def modifies_resource?
51
55
  http_method_modifies_resource? && body_specified?
52
56
  end
@@ -1,5 +1,5 @@
1
1
  module Pact
2
2
  module Support
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -0,0 +1,92 @@
1
+ require 'pact/consumer_contract/query_hash'
2
+ require 'pact/consumer_contract/query_string'
3
+
4
+ module Pact
5
+ describe QueryHash do
6
+
7
+ subject { QueryHash.new(query) }
8
+
9
+ let(:query) { { param: 'thing' } }
10
+ let(:query_with_array) { { param: ['thing'] } }
11
+
12
+ describe "difference" do
13
+ context "when the other is the same" do
14
+
15
+ let(:other) { QueryString.new('param=thing') }
16
+
17
+ it 'returns an empty diff' do
18
+ expect(subject.difference(other)).to be_empty
19
+ end
20
+ end
21
+
22
+ context "when the other is different" do
23
+ let(:other) { QueryString.new('param=thing1') }
24
+
25
+ it 'returns the diff' do
26
+ expect(subject.difference(other)).to_not be_empty
27
+ end
28
+ end
29
+
30
+ context "when the other has an extra param" do
31
+ let(:other) { QueryString.new('param=thing&param2=blah') }
32
+
33
+ it 'returns the diff' do
34
+ expect(subject.difference(other)).to_not be_empty
35
+ end
36
+ end
37
+ end
38
+
39
+ describe "#as_json" do
40
+ it "returns the query as a Hash" do
41
+ expect(subject.as_json).to eq query_with_array
42
+ end
43
+ end
44
+
45
+ describe "#to_json" do
46
+ context "when the query contains a Pact::Term" do
47
+ let(:term) { Pact::Term.new(generate: "thing", matcher: /th/) }
48
+ let(:query) { { param: term } }
49
+ let(:query_with_array) { { param: [term] } }
50
+
51
+ it "serialises the Pact::Term as Ruby specific JSON" do
52
+ expect(subject.to_json).to eq query_with_array.to_json
53
+ end
54
+ end
55
+ end
56
+
57
+ describe "#==" do
58
+ context "when the query is not an identical match" do
59
+ let(:other) { QueryHash.new(param: 'other thing')}
60
+ it "returns false" do
61
+ expect(subject == other).to be false
62
+ end
63
+ end
64
+
65
+ context "when the query is an identical match" do
66
+ let(:other) { QueryHash.new(query) }
67
+ it "returns true" do
68
+ expect(subject == other).to be true
69
+ end
70
+ end
71
+ end
72
+
73
+ describe "#to_s" do
74
+ it "returns the query Hash as a string" do
75
+ expect(subject.to_s).to eq query_with_array.to_s
76
+ end
77
+ end
78
+
79
+ describe "#as_json" do
80
+ it "returns the query Hash" do
81
+ expect(subject.as_json).to eq query_with_array
82
+ end
83
+ end
84
+
85
+ describe "#to_json" do
86
+ it "returns the query Hash as JSON" do
87
+ expect(subject.to_json).to eq query_with_array.to_json
88
+ end
89
+ end
90
+
91
+ end
92
+ end
@@ -87,6 +87,7 @@ module Pact
87
87
  describe "#content_type" do
88
88
 
89
89
  subject { TestRequest.new("get", "/something", headers, {} , "") }
90
+
90
91
  context "when there are no expected headers" do
91
92
  let(:headers) { Pact::KeyNotFound.new }
92
93
  it "returns nil" do
@@ -107,6 +108,23 @@ module Pact
107
108
  end
108
109
  end
109
110
 
111
+ describe "content_type?" do
112
+ subject { TestRequest.new("get", "/something", headers, {} , "") }
113
+ let(:headers) { {'content-type' => 'blah'} }
114
+
115
+ context "when the content type is the same" do
116
+ it "returns true" do
117
+ expect(subject.content_type?('blah')).to be true
118
+ end
119
+ end
120
+ context "when the content type is not the same" do
121
+ it "returns false" do
122
+ expect(subject.content_type?('apple')).to be false
123
+ end
124
+ end
125
+
126
+ end
127
+
110
128
  describe "modifies_resource?" do
111
129
 
112
130
  subject { Pact::Request::Expected.from_hash(request).modifies_resource? }
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.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Fraser
@@ -226,7 +226,6 @@ files:
226
226
  - .travis.yml
227
227
  - CHANGELOG.md
228
228
  - Gemfile
229
- - Gemfile.lock
230
229
  - LICENSE.txt
231
230
  - README.md
232
231
  - Rakefile
@@ -287,6 +286,7 @@ files:
287
286
  - spec/lib/pact/consumer_contract/consumer_contract_spec.rb
288
287
  - spec/lib/pact/consumer_contract/headers_spec.rb
289
288
  - spec/lib/pact/consumer_contract/interaction_spec.rb
289
+ - spec/lib/pact/consumer_contract/query_hash_spec.rb
290
290
  - spec/lib/pact/consumer_contract/query_string_spec.rb
291
291
  - spec/lib/pact/consumer_contract/request_spec.rb
292
292
  - spec/lib/pact/consumer_contract/response_spec.rb
@@ -364,6 +364,7 @@ test_files:
364
364
  - spec/lib/pact/consumer_contract/consumer_contract_spec.rb
365
365
  - spec/lib/pact/consumer_contract/headers_spec.rb
366
366
  - spec/lib/pact/consumer_contract/interaction_spec.rb
367
+ - spec/lib/pact/consumer_contract/query_hash_spec.rb
367
368
  - spec/lib/pact/consumer_contract/query_string_spec.rb
368
369
  - spec/lib/pact/consumer_contract/request_spec.rb
369
370
  - spec/lib/pact/consumer_contract/response_spec.rb
@@ -1,80 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- pact-support (0.1.0)
5
- awesome_print (~> 1.1)
6
- find_a_port (~> 1.0.1)
7
- json
8
- rack-test (~> 0.6.2)
9
- randexp (~> 0.1.7)
10
- rspec (>= 2.14)
11
- term-ansicolor (~> 1.0)
12
- thor
13
-
14
- GEM
15
- remote: https://rubygems.org/
16
- specs:
17
- activesupport (4.1.1)
18
- i18n (~> 0.6, >= 0.6.9)
19
- json (~> 1.7, >= 1.7.7)
20
- minitest (~> 5.1)
21
- thread_safe (~> 0.1)
22
- tzinfo (~> 1.1)
23
- addressable (2.3.6)
24
- awesome_print (1.2.0)
25
- coderay (1.1.0)
26
- crack (0.4.2)
27
- safe_yaml (~> 1.0.0)
28
- diff-lcs (1.2.5)
29
- fakefs (0.5.2)
30
- find_a_port (1.0.1)
31
- hashie (2.1.1)
32
- i18n (0.6.9)
33
- json (1.8.1)
34
- method_source (0.8.2)
35
- minitest (5.3.4)
36
- pry (0.10.0)
37
- coderay (~> 1.1.0)
38
- method_source (~> 0.8.1)
39
- slop (~> 3.4)
40
- rack (1.5.2)
41
- rack-test (0.6.2)
42
- rack (>= 1.0)
43
- rake (10.0.4)
44
- randexp (0.1.7)
45
- rspec (3.1.0)
46
- rspec-core (~> 3.1.0)
47
- rspec-expectations (~> 3.1.0)
48
- rspec-mocks (~> 3.1.0)
49
- rspec-core (3.1.7)
50
- rspec-support (~> 3.1.0)
51
- rspec-expectations (3.1.2)
52
- diff-lcs (>= 1.2.0, < 2.0)
53
- rspec-support (~> 3.1.0)
54
- rspec-mocks (3.1.3)
55
- rspec-support (~> 3.1.0)
56
- rspec-support (3.1.2)
57
- safe_yaml (1.0.3)
58
- slop (3.5.0)
59
- term-ansicolor (1.3.0)
60
- tins (~> 1.0)
61
- thor (0.19.1)
62
- thread_safe (0.3.4)
63
- tins (1.3.3)
64
- tzinfo (1.2.1)
65
- thread_safe (~> 0.1)
66
- webmock (1.18.0)
67
- addressable (>= 2.3.6)
68
- crack (>= 0.3.2)
69
-
70
- PLATFORMS
71
- ruby
72
-
73
- DEPENDENCIES
74
- activesupport
75
- fakefs (~> 0.4)
76
- hashie (~> 2.0)
77
- pact-support!
78
- pry
79
- rake (~> 10.0.3)
80
- webmock (~> 1.18.0)