pact-support 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZmE3YmExODMzYzc4ODljOWNiMjQ5NTZmMjFlYjUwYjBkZmZjNTY1Zg==
4
+ NWE0OThiMTk0ZTVjOTU1YWE5MGZmODZiZDM2MjIzNTc3M2YwYTZhYw==
5
5
  data.tar.gz: !binary |-
6
- MGYzMWNkOTU5M2MxOWQwMzY2Mzg2NTI4YWMyNWM2ZTVhN2QxOTBlMA==
6
+ NGE1ZmFlOGY4M2NjZTUyMTMxODhhYzNkODU0YmU4ZjY2OGNiYWEwMw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NmM1ZjFlODEwNTlmNzM3ZTU2NjM1ZmJkOWI4OGQ0YjE4NjlkNDMwNThiZjI3
10
- MDZhZDIzMDk4NTBmZDY2Y2EzZThjYjViMWVhM2FlNDVmMTVhNmY3YjU2NGM1
11
- M2JlY2IzNzRkZDM4OGQ3NzhjOGIwYWE4YmI1YmE3N2Y2MmI0ZmM=
9
+ M2QzYmJlY2M5MzJjMWQwY2RiOTRlNDBhMWRkYTc2MDc4Mjk3MjY4NDIzZWYw
10
+ Zjc3ODE5OWJhN2JiYzk5MDU0NzI2YWI0Mjg4YmUwMmQ0NjhhZWVmMTEwZDI2
11
+ NDNlOTYzYjI2NmQ4YWM4YTVlMTQ2NDlmMWFkOTE5OTAzOWVhYWY=
12
12
  data.tar.gz: !binary |-
13
- YjJiOGEwMmJmOGNmZjczMjY4MDU3ZDE2NzY3NmQ2NDMwZTVkN2FlYzA1MzZk
14
- MmQ5MGMyNDdlNDg5YmE0MzA2N2M2ODg2ZDI3YzQ2MjI2NTI4Y2QxYWI5ZmE5
15
- OTY2YTJlNWEzMGVmNzliYzI4ZmUwNzQ2MDFlM2M1OWQ0YmMwNGI=
13
+ YTBlNGY3YWQ2MzViNjgwNTdiODI2YzM0MzNiMGJiOTAxNTkyOTVmNzAzZTQw
14
+ OWY4YTA5YTAwYmZjNTZhZWQ4MmU3Y2NkZmNlNjJkZjcxYWUyNWY4NmUxNzY3
15
+ ODFkODcxNjkxYjZiZjhkNTFmZTJlOWM0NThjZDAyYTEzZGUyMWI=
data/CHANGELOG.md CHANGED
@@ -2,3 +2,12 @@ Do this to generate your change history
2
2
 
3
3
  git log --pretty=format:' * %h - %s (%an, %ad)'
4
4
 
5
+ ### 0.0.2 (12 October 2014)
6
+
7
+ * e7080fe - Added a QueryString class in preparation for a QueryHash class (Beth, Sun Oct 12 14:32:15 2014 +1100)
8
+ * 8839151 - Added Travis config (Beth, Sun Oct 12 12:31:44 2014 +1100)
9
+ * 81ade54 - Removed CLI (Beth, Sun Oct 12 12:29:22 2014 +1100)
10
+ * 3bdde98 - Removing unused files (Beth, Sun Oct 12 12:11:48 2014 +1100)
11
+ * ef95717 - Made it build (Beth, Sat Oct 11 13:24:35 2014 +1100)
12
+ * 1e78b62 - Removed pact-test.rake (Beth, Sat Oct 11 13:20:49 2014 +1100)
13
+ * 3389b5e - Initial commit (Beth, Sat Oct 11 13:13:23 2014 +1100)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pact-support (0.0.1)
4
+ pact-support (0.0.2)
5
5
  awesome_print (~> 1.1)
6
6
  find_a_port (~> 1.0.1)
7
7
  json
@@ -0,0 +1,52 @@
1
+ require 'pact/shared/active_support_support'
2
+ require 'pact/matchers'
3
+
4
+ module Pact
5
+ class QueryString
6
+
7
+ include ActiveSupportSupport
8
+ include Pact::Matchers
9
+
10
+ def initialize query
11
+ @query = query.nil? ? query : query.dup
12
+ end
13
+
14
+ def as_json opts = {}
15
+ @query
16
+ end
17
+
18
+ def to_json opts = {}
19
+ as_json(opts).to_json(opts)
20
+ end
21
+
22
+ def eql? other
23
+ self == other
24
+ end
25
+
26
+ def == other
27
+ QueryString === other && other.query == query
28
+ end
29
+
30
+ def difference(other)
31
+ diff(query, other.query)
32
+ end
33
+
34
+ def query
35
+ @query
36
+ end
37
+
38
+ def to_s
39
+ @query
40
+ end
41
+
42
+ def empty?
43
+ @query && @query.empty?
44
+ end
45
+
46
+ # Naughty...
47
+ def nil?
48
+ @query.nil?
49
+ end
50
+
51
+ end
52
+ end
@@ -35,16 +35,22 @@ module Pact
35
35
  end
