cucumber-http 0.4.0 → 0.7.0

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
  SHA256:
3
- metadata.gz: 760307f677ade8fcdc3a4b6629f7143e311377f2856d57664f0a4ccfed60fa24
4
- data.tar.gz: 68e7faacc18737c3ef9ceb560ae4f362610dfeaf92a4fa08dd0723c2ef36827b
3
+ metadata.gz: 505a70f70933a819f67d4fa163985fe75115233481959ff1742cffc61cac4adb
4
+ data.tar.gz: 2ae449691aa78c1008fedf802b5309cf0f74b29b75d08fa1e274335b0e0630e0
5
5
  SHA512:
6
- metadata.gz: 8500cc4964f737ee94d3a28ceb1f10c1b2996e29171f04219ba7e0ed0039b996190a4d1ec57bbaae56d5bdf1eb8ae5a0422440f69561b6398cb1ab645651967d
7
- data.tar.gz: 9373aad646952bac2bb998744238f5ff7f143531c385df8e4cf391f429fe2560af3c37f6c60ad66b985cd99f0ecf2366701b2c3d284ea2438c4c5951be205e2f
6
+ metadata.gz: 46653d3f35be042a2f0c10333e241cffc4c4ae64e10731b6e6b10769d9809e764eb8ebf4932b1ab402eb598781cde0531f55d0e16acde1d6bd34b5a5b2199d88
7
+ data.tar.gz: 17d7bbabe915ec23ca015a39806f275e4ae44f0d90d6b65b4f71a92666f6fb406f310bbdd6df69a2b9147bb738f4b76bbb102b2c0e4ee3f6ca01c5fb7a3cf77c
data/README.md CHANGED
@@ -50,6 +50,25 @@ Feature: Test the UDB3 labels API
50
50
  And the JSON response at "privacy" should be "public"
51
51
  ```
52
52
 
53
+ ```ruby
54
+ @api @images
55
+ Feature: Test the UDB3 image API
56
+
57
+ Background:
58
+ Given I am using the UDB3 development environment
59
+ And I am authorized as user "centraal_beheerder"
60
+ And I accept "application/json"
61
+
62
+ @imagecreate
63
+ Scenario: Create image
64
+ Given I set the form data properties to:
65
+ | description | logo |
66
+ | copyrightHolder | me |
67
+ | language | nl |
68
+ When I upload "file" from path "images/UDB.jpg" to "/images/"
69
+ Then the response status should be "201"
70
+ ```
71
+
53
72
  #### Benchmarking
54
73
 
55
74
  ```ruby
@@ -57,7 +76,7 @@ Given /^I am benchmarking$/
57
76
  ```
58
77
 
59
78
  ```ruby
