rest_baby 0.6 → 0.8

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: 86630eb56f0b1daee5aa7f2e7a28776a1e38d3b6
4
- data.tar.gz: 6a44e6984e440e831bd7eb9f1ade1dc7834504bb
3
+ metadata.gz: 025aec7dd8041866fecfa8cf50d579d0e5936a68
4
+ data.tar.gz: 1e1650c191318c9e9964a35835d866ce8700a570
5
5
  SHA512:
6
- metadata.gz: 7be630a9887bcbbcc1b9130f3886d9beeb42ead8e1809bedd390a73d0fc0b83447a59a2a80b145dbe7cc35adc2752afac0fb8d3918ded85185656a258c527d6e
7
- data.tar.gz: ac1c5a81bc2e75166a60ad9a1a7cc1bc69bd96bea059e2d4329006ebd845b3fc10fe958ce637cb0e2b86112729d56cb90f6262d3944395b34542c63ebf736008
6
+ metadata.gz: ba7e003cdc97de5bc736cc2e89b56e2385da4553c3a3f9c110ca702a417e37b5d24f2cb39d3bdb288527c9cbbf3edb0b25dcd6dfbe0d267a20d40e0a06fa43f9
7
+ data.tar.gz: da93cbc88179db54ae4aac3ee9ba75ea40ca777c8e4ac0d3c5b2d4368e9294d95be513509be4225a19682f2a377abc7d12c63acafeb19b272452d264bb30569d
data/ChangeLog CHANGED
@@ -21,7 +21,11 @@
21
21
  === Version 0.5 / 2014-07-27
22
22
  * Enabled use of query parameters on GET calls
23
23
  * Revised tests to replace expect with should
24
- === Version 0.5 / 2014-07-27
24
+ === Version 0.6 / 2015-02-01
25
25
  * Fixed reference to nokogiri' (~> 0)
26
26
  * Fixed all cukes, no more @wip
27
27
  * Added rubocop style-checker/lint compliance
28
+ === Version 0.7 / 2014-02-10
29
+ * Tested debug fix of json printing
30
+ === Version 0.8 / 2014-02-10
31
+ * Fixed json pretty_print
data/Gemfile.lock ADDED
@@ -0,0 +1,68 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ addressable (2.3.7)
5
+ ast (2.0.0)
6
+ astrolabe (1.3.0)
7
+ parser (>= 2.2.0.pre.3, < 3.0)
8
+ builder (3.2.2)
9
+ crack (0.4.2)
10
+ safe_yaml (~> 1.0.0)
11
+ cucumber (1.3.18)
12
+ builder (>= 2.1.2)
13
+ diff-lcs (>= 1.1.3)
14
+ gherkin (~> 2.12)
15
+ multi_json (>= 1.7.5, < 2.0)
16
+ multi_test (>= 0.1.1)
17
+ diff-lcs (1.2.5)
18
+ fig_newton (0.11)
19
+ yml_reader (>= 0.3)
20
+ gherkin (2.12.2)
21
+ multi_json (~> 1.3)
22
+ json (1.8.2)
23
+ mini_portile (0.6.2)
24
+ multi_json (1.10.1)
25
+ multi_test (0.1.1)
26
+ nokogiri (1.6.6.2)
27
+ mini_portile (~> 0.6.0)
28
+ parser (2.2.0.2)
29
+ ast (>= 1.1, < 3.0)
30
+ powerpack (0.1.0)
31
+ rainbow (2.0.0)
32
+ rspec (3.2.0)
33
+ rspec-core (~> 3.2.0)
34
+ rspec-expectations (~> 3.2.0)
35
+ rspec-mocks (~> 3.2.0)
36
+ rspec-core (3.2.0)
37
+ rspec-support (~> 3.2.0)
38
+ rspec-expectations (3.2.0)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.2.0)
41
+ rspec-mocks (3.2.0)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.2.0)
44
+ rspec-support (3.2.1)
45
+ rubocop (0.29.0)
46
+ astrolabe (~> 1.3)
47
+ parser (>= 2.2.0.1, < 3.0)
48
+ powerpack (~> 0.1)
49
+ rainbow (>= 1.99.1, < 3.0)
50
+ ruby-progressbar (~> 1.4)
51
+ ruby-progressbar (1.7.1)
52
+ safe_yaml (1.0.4)
53
+ webmock (1.20.4)
54
+ addressable (>= 2.3.6)
55
+ crack (>= 0.3.2)
56
+ yml_reader (0.5)
57
+
58
+ PLATFORMS
59
+ ruby
60
+
61
+ DEPENDENCIES
62
+ cucumber
63
+ fig_newton
64
+ json
65
+ nokogiri
66
+ rspec
67
+ rubocop
68
+ webmock
@@ -17,8 +17,10 @@ Scenario: client uses an Accept header for a GET
17
17
  Scenario: client uses an Accept and a Content-Type header for a POST
18
18
  Given I have a web service
19
19
  And I have "POST" service for "/test" with the following headers
20
- | Content-Type | application/json |
21
- | Accept | application/json |
20
+ | Content-Type | application/json |
21
+ | Accept | application/json |
22
+ | Accept-Encoding | gzip;q=1.0,deflate;q=0.6,identity;q=0.3 |
23
+ | User-Agent | Ruby |
22
24
  And I am a rest client
23
25
  When I have the following header
24
26
  | Content-Type | application/json |
@@ -8,7 +8,7 @@ end
8
8
  Given(/^I have "(GET|PUT|POST|DELETE)" service for "([^"]*)" \
9
9
  with the following headers$/) do |type, path, table|
10
10
  @path = path
