rest-assured 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -1
- data/.travis.yml +1 -1
- data/Gemfile +25 -23
- data/Gemfile.lock +182 -0
- data/Procfile +1 -0
- data/README.markdown +33 -6
- data/bin/heroku_runner +26 -0
- data/bin/rest-assured +6 -6
- data/features/command_line_options.feature +31 -13
- data/features/ruby_api/create_double.feature +3 -3
- data/features/step_definitions/command_line_options_steps.rb +6 -6
- data/features/support/env.rb +1 -1
- data/lib/rest-assured/config.rb +16 -8
- data/lib/rest-assured/models/double.rb +5 -0
- data/lib/rest-assured/routes/double.rb +8 -8
- data/lib/rest-assured/version.rb +1 -1
- data/rest-assured.gemspec +3 -3
- data/spec/functional/response_spec.rb +6 -6
- data/spec/spec_helper.rb +1 -1
- metadata +21 -18
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -3,35 +3,37 @@ source "http://rubygems.org"
|
|
3
3
|
# Specify your gem's dependencies in rest-assured.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
gem '
|
7
|
-
gem 'cucumber'
|
8
|
-
gem 'database_cleaner'
|
9
|
-
gem 'rspec'
|
10
|
-
gem 'shoulda-matchers'
|
11
|
-
gem 'rack-test'
|
12
|
-
gem 'capybara'
|
13
|
-
gem 'capybara-firebug'
|
14
|
-
gem 'rake'
|
15
|
-
gem 'mysql2'
|
16
|
-
gem 'sqlite3'
|
6
|
+
gem 'pg'
|
17
7
|
gem 'thin'
|
18
|
-
gem 'relish'
|
19
|
-
gem "spork", "> 0.9.0.rc"
|
20
|
-
gem 'childprocess'
|
21
8
|
|
22
|
-
|
9
|
+
# skipped for heroku
|
10
|
+
group :test do
|
11
|
+
gem 'awesome_print'
|
12
|
+
gem 'cucumber'
|
13
|
+
gem 'database_cleaner'
|
14
|
+
gem 'rspec'
|
15
|
+
gem 'shoulda-matchers'
|
16
|
+
gem 'rack-test'
|
17
|
+
gem 'capybara'
|
18
|
+
gem 'capybara-firebug'
|
19
|
+
gem 'rake'
|
20
|
+
gem 'mysql2'
|
21
|
+
gem 'sqlite3'
|
22
|
+
gem 'relish'
|
23
|
+
gem 'sinatra-activerecord'
|
24
|
+
gem "spork", "> 0.9.0.rc"
|
25
|
+
gem 'simplecov', :platforms => :ruby_19
|
26
|
+
end
|
27
|
+
|
28
|
+
# skipped for heroku and travis
|
29
|
+
group :development do
|
23
30
|
gem 'ruby-debug', :platform => :mri_18
|
24
31
|
gem 'ruby-debug19', :platform => :mri_19
|
25
|
-
gem 'awesome_print'
|
26
32
|
gem 'interactive_editor'
|
27
33
|
gem 'launchy'
|
28
34
|
gem "guard-spork"
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
gem 'rb-readline'
|
33
|
-
end
|
34
|
-
gem 'sinatra-activerecord'
|
35
|
-
gem 'simplecov', :platforms => :ruby_19
|
35
|
+
gem 'growl'
|
36
|
+
gem 'rb-fsevent'
|
37
|
+
gem 'rb-readline'
|
36
38
|
end
|
37
39
|
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rest-assured (1.1.2)
|
5
|
+
activerecord (~> 3.2.0)
|
6
|
+
activeresource (~> 3.2.0)
|
7
|
+
childprocess (~> 0.3.0)
|
8
|
+
haml (>= 3.1.3)
|
9
|
+
sinatra (~> 1.3.2)
|
10
|
+
sinatra-flash
|
11
|
+
|
12
|
+
GEM
|
13
|
+
remote: http://rubygems.org/
|
14
|
+
specs:
|
15
|
+
activemodel (3.2.1)
|
16
|
+
activesupport (= 3.2.1)
|
17
|
+
builder (~> 3.0.0)
|
18
|
+
activerecord (3.2.1)
|
19
|
+
activemodel (= 3.2.1)
|
20
|
+
activesupport (= 3.2.1)
|
21
|
+
arel (~> 3.0.0)
|
22
|
+
tzinfo (~> 0.3.29)
|
23
|
+
activeresource (3.2.1)
|
24
|
+
activemodel (= 3.2.1)
|
25
|
+
activesupport (= 3.2.1)
|
26
|
+
activesupport (3.2.1)
|
27
|
+
i18n (~> 0.6)
|
28
|
+
multi_json (~> 1.0)
|
29
|
+
addressable (2.2.7)
|
30
|
+
archive-tar-minitar (0.5.2)
|
31
|
+
arel (3.0.0)
|
32
|
+
awesome_print (1.0.2)
|
33
|
+
builder (3.0.0)
|
34
|
+
capybara (1.1.2)
|
35
|
+
mime-types (>= 1.16)
|
36
|
+
nokogiri (>= 1.3.3)
|
37
|
+
rack (>= 1.0.0)
|
38
|
+
rack-test (>= 0.5.4)
|
39
|
+
selenium-webdriver (~> 2.0)
|
40
|
+
xpath (~> 0.1.4)
|
41
|
+
capybara-firebug (1.1.0)
|
42
|
+
capybara (~> 1.0)
|
43
|
+
childprocess (0.3.1)
|
44
|
+
ffi (~> 1.0.6)
|
45
|
+
columnize (0.3.6)
|
46
|
+
cucumber (1.1.4)
|
47
|
+
builder (>= 2.1.2)
|
48
|
+
diff-lcs (>= 1.1.2)
|
49
|
+
gherkin (~> 2.7.1)
|
50
|
+
json (>= 1.4.6)
|
51
|
+
term-ansicolor (>= 1.0.6)
|
52
|
+
daemons (1.1.8)
|
53
|
+
database_cleaner (0.7.1)
|
54
|
+
diff-lcs (1.1.3)
|
55
|
+
eventmachine (0.12.10)
|
56
|
+
ffi (1.0.11)
|
57
|
+
gherkin (2.7.7)
|
58
|
+
json (>= 1.4.6)
|
59
|
+
growl (1.0.3)
|
60
|
+
guard (1.0.0)
|
61
|
+
ffi (>= 0.5.0)
|
62
|
+
thor (~> 0.14.6)
|
63
|
+
guard-spork (0.5.2)
|
64
|
+
guard (>= 0.10.0)
|
65
|
+
spork (>= 0.8.4)
|
66
|
+
haml (3.1.4)
|
67
|
+
i18n (0.6.0)
|
68
|
+
interactive_editor (0.0.10)
|
69
|
+
spoon (>= 0.0.1)
|
70
|
+
json (1.6.5)
|
71
|
+
launchy (2.0.5)
|
72
|
+
addressable (~> 2.2.6)
|
73
|
+
linecache (0.46)
|
74
|
+
rbx-require-relative (> 0.0.4)
|
75
|
+
linecache19 (0.5.13)
|
76
|
+
ruby_core_source (>= 0.1.4)
|
77
|
+
mime-types (1.17.2)
|
78
|
+
multi_json (1.0.4)
|
79
|
+
mysql2 (0.3.11)
|
80
|
+
nokogiri (1.5.0)
|
81
|
+
pg (0.13.2)
|
82
|
+
rack (1.4.1)
|
83
|
+
rack-protection (1.2.0)
|
84
|
+
rack
|
85
|
+
rack-test (0.6.1)
|
86
|
+
rack (>= 1.0)
|
87
|
+
rake (0.9.2.2)
|
88
|
+
rb-fsevent (0.9.0)
|
89
|
+
rb-readline (0.4.2)
|
90
|
+
rbx-require-relative (0.0.5)
|
91
|
+
relish (0.5.3)
|
92
|
+
archive-tar-minitar (>= 0.5.2)
|
93
|
+
json (>= 1.4.6)
|
94
|
+
rest-client (>= 1.6.1)
|
95
|
+
rest-client (1.6.7)
|
96
|
+
mime-types (>= 1.16)
|
97
|
+
rspec (2.8.0)
|
98
|
+
rspec-core (~> 2.8.0)
|
99
|
+
rspec-expectations (~> 2.8.0)
|
100
|
+
rspec-mocks (~> 2.8.0)
|
101
|
+
rspec-core (2.8.0)
|
102
|
+
rspec-expectations (2.8.0)
|
103
|
+
diff-lcs (~> 1.1.2)
|
104
|
+
rspec-mocks (2.8.0)
|
105
|
+
ruby-debug (0.10.4)
|
106
|
+
columnize (>= 0.1)
|
107
|
+
ruby-debug-base (~> 0.10.4.0)
|
108
|
+
ruby-debug-base (0.10.4)
|
109
|
+
linecache (>= 0.3)
|
110
|
+
ruby-debug-base19 (0.11.26)
|
111
|
+
columnize (>= 0.3.1)
|
112
|
+
linecache19 (>= 0.5.11)
|
113
|
+
ruby_core_source (>= 0.1.4)
|
114
|
+
ruby-debug19 (0.11.6)
|
115
|
+
columnize (>= 0.3.1)
|
116
|
+
linecache19 (>= 0.5.11)
|
117
|
+
ruby-debug-base19 (>= 0.11.19)
|
118
|
+
ruby_core_source (0.1.5)
|
119
|
+
archive-tar-minitar (>= 0.5.2)
|
120
|
+
rubyzip (0.9.6.1)
|
121
|
+
selenium-webdriver (2.19.0)
|
122
|
+
childprocess (>= 0.2.5)
|
123
|
+
ffi (~> 1.0.9)
|
124
|
+
multi_json (~> 1.0.4)
|
125
|
+
rubyzip
|
126
|
+
shoulda-matchers (1.0.0)
|
127
|
+
simplecov (0.5.4)
|
128
|
+
multi_json (~> 1.0.3)
|
129
|
+
simplecov-html (~> 0.5.3)
|
130
|
+
simplecov-html (0.5.3)
|
131
|
+
sinatra (1.3.2)
|
132
|
+
rack (~> 1.3, >= 1.3.6)
|
133
|
+
rack-protection (~> 1.2)
|
134
|
+
tilt (~> 1.3, >= 1.3.3)
|
135
|
+
sinatra-activerecord (0.1.3)
|
136
|
+
sinatra (>= 0.9.4)
|
137
|
+
sinatra-flash (0.3.0)
|
138
|
+
sinatra (>= 1.0.0)
|
139
|
+
spoon (0.0.1)
|
140
|
+
spork (1.0.0rc2)
|
141
|
+
sqlite3 (1.3.5)
|
142
|
+
term-ansicolor (1.0.7)
|
143
|
+
thin (1.3.1)
|
144
|
+
daemons (>= 1.0.9)
|
145
|
+
eventmachine (>= 0.12.6)
|
146
|
+
rack (>= 1.0.0)
|
147
|
+
thor (0.14.6)
|
148
|
+
tilt (1.3.3)
|
149
|
+
tzinfo (0.3.31)
|
150
|
+
xpath (0.1.4)
|
151
|
+
nokogiri (~> 1.3)
|
152
|
+
|
153
|
+
PLATFORMS
|
154
|
+
ruby
|
155
|
+
|
156
|
+
DEPENDENCIES
|
157
|
+
awesome_print
|
158
|
+
capybara
|
159
|
+
capybara-firebug
|
160
|
+
cucumber
|
161
|
+
database_cleaner
|
162
|
+
growl
|
163
|
+
guard-spork
|
164
|
+
interactive_editor
|
165
|
+
launchy
|
166
|
+
mysql2
|
167
|
+
pg
|
168
|
+
rack-test
|
169
|
+
rake
|
170
|
+
rb-fsevent
|
171
|
+
rb-readline
|
172
|
+
relish
|
173
|
+
rest-assured!
|
174
|
+
rspec
|
175
|
+
ruby-debug
|
176
|
+
ruby-debug19
|
177
|
+
shoulda-matchers
|
178
|
+
simplecov
|
179
|
+
sinatra-activerecord
|
180
|
+
spork (> 0.9.0.rc)
|
181
|
+
sqlite3
|
182
|
+
thin
|
data/Procfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
web: bundle exec ./bin/heroku_runner
|
data/README.markdown
CHANGED
@@ -4,8 +4,8 @@
|
|
4
4
|
|
5
5
|
## Overview
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
Stub/spy http(s) based external dependencies in your integration/acceptance tests.
|
8
|
+
In essense, here is what it could be useful for:
|
9
9
|
|
10
10
|
* stub out external data sources with predefined data
|
11
11
|
* verify requests to external services (aka spying)
|
@@ -15,11 +15,11 @@ There are three main use cases:
|
|
15
15
|
|
16
16
|
You are going to need MRI ruby >= 1.8.7 on Linux/MacOS.
|
17
17
|
|
18
|
-
Rest-assured requires a database to run. Either sqlite or
|
18
|
+
Rest-assured requires a database to run. Either sqlite, mysql or postgres. So, make sure there is one and its backed with corresponding client gem:
|
19
19
|
|
20
|
-
bash$ gem install sqlite3 # or mysql2
|
20
|
+
bash$ gem install sqlite3 # or mysql2 or pg
|
21
21
|
|
22
|
-
If using mysql, rest-assured expects database `rest_assured` to be accessible by user `root` with no password. Those are defaults and can be changed with cli options.
|
22
|
+
If using mysql/postgres, rest-assured expects database `rest_assured` to be accessible by user `root` with no password. Those are defaults and can be changed with cli options.
|
23
23
|
|
24
24
|
It is also recommended to have thin installed. This improves startup time (over default webrick) and also it works with in-memory sqlite (which webrick does not):
|
25
25
|
|
@@ -30,7 +30,7 @@ Then install gem and run:
|
|
30
30
|
bash$ gem install rest-assured
|
31
31
|
bash$ rest-assured &
|
32
32
|
|
33
|
-
Or clone
|
33
|
+
Or clone and run:
|
34
34
|
|
35
35
|
bash$ git clone git@github.com:BBC/rest-assured.git
|
36
36
|
bash$ cd rest-assured && bundle install
|
@@ -40,6 +40,17 @@ This starts up an instance of rest-assured on port 4578. It is accessible via RE
|
|
40
40
|
|
41
41
|
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.
|
42
42
|
|
43
|
+
You can also deploy it to heroku:
|
44
|
+
|
45
|
+
bash$ git clone git@github.com:BBC/rest-assured.git
|
46
|
+
bash$ cd rest-assured
|
47
|
+
|
48
|
+
bash$ gem install heroku
|
49
|
+
bash$ heroku login # assuming you already have an account
|
50
|
+
bash$ heroku create --stack cedar
|
51
|
+
|
52
|
+
bash$ git push heroku master
|
53
|
+
|
43
54
|
## Doubles
|
44
55
|
|
45
56
|
Double is a stub/spy of HTTP request. Create a double that has the same request fullpath and method as the one your app is sending to a dependant service and then convience your app that rest-assured is that dependency (hint: by making endpoints configurable).
|
@@ -82,6 +93,8 @@ Then let us assume that `http://localhost:4578/products` got POSTed as a result
|
|
82
93
|
|
83
94
|
```ruby
|
84
95
|
@double.wait_for_requests(1, timeout: 10) # defaults to 5 seconds
|
96
|
+
# or, if waiting for specific amount of requests does not suit the test, just
|
97
|
+
@double.reload # before verifying
|
85
98
|
|
86
99
|
req = @double.requests.first
|
87
100
|
|
@@ -191,6 +204,15 @@ Here is the rest API for managing redirects:
|
|
191
204
|
### Delete all redirects
|
192
205
|
|
193
206
|
HTTP DELETE to `/redirects/all` deletes all redirects. Useful for cleaning up between tests.
|
207
|
+
|
208
|
+
## Running tests
|
209
|
+
|
210
|
+
Tests require there to be mysql database `rest_assured_test` accessible by `root` with no password. Cucumber tests also need firefox.
|
211
|
+
|
212
|
+
bash$ git clone git@github.com:BBC/rest-assured.git
|
213
|
+
bash$ cd rest-assured && bundle install
|
214
|
+
bash$ bundle exec rspec spec
|
215
|
+
bash$ bundle exec cucumber
|
194
216
|
|
195
217
|
## Author
|
196
218
|
|
@@ -198,6 +220,11 @@ Here is the rest API for managing redirects:
|
|
198
220
|
|
199
221
|
## Changelog
|
200
222
|
|
223
|
+
#### 1.1.2 (04 Mar 2012)
|
224
|
+
|
225
|
+
* support postgres
|
226
|
+
* heroku deployable
|
227
|
+
|
201
228
|
#### 1.1.1 (01 Mar 2012)
|
202
229
|
|
203
230
|
* Add 'verb' to UI
|
data/bin/heroku_runner
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.push File.expand_path('../../lib', __FILE__)
|
4
|
+
|
5
|
+
require 'rest-assured/config'
|
6
|
+
require 'uri'
|
7
|
+
|
8
|
+
# disable buffering to have log messages sent straight to Heroku’s logging infrastructure
|
9
|
+
$stdout.sync = true
|
10
|
+
|
11
|
+
db = URI.parse(ENV['DATABASE_URL'])
|
12
|
+
|
13
|
+
opts = {
|
14
|
+
port: ENV['PORT'],
|
15
|
+
adapter: 'postgresql',
|
16
|
+
dbhost: db.host,
|
17
|
+
user: db.user,
|
18
|
+
dbpass: db.password,
|
19
|
+
database: db.path[1..-1],
|
20
|
+
encoding: 'utf8'
|
21
|
+
}
|
22
|
+
|
23
|
+
RestAssured::Config.build(opts)
|
24
|
+
|
25
|
+
require 'rest-assured/application'
|
26
|
+
RestAssured::Application.run!
|
data/bin/rest-assured
CHANGED
@@ -11,7 +11,7 @@ user_opts = {}
|
|
11
11
|
OptionParser.new do |opts|
|
12
12
|
opts.banner = "Usage: rest-assured [options]"
|
13
13
|
|
14
|
-
opts.on('-a', '--adapter mysql|sqlite') do |adapter|
|
14
|
+
opts.on('-a', '--adapter mysql|sqlite|postgresql') do |adapter|
|
15
15
|
user_opts[:adapter] = adapter
|
16
16
|
end
|
17
17
|
|
@@ -19,23 +19,23 @@ OptionParser.new do |opts|
|
|
19
19
|
user_opts[:database] = fname
|
20
20
|
end
|
21
21
|
|
22
|
-
opts.on('-u', '--dbuser DBUSER', "Db username (mysql only)") do |user|
|
22
|
+
opts.on('-u', '--dbuser DBUSER', "Db username (mysql, postgresql only)") do |user|
|
23
23
|
user_opts[:user] = user
|
24
24
|
end
|
25
25
|
|
26
|
-
opts.on('--dbpass DBPASSWORD', 'Db password (mysql only). Defaults to empty') do |password|
|
26
|
+
opts.on('--dbpass DBPASSWORD', 'Db password (mysql, postgresql only). Defaults to empty') do |password|
|
27
27
|
user_opts[:dbpass] = password
|
28
28
|
end
|
29
29
|
|
30
|
-
opts.on('--dbhost DBHOST', 'Db host (mysql only). Defaults to mysql default host (localhost)') do |dbhost|
|
30
|
+
opts.on('--dbhost DBHOST', 'Db host (mysql, postgresql only). Defaults to mysql default host (localhost)') do |dbhost|
|
31
31
|
user_opts[:dbhost] = dbhost
|
32
32
|
end
|
33
33
|
|
34
|
-
opts.on('--dbport DBPORT', Integer, 'Db port (mysql only). Defaults to
|
34
|
+
opts.on('--dbport DBPORT', Integer, 'Db port (mysql, postgresql only). Defaults to adapters default port') do |dbport|
|
35
35
|
user_opts[:dbport] = dbport
|
36
36
|
end
|
37
37
|
|
38
|
-
opts.on('--dbencoding DBENCODING', 'Db encoding (mysql only). Defaults to
|
38
|
+
opts.on('--dbencoding DBENCODING', 'Db encoding (mysql, postgresql only). Defaults to adapters default encoding') do |dbencoding|
|
39
39
|
user_opts[:dbencoding] = dbencoding
|
40
40
|
end
|
41
41
|
|
@@ -36,21 +36,39 @@ Feature: command line options
|
|
36
36
|
Scenario Outline: mysql options
|
37
37
|
When I start rest-assured with -a mysql <options>
|
38
38
|
Then database options should be:
|
39
|
-
| dbname | dbuser | dbpass | dbhost | dbport | dbencoding | dbsocket |
|
40
|
-
| <dbname> | <dbuser> | <dbpass> | <dbhost> | <dbport> | <dbencoding> | <dbsocket> |
|
39
|
+
| dbname | dbuser | dbpass | dbhost | dbport | dbencoding | dbsocket | adapter |
|
40
|
+
| <dbname> | <dbuser> | <dbpass> | <dbhost> | <dbport> | <dbencoding> | <dbsocket> | <adapter> |
|
41
41
|
|
42
42
|
Examples:
|
43
|
-
| options | dbname | dbuser | dbpass | dbhost | dbport | dbencoding | dbsocket |
|
44
|
-
| | rest_assured | root | | | | | |
|
45
|
-
| -d resta | resta | root | | | | | |
|
46
|
-
| --database resta | resta | root | | | | | |
|
47
|
-
| -u bob | rest_assured | bob | | | | | |
|
48
|
-
| --dbuser bob | rest_assured | bob | | | | | |
|
49
|
-
| --dbpass pswd | rest_assured | root | pswd | | | | |
|
50
|
-
| --dbhost remote | rest_assured | root | | remote | | | |
|
51
|
-
| --dbport 5555 | rest_assured | root | | | 5555 | | |
|
52
|
-
| --dbencoding utf16le | rest_assured | root | | | | utf16le | |
|
53
|
-
| --dbsocket /tmp/mysql.sock | rest_assured | root | | | | | /tmp/mysql.sock |
|
43
|
+
| options | dbname | dbuser | dbpass | dbhost | dbport | dbencoding | dbsocket | adapter |
|
44
|
+
| | rest_assured | root | | | | | | mysql2 |
|
45
|
+
| -d resta | resta | root | | | | | | mysql2 |
|
46
|
+
| --database resta | resta | root | | | | | | mysql2 |
|
47
|
+
| -u bob | rest_assured | bob | | | | | | mysql2 |
|
48
|
+
| --dbuser bob | rest_assured | bob | | | | | | mysql2 |
|
49
|
+
| --dbpass pswd | rest_assured | root | pswd | | | | | mysql2 |
|
50
|
+
| --dbhost remote | rest_assured | root | | remote | | | | mysql2 |
|
51
|
+
| --dbport 5555 | rest_assured | root | | | 5555 | | | mysql2 |
|
52
|
+
| --dbencoding utf16le | rest_assured | root | | | | utf16le | | mysql2 |
|
53
|
+
| --dbsocket /tmp/mysql.sock | rest_assured | root | | | | | /tmp/mysql.sock | mysql2 |
|
54
|
+
|
55
|
+
Scenario Outline: postgresql options
|
56
|
+
When I start rest-assured with -a postgresql <options>
|
57
|
+
Then database options should be:
|
58
|
+
| dbname | dbuser | dbpass | dbhost | dbport | dbencoding | adapter |
|
59
|
+
| <dbname> | <dbuser> | <dbpass> | <dbhost> | <dbport> | <dbencoding> | <adapter> |
|
60
|
+
|
61
|
+
Examples:
|
62
|
+
| options | dbname | dbuser | dbpass | dbhost | dbport | dbencoding | adapter |
|
63
|
+
| | rest_assured | root | | | | | postgresql |
|
64
|
+
| -d resta | resta | root | | | | | postgresql |
|
65
|
+
| --database resta | resta | root | | | | | postgresql |
|
66
|
+
| -u bob | rest_assured | bob | | | | | postgresql |
|
67
|
+
| --dbuser bob | rest_assured | bob | | | | | postgresql |
|
68
|
+
| --dbpass pswd | rest_assured | root | pswd | | | | postgresql |
|
69
|
+
| --dbhost remote | rest_assured | root | | remote | | | postgresql |
|
70
|
+
| --dbport 5555 | rest_assured | root | | | 5555 | | postgresql |
|
71
|
+
| --dbencoding utf16le | rest_assured | root | | | | utf16le | postgresql |
|
54
72
|
|
55
73
|
Scenario Outline: use ssl option
|
56
74
|
When I start rest-assured with <option>
|
@@ -23,14 +23,14 @@ Feature: create double
|
|
23
23
|
Scenario: specify response headers
|
24
24
|
When I create a double:
|
25
25
|
"""
|
26
|
-
@double = RestAssured::Double.create(:fullpath => '/some/api', :response_headers => { 'Content-
|
26
|
+
@double = RestAssured::Double.create(:fullpath => '/some/api', :response_headers => { 'Content-Type2' => 'text/html' })
|
27
27
|
"""
|
28
28
|
Then the following should be true:
|
29
29
|
"""
|
30
|
-
@double.response_headers.should == { 'Content-
|
30
|
+
@double.response_headers.should == { 'Content-Type2' => 'text/html' }
|
31
31
|
|
32
32
|
get @double.fullpath
|
33
|
-
last_response.headers['Content-
|
33
|
+
last_response.headers['Content-Type2'].should == 'text/html'
|
34
34
|
"""
|
35
35
|
|
36
36
|
Scenario: specify content
|
@@ -19,17 +19,17 @@ Then /^database options should be:$/ do |table|
|
|
19
19
|
res = table.hashes.first
|
20
20
|
|
21
21
|
empty_to_nil = lambda do |string|
|
22
|
-
string.empty? ? nil : string
|
22
|
+
string.try(:empty?) ? nil : string
|
23
23
|
end
|
24
24
|
|
25
|
-
@app_config[:db_config][:adapter].should
|
25
|
+
@app_config[:db_config][:adapter].should == res['adapter']
|
26
26
|
@app_config[:db_config][:database].should == res['dbname']
|
27
|
-
@app_config[:db_config][:
|
27
|
+
@app_config[:db_config][:username].should == res['dbuser']
|
28
28
|
@app_config[:db_config][:password].should == empty_to_nil[res['dbpass']]
|
29
|
-
@app_config[:db_config][:host].should
|
30
|
-
@app_config[:db_config][:port].should
|
29
|
+
@app_config[:db_config][:host].should == empty_to_nil[res['dbhost']]
|
30
|
+
@app_config[:db_config][:port].should == empty_to_nil[res['dbport']].try(:to_i)
|
31
31
|
@app_config[:db_config][:encoding].should == empty_to_nil[res['dbencoding']]
|
32
|
-
@app_config[:db_config][:socket].should
|
32
|
+
@app_config[:db_config][:socket].should == empty_to_nil[res['dbsocket']]
|
33
33
|
end
|
34
34
|
|
35
35
|
Then /^ssl certificate used should be "([^"]*)" and ssl key should be "([^"]*)"$/ do |ssl_cert, ssl_key|
|
data/features/support/env.rb
CHANGED
@@ -40,7 +40,7 @@ Spork.prefork do
|
|
40
40
|
World(Capybara, Rack::Test::Methods, RackHeaderHack, WorldHelpers)
|
41
41
|
|
42
42
|
require 'rest-assured/config'
|
43
|
-
db_opts = { :
|
43
|
+
db_opts = { :adapter => 'mysql' }
|
44
44
|
RestAssured::Config.build(db_opts)
|
45
45
|
|
46
46
|
require 'rest-assured'
|
data/lib/rest-assured/config.rb
CHANGED
@@ -138,7 +138,9 @@ module RestAssured
|
|
138
138
|
:adapter => 'sqlite3',
|
139
139
|
:database => AppConfig.database || default_database
|
140
140
|
}
|
141
|
-
elsif AppConfig.adapter =~ /mysql/i
|
141
|
+
elsif AppConfig.adapter =~ /postgres|mysql/i
|
142
|
+
adapter = $&.downcase
|
143
|
+
|
142
144
|
default_database = if AppConfig.environment != 'production'
|
143
145
|
"rest_assured_#{AppConfig.environment}"
|
144
146
|
else
|
@@ -146,18 +148,24 @@ module RestAssured
|
|
146
148
|
end
|
147
149
|
|
148
150
|
opts = {
|
149
|
-
:adapter
|
150
|
-
:
|
151
|
-
:pool => 20,
|
152
|
-
:user => AppConfig.user || 'root',
|
151
|
+
:adapter => 'postgresql',
|
152
|
+
:username => AppConfig.user || 'root',
|
153
153
|
:database => AppConfig.database || default_database
|
154
154
|
}
|
155
155
|
|
156
|
+
if adapter =~ /mysql/
|
157
|
+
opts.merge!(
|
158
|
+
:adapter => 'mysql2',
|
159
|
+
:reconnect => true,
|
160
|
+
:pool => 20
|
161
|
+
)
|
162
|
+
opts[:socket] = AppConfig.dbsocket if AppConfig.dbsocket
|
163
|
+
end
|
164
|
+
|
156
165
|
opts[:password] = AppConfig.dbpass if AppConfig.dbpass
|
157
|
-
opts[:host]
|
158
|
-
opts[:port]
|
166
|
+
opts[:host] = AppConfig.dbhost if AppConfig.dbhost
|
167
|
+
opts[:port] = AppConfig.dbport if AppConfig.dbport
|
159
168
|
opts[:encoding] = AppConfig.dbencoding if AppConfig.dbencoding
|
160
|
-
opts[:socket] = AppConfig.dbsocket if AppConfig.dbsocket
|
161
169
|
opts
|
162
170
|
else
|
163
171
|
raise "Unsupported db adapter '#{AppConfig.adapter}'. Valid adapters are sqlite and mysql"
|
@@ -17,6 +17,7 @@ module RestAssured
|
|
17
17
|
before_save :toggle_active
|
18
18
|
before_validation :set_verb
|
19
19
|
before_validation :set_status
|
20
|
+
before_validation :set_response_headers
|
20
21
|
after_destroy :set_active
|
21
22
|
|
22
23
|
has_many :requests, :dependent => :destroy
|
@@ -31,6 +32,10 @@ module RestAssured
|
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
35
|
+
def set_response_headers
|
36
|
+
self.response_headers = {} unless response_headers.present?
|
37
|
+
end
|
38
|
+
|
34
39
|
def set_verb
|
35
40
|
self.verb = 'GET' unless verb.present?
|
36
41
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'active_support/core_ext/hash/slice'
|
2
3
|
|
3
4
|
module RestAssured
|
4
5
|
module DoubleRoutes
|
@@ -36,15 +37,14 @@ module RestAssured
|
|
36
37
|
begin
|
37
38
|
data = request.body.read
|
38
39
|
d = JSON.parse(data)['double']
|
40
|
+
|
41
|
+
# fix acitve resource dumbness
|
42
|
+
if d['response_headers'] and d['response_headers']['response_headers']
|
43
|
+
d['response_headers'] = d['response_headers']['response_headers']
|
44
|
+
end
|
39
45
|
rescue
|
40
|
-
d = params['double'] ||
|
41
|
-
|
42
|
-
:content => params['content'],
|
43
|
-
:description => params['description'],
|
44
|
-
:verb => params['verb'],
|
45
|
-
:status => params['status']
|
46
|
-
}
|
47
|
-
d.merge!(:response_headers => params['response_headers']) if params['response_headers']
|
46
|
+
d = params['double'] ||
|
47
|
+
params.slice(*%w[fullpath content description verb status response_headers])
|
48
48
|
end
|
49
49
|
|
50
50
|
@double = Models::Double.create(d)
|
data/lib/rest-assured/version.rb
CHANGED
data/rest-assured.gemspec
CHANGED
@@ -20,11 +20,11 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.executables = ['rest-assured']
|
21
21
|
s.require_paths = ['lib']
|
22
22
|
|
23
|
-
s.add_dependency 'sinatra', '
|
23
|
+
s.add_dependency 'sinatra', '~> 1.3.2'
|
24
24
|
s.add_dependency 'childprocess', '~> 0.3.0'
|
25
25
|
s.add_dependency 'sinatra-flash'
|
26
26
|
s.add_dependency 'haml', '>= 3.1.3'
|
27
|
-
s.add_dependency 'activerecord', '~> 3.
|
28
|
-
s.add_dependency 'activeresource', '~> 3.
|
27
|
+
s.add_dependency 'activerecord', '~> 3.2.0'
|
28
|
+
s.add_dependency 'activeresource', '~> 3.2.0'
|
29
29
|
end
|
30
30
|
|
@@ -14,12 +14,12 @@ module RestAssured
|
|
14
14
|
let(:env) { stub(:to_json => 'env').as_null_object }
|
15
15
|
let(:request) {
|
16
16
|
double('Request',
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
:request_method => 'GET',
|
18
|
+
:fullpath => '/api',
|
19
|
+
:env => env,
|
20
|
+
:body => stub(:read => 'body').as_null_object,
|
21
|
+
:params => stub(:to_json => 'params')
|
22
|
+
)
|
23
23
|
}
|
24
24
|
let(:rest_assured_app) { double('App', :request => request).as_null_object }
|
25
25
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest-assured
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,22 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sinatra
|
16
|
-
requirement: &
|
16
|
+
requirement: &2162656220 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: 1.3.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2162656220
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: childprocess
|
27
|
-
requirement: &
|
27
|
+
requirement: &2162671380 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.3.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2162671380
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sinatra-flash
|
38
|
-
requirement: &
|
38
|
+
requirement: &2162670920 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2162670920
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: haml
|
49
|
-
requirement: &
|
49
|
+
requirement: &2162669840 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,29 +54,29 @@ dependencies:
|
|
54
54
|
version: 3.1.3
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2162669840
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: activerecord
|
60
|
-
requirement: &
|
60
|
+
requirement: &2162668460 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
64
64
|
- !ruby/object:Gem::Version
|
65
|
-
version: 3.
|
65
|
+
version: 3.2.0
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2162668460
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: activeresource
|
71
|
-
requirement: &
|
71
|
+
requirement: &2162665360 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: 3.
|
76
|
+
version: 3.2.0
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *2162665360
|
80
80
|
description:
|
81
81
|
email:
|
82
82
|
- artem.avetisyan@bbc.co.uk
|
@@ -89,11 +89,14 @@ files:
|
|
89
89
|
- .rspec
|
90
90
|
- .travis.yml
|
91
91
|
- Gemfile
|
92
|
+
- Gemfile.lock
|
92
93
|
- Guardfile
|
93
94
|
- LICENSE
|
95
|
+
- Procfile
|
94
96
|
- README.markdown
|
95
97
|
- Rakefile
|
96
98
|
- bin/console
|
99
|
+
- bin/heroku_runner
|
97
100
|
- bin/rest-assured
|
98
101
|
- cucumber.yml
|
99
102
|
- db/migrate/20110620161740_add_fixtures.rb
|
@@ -206,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
206
209
|
version: '0'
|
207
210
|
segments:
|
208
211
|
- 0
|
209
|
-
hash:
|
212
|
+
hash: 4067297550795796735
|
210
213
|
requirements: []
|
211
214
|
rubyforge_project: rest-assured
|
212
215
|
rubygems_version: 1.8.10
|