60
- Then /^the elapsed time should be less than (#{CAPTURE_FLOAT}) seconds?$/
79
+ Then 'the elapsed time should be less than {float} second(s)'
61
80
  ```
62
81
 
63
82
  #### HTTP
@@ -83,11 +102,15 @@ Given /^I send "(.*?)" and accept "(.*?)"$/
83
102
  ```
84
103
 
85
104
  ```ruby
86
- Given /^I send "(.*?)" and accept (XML|JSON)$/
105
+ Given /^I send "(.*?)" and accept JSON$/
87
106
  ```
88
107
 
89
108
  ```ruby
90
- Given /^I send and accept (XML|JSON)$/
109
+ Given /^I send and accept JSON$/
110
+ ```
111
+
112
+ ```ruby
113
+ Given 'I set the form data properties to:'
91
114
  ```
92
115
 
93
116
  ```ruby
@@ -103,11 +126,19 @@ When /^I send a (GET|POST|PATCH|PUT|DELETE) request to "([^"]*)"(?: with paramet
103
126
  ```
104
127
 
105
128
  ```ruby
106
- Then /^the response status should( not)? be "(#{CAPTURE_INTEGER})"$/
129
+ When 'I upload {string} from path {string} to {string}"'
130
+ ```
131
+
132
+ ```ruby
133
+ Then 'the response status should be "{int}"'
134
+ ```
135
+
136
+ ```ruby
137
+ Then 'the response status should not be "{int}"'
107
138
  ```
108
139
 
109
140
  ```ruby
110
- Then /^the response body should be valid (XML|JSON)$/
141
+ Then /^the response body should be valid JSON$/
111
142
  ```
112
143
 
113
144
  #### Debugging
@@ -138,7 +169,7 @@ Examples for testing the [REST API](https://apidoc.uitdatabank.be) of
138
169
 
139
170
  Creating an organizer with a random name:
140
171
  ```ruby
141
- When /^I create an organizer with a random name of (#{CAPTURE_INTEGER}) characters?$/ do |characters|
172
+ When 'I create an organizer with a random name of {integer} character(s)' do |characters|
142
173
  name = Faker::Lorem.characters(characters)
143
174
  steps %Q{
144
175
  Given I am using the UDB3 development environment
@@ -155,7 +186,7 @@ end
155
186
 
156
187
  Creating a role with a random name:
157
188
  ```ruby
158
- When /^I create a role with a random name of (#{CAPTURE_INTEGER}) characters?$/ do |characters|
189
+ When 'I create a role with a random name of {integer} character(s)' do |characters|
159
190
  name = Faker::Lorem.characters(characters)
160
191
  steps %Q{
161
192
  Given I am using the UDB3 development environment
@@ -2,7 +2,7 @@ Given /^I am benchmarking$/ do
2
2
  @scenario_start_time = Time.now
3
3
  end
4
4
 
5
- Then /^the elapsed time should be less than (#{CAPTURE_FLOAT}) seconds?$/ do |time|
5
+ Then 'the elapsed time should be less than {float} second(s)' do |time|
6
6
  elapsed = Time.now - @scenario_start_time
7
7
 
8
8
  expect(elapsed).to be < time
@@ -12,8 +12,6 @@ Then /^show me the( unparsed)? response$/ do |unparsed|
12
12
  if unparsed.nil?
13
13
  if response[:headers]['content-type'][0] =~ /json/
14
14
  body = JSON.pretty_generate(JSON.parse(response[:body]))
15
- elsif response[:headers]['content-type'][0] =~ /xml/
16
- body = Nokogiri::XML(response[:body])
17
15
  end
18
16
  end
19
17
 
@@ -3,6 +3,7 @@ After do
3
3
  clear_parameters
4
4
  clear_headers
5
5
  clear_payload
6
+ clear_multipart_payload
6
7
  clear_request
7
8
  clear_response
8
9
  end
@@ -1,4 +1,3 @@
1
- require 'nokogiri'
2
1
  require 'json_spec'
3
2
 
4
3
  Given /^I set headers?:$/ do |hdrs|
@@ -35,19 +34,19 @@ Given /^I send "(.*?)" and accept "(.*?)"$/ do |content_type, accept_type|
35
34
  }
36
35
  end
37
36
 
38
- Given /^I send "(.*?)" and accept (XML|JSON)$/ do |content_type, accept_type|
37
+ Given /^I send "(.*?)" and accept JSON$/ do |content_type|
39
38
  steps %Q{
40
39
  Given I set headers:
41
- | Content-Type | #{content_type} |
42
- | Accept | application/#{accept_type.downcase} |
40
+ | Content-Type | #{content_type} |
41
+ | Accept | application/json |
43
42
  }
44
43
  end
45
44
 
46
- Given /^I send and accept (XML|JSON)$/ do |type|
45
+ Given /^I send and accept JSON$/ do
47
46
  steps %Q{
48
47
  Given I set headers:
49
- | Content-Type | application/#{type.downcase} |
50
- | Accept | application/#{type.downcase} |
48
+ | Content-Type | application/json |
49
+ | Accept | application/json |
51
50
  }
52
51
  end
53
52
 
@@ -69,6 +68,13 @@ Given(/^I set the JSON request payload from "(.*?)"$/) do |filename|
69
68
  end
70
69
  end
71
70
 
71
+ Given 'I set the form data properties to:' do |table|
72
+ table.rows_hash.each { |name, value| add_multipart_payload(name, value) }
73
+
74
+ remove_header('Content-Type')
75
+ add_multipart_payload('multipart', true)
76
+ end
77
+
72
78
  When /^I send a (GET|POST|PATCH|PUT|DELETE) request to "([^"]*)"(?: with parameters?:)?$/ do |*args|
73
79
  method = args.shift
74
80
  endpoint = resolve(args.shift)
@@ -89,23 +95,35 @@ When /^I send a (GET|POST|PATCH|PUT|DELETE) request to "([^"]*)"(?: with paramet
89
95
  perform_request(method, request_url)
