spec/plaza/request_spec.rb in plaza-0.0.4 vs spec/plaza/request_spec.rb in plaza-0.1.0

- old
+ new

@@ -4,10 +4,11 @@ describe Request do context 'when Thread.current[:x_user_id] is set' do before do Thread.current[:x_user_id] = 4242 end + after do Thread.current[:x_user_id] = nil end %i(get post put delete).each do |method| it "##{method} should add X-User-Id to headers" do stub_request(method, "http://example.com/foobar"). with(:headers => { @@ -36,23 +37,17 @@ end end context "when trucker service is down" do - let(:request){ - exception = Faraday::Adapter::Test::Stubs.new do |stub| - %i(get put post delete).each do |method| - stub.send(method, '/failblog') {raise Faraday::Error::ConnectionFailed.new('Connection Failed')} - end - end - request = Request.new do |conn| - conn.adapter :test, exception - end - request - } %i(get put post delete).each do |method| describe "#{method}" do - let(:response){request.send(method, '/failblog')} + before do + stub_request(method, "http://example.com/failblog"). + to_raise(Faraday::Error::ConnectionFailed.new('Connection Failed')) + end + + let(:response){Request.new.send(method, '/failblog')} it 'response code should be 503' do expect{response}.to raise_error(Plaza::ConnectionError) end