36
36
 
37
37
  def difference(actual_request)
38
- request_diff = diff(to_hash_without_body, actual_request.to_hash_without_body)
39
- unless body.is_a? NullExpectation
40
- request_diff.merge(body_difference(actual_request.body))
41
- else
42
- request_diff
43
- end
38
+ request_diff = diff(to_hash_without_body_or_query, actual_request.to_hash_without_body_or_query)
39
+ request_diff.merge!(query_diff(actual_request.query))
40
+ request_diff.merge!(body_diff(actual_request.body))
44
41
  end
45
42
 
46
43
  protected
47
44
 
45
+ def query_diff actual_query
46
+ if specified?(:query)
47
+ query_diff = query.difference(actual_query)
48
+ query_diff.any? ? {query: query_diff} : {}
49
+ else
50
+ {}
51
+ end
52
+ end
53
+
48
54
  def self.key_not_found
49
55
  Pact::NullExpectation.new
50
56
  end
@@ -59,8 +65,12 @@ module Pact
59
65
  DEFAULT_OPTIONS.merge(symbolize_keys(options))
60
66
  end
61
67
 
62
- def body_difference(actual_body)
63
- body_differ.call({:body => body}, {body: actual_body}, allow_unexpected_keys: runtime_options[:allow_unexpected_keys_in_body])
68
+ def body_diff(actual_body)
69
+ if specified?(:body)
70
+ body_differ.call({:body => body}, {body: actual_body}, allow_unexpected_keys: runtime_options[:allow_unexpected_keys_in_body])
71
+ else
72
+ {}
73
+ end
64
74
  end
65
75
 
66
76
  def body_differ
@@ -19,6 +19,8 @@ module Pact
19
19
  end
20
20
  when Pact::Request::Base
21
21
  from_term(term.to_hash)
22
+ when Pact::QueryString
23
+ from_term(term.query)
22
24
  else
23
25
  term
24
26
  end
@@ -1,6 +1,7 @@
1
1
  require 'pact/matchers'
2
2
  require 'pact/symbolize_keys'
3
3
  require 'pact/consumer_contract/headers'
4
+ require 'pact/consumer_contract/query_string'
4
5
 
5
6
  module Pact
6
7
 
@@ -18,7 +19,7 @@ module Pact
18
19
  @path = path.chomp('/')
19
20
  @headers = Hash === headers ? Headers.new(headers) : headers # Could be a NullExpectation - TODO make this more elegant
20
21
  @body = body
21
- @query = query
22
+ @query = is_unspecified?(query) ? query : Pact::QueryString.new(query)
22
23
  end
23
24
 
24
25
  def to_json(options = {})
@@ -74,11 +75,15 @@ module Pact
74
75
  end
75
76
 
76
77
  def specified? key
77
- !(self.send(key).is_a? self.class.key_not_found.class)
78
+ !is_unspecified?(self.send(key))
78
79
  end
79
80
 
80
- def to_hash_without_body
81
- keep_keys = [:method, :path, :headers, :query]
81
+ def is_unspecified? value
82
+ value.is_a? self.class.key_not_found.class
83
+ end
84
+
85
+ def to_hash_without_body_or_query
86
+ keep_keys = [:method, :path, :headers]
82
87
  as_json.reject{ |key, value| !keep_keys.include? key }.tap do | hash |
83
88
  hash[:method] = method.upcase
84
89
  end
@@ -1,5 +1,5 @@
1
1
  module Pact
