rest-assured 2.0.0 → 2.0.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 +4 -0
- data/README.markdown +12 -19
- data/db/development.db +0 -0
- data/db/test.db +0 -0
- data/features/ruby_api/test_server.feature +4 -4
- data/features/step_definitions/command_line_options_steps.rb +1 -1
- data/features/step_definitions/doubles_steps.rb +1 -1
- data/features/support/env.rb +3 -3
- data/features/support/world_helpers.rb +2 -8
- data/lib/rest-assured/api/app_session.rb +6 -1
- data/lib/rest-assured/api/server.rb +2 -14
- data/lib/rest-assured/config.rb +10 -3
- data/lib/rest-assured/models/double.rb +0 -2
- data/lib/rest-assured/models/redirect.rb +1 -3
- data/lib/rest-assured/routes/double.rb +2 -2
- data/lib/rest-assured/version.rb +1 -1
- data/spec/api/app_session_spec.rb +11 -5
- data/spec/api/resource_double_spec.rb +14 -13
- data/spec/api/server_spec.rb +38 -43
- data/spec/config_spec.rb +3 -3
- data/spec/functional/double_routes_spec.rb +53 -53
- data/spec/functional/redirect_routes_spec.rb +27 -27
- data/spec/functional/response_spec.rb +18 -18
- data/spec/models/double_spec.rb +22 -27
- data/spec/models/redirect_spec.rb +12 -15
- data/spec/models/request_spec.rb +4 -4
- data/spec/port_explorer_spec.rb +3 -3
- data/spec/spec_helper.rb +30 -22
- metadata +24 -37
- data/.gitignore +0 -9
- data/.rspec +0 -1
- data/.travis.yml +0 -15
- data/Gemfile +0 -36
- data/Gemfile.lock +0 -176
- data/Guardfile +0 -10
- data/Procfile +0 -1
- data/Rakefile +0 -2
- data/bin/console +0 -11
- data/bin/heroku_runner +0 -27
- data/cucumber.yml +0 -3
- data/features/support/test-server.rb +0 -35
- data/rest-assured.gemspec +0 -31
data/spec/config_spec.rb
CHANGED
@@ -13,18 +13,18 @@ module RestAssured
|
|
13
13
|
describe 'cmd args array conversion' do
|
14
14
|
it 'converts true values in form of "value" => ["--#{value}"]' do
|
15
15
|
Config.build(:ssl => true)
|
16
|
-
Config.to_cmdargs.
|
16
|
+
expect(Config.to_cmdargs).to eq(['--ssl'])
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'does not include false values' do
|
20
20
|
Config.build(:ssl => false)
|
21
|
-
Config.to_cmdargs.
|
21
|
+
expect(Config.to_cmdargs).not_to include('--ssl')
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'converts key value pairs in form of "key => value" => ["--#{key}", "value"]' do
|
25
25
|
Config.build(:port => 1234, :database => ':memory:')
|
26
26
|
Config.to_cmdargs.each_slice(2) do |a|
|
27
|
-
(a == ['--port', '1234'] || a == ['--database', ':memory:']).
|
27
|
+
expect(a == ['--port', '1234'] || a == ['--database', ':memory:']).to eq(true)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -33,7 +33,7 @@ module RestAssured
|
|
33
33
|
context "Web UI", :ui => true do
|
34
34
|
it "makes doubles index root page" do
|
35
35
|
visit '/'
|
36
|
-
current_path.
|
36
|
+
expect(current_path).to eq('/doubles')
|
37
37
|
end
|
38
38
|
|
39
39
|
# this is tested in cucumber
|
@@ -43,47 +43,47 @@ module RestAssured
|
|
43
43
|
|
44
44
|
visit '/doubles'
|
45
45
|
|
46
|
-
page.
|
47
|
-
page.
|
48
|
-
page.
|
49
|
-
page.
|
50
|
-
page.
|
51
|
-
page.
|
46
|
+
expect(page).to have_content(f.fullpath)
|
47
|
+
expect(page).to have_content(f.description)
|
48
|
+
expect(page).to have_content(f.verb)
|
49
|
+
expect(page).to have_content(f1.fullpath)
|
50
|
+
expect(page).to have_content(f1.description)
|
51
|
+
expect(page).to have_content(f1.verb)
|
52
52
|
end
|
53
53
|
|
54
54
|
it "renders form for creating new double" do
|
55
55
|
visit '/doubles/new'
|
56
56
|
|
57
|
-
page.
|
58
|
-
page.
|
59
|
-
page.
|
60
|
-
page.
|
57
|
+
expect(page).to have_css('#double_fullpath')
|
58
|
+
expect(page).to have_css('#double_content')
|
59
|
+
expect(page).to have_css('#double_verb')
|
60
|
+
expect(page).to have_css('#double_description')
|
61
61
|
end
|
62
62
|
|
63
63
|
it "creates double" do
|
64
64
|
post '/doubles', valid_params
|
65
65
|
follow_redirect!
|
66
66
|
|
67
|
-
last_request.fullpath.
|
68
|
-
last_response.body.
|
67
|
+
expect(last_request.fullpath).to eq('/doubles')
|
68
|
+
expect(last_response.body).to match(/Double created/)
|
69
69
|
|
70
70
|
d = Models::Double.where(test_double.except(:response_headers)).first
|
71
|
-
d.response_headers['ACCEPT'].
|
71
|
+
expect(d.response_headers['ACCEPT']).to eq('text/html')
|
72
72
|
end
|
73
73
|
|
74
74
|
it "reports failure when creating with invalid parameters" do
|
75
75
|
post '/doubles', invalid_params
|
76
76
|
|
77
|
-
last_response.
|
78
|
-
last_response.body.
|
77
|
+
expect(last_response).to be_ok
|
78
|
+
expect(last_response.body).to match(/Crumps!.*Fullpath can't be blank/)
|
79
79
|
end
|
80
80
|
|
81
81
|
it "renders double edit form" do
|
82
82
|
f = Models::Double.create test_double
|
83
83
|
visit "/doubles/#{f.id}/edit"
|
84
84
|
|
85
|
-
find('#double_fullpath').value.
|
86
|
-
find('#double_content').value.
|
85
|
+
expect(find('#double_fullpath').value).to eq(f.fullpath)
|
86
|
+
expect(find('#double_content').value).to eq(f.content)
|
87
87
|
end
|
88
88
|
|
89
89
|
it "updates double" do
|
@@ -92,13 +92,13 @@ module RestAssured
|
|
92
92
|
put "/doubles/#{f.id}", 'double[fullpath]' => '/some/other/api'
|
93
93
|
follow_redirect!
|
94
94
|
|
95
|
-
last_request.fullpath.
|
96
|
-
last_response.body.
|
97
|
-
f.reload.fullpath.
|
98
|
-
f.content.
|
99
|
-
f.verb.
|
100
|
-
f.status.to_s.
|
101
|
-
f.response_headers.
|
95
|
+
expect(last_request.fullpath).to eq('/doubles')
|
96
|
+
expect(last_response.body).to match(/Double updated/)
|
97
|
+
expect(f.reload.fullpath).to eq('/some/other/api')
|
98
|
+
expect(f.content).to eq(test_double[:content])
|
99
|
+
expect(f.verb).to eq(test_double[:verb])
|
100
|
+
expect(f.status.to_s).to eq(test_double[:status])
|
101
|
+
expect(f.response_headers).to eq(test_double[:response_headers])
|
102
102
|
end
|
103
103
|
|
104
104
|
it "chooses active double" do
|
@@ -106,8 +106,8 @@ module RestAssured
|
|
106
106
|
|
107
107
|
ajax "/doubles/#{f.id}", :as => :put, :active => true
|
108
108
|
|
109
|
-
last_response.
|
110
|
-
last_response.body.
|
109
|
+
expect(last_response).to be_ok
|
110
|
+
expect(last_response.body).to eq('Changed')
|
111
111
|
end
|
112
112
|
|
113
113
|
it "deletes double" do
|
@@ -116,10 +116,10 @@ module RestAssured
|
|
116
116
|
delete "/doubles/#{f.id}"
|
117
117
|
follow_redirect!
|
118
118
|
|
119
|
-
last_response.
|
120
|
-
last_response.body.
|
119
|
+
expect(last_response).to be_ok
|
120
|
+
expect(last_response.body).to match(/Double deleted/)
|
121
121
|
|
122
|
-
Models::Double.exists?(test_double.except(:response_headers)).
|
122
|
+
expect(Models::Double.exists?(test_double.except(:response_headers))).to be_falsey
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
@@ -127,17 +127,17 @@ module RestAssured
|
|
127
127
|
it "creates double" do
|
128
128
|
post '/doubles.json', test_double
|
129
129
|
|
130
|
-
last_response.
|
130
|
+
expect(last_response).to be_ok
|
131
131
|
|
132
132
|
d = Models::Double.where(test_double.except(:response_headers)).first
|
133
|
-
d.response_headers['ACCEPT'].
|
133
|
+
expect(d.response_headers['ACCEPT']).to eq('text/html')
|
134
134
|
end
|
135
135
|
|
136
136
|
it "reports failure when creating with invalid parameters" do
|
137
137
|
post '/doubles.json', test_double.except(:fullpath)
|
138
138
|
|
139
|
-
last_response.
|
140
|
-
last_response.body.
|
139
|
+
expect(last_response).not_to be_ok
|
140
|
+
expect(last_response.body).to match(/\{"fullpath":\["can't be blank"\]\}/)
|
141
141
|
end
|
142
142
|
|
143
143
|
it "deletes double" do
|
@@ -145,9 +145,9 @@ module RestAssured
|
|
145
145
|
|
146
146
|
delete "/doubles/#{f.id}.json"
|
147
147
|
|
148
|
-
last_response.
|
148
|
+
expect(last_response).to be_ok
|
149
149
|
|
150
|
-
Models::Double.exists?(test_double.except(:response_headers)).
|
150
|
+
expect(Models::Double.exists?(test_double.except(:response_headers))).to be_falsey
|
151
151
|
end
|
152
152
|
|
153
153
|
it "deletes all doubles" do
|
@@ -155,39 +155,39 @@ module RestAssured
|
|
155
155
|
|
156
156
|
delete '/doubles/all'
|
157
157
|
|
158
|
-
last_response.
|
159
|
-
Models::Double.count.
|
158
|
+
expect(last_response).to be_ok
|
159
|
+
expect(Models::Double.count).to eq(0)
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
163
163
|
context 'REST (ActiveResource compatible) json api', :ui => false do
|
164
164
|
it "gets list of doubles" do
|
165
|
-
|
166
|
-
|
165
|
+
Models::Double.create test_double
|
166
|
+
Models::Double.create test_double.merge(:verb => 'GET')
|
167
167
|
|
168
168
|
get '/doubles.json'
|
169
169
|
|
170
|
-
json =
|
170
|
+
json = JSON.load(last_response.body)
|
171
171
|
|
172
|
-
json.first['
|
173
|
-
json.last['
|
172
|
+
expect(json.first['verb']).to eq('POST')
|
173
|
+
expect(json.last['verb']).to eq('GET')
|
174
174
|
end
|
175
175
|
|
176
176
|
it "creates double as AR resource" do
|
177
|
-
post '/doubles.json',
|
177
|
+
post '/doubles.json', test_double.to_json, 'CONTENT_TYPE' => 'Application/json'
|
178
178
|
|
179
|
-
last_response.
|
179
|
+
expect(last_response).to be_ok
|
180
180
|
|
181
181
|
d = Models::Double.where(test_double.except(:response_headers)).first
|
182
|
-
d.response_headers['ACCEPT'].
|
183
|
-
last_response.body.
|
182
|
+
expect(d.response_headers['ACCEPT']).to eq('text/html')
|
183
|
+
expect(last_response.body).to eq(d.to_json)
|
184
184
|
end
|
185
185
|
|
186
186
|
it "reports failure when creating with invalid parameters" do
|
187
|
-
post '/doubles.json',
|
187
|
+
post '/doubles.json', test_double.except(:fullpath).to_json, 'CONTENT_TYPE' => 'Application/json'
|
188
188
|
|
189
|
-
last_response.
|
190
|
-
last_response.body.
|
189
|
+
expect(last_response).not_to be_ok
|
190
|
+
expect(last_response.body).to match(/\{"fullpath":\["can't be blank"\]\}/)
|
191
191
|
end
|
192
192
|
|
193
193
|
it 'loads double as AR resource' do
|
@@ -195,14 +195,14 @@ module RestAssured
|
|
195
195
|
|
196
196
|
get "/doubles/#{d.id}.json", 'CONTENT_TYPE' => 'Application/json'
|
197
197
|
|
198
|
-
last_response.
|
199
|
-
last_response.body.
|
198
|
+
expect(last_response).to be_ok
|
199
|
+
expect(last_response.body).to eq(d.to_json(:include => :requests))
|
200
200
|
end
|
201
201
|
|
202
202
|
it '404s if double is not found' do
|
203
203
|
get "/doubles/345345.json", 'CONTENT_TYPE' => 'Application/json'
|
204
204
|
|
205
|
-
last_response.status.
|
205
|
+
expect(last_response.status).to eq(404)
|
206
206
|
end
|
207
207
|
end
|
208
208
|
end
|
@@ -20,39 +20,39 @@ module RestAssured
|
|
20
20
|
|
21
21
|
visit '/redirects'
|
22
22
|
|
23
|
-
page.
|
24
|
-
page.
|
23
|
+
expect(page).to have_content(r.pattern)
|
24
|
+
expect(page).to have_content(r.to)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "shows form for creating new redirect" do
|
28
28
|
visit '/redirects/new'
|
29
29
|
|
30
|
-
page.
|
31
|
-
page.
|
30
|
+
expect(page).to have_css('#redirect_pattern')
|
31
|
+
expect(page).to have_css('#redirect_to')
|
32
32
|
end
|
33
33
|
|
34
34
|
it "creates redirect" do
|
35
35
|
post '/redirects', valid_params
|
36
36
|
follow_redirect!
|
37
37
|
|
38
|
-
last_request.fullpath.
|
39
|
-
last_response.body.
|
40
|
-
Models::Redirect.exists?(redirect).
|
38
|
+
expect(last_request.fullpath).to eq('/redirects')
|
39
|
+
expect(last_response.body).to match(/Redirect created/)
|
40
|
+
expect(Models::Redirect.exists?(redirect)).to be true
|
41
41
|
end
|
42
42
|
|
43
43
|
it "reports failure when creating with invalid parameters" do
|
44
44
|
post '/redirects', invalid_params
|
45
45
|
|
46
|
-
last_response.
|
47
|
-
last_response.body.
|
46
|
+
expect(last_response).to be_ok
|
47
|
+
expect(last_response.body).to match(/Crumps!.*Pattern can't be blank/)
|
48
48
|
end
|
49
49
|
|
50
50
|
it "brings up redirect edit form" do
|
51
51
|
r = Models::Redirect.create redirect
|
52
52
|
visit "/redirects/#{r.id}/edit"
|
53
53
|
|
54
|
-
find('#redirect_pattern').value.
|
55
|
-
find('#redirect_to').value.
|
54
|
+
expect(find('#redirect_pattern').value).to eq(r.pattern)
|
55
|
+
expect(find('#redirect_to').value).to eq(r.to)
|
56
56
|
end
|
57
57
|
|
58
58
|
it "updates redirect" do
|
@@ -61,9 +61,9 @@ module RestAssured
|
|
61
61
|
put "/redirects/#{r.id}", 'redirect[to]' => '/some/other/api'
|
62
62
|
follow_redirect!
|
63
63
|
|
64
|
-
last_request.fullpath.
|
65
|
-
last_response.body.
|
66
|
-
r.reload.to.
|
64
|
+
expect(last_request.fullpath).to eq('/redirects')
|
65
|
+
expect(last_response.body).to match(/Redirect updated/)
|
66
|
+
expect(r.reload.to).to eq('/some/other/api')
|
67
67
|
end
|
68
68
|
|
69
69
|
it "reorders redirects" do
|
@@ -72,10 +72,10 @@ module RestAssured
|
|
72
72
|
|
73
73
|
put "/redirects/reorder", :redirect => [r2.id, r1.id]
|
74
74
|
|
75
|
-
last_response.
|
76
|
-
last_response.body.
|
77
|
-
r1.reload.position.
|
78
|
-
r2.reload.position.
|
75
|
+
expect(last_response).to be_ok
|
76
|
+
expect(last_response.body).to eq('Changed')
|
77
|
+
expect(r1.reload.position).to eq(1)
|
78
|
+
expect(r2.reload.position).to eq(0)
|
79
79
|
end
|
80
80
|
|
81
81
|
it "deletes redirect" do
|
@@ -84,10 +84,10 @@ module RestAssured
|
|
84
84
|
delete "/redirects/#{f.id}"
|
85
85
|
follow_redirect!
|
86
86
|
|
87
|
-
last_response.
|
88
|
-
last_response.body.
|
87
|
+
expect(last_response).to be_ok
|
88
|
+
expect(last_response.body).to match(/Redirect deleted/)
|
89
89
|
|
90
|
-
Models::Redirect.exists?(redirect).
|
90
|
+
expect(Models::Redirect.exists?(redirect)).to be_falsey
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
@@ -95,15 +95,15 @@ module RestAssured
|
|
95
95
|
it "creates redirect" do
|
96
96
|
post '/redirects.json', redirect
|
97
97
|
|
98
|
-
last_response.
|
99
|
-
Models::Redirect.count.
|
98
|
+
expect(last_response).to be_ok
|
99
|
+
expect(Models::Redirect.count).to eq(1)
|
100
100
|
end
|
101
101
|
|
102
102
|
it "reports failure when creating with invalid parameters" do
|
103
103
|
post '/redirects.json', redirect.except(:pattern)
|
104
104
|
|
105
|
-
last_response.
|
106
|
-
last_response.body.
|
105
|
+
expect(last_response).not_to be_ok
|
106
|
+
expect(last_response.body).to match(/Pattern can't be blank/)
|
107
107
|
end
|
108
108
|
|
109
109
|
it "deletes all redirects" do
|
@@ -111,8 +111,8 @@ module RestAssured
|
|
111
111
|
|
112
112
|
delete '/redirects/all'
|
113
113
|
|
114
|
-
last_response.
|
115
|
-
Models::Redirect.count.
|
114
|
+
expect(last_response).to be_ok
|
115
|
+
expect(Models::Redirect.count).to eq(0)
|
116
116
|
end
|
117
117
|
end
|
118
118
|
end
|
@@ -6,7 +6,7 @@ module RestAssured
|
|
6
6
|
[:get, :post, :put, :delete].each do |verb|
|
7
7
|
it "processes an unknown request" do
|
8
8
|
|
9
|
-
Response.
|
9
|
+
expect(Response).to receive(:perform).with(an_instance_of(RestAssured::Application))
|
10
10
|
send verb, '/some/path'
|
11
11
|
end
|
12
12
|
end
|
@@ -31,44 +31,44 @@ module RestAssured
|
|
31
31
|
:response_headers => { 'ACCEPT' => 'text/html' },
|
32
32
|
:status => 201
|
33
33
|
|
34
|
-
request.
|
34
|
+
allow(request).to receive(:fullpath).and_return(@double.fullpath)
|
35
35
|
end
|
36
36
|
|
37
37
|
it "returns double content" do
|
38
|
-
rest_assured_app.
|
38
|
+
expect(rest_assured_app).to receive(:body).with(@double.content)
|
39
39
|
|
40
40
|
Response.perform(rest_assured_app)
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'sets response status to the one from double' do
|
44
|
-
rest_assured_app.
|
44
|
+
expect(rest_assured_app).to receive(:status).with(@double.status)
|
45
45
|
|
46
46
|
Response.perform(rest_assured_app)
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'sets response headers to those in Double#response_headers' do
|
50
|
-
rest_assured_app.
|
50
|
+
expect(rest_assured_app).to receive(:headers).with(@double.response_headers)
|
51
51
|
|
52
52
|
Response.perform(rest_assured_app)
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'records request' do
|
56
56
|
requests = double
|
57
|
-
Models::Double.
|
57
|
+
allow(Models::Double).to receive_message_chain('where.first').and_return(double(:requests => requests).as_null_object)
|
58
58
|
|
59
|
-
requests.
|
59
|
+
expect(requests).to receive(:create!).with(:rack_env => 'env', :body => 'body', :params => 'params')
|
60
60
|
|
61
61
|
Response.perform(rest_assured_app)
|
62
62
|
end
|
63
63
|
|
64
64
|
it "returns double when redirect matches double" do
|
65
65
|
fullpath = '/some/other/path'
|
66
|
-
request.
|
67
|
-
Models::Redirect.
|
66
|
+
allow(request).to receive(:fullpath).and_return(fullpath)
|
67
|
+
allow(Models::Redirect).to receive(:find_redirect_url_for).with(fullpath).and_return('/some/path')
|
68
68
|
|
69
|
-
rest_assured_app.
|
70
|
-
rest_assured_app.
|
71
|
-
rest_assured_app.
|
69
|
+
expect(rest_assured_app).to receive(:body).with(@double.content)
|
70
|
+
expect(rest_assured_app).to receive(:status).with(@double.status)
|
71
|
+
expect(rest_assured_app).to receive(:headers).with(@double.response_headers)
|
72
72
|
|
73
73
|
Response.perform(rest_assured_app)
|
74
74
|
end
|
@@ -79,16 +79,16 @@ module RestAssured
|
|
79
79
|
#r = Models::Redirect.create :to => 'http://exmple.com/api', :pattern => '.*'
|
80
80
|
#
|
81
81
|
fullpath = '/some/other/path'
|
82
|
-
request.
|
83
|
-
Models::Redirect.
|
82
|
+
allow(request).to receive(:fullpath).and_return(fullpath)
|
83
|
+
allow(Models::Redirect).to receive(:find_redirect_url_for).with(fullpath).and_return('new_url')
|
84
84
|
|
85
|
-
rest_assured_app.
|
85
|
+
expect(rest_assured_app).to receive(:redirect).with('new_url')
|
86
86
|
|
87
87
|
Response.perform(rest_assured_app)
|
88
88
|
end
|
89
89
|
|
90
90
|
it "returns 404 if neither double nor redirect matches the request" do
|
91
|
-
rest_assured_app.
|
91
|
+
expect(rest_assured_app).to receive(:status).with(404)
|
92
92
|
|
93
93
|
Response.perform(rest_assured_app)
|
94
94
|
end
|
@@ -96,9 +96,9 @@ module RestAssured
|
|
96
96
|
# TODO change to instead exclude anything that does not respond_to?(:to_s)
|
97
97
|
it 'excludes "rack.input" and "rack.errors" as they break with "IOError - not opened for reading:" on consequent #to_json (as they are IO and StringIO)' do
|
98
98
|
requests = double.as_null_object
|
99
|
-
Models::Double.
|
99
|
+
allow(Models::Double).to receive_message_chain('where.first').and_return(double(:requests => requests).as_null_object)
|
100
100
|
|
101
|
-
env.
|
101
|
+
expect(env).to receive(:except).with('rack.input', 'rack.errors', 'rack.logger')
|
102
102
|
|
103
103
|
Response.perform(rest_assured_app)
|
104
104
|
end
|