cucumber-api 0.4 → 0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 4ee88961920f3ccbf02d62d5ea0c7343d2f483f0
4
- data.tar.gz: 5967edd044ec97f27368cf5a4c4a187004508fc5
2
+ SHA256:
3
+ metadata.gz: eb9862462c5142f231325c27317b186d462e5f0c06655e8f429459b34b822585
4
+ data.tar.gz: 6d2c5f53a30b2c55c6694211d57b7af194f4ed560d1a3dcf171c4fca70fb57f6
5
5
  SHA512:
6
- metadata.gz: b8c3e01637543cf39ad990443fb82759520b4412d5da5d6c45e1a73036d8401930af194f67e3600ea131bc10753ee27b40137213aaabc54915c6b571e349d8ca
7
- data.tar.gz: b1d4cbd828bbb829706ce0124e0a9e500f42cc2e1cc309b660e898797cd747f81c4806a20afd32d0ad8267cd87989dc9af22b2760dd5fb85f07be544a86aa5bd
6
+ metadata.gz: ec7eff4ad9c6713ee2a215202aeec1f4415c6d0a9730b1b4c20d5ee86501d2f62e27612694a0e731bd71dd58ce2866027122ee18ac2081e19c7aaf0aa60fe432
7
+ data.tar.gz: 3858d5dc859df864a60629c9cf7f66f3f97f4d24a7ee8ee38057c1325e1cce4c80547f29b52a47389260dafb359160b37bc59e836472da987a34caf76a65777f
data/.travis.yml CHANGED
@@ -1,2 +1,14 @@
1
1
  language: ruby
2
- script: "cucumber -p verbose"
2
+ sudo: false
3
+
4
+ rvm:
5
+ - 2.3
6
+ - 2.4
7
+ - ruby-head
8
+
9
+ matrix:
10
+ allow_failures:
11
+ - ruby-head
12
+
13
+ script: "cucumber -p verbose"
14
+
data/CHANGELOG.md CHANGED
@@ -1,6 +1,22 @@
1
1
  # Change Log
2
2
 
3
- ## [Current](https://github.com/hidroh/cucumber-api/compare/0.4...master)
3
+ ## [Current](https://github.com/hidroh/cucumber-api/compare/0.9...master)
4
+
5
+ ## [0.9](https://github.com/hidroh/cucumber-api/compare/0.9...0.8) (Mar 25, 2021)
6
+ * Replace URI.encode with CGI.escape #33
7
+
8
+ ## [0.8](https://github.com/hidroh/cucumber-api/compare/0.8...0.7) (Mar 23, 2021)
9
+ * Raise error when schema is expected but missing #32
10
+
11
+ ## [0.7](https://github.com/hidroh/cucumber-api/compare/0.6...0.7) (Aug 29, 2018)
12
+ * Allow clearing GET response cache #25
13
+
14
+ ## [0.6](https://github.com/hidroh/cucumber-api/compare/0.5...0.6) (May 08, 2018)
15
+ * Allow headers to use grabbed values #24
16
+
17
+ ## [0.5](https://github.com/hidroh/cucumber-api/compare/0.4...0.5) (January 26, 2018)
18
+ * Bump up dependencies, requires min Ruby version 2.3.0
19
+ * Fix bug where grabbed values are not shared #11
4
20
 
5
21
  ## [0.4](https://github.com/hidroh/cucumber-api/compare/0.3...0.4) (November 03, 2016)
