Sha256: ce28e96b31f8e2bd7f0fcd45fd88a297f8b808a439ec248caf3be6146152b406
Contents?: true
Size: 1.84 KB
Versions: 1
Compression:
Stored size: 1.84 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 let(:http_client) { stub(:request => stub(:code => '200')) } before do agent.stub(:http_client).and_return(http_client) agent.add_to_queue(event) ActiveSupport::JSON.stub(:encode => '{"abc":"def"}') end it 'should call Net::HTTP.post_form with the correct params' do post = stub post.should_receive(:set_form_data).with( 'api_key' => 'abc', 'log_entries' => '{"abc":"def"}' ) Net::HTTP::Post.should_receive(:new).with( '/api/1/log_entries' ).and_return(post) 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
justlogging-rails-0.0.5 | spec/justlogging/agent_spec.rb |