cucumber-http 0.6.0 → 0.7.0

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
2
  SHA256:
3
- metadata.gz: c75c0db8674ba9d8fd6b0cf5c1d9c7f8f8854f37a800dad01fe8d43b744beecf
4
- data.tar.gz: f8e1726ef35a5148f3327b94a8633b670dca929cf6dfc6193827c2a38df3f0c2
3
+ metadata.gz: 505a70f70933a819f67d4fa163985fe75115233481959ff1742cffc61cac4adb
4
+ data.tar.gz: 2ae449691aa78c1008fedf802b5309cf0f74b29b75d08fa1e274335b0e0630e0
5
5
  SHA512:
6
- metadata.gz: 605f04856f7872c474d30fc030cb0686bce7f7a7a2dc15e94e0f3c9c2905e6a891da62bad1d05df077ff380e66bdd66e375a85e9c981b3c2e71808891c886e28
7
- data.tar.gz: 61770eb34b0b42d4835c7ed090e1811f5e8bae21718d7b17e474a9a64b63c18cd951bdd50ef153f09d057dc97c674884b87048c7db14995b5dd711f12cb6119c
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
@@ -90,6 +109,10 @@ Given /^I send "(.*?)" and accept JSON$/
90
109
  Given /^I send and accept JSON$/
91
110
  ```
92
111
 
112
+ ```ruby
113
+ Given 'I set the form data properties to:'
114
+ ```
115
+
93
116
  ```ruby
94
117
  Given /^I set the JSON request payload to:$/
95
118
  ```
@@ -102,6 +125,10 @@ Given /^I set the JSON request payload from "(.*?)"$/
102
125
  When /^I send a (GET|POST|PATCH|PUT|DELETE) request to "([^"]*)"(?: with parameters?:)?$/
103
126
  ```
104
127
 
128
+ ```ruby
129
+ When 'I upload {string} from path {string} to {string}"'
130
+ ```
131
+
105
132
  ```ruby
106
133
  Then 'the response status should be "{int}"'
107
134
  ```
@@ -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
@@ -68,6 +68,13 @@ Given(/^I set the JSON request payload from "(.*?)"$/) do |filename|
68
68
  end
69
69
  end
70
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
+
71
78
  When /^I send a (GET|POST|PATCH|PUT|DELETE) request to "([^"]*)"(?: with parameters?:)?$/ do |*args|
72
79
  method = args.shift
73
80
  endpoint = resolve(args.shift)
@@ -88,6 +95,23 @@ When /^I send a (GET|POST|PATCH|PUT|DELETE) request to "([^"]*)"(?: with paramet
88
95
  perform_request(method, request_url)
89
96
  end
90
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
+
91
115
  When /^(?:I )?keep the value of the (?:JSON|json)(?: response)?(?: at "(.*)")? as "(.*)"$/ do |path, key|
92
116
  JsonSpec.memorize(key, parse_json(last_json, path))
93
117
  end
@@ -1,5 +1,5 @@
1
1
  module Cucumber
2
2
  module Http
3
- VERSION = "0.6.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'
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.6.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-02-11 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
@@ -111,6 +111,7 @@ files:
111
111
  - lib/cucumber/http/world_extensions.rb
112
112
  - lib/cucumber/http/world_extensions/headers.rb
113
113
  - lib/cucumber/http/world_extensions/json_spec_interface.rb
114
+ - lib/cucumber/http/world_extensions/multipart_payload.rb
114
115
  - lib/cucumber/http/world_extensions/parameters.rb
115
116
  - lib/cucumber/http/world_extensions/payload.rb
116
117
  - lib/cucumber/http/world_extensions/request.rb