cucumber-http 0.1.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +135 -1
- data/lib/cucumber/http/debug_steps.rb +20 -9
- data/lib/cucumber/http/hooks.rb +1 -0
- data/lib/cucumber/http/http_steps.rb +1 -1
- data/lib/cucumber/http/version.rb +1 -1
- data/lib/cucumber/http/world_extensions/headers.rb +2 -2
- data/lib/cucumber/http/world_extensions/parameters.rb +2 -2
- data/lib/cucumber/http/world_extensions/request.rb +19 -1
- data/lib/cucumber/http/world_extensions.rb +1 -1
- metadata +8 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3f339b7fcb6e66665649610987e764d35477b0863e41f858c655b9b42f2dd3d0
|
4
|
+
data.tar.gz: 649424fb563c9694a4fbc3abf55c84af851967b2c888f86eb44f63b69fbcf6bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 228e304b1837735dc8c95b3f261c40ee29c8463d9e839de284dfd40b27ff495449c0d2b1890946984d76edfbad0f1691925bbc5cb5a841f853b0fbccec6028b7
|
7
|
+
data.tar.gz: 91d3f65830cadcbf13b7442c746183baede530983d37b4c5ede0f4b6e1064e9e04f083189139a055c0ddf54bbe32a180cd096ea866fb9a4bab02a73695ba4fa2
|
data/README.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# Cucumber::Http
|
2
2
|
|
3
|
-
|
3
|
+
This library provides Cucumber steps to test JSON HTTP API's. The
|
4
|
+
steps are rather verbose (technical) in nature, somewhat contrary to the
|
5
|
+
Cucumber philosophy of high-level, descriptive tests. This is intentional as
|
6
|
+
it allows these steps to be bundled in larger, more high-level tests by
|
7
|
+
non-developers.
|
4
8
|
|
5
9
|
## Installation
|
6
10
|
|
@@ -20,6 +24,136 @@ Or install it yourself as:
|
|
20
24
|
|
21
25
|
## Usage
|
22
26
|
|
27
|
+
### Bundled steps
|
28
|
+
|
29
|
+
#### Examples
|
30
|
+
|
31
|
+
Examples for testing the [REST API](https://apidoc.uitdatabank.be) of
|
32
|
+
[UiTDatabank](https://www.uitdatabank.be):
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
@api @labels
|
36
|
+
Feature: Test the UDB3 labels API
|
37
|
+
|
38
|
+
Background:
|
39
|
+
Given I am using the UDB3 development environment
|
40
|
+
And I am authorized as user "centraal_beheerder"
|
41
|
+
And I send and accept JSON
|
42
|
+
|
43
|
+
@labelcreate
|
44
|
+
Scenario: Create label
|
45
|
+
When I create a label with a random name of 10 characters
|
46
|
+
And I keep the value of the JSON response at "uuid" as "uuid"
|
47
|
+
And I send a GET request to "/labels/%{uuid}"
|
48
|
+
Then the response status should be "200"
|
49
|
+
And the JSON response at "visibility" should be "visible"
|
50
|
+
And the JSON response at "privacy" should be "public"
|
51
|
+
```
|
52
|
+
|
53
|
+
#### Benchmarking
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
Given /^I am benchmarking$/
|
57
|
+
```
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
Then /^the elapsed time should be less than (#{CAPTURE_FLOAT}) seconds?$/
|
61
|
+
```
|
62
|
+
|
63
|
+
#### HTTP
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
Given /^I set headers?:$/
|
67
|
+
```
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
Given /^I send "(.*?)" and accept (XML|JSON)$/
|
71
|
+
```
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
Given /^I send and accept (XML|JSON)$/
|
75
|
+
```
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
Given /^I set the JSON request payload to:$/
|
79
|
+
```
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
Given /^I set the JSON request payload from "(.*?)"$/
|
83
|
+
```
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
When /^I send a (GET|POST|PATCH|PUT|DELETE) request to "([^"]*)"(?: with parameters?:)?$/
|
87
|
+
```
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
Then /^the response status should( not)? be "(#{CAPTURE_INTEGER})"$/
|
91
|
+
```
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
Then /^the response body should be valid (XML|JSON)$/
|
95
|
+
```
|
96
|
+
|
97
|
+
#### Debugging
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
Then /^show me the( unparsed)? response$/
|
101
|
+
```
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
Then /^show me the kept values?$/
|
105
|
+
```
|
106
|
+
|
107
|
+
#### JSON (through JsonSpec)
|
108
|
+
|
109
|
+
These steps are documented in the [json_spec README](https://github.com/collectiveidea/json_spec#cucumber)
|
110
|
+
|
111
|
+
### Making larger, more descriptive tests
|
112
|
+
|
113
|
+
The steps in this library are overly technical for use in Cucumber as a communication
|
114
|
+
tool between developers and business people. They are meant to be encapsulated in
|
115
|
+
larger, more general steps through the use of the `steps` method in Cucumber.
|
116
|
+
|
117
|
+
This allows easier reuse of code and the ability for non-developers to write
|
118
|
+
requirements.
|
119
|
+
|
120
|
+
Examples for testing the [REST API](https://apidoc.uitdatabank.be) of
|
121
|
+
[UiTDatabank](https://www.uitdatabank.be):
|
122
|
+
|
123
|
+
Creating an organizer with a random name:
|
124
|
+
```ruby
|
125
|
+
When /^I create an organizer with a random name of (#{CAPTURE_INTEGER}) characters?$/ do |characters|
|
126
|
+
name = Faker::Lorem.characters(characters)
|
127
|
+
steps %Q{
|
128
|
+
Given I am using the UDB3 development environment
|
129
|
+
And I am authorized as user "centraal_beheerder"
|
130
|
+
And I send and accept JSON
|
131
|
+
When I set the JSON request payload to:
|
132
|
+
"""
|
133
|
+
{"mainLanguage":"nl","website":"https://www.#{name}.be","name":"#{name}","contact":[]}
|
134
|
+
"""
|
135
|
+
And I send a POST request to "/organizers/"
|
136
|
+
}
|
137
|
+
end
|
138
|
+
```
|
139
|
+
|
140
|
+
Creating a role with a random name:
|
141
|
+
```ruby
|
142
|
+
When /^I create a role with a random name of (#{CAPTURE_INTEGER}) characters?$/ do |characters|
|
143
|
+
name = Faker::Lorem.characters(characters)
|
144
|
+
steps %Q{
|
145
|
+
Given I am using the UDB3 development environment
|
146
|
+
And I am authorized as user "centraal_beheerder"
|
147
|
+
And I send and accept JSON
|
148
|
+
When I set the JSON request payload to:
|
149
|
+
"""
|
150
|
+
{ "name": "#{name}" }
|
151
|
+
"""
|
152
|
+
And I send a POST request to "/roles/"
|
153
|
+
}
|
154
|
+
end
|
155
|
+
```
|
156
|
+
|
23
157
|
## Development
|
24
158
|
|
25
159
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
@@ -1,14 +1,25 @@
|
|
1
|
+
Then /^show me the request$/ do
|
2
|
+
puts "Method: " + request[:method]
|
3
|
+
puts "URL: " + request[:url]
|
4
|
+
puts "Parameters: " + request[:parameters].inspect
|
5
|
+
puts "Headers: " + request[:headers].inspect
|
6
|
+
puts "Payload: " + request[:payload].to_s
|
7
|
+
end
|
8
|
+
|
1
9
|
Then /^show me the( unparsed)? response$/ do |unparsed|
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
puts response[:body]
|
10
|
+
body = response[:body]
|
11
|
+
|
12
|
+
if unparsed.nil?
|
13
|
+
if response[:headers]['content-type'][0] =~ /json/
|
14
|
+
body = JSON.pretty_generate(JSON.parse(response[:body]))
|
15
|
+
elsif response[:headers]['content-type'][0] =~ /xml/
|
16
|
+
body = Nokogiri::XML(response[:body])
|
17
|
+
end
|
11
18
|
end
|
19
|
+
|
20
|
+
puts "Status: " + response[:status].to_s
|
21
|
+
puts "Headers: " + response[:headers].map { |k,v| { k.split('-').map(&:capitalize).join('-') => v.join } }.reduce(:merge).to_s
|
22
|
+
puts "Body: " + body
|
12
23
|
end
|
13
24
|
|
14
25
|
Then /^show me the kept values?$/ do
|
data/lib/cucumber/http/hooks.rb
CHANGED
@@ -44,7 +44,7 @@ When /^I send a (GET|POST|PATCH|PUT|DELETE) request to "([^"]*)"(?: with paramet
|
|
44
44
|
endpoint = resolve(args.shift)
|
45
45
|
params = args.shift
|
46
46
|
|
47
|
-
request_url = URI.join(url, endpoint).to_s
|
47
|
+
request_url = URI.join(url, URI::encode(endpoint)).to_s
|
48
48
|
|
49
49
|
unless params.nil?
|
50
50
|
if params.class == Cucumber::MultilineArgument::DataTable
|
@@ -6,11 +6,11 @@ module Cucumber
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def add_header(key, value)
|
9
|
-
headers[key
|
9
|
+
headers[key] = value
|
10
10
|
end
|
11
11
|
|
12
12
|
def remove_header(key)
|
13
|
-
headers.tap { |hdrs| hdrs.delete(key
|
13
|
+
headers.tap { |hdrs| hdrs.delete(key)}
|
14
14
|
end
|
15
15
|
|
16
16
|
def clear_headers
|
@@ -6,11 +6,11 @@ module Cucumber
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def add_parameter(key, value)
|
9
|
-
parameters[key
|
9
|
+
parameters[key] = value
|
10
10
|
end
|
11
11
|
|
12
12
|
def remove_parameter(key)
|
13
|
-
parameters.tap { |pars| pars.delete(key
|
13
|
+
parameters.tap { |pars| pars.delete(key)}
|
14
14
|
end
|
15
15
|
|
16
16
|
def clear_parameters
|
@@ -3,6 +3,14 @@ require 'rest-client'
|
|
3
3
|
module Cucumber
|
4
4
|
module Http
|
5
5
|
module Request
|
6
|
+
def request
|
7
|
+
@request ||= {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def set_request(key, value)
|
11
|
+
request[key.to_sym] = value
|
12
|
+
end
|
13
|
+
|
6
14
|
def perform_request(method, path)
|
7
15
|
add_header('params', parameters)
|
8
16
|
|
@@ -17,9 +25,19 @@ module Cucumber
|
|
17
25
|
r = e.response
|
18
26
|
end
|
19
27
|
|
28
|
+
set_request('url', path)
|
29
|
+
set_request('method', method.upcase)
|
30
|
+
set_request('headers', headers)
|
31
|
+
set_request('parameters', parameters)
|
32
|
+
set_request('payload', payload)
|
33
|
+
|
20
34
|
set_response('status', r.code)
|
21
35
|
set_response('body', r.body)
|
22
|
-
set_response('headers', r.
|
36
|
+
set_response('headers', r.raw_headers)
|
37
|
+
end
|
38
|
+
|
39
|
+
def clear_request
|
40
|
+
request.clear
|
23
41
|
end
|
24
42
|
end
|
25
43
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require_relative 'world_extensions/json_spec_interface'
|
2
|
-
require_relative 'world_extensions/url'
|
3
2
|
require_relative 'world_extensions/headers'
|
4
3
|
require_relative 'world_extensions/parameters'
|
5
4
|
require_relative 'world_extensions/payload'
|
6
5
|
require_relative 'world_extensions/request'
|
7
6
|
require_relative 'world_extensions/response'
|
7
|
+
require_relative 'world_extensions/url'
|
8
8
|
|
9
9
|
World(JsonSpecInterface)
|
10
10
|
World(Cucumber::Http::Headers)
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cucumber-http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.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:
|
11
|
+
date: 2021-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cucumber
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '2.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
26
|
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '2.0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '2.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: nokogiri
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -110,7 +110,7 @@ dependencies:
|
|
110
110
|
version: '1.9'
|
111
111
|
description: Cucumber steps to easily test external XML and JSON APIs
|
112
112
|
email:
|
113
|
-
- kristof.willaert@
|
113
|
+
- kristof.willaert@publiq.be
|
114
114
|
executables: []
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
@@ -150,8 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
150
|
- !ruby/object:Gem::Version
|
151
151
|
version: '0'
|
152
152
|
requirements: []
|
153
|
-
|
154
|
-
rubygems_version: 2.4.5
|
153
|
+
rubygems_version: 3.1.2
|
155
154
|
signing_key:
|
156
155
|
specification_version: 4
|
157
156
|
summary: Cucumber steps to easily test XML and JSON APIs
|