spec/leadlight/service_middleware_spec.rb in leadlight-0.0.2 vs spec/leadlight/service_middleware_spec.rb in leadlight-0.0.3
- old
+ new
@@ -15,67 +15,30 @@
let(:service) { stub(url: 'http://example.com', tints: []) }
let(:faraday_stubs) { Faraday::Adapter::Test::Stubs.new }
let(:app) { ->(env){stub(on_complete: nil)} }
let(:response) { [200, {}, ''] }
let(:result_env) {
- test_stack.get('/').env
+ do_get('/').env
}
let(:representation) { result_env[:leadlight_representation] }
+ let(:leadlight_request) { stub(:leadlight_request, represent: stub) }
+ def do_get(path)
+ test_stack.get(path) do |request|
+ request.options[:leadlight_request] = leadlight_request
+ end
+ end
+
before do
faraday_stubs.get('/') {response}
end
it 'adds :leadlight_service to env before app' do
- test_stack.get('/').env[:leadlight_service].should equal(service)
+ do_get('/').env[:leadlight_service].should equal(service)
end
- it 'extends the representation with Representation' do
- representation.should be_a(Representation)
- end
-
- it 'makes the representation hyperlinkable' do
- representation.should be_a(Hyperlinkable)
- end
-
it 'requests JSON, then YAML, then XML, then HTML' do
result_env[:request_headers]['Accept'].
should eq('application/json, text/x-yaml, application/xml, application/xhtml+xml, text/html, text/plain')
- end
-
- context 'with a no-content response' do
- let(:response) { [204, {}, ''] }
- let(:result_env) {
- test_stack.get('/').env
- }
-
- it 'sets :leadlight_representation to a Blank' do
- result_env[:leadlight_representation].should be_a(Blank)
- end
- end
-
- context 'with a blank JSON response' do
- let(:response) {
- [200, {'Content-Type' => 'application/json', 'Content-Length' => '0'}, '']
- }
- let(:result_env) {
- test_stack.get('/').env
- }
-
- it 'sets :leadlight_representation to a Blank' do
- result_env[:leadlight_representation].should be_a(Blank)
- end
- end
-
- context 'with a non-blank JSON response' do
- let(:response) {
- [200, {'Content-Type' => 'application/json', 'Content-Length' => '7'}, '[1,2,3]']
- }
- let(:result_env) {
- test_stack.get('/').env
- }
- it 'sets :leadlight_representation to the result of parsing the JSON' do
- result_env[:leadlight_representation].should eq([1,2,3])
- end
end
end
end