cucumber-api-steps 0.10 → 0.12
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.
- data/.gitignore +2 -1
- data/.rvmrc +1 -1
- data/.travis.yml +6 -0
- data/Gemfile +12 -1
- data/README.md +56 -4
- data/Rakefile +2 -0
- data/cucumber-api-steps.gemspec +5 -3
- data/features/authentication.feature +21 -0
- data/features/fixtures/fake_app.rb +33 -0
- data/features/header.feature +32 -0
- data/features/request.feature +25 -0
- data/features/response.feature +112 -0
- data/features/step_definitions/api_test_steps.rb +44 -0
- data/features/support/env.rb +20 -8
- data/lib/cucumber/api_steps.rb +118 -30
- data/lib/cucumber/api_steps/version.rb +1 -1
- metadata +23 -10
data/.gitignore
CHANGED
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm use
|
1
|
+
rvm use 1.9.3@cucumber-api-steps
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
#
|
1
|
+
# cucumber-api-steps
|
2
|
+
|
3
|
+
[](https://travis-ci.org/jayzes/cucumber-api-steps)
|
4
|
+
[](http://badge.fury.io/rb/cucumber-api-steps)
|
2
5
|
|
3
6
|
A set of [Cucumber](https://github.com/aslakhellesoy/cucumber) step definitions utilizing
|
4
7
|
[Rack-Test](https://github.com/brynary/rack-test) that ease basic
|
@@ -19,16 +22,65 @@ Add the following line to your Gemfile, preferably in the test or cucumber group
|
|
19
22
|
Then add the following line to your env.rb to make the step definitions available in your features:
|
20
23
|
|
21
24
|
require 'cucumber/api_steps'
|
22
|
-
|
25
|
+
|
23
26
|
# Usage
|
24
27
|
|
25
|
-
Still a work in progress. For now, read the api_steps.rb file or check out the [stashboard-rails](https://github.com/jayzes/stashboard-rails) project - its Cucumber features make extensive use of the steps in this gem.
|
28
|
+
Still a work in progress. For now, read the api_steps.rb file or check out the [stashboard-rails](https://github.com/jayzes/stashboard-rails) project - its Cucumber features make extensive use of the steps in this gem.
|
29
|
+
|
30
|
+
# Examples
|
31
|
+
|
32
|
+
Feature: API
|
33
|
+
|
34
|
+
Scenario: List tweets in JSON
|
35
|
+
When I send and accept JSON
|
36
|
+
And I send a GET request to "/api/tweets"
|
37
|
+
Then the response status should be "200"
|
38
|
+
And the JSON response should be:
|
39
|
+
"""
|
40
|
+
[{"tweet":"Hello World!"},{"tweet":"New Rails has been released"}]
|
41
|
+
"""
|
42
|
+
And the JSON response should have "$..tweet" with the text "Hello World!"
|
43
|
+
And the JSON response should have "$..tweet" with a length of 2
|
44
|
+
|
45
|
+
Scenario: List tweets in XML
|
46
|
+
When I send and accept XML
|
47
|
+
And I send a GET request to "/api/tweets"
|
48
|
+
Then the XML response should have "tweet" with text "Hello World!"
|
49
|
+
|
50
|
+
Scenario: Post tweet using POST-params
|
51
|
+
When I send a POST request to "/api/tweets" with the following:
|
52
|
+
| tweet | Hello World! |
|
53
|
+
| lat | 42.848282 |
|
54
|
+
| lng | 74.634933 |
|
55
|
+
Then the response status should be "201"
|
56
|
+
|
57
|
+
Scenario: Post tweet using json in POST body
|
58
|
+
When I send a POST request to "/api/tweets" with the following:
|
59
|
+
"""
|
60
|
+
{"tweet":"Hello World!","lat":"42.848282", "lng":"74.634933"}
|
61
|
+
"""
|
62
|
+
Then the response status should be "201"
|
63
|
+
|
64
|
+
Scenario: Basic authentication
|
65
|
+
When I authenticate as the user "joe" with the password "password123"
|
66
|
+
And I send a GET request to "/api/tweets"
|
67
|
+
Then the response status should be "200"
|
26
68
|
|
27
|
-
|
69
|
+
Scenario: Digest authentication
|
70
|
+
When I digest-authenticate as the user "joe" with the password "password123"
|
71
|
+
And I send a GET request to "/api/tweets"
|
72
|
+
Then the response status should be "200"
|
28
73
|
|
29
74
|
# Contributors
|
30
75
|
* Jay Zeschin
|
31
76
|
* Justin Smestad
|
77
|
+
* Kevin Pfefferle
|
78
|
+
* Kalys Osmonov
|
79
|
+
* Mingding Han
|
80
|
+
* Gabe Varela
|
81
|
+
* Steven Heidel
|
82
|
+
* Adam Elhardt
|
83
|
+
* Gonzalo Bulnes Guilpain
|
32
84
|
|
33
85
|
## Copyright
|
34
86
|
|
data/Rakefile
CHANGED
data/cucumber-api-steps.gemspec
CHANGED
@@ -11,10 +11,12 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.homepage = "http://github.com/jayzes/cucumber-api-steps"
|
12
12
|
s.summary = %q{Cucumber steps to easily test REST-based XML and JSON APIs}
|
13
13
|
s.description = %q{Cucumber steps to easily test REST-based XML and JSON APIs}
|
14
|
-
|
14
|
+
|
15
|
+
s.required_ruby_version = '~> 1.9.3'
|
16
|
+
|
15
17
|
s.add_dependency 'jsonpath', '>= 0.1.2'
|
16
|
-
s.add_dependency 'cucumber', '>=
|
17
|
-
s.
|
18
|
+
s.add_dependency 'cucumber', '>= 1.2.1'
|
19
|
+
s.add_dependency 'rspec', '>= 2.12.0'
|
18
20
|
|
19
21
|
s.files = `git ls-files`.split("\n")
|
20
22
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Feature:
|
2
|
+
As cucumber tester
|
3
|
+
I want to test basic authentication
|
4
|
+
|
5
|
+
Scenario: Basic authentication
|
6
|
+
When I perform the following steps:
|
7
|
+
"""
|
8
|
+
I authenticate as the user "joe" with the password "god"
|
9
|
+
I send a GET request for "/"
|
10
|
+
"""
|
11
|
+
Then I should be authenticated
|
12
|
+
|
13
|
+
|
14
|
+
@digest-auth
|
15
|
+
Scenario: Successful digest authentication
|
16
|
+
When I perform the following steps:
|
17
|
+
"""
|
18
|
+
I digest-authenticate as the user "joe" with the password "god"
|
19
|
+
I send a GET request for "/"
|
20
|
+
"""
|
21
|
+
Then I should be digest authenticated
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "sinatra/base"
|
3
|
+
|
4
|
+
module CucumberApiSteps
|
5
|
+
class FakeApp < Sinatra::Base
|
6
|
+
|
7
|
+
get '/' do end
|
8
|
+
|
9
|
+
get '/api/books' do
|
10
|
+
books = {books: [
|
11
|
+
{title: 'Pride and prejudice'},
|
12
|
+
{title: 'Metaprograming ruby'}
|
13
|
+
]}
|
14
|
+
|
15
|
+
if request.accept.empty? || request.accept?('application/json')
|
16
|
+
content_type :json
|
17
|
+
books.to_json
|
18
|
+
elsif request.accept?('application/xml')
|
19
|
+
content_type :xml
|
20
|
+
books.to_xml
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
post '/api/books' do
|
25
|
+
status 201 if params.values == ["Metaprograming ruby", "Pragprog"]
|
26
|
+
end
|
27
|
+
|
28
|
+
post '/api/publishers' do
|
29
|
+
input_data = JSON.parse request.env["rack.input"].read, symbolize_names: true
|
30
|
+
status 201 if input_data == {publisher: 'Pragprog'}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
Feature:
|
2
|
+
As cucumber tester
|
3
|
+
I should be able to set headers for request
|
4
|
+
|
5
|
+
Scenario: Set multiple headers
|
6
|
+
When I perform the following step with table:
|
7
|
+
"""
|
8
|
+
I set headers:
|
9
|
+
| Accept | application/vnd.myproject.v1 |
|
10
|
+
| User-Agent | Cucumber Api Steps Client |
|
11
|
+
"""
|
12
|
+
Then the request headers should be:
|
13
|
+
| HTTP_ACCEPT | application/vnd.myproject.v1 |
|
14
|
+
| HTTP_USER_AGENT | Cucumber Api Steps Client |
|
15
|
+
|
16
|
+
Scenario: Send and accept JSON
|
17
|
+
When I perform the following step:
|
18
|
+
"""
|
19
|
+
I send and accept JSON
|
20
|
+
"""
|
21
|
+
Then the request headers should be:
|
22
|
+
| HTTP_ACCEPT | application/json |
|
23
|
+
| CONTENT_TYPE | application/json |
|
24
|
+
|
25
|
+
Scenario: Send and accept HTML
|
26
|
+
When I perform the following step:
|
27
|
+
"""
|
28
|
+
I send and accept HTML
|
29
|
+
"""
|
30
|
+
Then the request headers should be:
|
31
|
+
| HTTP_ACCEPT | text/html |
|
32
|
+
| CONTENT_TYPE | application/x-www-form-urlencoded |
|
@@ -0,0 +1,25 @@
|
|
1
|
+
Feature:
|
2
|
+
|
3
|
+
Scenario: GET request
|
4
|
+
When I perform the following step:
|
5
|
+
"""
|
6
|
+
I send a GET request to "/api/books"
|
7
|
+
"""
|
8
|
+
Then the response status should be "200"
|
9
|
+
|
10
|
+
Scenario: POST request with params
|
11
|
+
When I perform the following step with table:
|
12
|
+
"""
|
13
|
+
I send a POST request to "/api/books" with the following:
|
14
|
+
| title | Metaprograming ruby |
|
15
|
+
| publisher | Pragprog |
|
16
|
+
"""
|
17
|
+
Then the response status should be "201"
|
18
|
+
|
19
|
+
Scenario: POST request with string
|
20
|
+
When I perform the following step with string:
|
21
|
+
"""
|
22
|
+
I send a POST request to "/api/publishers" with the following:
|
23
|
+
{"publisher": "Pragprog"}
|
24
|
+
"""
|
25
|
+
Then the response status should be "201"
|
@@ -0,0 +1,112 @@
|
|
1
|
+
Feature:
|
2
|
+
As cucumber tester
|
3
|
+
I want to test response
|
4
|
+
|
5
|
+
Scenario: Test response status
|
6
|
+
When I perform the following step:
|
7
|
+
"""
|
8
|
+
I send a GET request to "/"
|
9
|
+
"""
|
10
|
+
|
11
|
+
Then the response status should be "200"
|
12
|
+
|
13
|
+
Scenario: Test that JSON response contains a node
|
14
|
+
When I perform the following step:
|
15
|
+
"""
|
16
|
+
I send a GET request to "/api/books"
|
17
|
+
"""
|
18
|
+
Then the JSON response should have "$..title"
|
19
|
+
|
20
|
+
Scenario: Test that JSON response does not contain a node
|
21
|
+
When I perform the following step:
|
22
|
+
"""
|
23
|
+
I send a GET request to "/api/books"
|
24
|
+
"""
|
25
|
+
Then the JSON response should not have "$..nonexistent_key"
|
26
|
+
|
27
|
+
Scenario: Test that XML response contains a node
|
28
|
+
When I send and accept XML
|
29
|
+
When I perform the following step:
|
30
|
+
"""
|
31
|
+
I send a GET request to "/api/books"
|
32
|
+
"""
|
33
|
+
Then show me the unparsed response
|
34
|
+
Then the XML response should have "//title"
|
35
|
+
|
36
|
+
Scenario: Test that XML response does not contain a node
|
37
|
+
When I send and accept XML
|
38
|
+
When I perform the following step:
|
39
|
+
"""
|
40
|
+
I send a GET request to "/api/books"
|
41
|
+
"""
|
42
|
+
Then the XML response should not have "//nonexistent_element"
|
43
|
+
|
44
|
+
Scenario: Test if JSON response contains text
|
45
|
+
When I perform the following step:
|
46
|
+
"""
|
47
|
+
I send a GET request to "/api/books"
|
48
|
+
"""
|
49
|
+
Then the JSON response should have "$..title" with the text "Metaprograming ruby"
|
50
|
+
|
51
|
+
Scenario: Test if JSON response doesn't contain text
|
52
|
+
When I perform the following step:
|
53
|
+
"""
|
54
|
+
I send a GET request to "/api/books"
|
55
|
+
"""
|
56
|
+
Then the JSON response should not have "$..publisher" with the text "Metaprograming ruby"
|
57
|
+
|
58
|
+
Scenario: Test if XML response contains text
|
59
|
+
When I send and accept XML
|
60
|
+
And I perform the following step:
|
61
|
+
"""
|
62
|
+
I send a GET request to "/api/books"
|
63
|
+
"""
|
64
|
+
Then the XML response should have "//title" with the text "Metaprograming ruby"
|
65
|
+
|
66
|
+
Scenario: Test JSON response
|
67
|
+
When I perform the following step:
|
68
|
+
"""
|
69
|
+
I send a GET request to "/api/books"
|
70
|
+
"""
|
71
|
+
Then the JSON response should be:
|
72
|
+
"""
|
73
|
+
{"books":[{"title":"Pride and prejudice"},{"title":"Metaprograming ruby"}]}
|
74
|
+
"""
|
75
|
+
|
76
|
+
Scenario: Test JSON with length of some element
|
77
|
+
When I perform the following step:
|
78
|
+
"""
|
79
|
+
I send a GET request to "/api/books"
|
80
|
+
"""
|
81
|
+
Then the JSON response should have "$..title" with a length of 2
|
82
|
+
|
83
|
+
Scenario: Test debugging the XML response should not blow up
|
84
|
+
When I send and accept XML
|
85
|
+
And I perform the following step:
|
86
|
+
"""
|
87
|
+
I send a GET request to "/api/books"
|
88
|
+
"""
|
89
|
+
Then show me the response
|
90
|
+
|
91
|
+
Scenario: Test debugging the JSON response should not blow up
|
92
|
+
When I send and accept JSON
|
93
|
+
And I perform the following step:
|
94
|
+
"""
|
95
|
+
I send a GET request to "/api/books"
|
96
|
+
"""
|
97
|
+
Then show me the response
|
98
|
+
|
99
|
+
Scenario: Test debugging unparsed JSON response should not blow up
|
100
|
+
When I perform the following step:
|
101
|
+
"""
|
102
|
+
I send a GET request to "/api/books"
|
103
|
+
"""
|
104
|
+
Then show me the unparsed response
|
105
|
+
|
106
|
+
Scenario: Test debugging unparsed XML response should not blow up
|
107
|
+
When I send and accept XML
|
108
|
+
When I perform the following step:
|
109
|
+
"""
|
110
|
+
I send a GET request to "/api/books"
|
111
|
+
"""
|
112
|
+
Then show me the unparsed response
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'active_support/core_ext'
|
2
|
+
|
3
|
+
When /^I perform the following steps?:$/ do |step_strings|
|
4
|
+
steps = step_strings.split("\n")
|
5
|
+
steps.each {|step_string| step step_string }
|
6
|
+
end
|
7
|
+
|
8
|
+
Then /^the response should equal:$/ do |response_body|
|
9
|
+
last_response.body.should eq(response_body)
|
10
|
+
end
|
11
|
+
|
12
|
+
When /^I perform the following step with table:$/ do |step_definition|
|
13
|
+
lines = step_definition.split("\n")
|
14
|
+
step_string = lines.shift
|
15
|
+
|
16
|
+
raw = lines.map do |line|
|
17
|
+
line.squish.gsub(/^\|/, '').gsub(/\|$/, '').squish.split("|").map(&:squish)
|
18
|
+
end
|
19
|
+
|
20
|
+
step step_string, table(raw)
|
21
|
+
end
|
22
|
+
|
23
|
+
When /^I perform the following step with string:$/ do |step_definition|
|
24
|
+
lines = step_definition.split("\n")
|
25
|
+
step_string = lines.shift
|
26
|
+
|
27
|
+
param_string = lines.join("\n")
|
28
|
+
|
29
|
+
step step_string, param_string
|
30
|
+
end
|
31
|
+
|
32
|
+
Then /^the request headers should be:$/ do |headers|
|
33
|
+
headers_hash = headers.rows_hash
|
34
|
+
request '/'
|
35
|
+
last_request.env.slice(*headers_hash.keys).values.should eq(headers_hash.values)
|
36
|
+
end
|
37
|
+
|
38
|
+
Then /^I should be authenticated$/ do
|
39
|
+
last_request.env["HTTP_AUTHORIZATION"].should eq("Basic #{Base64.encode64("joe:god")}")
|
40
|
+
end
|
41
|
+
|
42
|
+
Then /^I should be digest authenticated$/ do
|
43
|
+
last_request.env["HTTP_AUTHORIZATION"].starts_with?("Digest ").should be_true
|
44
|
+
end
|
data/features/support/env.rb
CHANGED
@@ -1,11 +1,23 @@
|
|
1
1
|
require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
|
2
|
-
require '
|
2
|
+
require 'pry'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
# steps to use the XPath syntax.
|
8
|
-
Capybara.default_selector = :css
|
9
|
-
Capybara.default_driver = :rack_test
|
4
|
+
require 'rack'
|
5
|
+
require 'rack/test'
|
6
|
+
require File.dirname(__FILE__) + "/../fixtures/fake_app"
|
10
7
|
|
11
|
-
require 'cucumber/api_steps'
|
8
|
+
require 'cucumber/api_steps'
|
9
|
+
|
10
|
+
def app
|
11
|
+
Rack::Lint.new(CucumberApiSteps::FakeApp.new)
|
12
|
+
end
|
13
|
+
|
14
|
+
Before("@digest-auth") do
|
15
|
+
def app
|
16
|
+
app = Rack::Auth::Digest::MD5.new(CucumberApiSteps::FakeApp.new) do |username|
|
17
|
+
{ 'joe' => 'god' }[username]
|
18
|
+
end
|
19
|
+
app.realm = 'TestApi'
|
20
|
+
app.opaque = 'this-should-be-secret'
|
21
|
+
app
|
22
|
+
end
|
23
|
+
end
|
data/lib/cucumber/api_steps.rb
CHANGED
@@ -1,54 +1,104 @@
|
|
1
1
|
require 'jsonpath'
|
2
|
+
require 'nokogiri'
|
2
3
|
|
3
|
-
|
4
|
+
if defined?(Rack)
|
5
|
+
|
6
|
+
# Monkey patch Rack::MockResponse to work properly with response debugging
|
7
|
+
class Rack::MockResponse
|
8
|
+
def to_str
|
9
|
+
body
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
World(Rack::Test::Methods)
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
Given /^I set headers:$/ do |headers|
|
18
|
+
headers.rows_hash.each {|k,v| header k, v }
|
19
|
+
end
|
4
20
|
|
5
21
|
Given /^I send and accept (XML|JSON)$/ do |type|
|
6
|
-
|
7
|
-
|
22
|
+
header 'Accept', "application/#{type.downcase}"
|
23
|
+
header 'Content-Type', "application/#{type.downcase}"
|
24
|
+
end
|
25
|
+
|
26
|
+
Given /^I send and accept HTML$/ do
|
27
|
+
header 'Accept', "text/html"
|
28
|
+
header 'Content-Type', "application/x-www-form-urlencoded"
|
8
29
|
end
|
9
30
|
|
10
31
|
When /^I authenticate as the user "([^"]*)" with the password "([^"]*)"$/ do |user, pass|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
page.driver.browser.basic_authorize(user, pass)
|
17
|
-
elsif page.driver.respond_to?(:authorize)
|
18
|
-
page.driver.authorize(user, pass)
|
19
|
-
else
|
20
|
-
raise "Can't figure out how to log in with the current driver!"
|
21
|
-
end
|
32
|
+
authorize user, pass
|
33
|
+
end
|
34
|
+
|
35
|
+
When /^I digest\-authenticate as the user "(.*?)" with the password "(.*?)"$/ do |user, pass|
|
36
|
+
digest_authorize user, pass
|
22
37
|
end
|
23
38
|
|
24
39
|
When /^I send a (GET|POST|PUT|DELETE) request (?:for|to) "([^"]*)"(?: with the following:)?$/ do |*args|
|
25
40
|
request_type = args.shift
|
26
41
|
path = args.shift
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
42
|
+
input = args.shift
|
43
|
+
|
44
|
+
request_opts = {method: request_type.downcase.to_sym}
|
45
|
+
|
46
|
+
unless input.nil?
|
47
|
+
if input.class == Cucumber::Ast::Table
|
48
|
+
request_opts[:params] = input.rows_hash
|
49
|
+
else
|
50
|
+
request_opts[:input] = input
|
51
|
+
end
|
32
52
|
end
|
53
|
+
|
54
|
+
request path, request_opts
|
33
55
|
end
|
34
56
|
|
35
|
-
Then /^show me the response$/ do
|
36
|
-
|
37
|
-
|
57
|
+
Then /^show me the (unparsed)?\s?response$/ do |unparsed|
|
58
|
+
if unparsed == 'unparsed'
|
59
|
+
puts last_response.body
|
60
|
+
elsif last_response.headers['Content-Type'] =~ /json/
|
61
|
+
json_response = JSON.parse(last_response.body)
|
62
|
+
puts JSON.pretty_generate(json_response)
|
63
|
+
elsif last_response.headers['Content-Type'] =~ /xml/
|
64
|
+
puts Nokogiri::XML(last_response.body)
|
65
|
+
else
|
66
|
+
puts last_response.headers
|
67
|
+
puts last_response.body
|
68
|
+
end
|
38
69
|
end
|
39
70
|
|
40
71
|
Then /^the response status should be "([^"]*)"$/ do |status|
|
41
|
-
if
|
42
|
-
|
72
|
+
if self.respond_to? :should
|
73
|
+
last_response.status.should == status.to_i
|
43
74
|
else
|
44
|
-
assert_equal status.to_i,
|
75
|
+
assert_equal status.to_i, last_response.status
|
45
76
|
end
|
46
77
|
end
|
47
78
|
|
79
|
+
Then /^the JSON response should (not)?\s?have "([^"]*)"$/ do |negative, json_path|
|
80
|
+
json = JSON.parse(last_response.body)
|
81
|
+
results = JsonPath.new(json_path).on(json).to_a.map(&:to_s)
|
82
|
+
if self.respond_to?(:should)
|
83
|
+
if negative.present?
|
84
|
+
results.should be_empty
|
85
|
+
else
|
86
|
+
results.should_not be_empty
|
87
|
+
end
|
88
|
+
else
|
89
|
+
if negative.present?
|
90
|
+
assert results.empty?
|
91
|
+
else
|
92
|
+
assert !results.empty?
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
|
48
98
|
Then /^the JSON response should (not)?\s?have "([^"]*)" with the text "([^"]*)"$/ do |negative, json_path, text|
|
49
|
-
json = JSON.parse(
|
99
|
+
json = JSON.parse(last_response.body)
|
50
100
|
results = JsonPath.new(json_path).on(json).to_a.map(&:to_s)
|
51
|
-
if
|
101
|
+
if self.respond_to?(:should)
|
52
102
|
if negative.present?
|
53
103
|
results.should_not include(text)
|
54
104
|
else
|
@@ -63,11 +113,29 @@ Then /^the JSON response should (not)?\s?have "([^"]*)" with the text "([^"]*)"$
|
|
63
113
|
end
|
64
114
|
end
|
65
115
|
|
116
|
+
Then /^the XML response should (not)?\s?have "([^"]*)"$/ do |negative, xpath|
|
117
|
+
parsed_response = Nokogiri::XML(last_response.body)
|
118
|
+
elements = parsed_response.xpath(xpath)
|
119
|
+
if self.respond_to?(:should)
|
120
|
+
if negative.present?
|
121
|
+
elements.should be_empty
|
122
|
+
else
|
123
|
+
elements.should_not be_empty
|
124
|
+
end
|
125
|
+
else
|
126
|
+
if negative.present?
|
127
|
+
assert elements.empty?
|
128
|
+
else
|
129
|
+
assert !elements.empty?
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
66
134
|
Then /^the XML response should have "([^"]*)" with the text "([^"]*)"$/ do |xpath, text|
|
67
|
-
parsed_response = Nokogiri::XML(
|
135
|
+
parsed_response = Nokogiri::XML(last_response.body)
|
68
136
|
elements = parsed_response.xpath(xpath)
|
69
|
-
if
|
70
|
-
elements.should_not be_empty, "could not find #{xpath} in:\n#{
|
137
|
+
if self.respond_to?(:should)
|
138
|
+
elements.should_not be_empty, "could not find #{xpath} in:\n#{last_response.body}"
|
71
139
|
elements.find { |e| e.text == text }.should_not be_nil, "found elements but could not find #{text} in:\n#{elements.inspect}"
|
72
140
|
else
|
73
141
|
assert !elements.empty?, "could not find #{xpath} in:\n#{last_response.body}"
|
@@ -75,3 +143,23 @@ Then /^the XML response should have "([^"]*)" with the text "([^"]*)"$/ do |xpat
|
|
75
143
|
end
|
76
144
|
end
|
77
145
|
|
146
|
+
Then /^the JSON response should be:$/ do |json|
|
147
|
+
expected = JSON.parse(json)
|
148
|
+
actual = JSON.parse(last_response.body)
|
149
|
+
|
150
|
+
if self.respond_to?(:should)
|
151
|
+
actual.should == expected
|
152
|
+
else
|
153
|
+
assert_equal actual, response
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
Then /^the JSON response should have "([^"]*)" with a length of (\d+)$/ do |json_path, length|
|
158
|
+
json = JSON.parse(last_response.body)
|
159
|
+
results = JsonPath.new(json_path).on(json)
|
160
|
+
if self.respond_to?(:should)
|
161
|
+
results.length.should == length.to_i
|
162
|
+
else
|
163
|
+
assert_equal length.to_i, results.length
|
164
|
+
end
|
165
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cucumber-api-steps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.12'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-10-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jsonpath
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
37
|
+
version: 1.2.1
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,23 +42,23 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
45
|
+
version: 1.2.1
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: rspec
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
51
|
- - ! '>='
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
54
|
-
type: :
|
53
|
+
version: 2.12.0
|
54
|
+
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
58
58
|
requirements:
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 2.12.0
|
62
62
|
description: Cucumber steps to easily test REST-based XML and JSON APIs
|
63
63
|
email:
|
64
64
|
- jay.zeschin@modeset.com
|
@@ -68,10 +68,17 @@ extra_rdoc_files: []
|
|
68
68
|
files:
|
69
69
|
- .gitignore
|
70
70
|
- .rvmrc
|
71
|
+
- .travis.yml
|
71
72
|
- Gemfile
|
72
73
|
- README.md
|
73
74
|
- Rakefile
|
74
75
|
- cucumber-api-steps.gemspec
|
76
|
+
- features/authentication.feature
|
77
|
+
- features/fixtures/fake_app.rb
|
78
|
+
- features/header.feature
|
79
|
+
- features/request.feature
|
80
|
+
- features/response.feature
|
81
|
+
- features/step_definitions/api_test_steps.rb
|
75
82
|
- features/support/env.rb
|
76
83
|
- lib/cucumber/api_steps.rb
|
77
84
|
- lib/cucumber/api_steps/version.rb
|
@@ -84,9 +91,9 @@ require_paths:
|
|
84
91
|
required_ruby_version: !ruby/object:Gem::Requirement
|
85
92
|
none: false
|
86
93
|
requirements:
|
87
|
-
- -
|
94
|
+
- - ~>
|
88
95
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
96
|
+
version: 1.9.3
|
90
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
98
|
none: false
|
92
99
|
requirements:
|
@@ -100,4 +107,10 @@ signing_key:
|
|
100
107
|
specification_version: 3
|
101
108
|
summary: Cucumber steps to easily test REST-based XML and JSON APIs
|
102
109
|
test_files:
|
110
|
+
- features/authentication.feature
|
111
|
+
- features/fixtures/fake_app.rb
|
112
|
+
- features/header.feature
|
113
|
+
- features/request.feature
|
114
|
+
- features/response.feature
|
115
|
+
- features/step_definitions/api_test_steps.rb
|
103
116
|
- features/support/env.rb
|