Sha256: 50d51f93ee01e97ccf6df44dbacedd8d3bf58e7cad86ccbc73b614fcc0f354cd
Contents?: true
Size: 1.76 KB
Versions: 4
Compression:
Stored size: 1.76 KB
Contents
require 'spec_helper' describe Justlogging::Agent do before :each do Thread.stub(:new) end let(:agent) { Justlogging::Agent.new } let(:event) { stub(:name => 'event') } describe '#add_to_queue' do it 'should add the event to the queue' do expect { agent.add_to_queue(event) }.to change(agent, :queue).to([event]) end end describe '#send_queue' do before do agent.add_to_queue(event) ActiveSupport::JSON.stub(:encode => '{"abc":"def"}') Net::HTTP.stub(:post_form).and_return(stub(:code => '200')) end it 'should call Net::HTTP.post_form with the correct params' do Net::HTTP.should_receive(:post_form).with( URI('http://localhost:3000/api/1/log_entries'), 'api_key' => 'abc', 'log_entries' => '{"abc":"def"}' ).and_return(stub(:code => '200')) end it "should call handle_result" do agent.should_receive(:handle_result).with('200') end after { agent.send_queue } end describe '#handle_result' do before do agent.add_to_queue(event) end it "should empty the queue for 200" do expect { agent.handle_result('200') }.to change(agent, :queue).to([]) end it "should raise the sleep_time time for 403" do expect { agent.handle_result('403') }.to change(agent, :sleep_time).to(7.5) end context "any other response" do it "should deactivate for any other response code" do expect { agent.handle_result('500') }.to change(agent, :active).to(false) end it "should unsubscribe from the justlogging subscriber" do ActiveSupport::Notifications.should_receive(:unsubscribe) agent.handle_result('500') end end end end
Version data entries
4 entries across 4 versions & 1 rubygems