rest-assured 0.2.0.rc8 → 0.2.0
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/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
@@ -1,108 +1,119 @@
|
|
1
1
|
require File.expand_path('../../spec_helper', __FILE__)
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
module RestAssured
|
4
|
+
describe 'Redirects routes' do
|
5
|
+
let :redirect do
|
6
|
+
{ :pattern => '/sdf.*', :to => 'http://google.com/api' }
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
let :valid_params do
|
10
|
+
{ 'redirect[pattern]' => redirect[:pattern], 'redirect[to]' => redirect[:to] }
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
let :invalid_params do
|
14
|
+
{ 'redirect[to]' => redirect[:to] }
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
context 'via ui', :ui => true do
|
18
|
+
it 'shows list of redirects' do
|
19
|
+
r = Models::Redirect.create redirect
|
19
20
|
|
20
|
-
|
21
|
+
visit '/redirects'
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
page.should have_content(r.pattern)
|
24
|
+
page.should have_content(r.to)
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
27
|
+
it "shows form for creating new redirect" do
|
28
|
+
visit '/redirects/new'
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
page.should have_css('#redirect_pattern')
|
31
|
+
page.should have_css('#redirect_to')
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
it "creates redirect" do
|
35
|
+
post '/redirects', valid_params
|
36
|
+
follow_redirect!
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
last_request.fullpath.should == '/redirects'
|
39
|
+
last_response.body.should =~ /Redirect created/
|
40
|
+
Models::Redirect.exists?(redirect).should be true
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
43
|
+
it "reports failure when creating with invalid parameters" do
|
44
|
+
post '/redirects', invalid_params
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
last_response.should be_ok
|
47
|
+
last_response.body.should =~ /Crumps!.*Pattern can't be blank/
|
48
|
+
end
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
it "brings up redirect edit form" do
|
51
|
+
r = Models::Redirect.create redirect
|
52
|
+
visit "/redirects/#{r.id}/edit"
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
find('#redirect_pattern').value.should == r.pattern
|
55
|
+
find('#redirect_to').value.should == r.to
|
56
|
+
end
|
56
57
|
|
57
|
-
|
58
|
-
|
58
|
+
it "updates redirect" do
|
59
|
+
r = Models::Redirect.create redirect
|
59
60
|
|
60
|
-
|
61
|
-
|
61
|
+
put "/redirects/#{r.id}", 'redirect[to]' => '/some/other/api'
|
62
|
+
follow_redirect!
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
last_request.fullpath.should == '/redirects'
|
65
|
+
last_response.body.should =~ /Redirect updated/
|
66
|
+
r.reload.to.should == '/some/other/api'
|
67
|
+
end
|
67
68
|
|
68
|
-
|
69
|
-
|
70
|
-
|
69
|
+
it "reorders redirects" do
|
70
|
+
r1 = Models::Redirect.create! redirect
|
71
|
+
r2 = Models::Redirect.create! redirect
|
71
72
|
|
72
|
-
|
73
|
+
put "/redirects/reorder", :redirect => [r2.id, r1.id]
|
73
74
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
75
|
+
last_response.should be_ok
|
76
|
+
last_response.body.should == 'Changed'
|
77
|
+
r1.reload.position.should == 1
|
78
|
+
r2.reload.position.should == 0
|
79
|
+
end
|
79
80
|
|
80
|
-
|
81
|
-
|
81
|
+
it "deletes redirect" do
|
82
|
+
f = Models::Redirect.create redirect
|
82
83
|
|
83
|
-
|
84
|
-
|
84
|
+
delete "/redirects/#{f.id}"
|
85
|
+
follow_redirect!
|
85
86
|
|
86
|
-
|
87
|
-
|
87
|
+
last_response.should be_ok
|
88
|
+
last_response.body.should =~ /Redirect deleted/
|
88
89
|
|
89
|
-
|
90
|
+
Models::Redirect.exists?(redirect).should be_false
|
91
|
+
end
|
90
92
|
end
|
91
|
-
end
|
92
93
|
|
93
|
-
|
94
|
-
|
95
|
-
|
94
|
+
context 'via api', :ui => false do
|
95
|
+
it "creates redirect" do
|
96
|
+
post '/redirects', redirect
|
96
97
|
|
97
|
-
|
98
|
-
|
99
|
-
|
98
|
+
last_response.should be_ok
|
99
|
+
Models::Redirect.count.should == 1
|
100
|
+
end
|
101
|
+
|
102
|
+
it "reports failure when creating with invalid parameters" do
|
103
|
+
post '/redirects', redirect.except(:pattern)
|
104
|
+
|
105
|
+
last_response.should_not be_ok
|
106
|
+
last_response.body.should =~ /Pattern can't be blank/
|
107
|
+
end
|
108
|
+
|
109
|
+
it "deletes all redirects" do
|
110
|
+
Models::Redirect.create redirect
|
100
111
|
|
101
|
-
|
102
|
-
post '/redirects', redirect.except(:pattern)
|
112
|
+
delete '/redirects/all'
|
103
113
|
|
104
|
-
|
105
|
-
|
114
|
+
last_response.should be_ok
|
115
|
+
Models::Redirect.count.should == 0
|
116
|
+
end
|
106
117
|
end
|
107
118
|
end
|
108
119
|
end
|
@@ -1,78 +1,80 @@
|
|
1
1
|
require File.expand_path('../../spec_helper', __FILE__)
|
2
2
|
require 'rest-assured/routes/response'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
module RestAssured
|
5
|
+
describe Response do
|
6
|
+
[:get, :post, :put, :delete].each do |verb|
|
7
|
+
it "processes an unknown request" do
|
8
|
+
|
9
|
+
Response.should_receive(:perform).with(an_instance_of(RestAssured::Application))
|
10
|
+
send verb, '/some/path'
|
11
|
+
end
|
10
12
|
end
|
11
|
-
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
context 'when double matches request' do
|
26
|
-
before do
|
27
|
-
@double = Double.create :fullpath => '/some/path', :content => 'content', :status => 201
|
28
|
-
request.stub(:fullpath).and_return(@double.fullpath)
|
29
|
-
end
|
14
|
+
let(:env) { stub(:to_json => 'env').as_null_object }
|
15
|
+
let(:request) {
|
16
|
+
double('Request',
|
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
|
+
}
|
24
|
+
let(:rest_assured_app) { double('App', :request => request).as_null_object }
|
30
25
|
|
31
|
-
|
32
|
-
|
26
|
+
context 'when double matches request' do
|
27
|
+
before do
|
28
|
+
@double = Models::Double.create :fullpath => '/some/path', :content => 'content', :status => 201
|
29
|
+
request.stub(:fullpath).and_return(@double.fullpath)
|
30
|
+
end
|
33
31
|
|
34
|
-
|
35
|
-
|
32
|
+
it "returns double content" do
|
33
|
+
rest_assured_app.should_receive(:body).with(@double.content)
|
36
34
|
|
37
|
-
|
38
|
-
|
35
|
+
Response.perform(rest_assured_app)
|
36
|
+
end
|
39
37
|
|
40
|
-
|
38
|
+
it 'sets response status to the one from double' do
|
39
|
+
rest_assured_app.should_receive(:status).with(@double.status)
|
40
|
+
|
41
|
+
Response.perform(rest_assured_app)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'records request' do
|
45
|
+
requests = double
|
46
|
+
Models::Double.stub_chain('where.first').and_return(double(:requests => requests).as_null_object)
|
47
|
+
|
48
|
+
requests.should_receive(:create!).with(:rack_env => 'env', :body => 'body', :params => 'params')
|
49
|
+
|
50
|
+
Response.perform(rest_assured_app)
|
51
|
+
end
|
41
52
|
end
|
42
53
|
|
43
|
-
it
|
44
|
-
|
45
|
-
|
54
|
+
it "redirects if double not hit but there is redirect that matches request" do
|
55
|
+
r = Models::Redirect.create :to => 'http://exmple.com/api', :pattern => '.*'
|
56
|
+
fullpath = '/some/other/path'
|
57
|
+
request.stub(:fullpath).and_return(fullpath)
|
46
58
|
|
47
|
-
|
59
|
+
rest_assured_app.should_receive(:redirect).with(r.to + fullpath)
|
48
60
|
|
49
61
|
Response.perform(rest_assured_app)
|
50
62
|
end
|
51
|
-
end
|
52
63
|
|
53
|
-
|
54
|
-
|
55
|
-
fullpath = '/some/other/path'
|
56
|
-
request.stub(:fullpath).and_return(fullpath)
|
64
|
+
it "returns 404 if neither double nor redirect matches the request" do
|
65
|
+
rest_assured_app.should_receive(:status).with(404)
|
57
66
|
|
58
|
-
|
67
|
+
Response.perform(rest_assured_app)
|
68
|
+
end
|
59
69
|
|
60
|
-
|
61
|
-
|
70
|
+
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
|
71
|
+
requests = double.as_null_object
|
72
|
+
Models::Double.stub_chain('where.first').and_return(double(:requests => requests).as_null_object)
|
62
73
|
|
63
|
-
|
64
|
-
rest_assured_app.should_receive(:status).with(404)
|
65
|
-
|
66
|
-
Response.perform(rest_assured_app)
|
67
|
-
end
|
74
|
+
env.should_receive(:except).with('rack.input', 'rack.errors', 'rack.logger')
|
68
75
|
|
69
|
-
|
70
|
-
|
71
|
-
Double.stub_chain('where.first').and_return(double(:requests => requests).as_null_object)
|
72
|
-
|
73
|
-
env.should_receive(:except).with('rack.input', 'rack.errors', 'rack.logger')
|
76
|
+
Response.perform(rest_assured_app)
|
77
|
+
end
|
74
78
|
|
75
|
-
Response.perform(rest_assured_app)
|
76
79
|
end
|
77
|
-
|
78
80
|
end
|
data/spec/models/double_spec.rb
CHANGED
@@ -1,90 +1,92 @@
|
|
1
1
|
require File.expand_path('../../spec_helper', __FILE__)
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
it { should validate_presence_of(:fullpath) }
|
9
|
-
it { should validate_inclusion_of(:verb, Double::VERBS) }
|
10
|
-
it { should validate_inclusion_of(:status, Double::STATUSES) }
|
11
|
-
it { should allow_mass_assignment_of(:fullpath) }
|
12
|
-
it { should allow_mass_assignment_of(:content) }
|
13
|
-
it { should allow_mass_assignment_of(:verb) }
|
14
|
-
it { should allow_mass_assignment_of(:status) }
|
15
|
-
|
16
|
-
it { should have_many(:requests) }
|
17
|
-
|
18
|
-
it 'creates double with valid params' do
|
19
|
-
d = Double.new valid_params
|
20
|
-
d.should be_valid
|
21
|
-
end
|
3
|
+
module RestAssured::Models
|
4
|
+
describe Double do
|
5
|
+
let :valid_params do
|
6
|
+
{ :fullpath => '/some/api', :content => 'some content', :verb => 'GET', :status => '303' }
|
7
|
+
end
|
22
8
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
9
|
+
it { should validate_presence_of(:fullpath) }
|
10
|
+
it { should validate_inclusion_of(:verb, Double::VERBS) }
|
11
|
+
it { should validate_inclusion_of(:status, Double::STATUSES) }
|
12
|
+
it { should allow_mass_assignment_of(:fullpath) }
|
13
|
+
it { should allow_mass_assignment_of(:content) }
|
14
|
+
it { should allow_mass_assignment_of(:verb) }
|
15
|
+
it { should allow_mass_assignment_of(:status) }
|
27
16
|
|
28
|
-
|
29
|
-
f = Double.create valid_params.except(:status)
|
30
|
-
f.status.should == 200
|
31
|
-
end
|
17
|
+
it { should have_many(:requests) }
|
32
18
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
19
|
+
it 'creates double with valid params' do
|
20
|
+
d = Double.new valid_params
|
21
|
+
d.should be_valid
|
22
|
+
end
|
37
23
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
f3 = Double.create valid_params.merge(:fullpath => '/some/other/api')
|
24
|
+
it "defaults verb to GET" do
|
25
|
+
f = Double.create valid_params.except(:verb)
|
26
|
+
f.verb.should == 'GET'
|
27
|
+
end
|
43
28
|
|
44
|
-
|
45
|
-
|
46
|
-
|
29
|
+
it "defaults status to 200" do
|
30
|
+
f = Double.create valid_params.except(:status)
|
31
|
+
f.status.should == 200
|
47
32
|
end
|
48
|
-
end
|
49
33
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
f3 = Double.create valid_params.merge(:fullpath => '/some/other/api')
|
34
|
+
it "makes double active by default" do
|
35
|
+
f = Double.create valid_params.except(:active)
|
36
|
+
f.active.should be true
|
37
|
+
end
|
55
38
|
|
56
|
-
|
57
|
-
|
39
|
+
describe 'when created' do
|
40
|
+
it "toggles active double for the same fullpath" do
|
41
|
+
f1 = Double.create valid_params
|
42
|
+
f2 = Double.create valid_params
|
43
|
+
f3 = Double.create valid_params.merge(:fullpath => '/some/other/api')
|
58
44
|
|
59
|
-
|
60
|
-
|
45
|
+
f1.reload.active.should be false
|
46
|
+
f2.reload.active.should be true
|
47
|
+
f3.reload.active.should be true
|
48
|
+
end
|
61
49
|
end
|
62
50
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
51
|
+
describe 'when saved' do
|
52
|
+
it "toggles active double for the same fullpath" do
|
53
|
+
f1 = Double.create valid_params
|
54
|
+
f2 = Double.create valid_params
|
55
|
+
f3 = Double.create valid_params.merge(:fullpath => '/some/other/api')
|
67
56
|
|
68
|
-
|
69
|
-
|
57
|
+
f1.active = true
|
58
|
+
f1.save
|
70
59
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
75
|
-
end
|
60
|
+
f2.reload.active.should be false
|
61
|
+
f3.reload.active.should be true
|
62
|
+
end
|
76
63
|
|
77
|
-
|
78
|
-
context 'active double' do
|
79
|
-
it "makes another double for the same fullpath active" do
|
64
|
+
it "makes other doubles inactive only when active bit set to true" do
|
80
65
|
f1 = Double.create valid_params
|
81
66
|
f2 = Double.create valid_params
|
82
67
|
f3 = Double.create valid_params.merge(:fullpath => '/some/other/api')
|
83
68
|
|
84
|
-
|
85
|
-
|
69
|
+
f1.reload.save
|
70
|
+
f2.reload.save
|
71
|
+
|
72
|
+
f1.reload.active.should be false
|
73
|
+
f2.reload.active.should be true
|
86
74
|
f3.reload.active.should be true
|
87
75
|
end
|
88
76
|
end
|
77
|
+
|
78
|
+
describe 'when destroying' do
|
79
|
+
context 'active double' do
|
80
|
+
it "makes another double for the same fullpath active" do
|
81
|
+
f1 = Double.create valid_params
|
82
|
+
f2 = Double.create valid_params
|
83
|
+
f3 = Double.create valid_params.merge(:fullpath => '/some/other/api')
|
84
|
+
|
85
|
+
f2.destroy
|
86
|
+
f1.reload.active.should be true
|
87
|
+
f3.reload.active.should be true
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
89
91
|
end
|
90
92
|
end
|