kookaburra 0.18.3 → 0.20.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 +1 -1
- data/Gemfile.lock +2 -1
- data/README.markdown +114 -135
- data/VERSION +1 -1
- data/kookaburra.gemspec +8 -10
- data/lib/kookaburra.rb +22 -31
- data/lib/kookaburra/api_driver.rb +95 -11
- data/lib/kookaburra/given_driver.rb +32 -16
- data/lib/kookaburra/json_api_driver.rb +43 -70
- data/lib/kookaburra/{test_data.rb → mental_model.rb} +15 -9
- data/lib/kookaburra/null_browser.rb +4 -0
- data/lib/kookaburra/test_helpers.rb +2 -4
- data/lib/kookaburra/ui_driver.rb +15 -11
- data/lib/kookaburra/ui_driver/ui_component.rb +22 -5
- data/spec/integration/test_a_rack_application_spec.rb +171 -137
- data/spec/kookaburra/api_driver_spec.rb +126 -0
- data/spec/kookaburra/json_api_driver_spec.rb +85 -30
- data/spec/kookaburra/{test_data_spec.rb → mental_model_spec.rb} +6 -6
- data/spec/kookaburra/ui_driver_spec.rb +5 -3
- data/spec/kookaburra_spec.rb +9 -41
- metadata +9 -11
- data/lib/kookaburra/rack_driver.rb +0 -109
- data/lib/kookaburra/utils/active_record_shared_connection.rb +0 -14
- data/spec/kookaburra/rack_driver_spec.rb +0 -42
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'kookaburra/api_driver'
|
2
|
+
|
3
|
+
describe Kookaburra::APIDriver do
|
4
|
+
let(:api) { Kookaburra::APIDriver.new(:http_client => client) }
|
5
|
+
|
6
|
+
let(:response) {
|
7
|
+
stub('Patron::Response', :body => 'foo', :status => 200, :url => '/foo')
|
8
|
+
}
|
9
|
+
|
10
|
+
let(:client) {
|
11
|
+
mock('Patron::Session', :post => response, :get => response,
|
12
|
+
:put => response, :delete => response)
|
13
|
+
}
|
14
|
+
|
15
|
+
describe '#initialize' do
|
16
|
+
it 'instantiates a new http client if no :http_client option is passed' do
|
17
|
+
Patron::Session.should_receive(:new).and_return(stub.as_null_object)
|
18
|
+
Kookaburra::APIDriver.new({})
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'does not instantiate a new http client if an :http_client option is passed' do
|
22
|
+
Patron::Session.should_receive(:new).never
|
23
|
+
Kookaburra::APIDriver.new(:http_client => stub.as_null_object)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#post' do
|
28
|
+
before(:each) do
|
29
|
+
response.stub!(:status => 201)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'delegates to the http client' do
|
33
|
+
client.should_receive(:post).with('/foo', 'bar', {}) \
|
34
|
+
.and_return(response)
|
35
|
+
api.post('/foo', 'bar')
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'returns the response body' do
|
39
|
+
api.post('/foo', 'bar').should == 'foo'
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'does not raise an UnexpectedResponse if the response status matches the specified expectation' do
|
43
|
+
response.stub!(:status => 666)
|
44
|
+
lambda { api.post('/foo', 'bar', :expected_response_status => 666) } \
|
45
|
+
.should_not raise_error
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'raises an UnexpectedResponse if the response status is not the specified status' do
|
49
|
+
lambda { api.post('/foo', 'bar', :expected_response_status => 666) } \
|
50
|
+
.should raise_error(Kookaburra::UnexpectedResponse,
|
51
|
+
"POST to /foo responded with 201 status, not 666 as expected\n\nfoo")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#put' do
|
56
|
+
it 'delegates to the http client' do
|
57
|
+
client.should_receive(:put).with('/foo', 'bar', {}) \
|
58
|
+
.and_return(response)
|
59
|
+
api.put('/foo', 'bar')
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'returns the response body' do
|
63
|
+
api.put('/foo', 'bar').should == 'foo'
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'does not raise an UnexpectedResponse if the response status matches the specified expectation' do
|
67
|
+
response.stub!(:status => 666)
|
68
|
+
lambda { api.put('/foo', 'bar', :expected_response_status => 666) } \
|
69
|
+
.should_not raise_error
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'raises an UnexpectedResponse if the response status is not the specified status' do
|
73
|
+
lambda { api.put('/foo', 'bar', :expected_response_status => 666) } \
|
74
|
+
.should raise_error(Kookaburra::UnexpectedResponse,
|
75
|
+
"PUT to /foo responded with 200 status, not 666 as expected\n\nfoo")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#get' do
|
80
|
+
it 'delegates to the http client' do
|
81
|
+
client.should_receive(:get).with('/foo', {}) \
|
82
|
+
.and_return(response)
|
83
|
+
api.get('/foo')
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'returns the response body' do
|
87
|
+
api.get('/foo').should == 'foo'
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'does not raise an UnexpectedResponse if the response status matches the specified expectation' do
|
91
|
+
response.stub!(:status => 666)
|
92
|
+
lambda { api.get('/foo', :expected_response_status => 666) } \
|
93
|
+
.should_not raise_error
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'raises an UnexpectedResponse if the response status is not the specified status' do
|
97
|
+
lambda { api.get('/foo', :expected_response_status => 666) } \
|
98
|
+
.should raise_error(Kookaburra::UnexpectedResponse,
|
99
|
+
"GET to /foo responded with 200 status, not 666 as expected\n\nfoo")
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe '#delete' do
|
104
|
+
it 'delegates to the http client' do
|
105
|
+
client.should_receive(:delete).with('/foo', {}) \
|
106
|
+
.and_return(response)
|
107
|
+
api.delete('/foo')
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'returns the response body' do
|
111
|
+
api.delete('/foo').should == 'foo'
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'does not raise an UnexpectedResponse if the response status matches the specified expectation' do
|
115
|
+
response.stub!(:status => 666)
|
116
|
+
lambda { api.delete('/foo', :expected_response_status => 666) } \
|
117
|
+
.should_not raise_error
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'raises an UnexpectedResponse if the response status is not the specified status' do
|
121
|
+
lambda { api.delete('/foo', :expected_response_status => 666) } \
|
122
|
+
.should raise_error(Kookaburra::UnexpectedResponse,
|
123
|
+
"DELETE to /foo responded with 200 status, not 666 as expected\n\nfoo")
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -1,36 +1,91 @@
|
|
1
1
|
require 'kookaburra/json_api_driver'
|
2
2
|
|
3
3
|
describe Kookaburra::JsonApiDriver do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
4
|
+
let(:response) { '{"foo":"bar"}' }
|
5
|
+
|
6
|
+
let(:api) {
|
7
|
+
stub('APIDriver', :get => response, :post => response, :put => response,
|
8
|
+
:delete => response, :headers => {})
|
9
|
+
}
|
10
|
+
|
11
|
+
let(:json) { Kookaburra::JsonApiDriver.new(:api_driver => api) }
|
12
|
+
|
13
|
+
describe '#initialize' do
|
14
|
+
it 'instantiates a new APIDriver if no :api_driver option is passed' do
|
15
|
+
Kookaburra::APIDriver.should_receive(:new).and_return(stub.as_null_object)
|
16
|
+
Kookaburra::JsonApiDriver.new({})
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'does not instantiate a new APIDriver if an :api_driver option is passed' do
|
20
|
+
Kookaburra::APIDriver.should_receive(:new).never
|
21
|
+
Kookaburra::JsonApiDriver.new(:api_driver => stub.as_null_object)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'sets appropriate headers for a JSON API request' do
|
25
|
+
Kookaburra::JsonApiDriver.new(:api_driver => api)
|
26
|
+
api.headers.should == {
|
27
|
+
'Content-Type' => 'application/json',
|
28
|
+
'Accept' => 'application/json'
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'delegates to a Kookaburra::APIDriver by default' do
|
34
|
+
delegate = stub('Kookaburra::APIDriver', :foo => :bar).as_null_object
|
35
|
+
Kookaburra::APIDriver.should_receive(:new).once.and_return(delegate)
|
36
|
+
json = Kookaburra::JsonApiDriver.new
|
37
|
+
json.foo.should == :bar
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#post' do
|
41
|
+
it 'delegates to the api driver as a JSON request' do
|
42
|
+
api.should_receive(:post) \
|
43
|
+
.with('/foo', '{"foo":"bar"}') \
|
44
|
+
.and_return('{"baz":"bam"}')
|
45
|
+
json.post('/foo', 'foo' => 'bar')
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'returns the JSON-decoded response body' do
|
49
|
+
json.post('/foo', 'bar').should == {'foo' => 'bar'}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#put' do
|
54
|
+
it 'delegates to the api driver as a JSON request' do
|
55
|
+
api.should_receive(:put) \
|
56
|
+
.with('/foo', '{"foo":"bar"}') \
|
57
|
+
.and_return('{"baz":"bam"}')
|
58
|
+
json.put('/foo', 'foo' => 'bar')
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns the JSON-decoded response body' do
|
62
|
+
json.put('/foo', 'bar').should == {'foo' => 'bar'}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#get' do
|
67
|
+
it 'delegates to the api driver as a JSON request' do
|
68
|
+
api.should_receive(:get) \
|
69
|
+
.with('/foo') \
|
70
|
+
.and_return('{"baz":"bam"}')
|
71
|
+
json.get('/foo')
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'returns the JSON-decoded response body' do
|
75
|
+
json.get('/foo').should == {'foo' => 'bar'}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#delete' do
|
80
|
+
it 'delegates to the api driver as a JSON request' do
|
81
|
+
api.should_receive(:delete) \
|
82
|
+
.with('/foo') \
|
83
|
+
.and_return('{"baz":"bam"}')
|
84
|
+
json.delete('/foo')
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'returns the JSON-decoded response body' do
|
88
|
+
json.delete('/foo').should == {'foo' => 'bar'}
|
34
89
|
end
|
35
90
|
end
|
36
91
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require 'kookaburra/
|
1
|
+
require 'kookaburra/mental_model'
|
2
2
|
|
3
|
-
describe Kookaburra::
|
3
|
+
describe Kookaburra::MentalModel do
|
4
4
|
describe '#method_missing' do
|
5
5
|
it 'returns a Collection' do
|
6
|
-
subject.foo.should be_kind_of(Kookaburra::
|
6
|
+
subject.foo.should be_kind_of(Kookaburra::MentalModel::Collection)
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'returns different Collections for different messages' do
|
@@ -11,8 +11,8 @@ describe Kookaburra::TestData do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
describe Kookaburra::
|
15
|
-
let(:collection) { Kookaburra::
|
14
|
+
describe Kookaburra::MentalModel::Collection do
|
15
|
+
let(:collection) { Kookaburra::MentalModel::Collection.new('widgets') }
|
16
16
|
|
17
17
|
describe '#slice' do
|
18
18
|
it 'returns an array of items matching the specified keys' do
|
@@ -25,7 +25,7 @@ describe Kookaburra::TestData do
|
|
25
25
|
|
26
26
|
it 'raises a Kookaburra::UnknownKeyError exception for #[] with a missing key' do
|
27
27
|
lambda { collection[:foo] }.should \
|
28
|
-
raise_error(Kookaburra::UnknownKeyError, "Can't find
|
28
|
+
raise_error(Kookaburra::UnknownKeyError, "Can't find mental_model.widgets[:foo]. Did you forget to set it?")
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -6,14 +6,16 @@ describe Kookaburra::UIDriver do
|
|
6
6
|
it 'adds an accessor method for the named component that defaults to an instance of the specified class' do
|
7
7
|
foo_component_class = mock(Class)
|
8
8
|
foo_component_class.should_receive(:new) \
|
9
|
-
.with(:browser => :a_browser, :server_error_detection => :server_error_detection
|
9
|
+
.with(:browser => :a_browser, :server_error_detection => :server_error_detection,
|
10
|
+
:app_host => :a_url) \
|
10
11
|
.and_return(:a_foo_component)
|
11
12
|
|
12
13
|
ui_driver_class = Class.new(Kookaburra::UIDriver) do
|
13
14
|
ui_component :foo, foo_component_class
|
14
15
|
end
|
15
16
|
|
16
|
-
ui = ui_driver_class.new(:browser => :a_browser, :server_error_detection => :server_error_detection
|
17
|
+
ui = ui_driver_class.new(:browser => :a_browser, :server_error_detection => :server_error_detection,
|
18
|
+
:app_host => :a_url)
|
17
19
|
ui.foo.should == :a_foo_component
|
18
20
|
end
|
19
21
|
end
|
@@ -21,6 +23,6 @@ describe Kookaburra::UIDriver do
|
|
21
23
|
describe 'dependency accessors' do
|
22
24
|
let(:subject_class) { Kookaburra::UIDriver }
|
23
25
|
|
24
|
-
it_behaves_like :it_has_a_dependency_accessor, :
|
26
|
+
it_behaves_like :it_has_a_dependency_accessor, :mental_model
|
25
27
|
end
|
26
28
|
end
|
data/spec/kookaburra_spec.rb
CHANGED
@@ -2,47 +2,15 @@ require 'kookaburra'
|
|
2
2
|
|
3
3
|
describe Kookaburra do
|
4
4
|
describe '#given' do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
.and_return(:an_api_driver)
|
11
|
-
|
12
|
-
my_given_driver_class = mock(Class)
|
13
|
-
my_given_driver_class.should_receive(:new) do |options|
|
14
|
-
options[:api].should == :an_api_driver
|
15
|
-
:a_given_driver
|
16
|
-
end
|
17
|
-
|
18
|
-
k = Kookaburra.new(:given_driver_class => my_given_driver_class,
|
19
|
-
:api_driver_class => my_api_driver_class)
|
20
|
-
k.given.should == :a_given_driver
|
5
|
+
it 'returns an instance of the configured GivenDriver' do
|
6
|
+
my_given_driver_class = mock(Class)
|
7
|
+
my_given_driver_class.should_receive(:new) do |options|
|
8
|
+
options[:mental_model].should be_kind_of(Kookaburra::MentalModel)
|
9
|
+
:a_given_driver
|
21
10
|
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'with a :rack_app specified' do
|
25
|
-
it 'returns an instance of the configured GivenDriver' do
|
26
|
-
Kookaburra::RackDriver.should_receive(:new) \
|
27
|
-
.with(:a_rack_app) \
|
28
|
-
.and_return(:a_rack_driver)
|
29
11
|
|
30
|
-
|
31
|
-
|
32
|
-
.with(:a_rack_driver) \
|
33
|
-
.and_return(:an_api_driver)
|
34
|
-
|
35
|
-
my_given_driver_class = mock(Class)
|
36
|
-
my_given_driver_class.should_receive(:new) do |options|
|
37
|
-
options[:api].should == :an_api_driver
|
38
|
-
:a_given_driver
|
39
|
-
end
|
40
|
-
|
41
|
-
k = Kookaburra.new(:given_driver_class => my_given_driver_class,
|
42
|
-
:api_driver_class => my_api_driver_class,
|
43
|
-
:rack_app => :a_rack_app)
|
44
|
-
k.given.should == :a_given_driver
|
45
|
-
end
|
12
|
+
k = Kookaburra.new(:given_driver_class => my_given_driver_class)
|
13
|
+
k.given.should == :a_given_driver
|
46
14
|
end
|
47
15
|
end
|
48
16
|
|
@@ -65,8 +33,8 @@ describe Kookaburra do
|
|
65
33
|
it 'returns a equivalent copy of the test data collection specified' do
|
66
34
|
k = Kookaburra.new
|
67
35
|
foos = {:spam => 'ham'}
|
68
|
-
|
69
|
-
k.stub!(:
|
36
|
+
mental_model = stub(:foos => foos)
|
37
|
+
k.stub!(:mental_model => mental_model)
|
70
38
|
k.get_data(:foos).should == foos
|
71
39
|
end
|
72
40
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kookaburra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 79
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 20
|
9
|
+
- 0
|
10
|
+
version: 0.20.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- John Wilger
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2012-03-
|
20
|
+
date: 2012-03-22 00:00:00 Z
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
23
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
@@ -72,7 +72,7 @@ dependencies:
|
|
72
72
|
segments:
|
73
73
|
- 0
|
74
74
|
version: "0"
|
75
|
-
name:
|
75
|
+
name: patron
|
76
76
|
prerelease: false
|
77
77
|
type: :runtime
|
78
78
|
requirement: *id004
|
@@ -216,18 +216,16 @@ files:
|
|
216
216
|
- lib/kookaburra/exceptions.rb
|
217
217
|
- lib/kookaburra/given_driver.rb
|
218
218
|
- lib/kookaburra/json_api_driver.rb
|
219
|
+
- lib/kookaburra/mental_model.rb
|
219
220
|
- lib/kookaburra/null_browser.rb
|
220
|
-
- lib/kookaburra/rack_driver.rb
|
221
|
-
- lib/kookaburra/test_data.rb
|
222
221
|
- lib/kookaburra/test_helpers.rb
|
223
222
|
- lib/kookaburra/ui_driver.rb
|
224
223
|
- lib/kookaburra/ui_driver/ui_component.rb
|
225
|
-
- lib/kookaburra/utils/active_record_shared_connection.rb
|
226
224
|
- spec/integration/test_a_rack_application_spec.rb
|
225
|
+
- spec/kookaburra/api_driver_spec.rb
|
227
226
|
- spec/kookaburra/json_api_driver_spec.rb
|
227
|
+
- spec/kookaburra/mental_model_spec.rb
|
228
228
|
- spec/kookaburra/null_browser_spec.rb
|
229
|
-
- spec/kookaburra/rack_driver_spec.rb
|
230
|
-
- spec/kookaburra/test_data_spec.rb
|
231
229
|
- spec/kookaburra/test_helpers_spec.rb
|
232
230
|
- spec/kookaburra/ui_driver/ui_component_spec.rb
|
233
231
|
- spec/kookaburra/ui_driver_spec.rb
|
@@ -1,109 +0,0 @@
|
|
1
|
-
require 'kookaburra/exceptions'
|
2
|
-
require 'rack/test'
|
3
|
-
|
4
|
-
class Kookaburra
|
5
|
-
# This is a small wrapper around the `Rack::Test::Methods` which is used by
|
6
|
-
# your {APIDriver}.
|
7
|
-
class RackDriver
|
8
|
-
include Rack::Test::Methods
|
9
|
-
|
10
|
-
# This is the Rack application instance
|
11
|
-
attr_reader :app
|
12
|
-
|
13
|
-
# @param [#call] rack_app The Rack application object for the application under test
|
14
|
-
def initialize(rack_app)
|
15
|
-
@app = rack_app
|
16
|
-
end
|
17
|
-
|
18
|
-
# Sends a POST request to the application.
|
19
|
-
#
|
20
|
-
# Similar to `Rack::Test::Methods#post` except that it adds more convenient
|
21
|
-
# access to setting request headers, it raises an exception if the response
|
22
|
-
# status is not 201, and it returns the response body.
|
23
|
-
#
|
24
|
-
# @param [String] path The path portion of the URI to request from the
|
25
|
-
# application
|
26
|
-
# @param [Object] params The request params or body
|
27
|
-
# @param [Hash] headers A hash of any additional HTTP headers to be set on
|
28
|
-
# the request.
|
29
|
-
# @param [Hash] env Additional environment variables that should be present
|
30
|
-
# on the request.
|
31
|
-
# @yield [Rack::Response] Yields the last response to the block if a
|
32
|
-
# block is given.
|
33
|
-
def post(path, params = {}, headers = {}, env = {}, &block)
|
34
|
-
set_headers(headers)
|
35
|
-
super path, params, env, &block
|
36
|
-
check_response_status!(:post, 201, path)
|
37
|
-
last_response.body
|
38
|
-
end
|
39
|
-
|
40
|
-
# Sends a PUT request to the application.
|
41
|
-
#
|
42
|
-
# Similar to `Rack::Test::Methods#put` except that it adds more convenient
|
43
|
-
# access to setting request headers, it raises an exception if the response
|
44
|
-
# status is not 200, and it returns the response body.
|
45
|
-
#
|
46
|
-
# @param [String] path The path portion of the URI to request from the
|
47
|
-
# application
|
48
|
-
# @param [Object] params The request params or body
|
49
|
-
# @param [Hash] headers A hash of any additional HTTP headers to be set on
|
50
|
-
# the request.
|
51
|
-
# @param [Hash] env Additional environment variables that should be present
|
52
|
-
# on the request.
|
53
|
-
# @yield [Rack::Response] Yields the last response to the block if a
|
54
|
-
# block is given.
|
55
|
-
def put(path, params = {}, headers = {}, env = {}, &block)
|
56
|
-
set_headers(headers)
|
57
|
-
super path, params, env, &block
|
58
|
-
check_response_status!(:put, 200, path)
|
59
|
-
last_response.body
|
60
|
-
end
|
61
|
-
|
62
|
-
# Sends a GET request to the application.
|
63
|
-
#
|
64
|
-
# Similar to `Rack::Test::Methods#get` except that it adds more convenient
|
65
|
-
# access to setting request headers, it raises an exception if the response
|
66
|
-
# status is not 200, and it returns the response body.
|
67
|
-
#
|
68
|
-
# @param [String] path The path portion of the URI to request from the
|
69
|
-
# application
|
70
|
-
# @param [Object] params The request params or body
|
71
|
-
# @param [Hash] headers A hash of any additional HTTP headers to be set on
|
72
|
-
# the request.
|
73
|
-
# @param [Hash] env Additional environment variables that should be present
|
74
|
-
# on the request.
|
75
|
-
# @yield [Rack::Response] Yields the last response to the block if a
|
76
|
-
# block is given.
|
77
|
-
def get(path, params = {}, headers = {}, env = {}, &block)
|
78
|
-
set_headers(headers)
|
79
|
-
super path, params, env, &block
|
80
|
-
check_response_status!(:get, 200, path)
|
81
|
-
last_response.body
|
82
|
-
end
|
83
|
-
|
84
|
-
private
|
85
|
-
|
86
|
-
def check_response_status!(verb, expected_status, path)
|
87
|
-
actual_status = response_status
|
88
|
-
unless actual_status == expected_status
|
89
|
-
raise UnexpectedResponse,
|
90
|
-
"#{verb} to #{path} unexpectedly responded with an HTTP status of #{actual_status}:\n" \
|
91
|
-
+ response_body
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def response_status
|
96
|
-
last_response.status
|
97
|
-
end
|
98
|
-
|
99
|
-
def response_body
|
100
|
-
last_response.body
|
101
|
-
end
|
102
|
-
|
103
|
-
def set_headers(headers)
|
104
|
-
headers.each do |name, value|
|
105
|
-
header name, value
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|