90
96
  end
91
97
 
98
+ When 'I upload {string} from path {string} to {string}' do |key, filename, endpoint|
99
+ method = 'post'
100
+ payload_key = key
101
+ path = "#{Dir.pwd}/features/support/data/#{filename}"
102
+
103
+ request_url = URI.join(url, URI::encode(endpoint)).to_s
104
+
105
+ if File.file? path
106
+ remove_header('Content-Type')
107
+ add_multipart_payload(payload_key, File.new(path, 'rb'))
108
+ else
109
+ raise "File not found: '#{path}'"
110
+ end
111
+
112
+ perform_request(method, request_url)
113
+ end
114
+
92
115
  When /^(?:I )?keep the value of the (?:JSON|json)(?: response)?(?: at "(.*)")? as "(.*)"$/ do |path, key|
93
116
  JsonSpec.memorize(key, parse_json(last_json, path))
94
117
  end
95
118
 
96
- Then /^the response status should( not)? be "(#{CAPTURE_INTEGER})"$/ do |negative, status_code|
97
- if negative
98
- expect(response[:status]).not_to eq(status_code)
99
- else
100
- expect(response[:status]).to eq(status_code)
101
- end
119
+ Then 'the response status should be "{int}"' do |status_code|
120
+ expect(response[:status]).to eq(status_code)
102
121
  end
103
122
 
104
- Then /^the response body should be valid (XML|JSON)$/ do |type|
105
- case type
106
- when 'XML'
107
- expect { Nokogiri::XML(response[:body]) { |config| config.strict } }.not_to raise_error
108
- when 'JSON'
109
- expect { JSON.parse(response[:body]) }.not_to raise_error
110
- end
123
+ Then 'the response status should not be "{int}"' do |status_code|
124
+ expect(response[:status]).not_to eq(status_code)
125
+ end
126
+
127
+ Then /^the response body should be valid JSON$/ do
128
+ expect { JSON.parse(response[:body]) }.not_to raise_error
111
129
  end
@@ -1,5 +1,5 @@
1
1
  module Cucumber
2
2
  module Http
3
- VERSION = "0.4.0"
3
+ VERSION = "0.7.0"
4
4
  end
5
5
  end
@@ -0,0 +1,21 @@
1
+ module Cucumber
2
+ module Http
3
+ module Payload
4
+ def multipart_payload
5
+ @multipart_payload ||= {}
6
+ end
7
+
8
+ def add_multipart_payload(key, value)
9
+ multipart_payload[key] = value
10
+ end
11
+
12
+ def remove_multipart_payload(key)
13
+ multipart_payload.tap { |p| p.delete(key)}
14
+ end
15
+
16
+ def clear_multipart_payload
17
+ multipart_payload.clear
18
+ end
19
+ end
20
+ end
21
+ end
@@ -14,12 +14,14 @@ module Cucumber
14
14
  def perform_request(method, path)
15
15
  add_header('params', parameters)
16
16
 
17
+ request_payload = multipart_payload.empty? ? payload : multipart_payload
18
+
17
19
  begin
18
20
  r = RestClient::Request.execute(
19
21
  method: method.downcase,
20
22
  url: path,
21
23
  headers: headers,
22
- payload: payload
24
+ payload: request_payload
23
25
  )
24
26
  rescue RestClient::Exception => e
25
27
  r = e.response