11
- @mockservice.store_msg(type, path, DEFAULT_MSG, table.rows_hash)
11
+ @mockservice.store_msg(type, path, DEFAULT_MSG, table.rows_hash, nil, nil, DEFAULT_RESPONSE)
12
12
  end
13
13
 
14
14
  Given(/^I have "(GET|DELETE)" service for "([^"]*)" for \
@@ -1,4 +1,5 @@
1
- DEFAULT_MSG = "{\"Answer\": \"What did you expect?\"}"
1
+ DEFAULT_MSG = '{"Answer": "What did you expect?"}'
2
+ DEFAULT_RESPONSE = '{"Question": "What is the meaning of life?"}'
2
3
 
3
4
  Given(/^I have a web service$/) do
4
5
  @protocol = 'http'
@@ -8,25 +9,27 @@ Given(/^I have a web service$/) do
8
9
  end
9
10
 
10
11
  Given(/^I have "(GET|PUT|POST|DELETE)" service for "([^"]*)"$/) do |type, path|
12
+ @path = path
11
13
  if type == 'GET'
12
- create_get(type, path)
14
+ create_get(path)
13
15
  else
14
16
  @path = path
15
- @mockservice.store_msg(type, path, DEFAULT_MSG)
17
+ @mockservice.store_msg(type, path, DEFAULT_MSG,
18
+ {}, nil, nil, DEFAULT_RESPONSE)
16
19
  end
17
20
  end
18
21
 
19
22
  Given(/^I have "(GET|PUT|POST|DELETE)" service for "([^"]*)" as follows$/) \
20
23
  do |type, path, message|
24
+ @path = path
21
25
  if type == 'GET'
22
- create_get(type, path, message)
26
+ create_get(path, message)
23
27
  else
24
- @path = path
25
- @mockservice.store_msg(type, path, message)
28
+ @mockservice.store_msg(type, path, DEFAULT_MSG, {}, nil, nil, message)
26
29
  end
27
30
  end
28
31
 
29
- def create_get(_type, path, message = DEFAULT_MSG)
32
+ def create_get(path, message = DEFAULT_MSG)
30
33
  @path = path.split('?')[0]
31
34
  if path.split('?').length == 1
32
35
  @mockservice.store_msg('GET', @path, message)
@@ -50,7 +53,7 @@ end
50
53
 
51
54
  When(/^I "(PUT|POST)" to the web service with the following$/) \
52
55
  do |type, message|
53
- @message = JSON(message)
56
+ @message = message.strip
54
57
  case type.downcase
55
58
  when 'put'
56
59
  @response = @restbaby.put(@message)
@@ -72,11 +75,6 @@ Then(/^I receive the expected message$/) do
72
75
  expect(@response.body).to eq(DEFAULT_MSG)
73
76
  end
74
77
 
75
- # Then(/^I receive the following$/) do |message|
76
- # @response.code.should eq('200')
77
- # @response.body.should eq(message)
78
- # end
79
-
80
78
  Then(/^I receive a message with "([^"]*)"$/) do |message|
81
79
  @response.code.should eq('200')
82
80
  @response.body.should eq(message)
@@ -15,18 +15,19 @@ class MockRestService
15
15
  @messages = {}
16
16
  end
17
17
 
18
- def store_msg(type, path, message, headers = {}, user = nil, password = nil)
18
+ def store_msg(type, path, message, headers = {},
19
+ user = nil, password = nil, body = nil)
19
20
  url = "#{@protocol}://#{auth_string(user, password)}#{@host}:#{@port}#{path}"
20
21
  case type.downcase
21
22
  when 'get', 'delete'
22
23
  WebMock.stub_request(type.downcase.to_sym, url)
23
24
  .with(headers: merge_headers(headers))
24
- .to_return({ status: 200, body: "#{message}" }, headers: {})
25
+ .to_return({ status: 200, body: message }, headers: {})
25
26
  when 'put', 'post'
26
- WebMock.stub_request(:put, url)
27
+ WebMock.stub_request(type.downcase.to_sym, url)
27
28
  .with(body: body,
28
29
  headers: merge_headers(headers))
29
- .to_return({ status: 200, body: "#{message}" }, headers: {})
30
+ .to_return({ status: 200, body: message }, headers: {})
30
31
  else
31
32
  fail "Unsupported type: #{type}"
32
33
  end
@@ -1,4 +1,4 @@
1
1
  # Identify the version
2
2
  module RestBaby
3
- VERSION = '0.6'
3
+ VERSION = '0.8'
4
4
  end
data/lib/rest_baby.rb CHANGED
@@ -159,7 +159,7 @@ module RestBaby
159
159
  return '[Empty]' if response_body.nil?
160
160
  case type
161
161
  when 'application/json'
162
- JSON.pretty_generate(response_body)
162
+ pretty_json(response_body)
163
163
  when 'application/xml'
164
164
  pretty_xml(response_body)
165
165
  else
@@ -167,6 +167,11 @@ module RestBaby
167
167
  end
168
168
  end
169
169
 
170
+ def pretty_json(json)
171
+ json = JSON(json) unless json.class == Hash
172
+ JSON.pretty_generate(json)
173
+ end
174
+
170
175
  def pretty_xml(xml)
171
176
  doc = Nokogiri.XML(xml) { |config| config.default_xml.noblanks }
172
177
  doc.to_xml(indent: 2)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest_baby
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.6'
4
+ version: '0.8'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave McNulla
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-02 00:00:00.000000000 Z
11
+ date: 2015-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -156,6 +156,7 @@ files:
156
156
  - ".rubocop.yml"
157
157
  - ChangeLog
158
158
  - Gemfile
159
+ - Gemfile.lock
159
160
  - LICENSE.txt
160
161
  - README.md
161
162
  - Rakefile