6
22
  * Support additional request headers
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  [![Build Status](https://travis-ci.org/hidroh/cucumber-api.svg?branch=master)](https://travis-ci.org/hidroh/cucumber-api) [![Gem Version](https://badge.fury.io/rb/cucumber-api.svg)](http://badge.fury.io/rb/cucumber-api) [![Dependency Status](https://gemnasium.com/hidroh/cucumber-api.svg)](https://gemnasium.com/hidroh/cucumber-api)
3
3
  [![Code Climate](https://codeclimate.com/github/hidroh/cucumber-api/badges/gpa.svg)](https://codeclimate.com/github/hidroh/cucumber-api) [![Total Downloads](http://ruby-gem-downloads-badge.herokuapp.com/cucumber-api?type=total)](https://rubygems.org/gems/cucumber-api)
4
4
 
5
- API validator in BBD style with [Cucumber](https://cukes.info/). **cucumber-api** lets one validate public APIs JSON response in blazingly fast time.
5
+ API validator in BDD style with [Cucumber](https://cukes.info/). **cucumber-api** lets one validate public APIs JSON response in blazingly fast time.
6
6
 
7
7
  Inspired by [cucumber-api-steps](https://github.com/jayzes/cucumber-api-steps).
8
8
 
@@ -176,6 +176,12 @@ Response caching is provided for GET requests by default. This is useful when yo
176
176
 
177
177
  Only the first request to that endpoint is made, subsequent requests will use cached response. Response caching is only available for GET method.
178
178
 
179
+ The response cache can also be cleared if needed:
180
+
181
+ ```gherkin
182
+ Given I clear the response cache
183
+ ```
184
+
179
185
  ## Dependencies
180
186
  * [cucumber](https://github.com/cucumber/cucumber) for BDD style specs
181
187
  * [jsonpath](https://github.com/joshbuddy/jsonpath) for traversal of JSON response via [JSON path](http://goessner.net/articles/JsonPath/)
data/cucumber-api.gemspec CHANGED
@@ -13,11 +13,12 @@ Gem::Specification.new do |s|
13
13
  s.description = %q{cucumber-api allows API JSON response validation and verification in BDD style.}
14
14
  s.files = `git ls-files`.split("\n")
15
15
  s.require_paths = ["lib"]
16
- s.required_ruby_version = '>= 1.9.3'
16
+ s.required_ruby_version = '>= 2.3.0'
17
17
  s.license = 'Apache-2.0'
18
18
 
19
- s.add_dependency('cucumber', '~> 2.0')
20
- s.add_dependency('jsonpath', '~> 0.5')
21
- s.add_dependency('rest-client', '~> 1.8')
22
- s.add_dependency('json-schema', '~> 2.5')
23
- end
19
+ s.add_dependency('addressable', '2.5')
20
+ s.add_dependency('cucumber', '~> 3.1.0')
21
+ s.add_dependency('jsonpath', '~> 0.8')
22
+ s.add_dependency('rest-client', '~> 2.0.2')
23
+ s.add_dependency('json-schema', '~> 2.8.0')
24
+ end
@@ -1,17 +1,18 @@
1
1
  # https://github.com/HackerNews/API
2
2
  Feature: Hacker News REST API validation
3
3
 
4
- Scenario: Verify top stories JSON schema
4
+ Background:
5
5
  Given I send and accept JSON
6
- And I add Headers:
6
+
7
+ Scenario: Verify top stories JSON schema
8
+ When I add Headers:
7
9
  | Cache-Control | no-cache |
8
- When I send a GET request to "https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty"
10
+ And I send a GET request to "https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty"
9
11
  Then the response status should be "200"
10
12
  And the JSON response should follow "features/schemas/topstories.json"
11
13
 
12
14
  Scenario Outline: Verify item JSON schema
13
- When I send and accept JSON
14
- And I send a GET request to "https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty"
15
+ When I send a GET request to "https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty"
15
16
  Then the response status should be "200"
16
17
  And the JSON response root should be array
17
18
  When I grab "$[0]" as "id"
@@ -30,8 +31,7 @@ Feature: Hacker News REST API validation
30
31
  | url | string | optional |
31
32
 
32
33
  Scenario: Demonstrate setting the JSON body with a docstring
33
- Given I send and accept JSON
34
- And I set JSON request body to:
34
+ When I set JSON request body to:
35
35
  """
36
36
  {
37
37
  "title": "foo",
@@ -39,7 +39,7 @@ Feature: Hacker News REST API validation
39
39
  "userId": 1
40
40
  }
41
41
  """
42
- When I send a POST request to "http://jsonplaceholder.typicode.com/posts"
42
+ And I send a POST request to "http://jsonplaceholder.typicode.com/posts"
43
43
  Then the response status should be "201"
44
44
  And the JSON response should have "id" of type numeric and value "101"
45
45
  And the JSON response should have "title" of type string and value "foo"
@@ -0,0 +1,21 @@
1
+ module CucumberApi
2
+ module Helpers
3
+ # Bind grabbed values into placeholders in given URL
4
+ # Ex: http://example.com?id={id} with {id => 1} becomes http://example.com?id=1
5
+ # @param url [String] parameterized URL with placeholders
6
+ # @return [String] binded URL or original URL if no placeholders
7
+ def resolve url
8
+ url.gsub!(/\{([a-zA-Z0-9_]+)\}/) do |s|
9
+ s.gsub!(/[\{\}]/, '')
10
+ if instance_variable_defined?("@#{s}")
11
+ CGI.escape %/#{instance_variable_get("@#{s}")}/
12
+ else
13
+ raise 'Did you forget to "grab" ' + s + '?'
14
+ end
15
+ end
16
+ url
17
+ end
18
+ end
19
+ end
20
+
21
+ World(CucumberApi::Helpers)
@@ -6,9 +6,6 @@ module CucumberApi
6
6
 
7
7
  # Extension of {RestClient::Response} with support for JSON path traversal and validation
8
8
  module Response
9
-
10
- include RestClient::Response
11
-
12
9
  # Create a Response with JSON path support
13
10
  # @param response [RestClient::Response] original response
14
11
  # @return [Response] self
@@ -115,5 +112,6 @@ module CucumberApi
115
112
  ''
116
113
  end
117
114
  end
115
+ RestClient::Response.send(:include, self)
118
116
  end
119
117
  end
@@ -1,4 +1,5 @@
1
1
  require 'cucumber-api/response'
2
+ require 'cucumber-api/helpers'
2
3
  require 'rest-client'
3
4
  require 'json-schema'
4
5
 
@@ -8,6 +9,10 @@ end
8
9
 
9
10
  $cache = {}
10
11
 
12
+ Given(/^I clear the response cache$/) do
13
+ $cache = {}
14
+ end
15
+
11
16
  Given(/^I send and accept JSON$/) do
12
17
  steps %Q{
13
18
  Given I send "application/json" and accept JSON
@@ -23,7 +28,7 @@ end
23
28
 
24
29
  Given(/^I add Headers:$/) do |params|
25
30
  params.rows_hash.each do |key, value|
26
- @headers[key.to_sym] = value
31
+ @headers[key.to_sym] = resolve(value)
27
32
  end
28
33
  end
29
34
 
@@ -87,7 +92,7 @@ end
87
92
 
88
93
  When(/^I send a (GET|POST|PATCH|PUT|DELETE) request to "(.*?)" with:$/) do |method, url, params|
89
94
  unless params.hashes.empty?
90
- query = params.hashes.first.map{|key, value| %/#{key}=#{value}/}.join("&")
95
+ query = params.hashes.first.map{|key, value| %/CGI.escape #{key}=#{value}/}.join("&")
91
96
  url = url.include?('?') ? %/#{url}&#{query}/ : %/#{url}?#{query}/
92
97
  end
93
98
  steps %Q{
@@ -96,7 +101,7 @@ When(/^I send a (GET|POST|PATCH|PUT|DELETE) request to "(.*?)" with:$/) do |meth
96
101
  end
97
102
 
98
103
  When(/^I send a (GET|POST|PATCH|PUT|DELETE) request to "(.*?)"$/) do |method, url|
99
- request_url = URI.encode resolve(url)
104
+ request_url = resolve(url)
100
105
  if 'GET' == %/#{method}/ and $cache.has_key? %/#{request_url}/
101
106
  @response = $cache[%/#{request_url}/]
102
107
  @headers = nil
@@ -141,8 +146,7 @@ Then(/^the JSON response should follow "(.*?)"$/) do |schema|
141
146
  $!.fragments, $!.failed_attribute, $!.schema)
142
147
  end
143
148
  else
144
- puts %/WARNING: missing schema '#{file_path}'/
145
- pending
149
+ raise %/Schema not found: '#{file_path}'/
146
150
  end
147
151
  end
148
152
 
@@ -174,20 +178,3 @@ Then(/^the JSON response should have "([^"]*)" of type \
174
178
  (numeric|string|boolean|numeric_string) and value "([^"]*)"$/) do |json_path, type, value|
175
179
  @response.get_as_type_and_check_value json_path, type, resolve(value)
176
180
  end
177
-
178
- # Bind grabbed values into placeholders in given URL
179
- # Ex: http://example.com?id={id} with {id => 1} becomes http://example.com?id=1
180
- # @param url [String] parameterized URL with placeholders
181
- # @return [String] binded URL or original URL if no placeholders
182
- def resolve url
183
- url.gsub!(/\{([a-zA-Z0-9_]+)\}/) do |s|
184
- s.gsub!(/[\{\}]/, '')
185
- if instance_variable_defined?("@#{s}")
186
- instance_variable_get("@#{s}")
187
- else
188
- raise 'Did you forget to "grab" ' + s + '?'
189
- end
190
- end
191
- url
192
- end
193
-
@@ -1,3 +1,3 @@
1
1
  module CucumberApi
2
- VERSION = "0.4"
3
- end
2
+ VERSION = "0.9"
3
+ end
metadata CHANGED
@@ -1,71 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber-api
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.4'
4
+ version: '0.9'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ha Duy Trung
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-03 00:00:00.000000000 Z
11
+ date: 2021-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: addressable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: '2.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: '2.5'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: cucumber
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '2.0'
33
+ version: 3.1.0
20
34
  type: :runtime
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '2.0'
40
+ version: 3.1.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: jsonpath
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '0.5'
47
+ version: '0.8'
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '0.5'
54
+ version: '0.8'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rest-client
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '1.8'
61
+ version: 2.0.2
48
62
  type: :runtime
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '1.8'
68
+ version: 2.0.2
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: json-schema
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '2.5'
75
+ version: 2.8.0
62
76
  type: :runtime
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '2.5'
82
+ version: 2.8.0
69
83
  description: cucumber-api allows API JSON response validation and verification in
70
84
  BDD style.
71
85
  email:
@@ -86,6 +100,7 @@ files:
86
100
  - features/schemas/topstories.json
87
101
  - features/support/env.rb
88
102
  - lib/cucumber-api.rb
103
+ - lib/cucumber-api/helpers.rb
89
104
  - lib/cucumber-api/response.rb
90
105
  - lib/cucumber-api/steps.rb
91
106
  - lib/cucumber-api/version.rb
@@ -93,7 +108,7 @@ homepage: https://github.com/hidroh/cucumber-api
93
108
  licenses:
94
109
  - Apache-2.0
95
110
  metadata: {}
96
- post_install_message:
111
+ post_install_message:
97
112
  rdoc_options: []
98
113
  require_paths:
99
114
  - lib
@@ -101,16 +116,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
116
  requirements:
102
117
  - - ">="
103
118
  - !ruby/object:Gem::Version
104
- version: 1.9.3
119
+ version: 2.3.0
105
120
  required_rubygems_version: !ruby/object:Gem::Requirement
106
121
  requirements:
107
122
  - - ">="
108
123
  - !ruby/object:Gem::Version
109
124
  version: '0'
110
125
  requirements: []
111
- rubyforge_project:
112
- rubygems_version: 2.2.2
113
- signing_key:
126
+ rubygems_version: 3.2.3
127
+ signing_key:
114
128
  specification_version: 4
115
129
  summary: API validator with Cucumber
116
130
  test_files: []