@@ -27,13 +29,16 @@ module Cucumber
27
29
 
28
30
  set_request('url', path)
29
31
  set_request('method', method.upcase)
30
- set_request('headers', headers)
32
+ set_request('headers', headers.tap { |hdrs| hdrs.delete('params')})
31
33
  set_request('parameters', parameters)
32
- set_request('payload', payload)
34
+ set_request('payload', request_payload)
33
35
 
34
36
  set_response('status', r.code)
35
37
  set_response('body', r.body)
36
38
  set_response('headers', r.raw_headers)
39
+
40
+ clear_multipart_payload
41
+ clear_payload
37
42
  end
38
43
 
39
44
  def clear_request
@@ -2,6 +2,7 @@ require_relative 'world_extensions/json_spec_interface'
2
2
  require_relative 'world_extensions/headers'
3
3
  require_relative 'world_extensions/parameters'
4
4
  require_relative 'world_extensions/payload'
5
+ require_relative 'world_extensions/multipart_payload'
5
6
  require_relative 'world_extensions/request'
6
7
  require_relative 'world_extensions/response'
7
8
  require_relative 'world_extensions/url'
data/lib/cucumber/http.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'cucumber/http/transforms'
2
1
  require 'cucumber/http/world_extensions'
3
2
  require 'cucumber/http/hooks'
4
3
  require 'cucumber/http/http_steps'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kristof Willaert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-21 00:00:00.000000000 Z
11
+ date: 2022-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cucumber
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.0'
19
+ version: '3.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.0'
26
+ version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: json_spec
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.0'
55
- - !ruby/object:Gem::Dependency
56
- name: nokogiri
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '1.6'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '1.6'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: faker
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +72,14 @@ dependencies:
86
72
  requirements:
87
73
  - - "~>"
88
74
  - !ruby/object:Gem::Version
89
- version: '10.0'
75
+ version: '13.0'
90
76
  type: :development
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
80
  - - "~>"
95
81
  - !ruby/object:Gem::Version
96
- version: '10.0'
82
+ version: '13.0'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: bundler
99
85
  requirement: !ruby/object:Gem::Requirement
@@ -108,7 +94,7 @@ dependencies:
108
94
  - - "~>"
109
95
  - !ruby/object:Gem::Version
110
96
  version: '1.9'
111
- description: Cucumber steps to easily test external XML and JSON APIs
97
+ description: Cucumber steps to easily test external JSON APIs
112
98
  email:
113
99
  - kristof.willaert@publiq.be
114
100
  executables: []
@@ -121,11 +107,11 @@ files:
121
107
  - lib/cucumber/http/debug_steps.rb
122
108
  - lib/cucumber/http/hooks.rb
123
109
  - lib/cucumber/http/http_steps.rb
124
- - lib/cucumber/http/transforms.rb
125
110
  - lib/cucumber/http/version.rb
126
111
  - lib/cucumber/http/world_extensions.rb
127
112
  - lib/cucumber/http/world_extensions/headers.rb
128
113
  - lib/cucumber/http/world_extensions/json_spec_interface.rb
114
+ - lib/cucumber/http/world_extensions/multipart_payload.rb
129
115
  - lib/cucumber/http/world_extensions/parameters.rb
130
116
  - lib/cucumber/http/world_extensions/payload.rb
131
117
  - lib/cucumber/http/world_extensions/request.rb
@@ -153,5 +139,5 @@ requirements: []
153
139
  rubygems_version: 3.1.2
154
140
  signing_key:
155
141
  specification_version: 4
156
- summary: Cucumber steps to easily test XML and JSON APIs
142
+ summary: Cucumber steps to easily test JSON APIs
157
143
  test_files: []
@@ -1,7 +0,0 @@
1
- CAPTURE_INTEGER = Transform /^(-?\d+)$/ do |number_string|
2
- number_string.to_i
3
- end
4
-
5
- CAPTURE_FLOAT = Transform /^(-?[\d.]+)$/ do |number_string|
6
- number_string.to_f
7
- end