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.
Files changed (40) hide show
  1. data/Gemfile.lock +2 -2
  2. data/LICENSE +4 -19
  3. data/README.markdown +123 -36
  4. data/bin/console +1 -2
  5. data/bin/rest-assured +12 -0
  6. data/features/command_line_options.feature +20 -1
  7. data/features/{doubles_via_api.feature → rest_api/doubles.feature} +0 -0
  8. data/features/{redirect_rules_via_api.feature → rest_api/redirects.feature} +11 -8
  9. data/features/{call_history.feature → ruby_api/verify_requests.feature} +0 -0
  10. data/features/ruby_api/wait_for_requests.feature +39 -0
  11. data/features/step_definitions/command_line_options_steps.rb +12 -0
  12. data/features/step_definitions/doubles_steps.rb +10 -10
  13. data/features/step_definitions/redirect_rules_steps.rb +24 -5
  14. data/features/step_definitions/ruby_api_steps.rb +69 -0
  15. data/features/support/env.rb +3 -1
  16. data/features/{doubles_via_ui.feature → web_ui/doubles.feature} +0 -0
  17. data/features/{redirect_rules_via_ui.feature → web_ui/redirects.feature} +0 -0
  18. data/lib/rest-assured.rb +2 -1
  19. data/lib/rest-assured/client/resources.rb +12 -2
  20. data/lib/rest-assured/config.rb +24 -0
  21. data/lib/rest-assured/models/double.rb +32 -28
  22. data/lib/rest-assured/models/redirect.rb +28 -24
  23. data/lib/rest-assured/models/request.rb +11 -7
  24. data/lib/rest-assured/routes/double.rb +8 -8
  25. data/lib/rest-assured/routes/redirect.rb +8 -8
  26. data/lib/rest-assured/routes/response.rb +16 -14
  27. data/lib/rest-assured/version.rb +1 -1
  28. data/lib/sinatra/handler_options_patch.rb +25 -0
  29. data/spec/client/resource_double_spec.rb +42 -6
  30. data/spec/config_spec.rb +35 -0
  31. data/spec/functional/double_routes_spec.rb +109 -107
  32. data/spec/functional/redirect_routes_spec.rb +86 -75
  33. data/spec/functional/response_spec.rb +57 -55
  34. data/spec/models/double_spec.rb +67 -65
  35. data/spec/models/redirect_spec.rb +28 -26
  36. data/spec/models/request_spec.rb +10 -8
  37. data/ssl/localhost.crt +14 -0
  38. data/ssl/localhost.key +15 -0
  39. metadata +25 -24
  40. 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
- describe 'Redirects routes' do
4
- let :redirect do
5
- { :pattern => '/sdf.*', :to => 'http://google.com/api' }
6
- end
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
- let :valid_params do
9
- { 'redirect[pattern]' => redirect[:pattern], 'redirect[to]' => redirect[:to] }
10
- end
9
+ let :valid_params do
10
+ { 'redirect[pattern]' => redirect[:pattern], 'redirect[to]' => redirect[:to] }
11
+ end
11
12
 
12
- let :invalid_params do
13
- { 'redirect[to]' => redirect[:to] }
14
- end
13
+ let :invalid_params do
14
+ { 'redirect[to]' => redirect[:to] }
15
+ end
15
16
 
16
- context 'via ui', :ui => true do
17
- it 'shows list of redirects' do
18
- r = Redirect.create redirect
17
+ context 'via ui', :ui => true do
18
+ it 'shows list of redirects' do
19
+ r = Models::Redirect.create redirect
19
20
 
20
- visit '/redirects'
21
+ visit '/redirects'
21
22
 
22
- page.should have_content(r.pattern)
23
- page.should have_content(r.to)
24
- end
23
+ page.should have_content(r.pattern)
24
+ page.should have_content(r.to)
25
+ end
25
26
 
26
- it "shows form for creating new redirect" do
27
- visit '/redirects/new'
27
+ it "shows form for creating new redirect" do
28
+ visit '/redirects/new'
28
29
 
