rest-assured 0.2.0.rc8 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +2 -2
- data/LICENSE +4 -19
- data/README.markdown +123 -36
- data/bin/console +1 -2
- data/bin/rest-assured +12 -0
- data/features/command_line_options.feature +20 -1
- data/features/{doubles_via_api.feature → rest_api/doubles.feature} +0 -0
- data/features/{redirect_rules_via_api.feature → rest_api/redirects.feature} +11 -8
- data/features/{call_history.feature → ruby_api/verify_requests.feature} +0 -0
- data/features/ruby_api/wait_for_requests.feature +39 -0
- data/features/step_definitions/command_line_options_steps.rb +12 -0
- data/features/step_definitions/doubles_steps.rb +10 -10
- data/features/step_definitions/redirect_rules_steps.rb +24 -5
- data/features/step_definitions/ruby_api_steps.rb +69 -0
- data/features/support/env.rb +3 -1
- data/features/{doubles_via_ui.feature → web_ui/doubles.feature} +0 -0
- data/features/{redirect_rules_via_ui.feature → web_ui/redirects.feature} +0 -0
- data/lib/rest-assured.rb +2 -1
- data/lib/rest-assured/client/resources.rb +12 -2
- data/lib/rest-assured/config.rb +24 -0
- data/lib/rest-assured/models/double.rb +32 -28
- data/lib/rest-assured/models/redirect.rb +28 -24
- data/lib/rest-assured/models/request.rb +11 -7
- data/lib/rest-assured/routes/double.rb +8 -8
- data/lib/rest-assured/routes/redirect.rb +8 -8
- data/lib/rest-assured/routes/response.rb +16 -14
- data/lib/rest-assured/version.rb +1 -1
- data/lib/sinatra/handler_options_patch.rb +25 -0
- data/spec/client/resource_double_spec.rb +42 -6
- data/spec/config_spec.rb +35 -0
- data/spec/functional/double_routes_spec.rb +109 -107
- data/spec/functional/redirect_routes_spec.rb +86 -75
- data/spec/functional/response_spec.rb +57 -55
- data/spec/models/double_spec.rb +67 -65
- data/spec/models/redirect_spec.rb +28 -26
- data/spec/models/request_spec.rb +10 -8
- data/ssl/localhost.crt +14 -0
- data/ssl/localhost.key +15 -0
- metadata +25 -24
- data/features/step_definitions/call_history_steps.rb +0 -24
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rest-assured (0.2.0
|
4
|
+
rest-assured (0.2.0)
|
5
5
|
activerecord (~> 3.1.0)
|
6
6
|
activeresource (~> 3.1.0)
|
7
7
|
haml (>= 3.1.3)
|
@@ -113,7 +113,7 @@ GEM
|
|
113
113
|
term-ansicolor (1.0.7)
|
114
114
|
thor (0.14.6)
|
115
115
|
tilt (1.3.3)
|
116
|
-
tzinfo (0.3.
|
116
|
+
tzinfo (0.3.31)
|
117
117
|
xpath (0.1.4)
|
118
118
|
nokogiri (~> 1.3)
|
119
119
|
|
data/LICENSE
CHANGED
@@ -1,22 +1,7 @@
|
|
1
|
-
Copyright
|
1
|
+
Copyright 2010 British Broadcasting Corporation
|
2
2
|
|
3
|
-
|
4
|
-
obtaining a copy of this software and associated documentation
|
5
|
-
files (the "Software"), to deal in the Software without
|
6
|
-
restriction, including without limitation the rights to use,
|
7
|
-
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
-
copies of the Software, and to permit persons to whom the
|
9
|
-
Software is furnished to do so, subject to the following
|
10
|
-
conditions:
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
11
4
|
|
12
|
-
|
13
|
-
included in all copies or substantial portions of the Software.
|
5
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
14
6
|
|
15
|
-
|
16
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
-
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
-
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
-
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
-
OTHER DEALINGS IN THE SOFTWARE.
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
data/README.markdown
CHANGED
@@ -2,82 +2,169 @@
|
|
2
2
|
|
3
3
|
## Overview
|
4
4
|
|
5
|
-
A tool for stubbing/mocking external http based services that app under test
|
5
|
+
A tool for stubbing/mocking external http based services that your app under test interacts with. This is useful for blackbox/integration testing.
|
6
6
|
There are three main use cases:
|
7
7
|
|
8
|
-
* stubbing out external data sources with predefined data
|
9
|
-
*
|
10
|
-
*
|
8
|
+
* stubbing out external data sources with predefined data
|
9
|
+
* verify requests to external services
|
10
|
+
* quickly emulate different behavior of external services during development (using web UI)
|
11
11
|
|
12
12
|
## Usage
|
13
13
|
|
14
|
-
You are going to need ruby >= 1.8.7.
|
14
|
+
You are going to need ruby >= 1.8.7.
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
First make sure there is database adapter:
|
17
|
+
|
18
|
+
bash$ gem install mysql # or sqlite
|
19
|
+
|
20
|
+
If using mysql, rest-assured expects database 'rest\_assured' to be accessible by user 'root' with no password. Those are defaults and are changeable with command line options.
|
21
|
+
|
22
|
+
Then install gem and run:
|
23
|
+
|
24
|
+
bash$ gem install rest-assured
|
25
|
+
bash$ rest-assured -a mysql &
|
18
26
|
|
19
27
|
Or clone from github and run:
|
20
28
|
|
21
29
|
bash$ git clone git@github.com:BBC/rest-assured.git
|
22
|
-
bash$ cd rest-assured && bundle install
|
23
|
-
bash$ ./bin/rest-assured &
|
30
|
+
bash$ cd rest-assured && bundle install
|
31
|
+
bash$ ./bin/rest-assured -a mysql &
|
32
|
+
|
33
|
+
This starts an instance of rest-assured on port 4578 (changable with --port option). You can now access it via REST or web interfaces on 'http://localhost:4578'
|
24
34
|
|
25
|
-
|
35
|
+
Various options (such as ssl, port, db credentials, etc.) are available through command line options. Check out `rest-assured -h` to see what they are.
|
36
|
+
|
37
|
+
NOTE that although sqlite is an option, I found it locking under any non-trivial load. Mysql feels much more reliable. But may be that is me sqliting it wrong.
|
38
|
+
|
39
|
+
## REST API
|
26
40
|
|
27
41
|
### Doubles
|
28
42
|
|
29
|
-
Double is a stub/mock of a particular external call.
|
43
|
+
Double is a stub/mock of a particular external call.
|
44
|
+
|
45
|
+
#### Ruby Client API
|
46
|
+
|
47
|
+
Rest-assured provides client library which partially implements ActiveResource (create and get). To make it available put the following in your test setup code (e.g. env.rb)
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
require 'rest-assured/client'
|
51
|
+
|
52
|
+
RestAssured::Client.config.server_address = 'http://localhost:4578' # or wherever your rest-assured is
|
53
|
+
```
|
54
|
+
|
55
|
+
You can then create doubles in your tests
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
RestAssured::Double.create(fullpath: '/products', content: 'this is content')
|
59
|
+
```
|
60
|
+
|
61
|
+
Or, in case you need verifications, create double in a Given part
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
@double = RestAssured::Double.create(fullpath: '/products', verb: 'POST')
|
65
|
+
```
|
66
|
+
|
67
|
+
And verify requests happened on that double in a Then part
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
@double.wait_for_requests(1, :timeout => 10) # default timeout 5 seconds
|
71
|
+
|
72
|
+
req = @double.requests.first
|
30
73
|
|
31
|
-
|
32
|
-
|
74
|
+
req.body.should == expected_payload
|
75
|
+
JSON.parse(req.params).should == expected_params_hash
|
76
|
+
JSON.parse(req.rack_env)['ACCEPT'].should == 'Application/json'
|
77
|
+
```
|
33
78
|
|
34
|
-
|
35
|
-
|
79
|
+
#### Plain REST API
|
80
|
+
|
81
|
+
##### Create double
|
82
|
+
HTTP POST to '/doubles.json' creates double and returns its json representation.
|
83
|
+
The following options can be passed as request parameters:
|
84
|
+
|
85
|
+
- __fullpath__ - e.g., '/some/api/object', or with parameters in query string (useful for doubling GETs) - '/some/other/api/object?a=2&b=c'. Mandatory.
|
86
|
+
- __content__ - whatever you want this double to respond with. Optional.
|
36
87
|
- __verb__ - one of http the following http verbs: GET, POST, PUT, DELETE. Optional. GET is default.
|
88
|
+
- __status__ - status returned when double is requested. Optional. 200 is default.
|
37
89
|
|
38
90
|
Example (using ruby RestClient):
|
39
91
|
|
40
|
-
|
92
|
+
```ruby
|
93
|
+
response = RestClient.post 'http://localhost:4578/doubles', { fullpath: '/api/v2/products?type=fresh', verb: 'GET', content: 'this is list of products', status: 200 }
|
94
|
+
puts response.body
|
95
|
+
```
|
96
|
+
Produces:
|
97
|
+
|
98
|
+
"{\"double\":{\"fullpath\":\"/api/v2/products?type=fresh\",\"verb\":\"GET\",\"id\":123,\"content\":\"this is list of products\",\"description\":null,\"status\":null,\"active\":true}}"
|
41
99
|
|
42
|
-
|
100
|
+
And then GETting 'http://localhost:4578/api/v2/products?type=fresh' (in browser for instance) should return "this is list of products".
|
43
101
|
|
44
|
-
If there is more than one double for the same
|
102
|
+
If there is more than one double for the same fullpath and verb, the last created one gets served. In UI you can manually control which double is 'active' (gets served).
|
45
103
|
|
46
|
-
|
47
|
-
|
104
|
+
##### Get double state
|
105
|
+
HTTP GET to '/double/:id.json' returns json with double current state. Use id from create json as :id.
|
106
|
+
|
107
|
+
Example (using ruby RestClient):
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
response = RestClient.get 'http://localhost:4578/doubles/123.json'
|
111
|
+
puts response.body
|
112
|
+
```
|
113
|
+
|
114
|
+
Assuming the above double has been requested once, this call would produce
|
115
|
+
|
116
|
+
"{\"double\":{\"fullpath\":\"/api/v2/products?type=fresh\",\"verb\":\"GET\",\"id\":123,\"requests\":[{\"rack_env\":\"LOOK FOR YOUR HEADERS HERE\",\"created_at\":\"2011-11-07T18:34:21+00:00\",\"body\":\"\",\"params\":\"{}\"}],\"content\":\"this is list of products\",\"description\":null,\"status\":null,\"active\":true}}"
|
117
|
+
|
118
|
+
The important bit here is 'requests' array. This is history of requests for that double (in chronological order). Each element contains the following data (keys):
|
119
|
+
|
120
|
+
- __body__ - request payload
|
121
|
+
- __params__ - request parameters
|
122
|
+
- __created_at__ - request timestamp
|
123
|
+
- __rack_env__ - raw request dump (key value pairs). Including request headers
|
124
|
+
|
125
|
+
##### Delete all doubles
|
126
|
+
HTTP DELETE to '/doubles/all' deletes all doubles. Useful for cleaning up between tests.
|
48
127
|
|
49
128
|
### Redirects
|
50
129
|
|
51
130
|
It is sometimes desirable to only double certain calls while letting others through to the 'real' services. Meet Redirects. Kind of "rewrite rules" for requests that didn't match any double. Here is the rest API for managing redirects:
|
52
131
|
|
53
|
-
|
132
|
+
#### Create redirect
|
133
|
+
HTTP POST to '/redirects' creates redirect.
|
134
|
+
The following options can be passed as request parameters:
|
54
135
|
|
55
136
|
- __pattern__ - regex (perl5 style) tested against request fullpath. Mandatory
|
56
|
-
- __to__ - url base e.g.,
|
137
|
+
- __to__ - url base e.g., 'https://myserver:8787/api'. Mandatory
|
57
138
|
|
58
139
|
Example (using ruby RestClient):
|
59
140
|
|
60
|
-
|
141
|
+
```ruby
|
142
|
+
RestClient.post 'http://localhost:4578/redirects', { pattern: '^/auth', to: 'https://myserver.com/api' }
|
143
|
+
```
|
61
144
|
|
62
|
-
Now request (any verb) to http://localhost:4578/auth/services/1 will get redirected to https://myserver.com/api/auth/services/1. Provided of course there is no double matched for that fullpath and verb.
|
145
|
+
Now request (any verb) to 'http://localhost:4578/auth/services/1' will get redirected to 'https://myserver.com/api/auth/services/1.' Provided of course there is no double matched for that fullpath and verb.
|
63
146
|
Much like rewrite rules, redirects are evaluated in order (of creation). In UI you can manually rearrange the order.
|
64
147
|
|
65
|
-
|
66
|
-
|
67
|
-
By default when you start rest-assured it creates (unless already exists) sqlite database and stores it into file in the current directory. This is good for using it for development - when you want doubles/redirects to persist across restarts - but may not be so desirable for using with tests, where you want each test run to start from blank slate. For that reason, you can specify `--database :memory:` so that database is kept in memory.
|
68
|
-
|
69
|
-
### Logging
|
70
|
-
|
71
|
-
It is sometimes useful to see what requests rest-assured is being hit. Either to explore what requests your app is making or to check that test setup is right and doubles indeed get returned. By default, when started, rest-assured creates log file in the current directory. This is configurable with `--logfile` option.
|
148
|
+
#### Delete all redirects
|
149
|
+
HTTP DELETE to '/redirects/all' deletes all redirects. Useful for cleaning up between tests.
|
72
150
|
|
73
151
|
## TODO
|
74
152
|
|
75
|
-
*
|
76
|
-
*
|
77
|
-
*
|
78
|
-
* Support verbs in UI (at the moment it is always GET)
|
79
|
-
* Don't allow to double internal routes. Just in case
|
153
|
+
* Hide wiring rest-assured into ruby project behind client api
|
154
|
+
* Bring UI upto date with rest-api (add verbs, statuses, request history)
|
155
|
+
* Add custom response headers
|
80
156
|
|
81
157
|
## Author
|
82
158
|
|
83
159
|
[Artem Avetisyan](https://github.com/artemave)
|
160
|
+
|
161
|
+
## Changelog
|
162
|
+
|
163
|
+
0.2
|
164
|
+
- adds verifications
|
165
|
+
- adds ruby client
|
166
|
+
- adds custom return statuses
|
167
|
+
- adds ssl
|
168
|
+
- adds mysql support
|
169
|
+
0.1 initial public release
|
170
|
+
|
data/bin/console
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require "irb"
|
3
|
-
require 'bundler/setup'
|
4
3
|
|
5
4
|
$:.push File.expand_path('../../lib', __FILE__)
|
6
5
|
|
7
6
|
require 'rest-assured/config'
|
8
|
-
|
7
|
+
RestAssured::Config.build :database => ( ENV['FRS_DB'] || File.expand_path('../../db/development.db', __FILE__) )
|
9
8
|
|
10
9
|
require 'rest-assured'
|
11
10
|
|
data/bin/rest-assured
CHANGED
@@ -51,6 +51,18 @@ OptionParser.new do |opts|
|
|
51
51
|
user_opts[:logfile] = logfile
|
52
52
|
end
|
53
53
|
|
54
|
+
opts.on('--ssl', "Whether or not to run on https. Defaults to false (http)") do |use_ssl|
|
55
|
+
user_opts[:use_ssl] = true
|
56
|
+
end
|
57
|
+
|
58
|
+
opts.on('-c', '--ssl_cert FILENAME', "Path to ssl_cert. Defaults to self signed certificate shipped with rest-assured") do |ssl_cert|
|
59
|
+
user_opts[:ssl_cert] = ssl_cert
|
60
|
+
end
|
61
|
+
|
62
|
+
opts.on('-k', '--ssl_key FILENAME', "Path to ssl_key. Defaults to key shipped with rest-assured") do |ssl_key|
|
63
|
+
user_opts[:ssl_key] = ssl_key
|
64
|
+
end
|
65
|
+
|
54
66
|
opts.on_tail("--help", "Show this message") do
|
55
67
|
puts opts
|
56
68
|
exit
|
@@ -33,7 +33,6 @@ Feature: command line options
|
|
33
33
|
| -d /tmp/ratest.db | /tmp/ratest.db |
|
34
34
|
| --database /tmp/resta.db | /tmp/resta.db |
|
35
35
|
|
36
|
-
@now
|
37
36
|
Scenario Outline: mysql options
|
38
37
|
When I start rest-assured with -a mysql <options>
|
39
38
|
Then database options should be:
|
@@ -53,3 +52,23 @@ Feature: command line options
|
|
53
52
|
| --dbencoding utf16le | rest_assured | root | | | | utf16le | |
|
54
53
|
| --dbsocket /tmp/mysql.sock | rest_assured | root | | | | | /tmp/mysql.sock |
|
55
54
|
|
55
|
+
Scenario Outline: use ssl option
|
56
|
+
When I start rest-assured with <option>
|
57
|
+
Then rest-assured should "<use_ssl>"
|
58
|
+
|
59
|
+
Examples:
|
60
|
+
| option | use_ssl |
|
61
|
+
| | false |
|
62
|
+
| --ssl | true |
|
63
|
+
|
64
|
+
Scenario Outline: specifying ssl options
|
65
|
+
When I start rest-assured with <option>
|
66
|
+
Then ssl certificate used should be "<ssl_cert>" and ssl key should be "<ssl_key>"
|
67
|
+
|
68
|
+
Examples:
|
69
|
+
| option | ssl_cert | ssl_key |
|
70
|
+
| -c /tmp/mycert.crt | /tmp/mycert.crt | DEFAULT_KEY |
|
71
|
+
| --ssl_cert ./mycert.crt | ./mycert.crt | DEFAULT_KEY |
|
72
|
+
| | DEFAULT_CERT | DEFAULT_KEY |
|
73
|
+
| -k /tmp/mykey.key | DEFAULT_CERT | /tmp/mykey.key |
|
74
|
+
| --ssl_key ./mykey.key | DEFAULT_CERT | ./mykey.key |
|
File without changes
|
@@ -3,27 +3,30 @@ Feature: manage redirect rules
|
|
3
3
|
As a developer
|
4
4
|
I want to redirect to real api if there are no doubles for requested fullpath
|
5
5
|
|
6
|
-
Background:
|
7
|
-
Given there are no redirect rules
|
8
|
-
And there are no doubles
|
9
|
-
|
10
6
|
Scenario: no redirect rules
|
7
|
+
Given blank slate
|
11
8
|
When I request "/api/something"
|
12
9
|
Then I should get 404
|
13
10
|
|
14
11
|
Scenario: add redirect rule
|
12
|
+
Given blank slate
|
15
13
|
When I register redirect with pattern "^/api" and uri "http://real.api.co.uk"
|
16
14
|
And I request "/api/something"
|
17
15
|
Then it should redirect to "http://real.api.co.uk/api/something"
|
18
16
|
|
19
17
|
Scenario: add second redirect that match the same request
|
20
|
-
|
21
|
-
|
18
|
+
Given there is redirect with pattern "/api/something" and uri "http://real.api.co.uk"
|
19
|
+
When I register redirect with pattern "/api/some.*" and uri "http://real.com"
|
22
20
|
And I request "/api/something"
|
23
21
|
Then it should redirect to "http://real.api.co.uk/api/something"
|
24
22
|
|
25
23
|
Scenario: add second redirect that does not match the same request
|
26
|
-
|
27
|
-
|
24
|
+
Given there is redirect with pattern "/api/something" and uri "http://real.api.co.uk"
|
25
|
+
When I register redirect with pattern "/api/some" and uri "http://real.com"
|
28
26
|
And I request "/api/someth"
|
29
27
|
Then it should redirect to "http://real.com/api/someth"
|
28
|
+
|
29
|
+
Scenario: clear redirects
|
30
|
+
Given there are some redirects
|
31
|
+
When I delete all redirects
|
32
|
+
Then there should be no redirects
|
File without changes
|
@@ -0,0 +1,39 @@
|
|
1
|
+
Feature: wait for requests on double to happen
|
2
|
+
In order to know when it is a good time to verify requests on a double
|
3
|
+
As test developer
|
4
|
+
I want to be able to wait until specified number of requests happen
|
5
|
+
|
6
|
+
Background:
|
7
|
+
Given I created a double:
|
8
|
+
"""
|
9
|
+
@double = RestAssured::Double.create(:fullpath => '/some/api')
|
10
|
+
"""
|
11
|
+
|
12
|
+
Scenario: succesfully wait for requests
|
13
|
+
When I wait for 3 requests:
|
14
|
+
"""
|
15
|
+
@double.wait_for_requests(3)
|
16
|
+
"""
|
17
|
+
And that double gets requested 3 times
|
18
|
+
Then it should let me through
|
19
|
+
|
20
|
+
Scenario: wait for requests that never come
|
21
|
+
When I wait for 3 requests:
|
22
|
+
"""
|
23
|
+
@double.wait_for_requests(3)
|
24
|
+
"""
|
25
|
+
And that double gets requested 2 times
|
26
|
+
Then it should wait for 5 seconds (default timeout)
|
27
|
+
And it should raise MoreRequestsExpected error after with the following message:
|
28
|
+
"""
|
29
|
+
Expected 3 requests. Got 2.
|
30
|
+
"""
|
31
|
+
|
32
|
+
@now
|
33
|
+
Scenario: custom timeout
|
34
|
+
When I wait for 3 requests:
|
35
|
+
"""
|
36
|
+
@double.wait_for_requests(3, :timeout => 3)
|
37
|
+
"""
|
38
|
+
And that double gets requested 2 times
|
39
|
+
Then it should wait for 3 seconds
|
@@ -33,3 +33,15 @@ Then /^database options should be:$/ do |table|
|
|
33
33
|
@app_config[:db_config][:encoding].should == empty_to_nil[res['dbencoding']]
|
34
34
|
@app_config[:db_config][:socket].should == empty_to_nil[res['dbsocket']]
|
35
35
|
end
|
36
|
+
|
37
|
+
Then /^ssl certificate used should be "([^"]*)" and ssl key should be "([^"]*)"$/ do |ssl_cert, ssl_key|
|
38
|
+
ssl_cert = File.expand_path('../../../ssl/localhost.crt', __FILE__) if ssl_cert == 'DEFAULT_CERT'
|
39
|
+
ssl_key = File.expand_path('../../../ssl/localhost.key', __FILE__) if ssl_key == 'DEFAULT_KEY'
|
40
|
+
|
41
|
+
@app_config[:ssl_cert].should == ssl_cert
|
42
|
+
@app_config[:ssl_key].should == ssl_key
|
43
|
+
end
|
44
|
+
|
45
|
+
Then /^rest\-assured should "([^"]*)"$/ do |use|
|
46
|
+
@app_config[:use_ssl].to_s.should == use
|
47
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# REST api steps
|
2
2
|
|
3
3
|
Given /^there are no doubles$/ do
|
4
|
-
Double.destroy_all
|
4
|
+
RestAssured::Models::Double.destroy_all
|
5
5
|
end
|
6
6
|
|
7
7
|
When /^I create a double with "([^"]*)" as fullpath and "([^"]*)" as response content$/ do |fullpath, content|
|
@@ -19,19 +19,19 @@ Then /^I should get (#{CAPTURE_A_NUMBER}) in response status$/ do |status|
|
|
19
19
|
end
|
20
20
|
|
21
21
|
Then /^there should be (#{CAPTURE_A_NUMBER}) double with "([^"]*)" as fullpath and "([^"]*)" as response content$/ do |n, fullpath, content|
|
22
|
-
Double.where(:fullpath => fullpath, :content => content).count.should == n
|
22
|
+
RestAssured::Models::Double.where(:fullpath => fullpath, :content => content).count.should == n
|
23
23
|
end
|
24
24
|
|
25
25
|
Then /^there should be (#{CAPTURE_A_NUMBER}) double with "([^""]*)" as fullpath, "([^""]*)" as response content, "([^""]*)" as request verb and status as "(#{CAPTURE_A_NUMBER})"$/ do |n, fullpath, content, verb, status|
|
26
|
-
Double.where(:fullpath => fullpath, :content => content, :verb => verb, :status => status).count.should == n
|
26
|
+
RestAssured::Models::Double.where(:fullpath => fullpath, :content => content, :verb => verb, :status => status).count.should == n
|
27
27
|
end
|
28
28
|
|
29
29
|
Given /^there is double with "([^"]*)" as fullpath and "([^"]*)" as response content$/ do |fullpath, content|
|
30
|
-
Double.create(:fullpath => fullpath, :content => content)
|
30
|
+
RestAssured::Models::Double.create(:fullpath => fullpath, :content => content)
|
31
31
|
end
|
32
32
|
|
33
33
|
Given /^there is double with "([^"]*)" as fullpath, "([^"]*)" as response content, "([^"]*)" as request verb and "([^"]*)" as status$/ do |fullpath, content, verb, status|
|
34
|
-
Double.create(:fullpath => fullpath, :content => content, :verb => verb, :status => status)
|
34
|
+
RestAssured::Models::Double.create(:fullpath => fullpath, :content => content, :verb => verb, :status => status)
|
35
35
|
end
|
36
36
|
|
37
37
|
Given /^I register "([^"]*)" as fullpath and "([^"]*)" as response content$/ do |fullpath, content|
|
@@ -54,7 +54,7 @@ end
|
|
54
54
|
|
55
55
|
Given /^there are some doubles$/ do
|
56
56
|
[['fullpath1', 'content1'], ['fullpath2', 'content2'], ['fullpath3', 'content3']].each do |double|
|
57
|
-
Double.create(:fullpath => double[0], :content => double[1])
|
57
|
+
RestAssured::Models::Double.create(:fullpath => double[0], :content => double[1])
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -64,14 +64,14 @@ When /^I delete all doubles$/ do
|
|
64
64
|
end
|
65
65
|
|
66
66
|
Then /^there should be no doubles$/ do
|
67
|
-
Double.count.should == 0
|
67
|
+
RestAssured::Models::Double.count.should == 0
|
68
68
|
end
|
69
69
|
|
70
70
|
# UI steps
|
71
71
|
|
72
72
|
Given /^the following doubles exist:$/ do |doubles|
|
73
73
|
doubles.hashes.each do |row|
|
74
|
-
Double.create(:fullpath => row['fullpath'], :description => row['description'], :content => row['content'])
|
74
|
+
RestAssured::Models::Double.create(:fullpath => row['fullpath'], :description => row['description'], :content => row['content'])
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
@@ -115,8 +115,8 @@ Then /^I should (not)? ?see "([^"]*)"$/ do |see, text|
|
|
115
115
|
end
|
116
116
|
|
117
117
|
Given /^there are two doubles for the same fullpath$/ do
|
118
|
-
@first = Double.create :fullpath => '/api/something', :content => 'some content'
|
119
|
-
@second = Double.create :fullpath => '/api/something', :content => 'other content'
|
118
|
+
@first = RestAssured::Models::Double.create :fullpath => '/api/something', :content => 'some content'
|
119
|
+
@second = RestAssured::Models::Double.create :fullpath => '/api/something', :content => 'other content'
|
120
120
|
end
|
121
121
|
|
122
122
|
When /^I make (first|second) double active$/ do |ord|
|