2
2
  module Support
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -0,0 +1,131 @@
1
+ require 'spec_helper'
2
+ require 'pact/consumer_contract/query_string'
3
+
4
+ module Pact
5
+ describe QueryString do
6
+
7
+ subject { QueryString.new(query) }
8
+
9
+ context "when the query a Pact::Term" do
10
+
11
+ let(:query) { Pact::Term.new(generate: "param=thing", matcher: /param=.*/) }
12
+
13
+ describe "#as_json" do
14
+ it "returns the query as a string" do
15
+ expect(subject.as_json).to eq query
16
+ end
17
+ end
18
+
19
+ describe "#to_json" do
20
+ it "returns the query as JSON" do
21
+ expect(subject.to_json).to eq query.to_json
22
+ end
23
+ end
24
+
25
+ describe "#==" do
26
+ context "when the query is not an identical string match" do
27
+ let(:other) { QueryString.new("param=thing2")}
28
+ it "returns false" do
29
+ expect(subject == other).to be false
30
+ end
31
+ end
32
+
33
+ context "when the query is an identical string match" do
34
+ let(:other) { QueryString.new(query) }
35
+ it "returns true" do
36
+ expect(subject == other).to be true
37
+ end
38
+ end
39
+ end
40
+
41
+ describe "#to_s" do
42
+ it "returns the query string" do
43
+ expect(subject.to_s).to eq query
44
+ end
45
+ end
46
+
47
+ end
48
+
49
+ context "when the query is not nil" do
50
+
51
+ let(:query) { "param=thing" }
52
+
53
+ describe "#as_json" do
54
+ it "returns the query as a string" do
55
+ expect(subject.as_json).to eq query
56
+ end
57
+ end
58
+
59
+ describe "#to_json" do
60
+ it "returns the query as JSON" do
61
+ expect(subject.to_json).to eq query.to_json
62
+ end
63
+ end
64
+
65
+ describe "#==" do
66
+ context "when the query is not an identical string match" do
67
+ let(:other) { QueryString.new("param=thing2")}
68
+ it "returns false" do
69
+ expect(subject == other).to be false
70
+ end
71
+ end
72
+
73
+ context "when the query is an identical string match" do
74
+ let(:other) { QueryString.new(query) }
75
+ it "returns true" do
76
+ expect(subject == other).to be true
77
+ end
78
+ end
79
+ end
80
+
81
+ describe "#to_s" do
82
+ it "returns the query string" do
83
+ expect(subject.to_s).to eq query
84
+ end
85
+ end
86
+
87
+ end
88
+
89
+ context "when the query is nil" do
90
+
91
+ let(:query) { nil }
92
+
93
+ describe "#as_json" do
94
+ it "returns the query as a string" do
95
+ expect(subject.as_json).to eq query
96
+ end
97
+ end
98
+
99
+ describe "#to_json" do
100
+ it "returns the query as JSON" do
101
+ expect(subject.to_json).to eq query.to_json
102
+ end
103
+ end
104
+
105
+ describe "#==" do
106
+ context "when the query is not an identical string match" do
107
+ let(:other) { QueryString.new("param=thing2")}
108
+ it "returns false" do
109
+ expect(subject == other).to be false
110
+ end
111
+ end
112
+
113
+ context "when the query is an identical string match" do
114
+ let(:other) { QueryString.new(query) }
115
+ it "returns true" do
116
+ expect(subject == other).to be true
117
+ end
118
+ end
119
+ end
120
+
121
+ describe "#to_s" do
122
+ it "returns the query string" do
123
+ expect(subject.to_s).to eq query
124
+ end
125
+ end
126
+
127
+ end
128
+
129
+
130
+ end
131
+ end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'pact/consumer_contract/request'
3
- require 'support/shared_examples_for_request'
4
3
  require 'pact/consumer/request'
4
+ require 'support/shared_examples_for_request'
5
5
 
6
6
  module Pact
7
7
 
@@ -63,5 +63,17 @@ module Pact
63
63
 
64
64
  end
65
65
 
66
+ context "when Query" do
67
+
68
+ let(:query) { QueryString.new(Pact::Term.new(generate: "param=thing", matcher: /param=.*/)) }
69
+
70
+ subject { Reification.from_term(query)}
71
+
72
+ it "returns the contents of the generate" do
73
+ expect(subject).to eq("param=thing")
74
+ end
75
+
76
+ end
77
+
66
78
  end
67
79
  end
@@ -72,7 +72,7 @@ shared_examples "a request" do
72
72
  end
73
73
 
74
74
  it "extracts the query" do
75
- expect(subject.query).to eq 'query'
75
+ expect(subject.query).to eq Pact::QueryString.new('query')
76
76
  end
77
77
 
78
78
  it "blows up if method is absent" 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.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Fraser
@@ -238,6 +238,7 @@ files:
238
238
  - lib/pact/consumer_contract/headers.rb
239
239
  - lib/pact/consumer_contract/interaction.rb
240
240
  - lib/pact/consumer_contract/pact_file.rb
241
+ - lib/pact/consumer_contract/query_string.rb
241
242
  - lib/pact/consumer_contract/request.rb
242
243
  - lib/pact/consumer_contract/response.rb
243
244
  - lib/pact/consumer_contract/service_consumer.rb
@@ -282,6 +283,7 @@ files:
282
283
  - spec/lib/pact/consumer_contract/consumer_contract_spec.rb
283
284
  - spec/lib/pact/consumer_contract/headers_spec.rb
284
285
  - spec/lib/pact/consumer_contract/interaction_spec.rb
286
+ - spec/lib/pact/consumer_contract/query_string_spec.rb
285
287
  - spec/lib/pact/consumer_contract/request_spec.rb
286
288
  - spec/lib/pact/consumer_contract/response_spec.rb
287
289
  - spec/lib/pact/matchers/differ_spec.rb
@@ -356,6 +358,7 @@ test_files:
356
358
  - spec/lib/pact/consumer_contract/consumer_contract_spec.rb
357
359
  - spec/lib/pact/consumer_contract/headers_spec.rb
358
360
  - spec/lib/pact/consumer_contract/interaction_spec.rb
361
+ - spec/lib/pact/consumer_contract/query_string_spec.rb
359
362
  - spec/lib/pact/consumer_contract/request_spec.rb
360
363
  - spec/lib/pact/consumer_contract/response_spec.rb
361
364
  - spec/lib/pact/matchers/differ_spec.rb