29
- page.should have_css('#redirect_pattern')
30
- page.should have_css('#redirect_to')
31
- end
30
+ page.should have_css('#redirect_pattern')
31
+ page.should have_css('#redirect_to')
32
+ end
32
33
 
33
- it "creates redirect" do
34
- post '/redirects', valid_params
35
- follow_redirect!
34
+ it "creates redirect" do
35
+ post '/redirects', valid_params
36
+ follow_redirect!
36
37
 
37
- last_request.fullpath.should == '/redirects'
38
- last_response.body.should =~ /Redirect created/
39
- Redirect.exists?(redirect).should be true
40
- end
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
- it "reports failure when creating with invalid parameters" do
43
- post '/redirects', invalid_params
43
+ it "reports failure when creating with invalid parameters" do
44
+ post '/redirects', invalid_params
44
45
 
45
- last_response.should be_ok
46
- last_response.body.should =~ /Crumps!.*Pattern can't be blank/
47
- end
46
+ last_response.should be_ok
47
+ last_response.body.should =~ /Crumps!.*Pattern can't be blank/
48
+ end
48
49
 
49
- it "brings up redirect edit form" do
50
- r = Redirect.create redirect
51
- visit "/redirects/#{r.id}/edit"
50
+ it "brings up redirect edit form" do
51
+ r = Models::Redirect.create redirect
52
+ visit "/redirects/#{r.id}/edit"
52
53
 
53
- find('#redirect_pattern').value.should == r.pattern
54
- find('#redirect_to').value.should == r.to
55
- end
54
+ find('#redirect_pattern').value.should == r.pattern
55
+ find('#redirect_to').value.should == r.to
56
+ end
56
57
 
57
- it "updates redirect" do
58
- r = Redirect.create redirect
58
+ it "updates redirect" do
59
+ r = Models::Redirect.create redirect
59
60
 
60
- put "/redirects/#{r.id}", 'redirect[to]' => '/some/other/api'
61
- follow_redirect!
61
+ put "/redirects/#{r.id}", 'redirect[to]' => '/some/other/api'
62
+ follow_redirect!
62
63
 
63
- last_request.fullpath.should == '/redirects'
64
- last_response.body.should =~ /Redirect updated/
65
- r.reload.to.should == '/some/other/api'
66
- end
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
- it "reorders redirects" do
69
- r1 = Redirect.create! redirect
70
- r2 = Redirect.create! redirect
69
+ it "reorders redirects" do
70
+ r1 = Models::Redirect.create! redirect
71
+ r2 = Models::Redirect.create! redirect
71
72
 
72
- put "/redirects/reorder", :redirect => [r2.id, r1.id]
73
+ put "/redirects/reorder", :redirect => [r2.id, r1.id]
73
74
 
74
- last_response.should be_ok
75
- last_response.body.should == 'Changed'
76
- r1.reload.position.should == 1
77
- r2.reload.position.should == 0
78
- end
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
- it "deletes redirect" do
81
- f = Redirect.create redirect
81
+ it "deletes redirect" do
82
+ f = Models::Redirect.create redirect
82
83
 
83
- delete "/redirects/#{f.id}"
84
- follow_redirect!
84
+ delete "/redirects/#{f.id}"
85
+ follow_redirect!
85
86
 
86
- last_response.should be_ok
87
- last_response.body.should =~ /Redirect deleted/
87
+ last_response.should be_ok
88
+ last_response.body.should =~ /Redirect deleted/
88
89
 
89
- Redirect.exists?(redirect).should be_false
90
+ Models::Redirect.exists?(redirect).should be_false
91
+ end
90
92
  end
91
- end
92
93
 
93
- context 'via api', :ui => false do
94
- it "creates redirect" do
95
- post '/redirects', redirect
94
+ context 'via api', :ui => false do
95
+ it "creates redirect" do
96
+ post '/redirects', redirect
96
97
 
97
- last_response.should be_ok
98
- Redirect.count.should == 1
99
- end
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
- it "reports failure when creating with invalid parameters" do
102
- post '/redirects', redirect.except(:pattern)
112
+ delete '/redirects/all'
103
113
 
