cucumber-blendle-steps 0.3.0 → 0.3.1
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 +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/cucumber/blendle/steps/model_steps.rb +50 -0
- data/lib/cucumber/blendle/steps/resource_steps.rb +25 -1
- data/lib/cucumber/blendle/steps/rest_steps.rb +56 -2
- data/lib/cucumber/blendle/support/dump.rb +1 -1
- data/lib/cucumber/blendle/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0be27a2993064f1cf9e8e38c15565a7e133f7582
|
4
|
+
data.tar.gz: 1448623821ea97fe10e5af636ba4cc0180f35780
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 581b547e5072a223724382378f1522e27033203cb11d6651c2bbde4b09c4213b9525f4d7eb4d04a29c6cf5842223aaaf1993f7f0c1d662e7d02cd2ce6724655c
|
7
|
+
data.tar.gz: c9b38af4d4ad9ab240929419582e8e11a52d7e0872052ccd71fc92d531a071c6fc728a42f3498d3a3c641ea5a17a25c0db7c7ae44f26b71bc55c6914e74d9703
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
**v0.3.1** – 2015-12-12
|
2
|
+
|
3
|
+
* add new model steps [5275fcf]
|
4
|
+
* show last_response.body if status code assertion fails [d0a6d0f]
|
5
|
+
* show error message if Halidator JSON parsing fails [9e2e6ab]
|
6
|
+
* don't create mkmf.log when copying output to clipboard [59c63f4]
|
7
|
+
* add descriptions to all steps [37d5bd4]
|
8
|
+
|
1
9
|
**v0.3.0** – 2015-12-4
|
2
10
|
|
3
11
|
* add support for [type-casting model values](https://github.com/blendle/cucumber-blendle-steps/pull/2)
|
@@ -1,10 +1,16 @@
|
|
1
1
|
require 'active_support/core_ext/hash/keys'
|
2
|
+
require 'active_support/core_ext/hash/compact'
|
2
3
|
require 'active_support/core_ext/object/blank'
|
3
4
|
require 'active_support/core_ext/string/inflections'
|
4
5
|
require 'sequel'
|
5
6
|
|
6
7
|
# rubocop:disable Lint/Eval,Metrics/LineLength,Lint/UselessAssignment
|
7
8
|
|
9
|
+
# * Given the following items exist:
|
10
|
+
# | uid | price |
|
11
|
+
# | hello | 100 |
|
12
|
+
# | world | 10 |
|
13
|
+
#
|
8
14
|
Given(/^the following (\S+) exist:$/) do |object, table|
|
9
15
|
table.hashes.each do |row|
|
10
16
|
hash = parse_row(row)
|
@@ -14,6 +20,33 @@ Given(/^the following (\S+) exist:$/) do |object, table|
|
|
14
20
|
end
|
15
21
|
end
|
16
22
|
|
23
|
+
# * Given the item with uid "hello" exists
|
24
|
+
# * Given the item with uid "hello" and price "100" exists
|
25
|
+
# * Given the item with uid "hello" and the price "100" exists
|
26
|
+
#
|
27
|
+
Given(/^the (\S+) with (\S+) "([^"]*)"(?: and(?: the)? (\S+) "([^"]*)")? exists$/) do |object, attribute1, value1, attribute2, value2|
|
28
|
+
hash = { attribute1 => value1, attribute2 => value2 }.symbolize_keys.compact
|
29
|
+
|
30
|
+
assert eval("#{object.singularize.capitalize}.create(hash)")
|
31
|
+
step %(the following #{object.singularize} should exist:), table([hash.keys, hash.values])
|
32
|
+
end
|
33
|
+
|
34
|
+
# * Given the item with uid "hello" and the following description:
|
35
|
+
# """
|
36
|
+
# hello world
|
37
|
+
# """
|
38
|
+
#
|
39
|
+
Given(/^the (\S+) with (\S+) "([^"]*)" and the following (\S+):$/) do |object, attribute1, value1, attribute2, value2|
|
40
|
+
hash = { attribute1 => value1, attribute2 => value2 }.symbolize_keys
|
41
|
+
|
42
|
+
assert eval("#{object.singularize.capitalize}.create(hash)")
|
43
|
+
step %(the following #{object.singularize} should exist:), table([hash.keys, hash.values])
|
44
|
+
end
|
45
|
+
|
46
|
+
# * Then the item with uid "hello" should exist
|
47
|
+
# * Then the item with uid "hello" should not exist
|
48
|
+
# * Then the item with labels (Array) "[10234, 64325]" should exist
|
49
|
+
#
|
17
50
|
Then(/^the (\S+) with (\S+)(?: \((\S+)\))? "([^"]*)" should( not)? exist$/) do |object, attribute, type, value, negate|
|
18
51
|
hash = parse_row("#{attribute} (#{type})" => value)
|
19
52
|
assertion = negate ? 'blank?' : 'present?'
|
@@ -22,6 +55,11 @@ Then(/^the (\S+) with (\S+)(?: \((\S+)\))? "([^"]*)" should( not)? exist$/) do |
|
|
22
55
|
%(#{object.capitalize} not found \(#{attribute}: #{value}\))
|
23
56
|
end
|
24
57
|
|
58
|
+
# * Then the following items should exist:
|
59
|
+
# | uid | price |
|
60
|
+
# | hello | 100 |
|
61
|
+
# * Then the following items should not exist:
|
62
|
+
#
|
25
63
|
Then(/^the following (\S+) should( not)? exist:$/) do |object, negate, table|
|
26
64
|
assertion = negate ? 'blank?' : 'present?'
|
27
65
|
|
@@ -32,6 +70,18 @@ Then(/^the following (\S+) should( not)? exist:$/) do |object, negate, table|
|
|
32
70
|
end
|
33
71
|
end
|
34
72
|
|
73
|
+
# parse_row
|
74
|
+
#
|
75
|
+
# Given a Cucumber table row, parses the type "numbers (Array)" and converts the
|
76
|
+
# string representation of the value "[1, 2, 3]" into a Sequel pg_array.
|
77
|
+
#
|
78
|
+
# @todo Rename method to a more sensible name
|
79
|
+
# @todo Move method to helper file
|
80
|
+
# @todo Add more types (Integer)
|
81
|
+
#
|
82
|
+
# @param [Object] row in Cucumber::Table
|
83
|
+
# @return [Hash] hash representation of key/values in table
|
84
|
+
#
|
35
85
|
def parse_row(row)
|
36
86
|
hash = row.map do |attribute, value|
|
37
87
|
value = case attribute[/\s\((\w+)\)$/, 1]
|
@@ -1,16 +1,25 @@
|
|
1
1
|
# rubocop:disable Metrics/LineLength
|
2
2
|
|
3
|
+
# * When the client does a GET request to the "items" resource
|
4
|
+
#
|
3
5
|
When(/^the client does a (GET|POST|DELETE) request to the "([^"]*)" resource$/) do |method, resource|
|
4
6
|
step %(the client does a #{method} request to the "#{resource}" resource with these parameters:), table([[]])
|
5
7
|
end
|
6
8
|
|
9
|
+
# * When the client does a GET request to the "item" resource with the template variable "item_uid" set to "hello"
|
10
|
+
#
|
7
11
|
When(/^the client does a (GET|POST|DELETE) request to the "([^"]*)" resource with the template variable "([^"]*)" set to "([^"]*)"$/) do |method, resource, key, value|
|
8
12
|
tables = [%w(key value), [key, value]]
|
9
13
|
|
10
14
|
step %(the client does a #{method} request to the "#{resource}" resource with these parameters:), table(tables)
|
11
15
|
end
|
12
16
|
|
13
|
-
When
|
17
|
+
# * When the client does a GET request to the "item" resource with these template variables:
|
18
|
+
# | key | value |
|
19
|
+
# | item_uid | hello |
|
20
|
+
# | user_uid | bartsimpson |
|
21
|
+
#
|
22
|
+
When(/^the client does a (GET|POST|DELETE) request to the "([^"]*)" resource with these template variables:$/) do |method, resource, table|
|
14
23
|
params = {}
|
15
24
|
current_accept_header = current_session.instance_variable_get(:@headers)['Accept']
|
16
25
|
|
@@ -30,6 +39,14 @@ When(/^the client does a (GET|POST|DELETE) request to the "([^"]*)" resource wit
|
|
30
39
|
step %(the client does a #{method} request to "#{url}")
|
31
40
|
end
|
32
41
|
|
42
|
+
# When the client does a POST request to the "items" resource with the following content:
|
43
|
+
# """json
|
44
|
+
# {
|
45
|
+
# "uid": "hello",
|
46
|
+
# "price": 100
|
47
|
+
# }
|
48
|
+
# """
|
49
|
+
#
|
33
50
|
When(/^the client does a (GET|POST|DELETE) request to the "([^"]*)" resource with the following content:$/) do |method, resource, content|
|
34
51
|
body = JSON.parse(get('/api').body)
|
35
52
|
api = HyperResource.from_body(body)
|
@@ -38,6 +55,13 @@ When(/^the client does a (GET|POST|DELETE) request to the "([^"]*)" resource wit
|
|
38
55
|
step %(the client does a #{method} request to "#{url}" with the following content:), content
|
39
56
|
end
|
40
57
|
|
58
|
+
# When the client does a PUT request to the "item" resource with the template variable "item_uid" set to "hello" and the following content:
|
59
|
+
# """json
|
60
|
+
# {
|
61
|
+
# "price": 10
|
62
|
+
# }
|
63
|
+
# """
|
64
|
+
#
|
41
65
|
When(/^the client does a (POST|PUT) request to the "([^"]*)" resource with the template variable "([^"]*)" set to "([^"]*)" and the following content:$/) do |method, resource, key, value, content|
|
42
66
|
body = JSON.parse(get('/api').body)
|
43
67
|
api = HyperResource.from_body(body)
|
@@ -3,32 +3,58 @@
|
|
3
3
|
require 'halidator'
|
4
4
|
require 'rack/utils'
|
5
5
|
|
6
|
+
# * When the client does a GET request to "/items"
|
7
|
+
#
|
6
8
|
When('the client does a GET request to "$1"') do |path|
|
7
9
|
get(path, {}, {})
|
8
10
|
end
|
9
11
|
|
12
|
+
# * When the client provides the header "Accept: application/hal+json"
|
13
|
+
#
|
10
14
|
When(/^the client provides the header ["']([^"']*)["']$/) do |header|
|
11
15
|
name, value = header.split(/\s*:\s*/)
|
12
16
|
header(name, value)
|
13
17
|
end
|
14
18
|
|
19
|
+
# * When the client does a DELETE request to "/item/hello"
|
20
|
+
#
|
15
21
|
When(/^the client does a (POST|DELETE) request to "([^"]*)"$/) do |method, path|
|
16
22
|
send(method.downcase, path, {})
|
17
23
|
end
|
18
24
|
|
25
|
+
# * When the client does a POST request to "/items" with the following content:
|
26
|
+
# """json
|
27
|
+
# {
|
28
|
+
# "uid": "hello",
|
29
|
+
# "price": 100
|
30
|
+
# }
|
31
|
+
# """
|
32
|
+
#
|
19
33
|
When(/^the client does a (POST|PUT) request to "([^"]*)" with the following content:$/) do |method, path, content|
|
20
34
|
send(method.downcase, path, content.strip)
|
21
35
|
end
|
22
36
|
|
37
|
+
# * Then the status code should be "200" (OK)
|
38
|
+
# * Then the status code should be "204" (No Content)
|
39
|
+
#
|
23
40
|
Then(/^the status code should be "(\d+)" \((.+)\)/) do |status_code, status_message|
|
24
|
-
assert_equal status_code.to_i, last_response.status
|
41
|
+
assert_equal status_code.to_i, last_response.status, last_response.body
|
25
42
|
assert_equal status_message, Rack::Utils::HTTP_STATUS_CODES[status_code.to_i]
|
26
43
|
end
|
27
44
|
|
45
|
+
# * Then the response should contain the header "Location" with value "https://example.org/item/hello"
|
46
|
+
#
|
28
47
|
Then('the response should contain the header "$" with value "$"') do |header, value|
|
29
48
|
assert_equal last_response.headers[header], value
|
30
49
|
end
|
31
50
|
|
51
|
+
# Then the response should be of type "application/json" with content:
|
52
|
+
# """json
|
53
|
+
# {
|
54
|
+
# "uid": "hello"
|
55
|
+
# }
|
56
|
+
# """
|
57
|
+
#
|
32
58
|
Then(/^the response should be of type "([^"]*)" with content:$/) do |content_type, content|
|
33
59
|
dump last_response.body
|
34
60
|
|
@@ -36,6 +62,12 @@ Then(/^the response should be of type "([^"]*)" with content:$/) do |content_typ
|
|
36
62
|
assert_equal content, last_response.body
|
37
63
|
end
|
38
64
|
|
65
|
+
# * Then the response should be JSON:
|
66
|
+
# """json
|
67
|
+
# {
|
68
|
+
# "uid": "hello"
|
69
|
+
# }
|
70
|
+
# """
|
39
71
|
Then(/^the response should be JSON:$/) do |json|
|
40
72
|
dump last_response.body
|
41
73
|
|
@@ -43,12 +75,32 @@ Then(/^the response should be JSON:$/) do |json|
|
|
43
75
|
expect(last_response.body).to be_json_eql(json)
|
44
76
|
end
|
45
77
|
|
78
|
+
# * Then the response should be HAL/JSON:
|
79
|
+
# """json
|
80
|
+
# {
|
81
|
+
# "uid": "hello"
|
82
|
+
# }
|
83
|
+
# """
|
84
|
+
# * Then the response should be HAL/JSON (disregarding value of "random_id"):
|
85
|
+
# """json
|
86
|
+
# {
|
87
|
+
# "uid": "hello",
|
88
|
+
# "random_id": 57303667592
|
89
|
+
# }
|
90
|
+
# """
|
91
|
+
#
|
46
92
|
Then(%r{^the response should be HAL/JSON(?: \(disregarding values? of "([^"]*)"\))?:$}) do |disregard, json|
|
47
93
|
dump last_response.body
|
48
94
|
|
49
95
|
assert_match %r{^application/hal\+json(;.*)?$}, last_response.headers['Content-Type']
|
50
96
|
|
51
|
-
hal =
|
97
|
+
hal = nil
|
98
|
+
begin
|
99
|
+
hal = Halidator.new(last_response.body)
|
100
|
+
rescue JSON::ParserError => e
|
101
|
+
assert false, [e.message, last_response.body].join("\n")
|
102
|
+
end
|
103
|
+
|
52
104
|
assert hal.valid?, "Halidator errors: #{hal.errors.join(',')}"
|
53
105
|
|
54
106
|
match = be_json_eql(json)
|
@@ -61,6 +113,8 @@ Then(%r{^the response should be HAL/JSON(?: \(disregarding values? of "([^"]*)"\
|
|
61
113
|
expect(last_response.body).to match
|
62
114
|
end
|
63
115
|
|
116
|
+
# * Then the response contains the "Location" header with value "https://example.org/item/hello"
|
117
|
+
#
|
64
118
|
Then(/^the response contains the "(.*?)" header with value "(.*?)"$/) do |header, value|
|
65
119
|
assert_equal value, last_response.headers[header]
|
66
120
|
end
|
@@ -9,7 +9,7 @@ require 'json'
|
|
9
9
|
def dump(data)
|
10
10
|
return unless ENV['DUMP']
|
11
11
|
require 'mkmf'
|
12
|
-
if %w(clipboard cb).include?(ENV['DUMP']) &&
|
12
|
+
if %w(clipboard cb).include?(ENV['DUMP']) && find_executable0('pbcopy')
|
13
13
|
IO.popen(['pbcopy'], 'w') { |f| f << pretty_sorted_json(data) }
|
14
14
|
elsif %w(file tmp).include?(ENV['DUMP'])
|
15
15
|
File.open('/tmp/dump', 'w') { |f| f << pretty_sorted_json(data) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cucumber-blendle-steps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean Mertz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|