104
- last_response.should_not be_ok
105
- last_response.body.should =~ /Pattern can't be blank/
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
- describe Response do
5
- [:get, :post, :put, :delete].each do |verb|
6
- it "processes an unknown request" do
7
-
8
- Response.should_receive(:perform).with(an_instance_of(RestAssured::Application))
9
- send verb, '/some/path'
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
- let(:env) { stub(:to_json => 'env').as_null_object }
14
- let(:request) {
15
- double('Request',
16
- :request_method => 'GET',
17
- :fullpath => '/api',
18
- :env => env,
19
- :body => stub(:read => 'body').as_null_object,
20
- :params => stub(:to_json => 'params')
21
- )
22
- }
23
- let(:rest_assured_app) { double('App', :request => request).as_null_object }
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
- it "returns double content" do
32
- rest_assured_app.should_receive(:body).with(@double.content)
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
- Response.perform(rest_assured_app)
35
- end
32
+ it "returns double content" do
33
+ rest_assured_app.should_receive(:body).with(@double.content)
36
34
 
37
- it 'sets response status to the one from double' do
38
- rest_assured_app.should_receive(:status).with(@double.status)
35
+ Response.perform(rest_assured_app)
36
+ end
39
37
 
40
- Response.perform(rest_assured_app)
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 'records request' do
44
- requests = double
45
- Double.stub_chain('where.first').and_return(double(:requests => requests).as_null_object)
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
- requests.should_receive(:create!).with(:rack_env => 'env', :body => 'body', :params => 'params')
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
- it "redirects if double not hit but there is redirect that matches request" do
54
- r = Redirect.create :to => 'http://exmple.com/api', :pattern => '.*'
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
- rest_assured_app.should_receive(:redirect).with(r.to + fullpath)
67
+ Response.perform(rest_assured_app)
68
+ end
59
69
 
60
- Response.perform(rest_assured_app)
61
- end
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
- it "returns 404 if neither double nor redirect matches the request" do
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
- 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
70
- requests = double.as_null_object
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
@@ -1,90 +1,92 @@
1
1
  require File.expand_path('../../spec_helper', __FILE__)
2
2
 
3
- describe Double do
4
- let :valid_params do
5
- { :fullpath => '/some/api', :content => 'some content', :verb => 'GET', :status => '303' }
6
- end
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
- it "defaults verb to GET" do
24
- f = Double.create valid_params.except(:verb)
25
- f.verb.should == 'GET'
26
- end
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
- it "defaults status to 200" do
29
- f = Double.create valid_params.except(:status)
30
- f.status.should == 200
31
- end
17
+ it { should have_many(:requests) }
32
18
 
33
- it "makes double active by default" do
34
- f = Double.create valid_params.except(:active)
35
- f.active.should be true
36
- end
19
+ it 'creates double with valid params' do
20
+ d = Double.new valid_params
21
+ d.should be_valid
22
+ end
37
23
 
38
- describe 'when created' do
39
- it "toggles active double for the same fullpath" do
40
- f1 = Double.create valid_params
41
- f2 = Double.create valid_params
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
- f1.reload.active.should be false
45
- f2.reload.active.should be true
46
- f3.reload.active.should be true
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
- describe 'when saved' do
51
- it "toggles active double for the same fullpath" do
52
- f1 = Double.create valid_params
53
- f2 = Double.create valid_params
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
- f1.active = true
57
- f1.save
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
- f2.reload.active.should be false
60
- f3.reload.active.should be true
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
- it "makes other doubles inactive only when active bit set to true" do
64
- f1 = Double.create valid_params
65
- f2 = Double.create valid_params
66
- f3 = Double.create valid_params.merge(:fullpath => '/some/other/api')
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
- f1.reload.save
69
- f2.reload.save
57
+ f1.active = true
58
+ f1.save
70
59
 
71
- f1.reload.active.should be false
72
- f2.reload.active.should be true
73
- f3.reload.active.should be true
74
- end
75
- end
60
+ f2.reload.active.should be false
61
+ f3.reload.active.should be true
62
+ end
76
63
 
77
- describe 'when destroying' do
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
- f2.destroy
85
- f1.reload.active.should be true
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