spec/lib/appsignal/hooks/sidekiq_spec.rb in appsignal-2.1.0.alpha.3 vs spec/lib/appsignal/hooks/sidekiq_spec.rb in appsignal-2.1.0.beta.1

- old
+ new

@@ -1,76 +1,79 @@ describe Appsignal::Hooks::SidekiqPlugin do let(:worker) { double } let(:queue) { double } let(:current_transaction) { background_job_transaction } - let(:item) {{ - 'class' => 'TestClass', - 'retry_count' => 0, - 'queue' => 'default', - 'enqueued_at' => Time.parse('01-01-2001 10:00:00UTC'), - 'args' => ['Model', 1], - 'extra' => 'data' - }} + let(:item) do + { + "class" => "TestClass", + "retry_count" => 0, + "queue" => "default", + "enqueued_at" => Time.parse("01-01-2001 10:00:00UTC"), + "args" => ["Model", 1], + "extra" => "data" + } + end let(:plugin) { Appsignal::Hooks::SidekiqPlugin.new } before do - Appsignal.stub(:is_ignored_exception? => false) Appsignal::Transaction.stub(:current => current_transaction) start_agent end context "with a performance call" do it "should wrap in a transaction with the correct params" do Appsignal.should_receive(:monitor_transaction).with( - 'perform_job.sidekiq', - :class => 'TestClass', - :method => 'perform', + "perform_job.sidekiq", + :class => "TestClass", + :method => "perform", :metadata => { - 'retry_count' => "0", - 'queue' => 'default', - 'extra' => 'data' + "retry_count" => "0", + "queue" => "default", + "extra" => "data" }, - :params => ['Model', "1"], - :queue_start => Time.parse('01-01-2001 10:00:00UTC'), - :queue_time => 60000.to_f + :params => ["Model", "1"], + :queue_start => Time.parse("01-01-2001 10:00:00UTC"), + :queue_time => 60_000.to_f ) end context "when wrapped by ActiveJob" do - let(:item) {{ - "class" => "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper", - "wrapped" => "TestClass", - "queue" => "default", - "args"=> [{ - "job_class" => "TestJob", - "job_id" => "23e79d48-6966-40d0-b2d4-f7938463a263", - "queue_name" => "default", - "arguments" => ['Model', 1], - }], - "retry" => true, - "jid" => "efb140489485999d32b5504c", - "created_at" => Time.parse('01-01-2001 10:00:00UTC').to_f, - "enqueued_at" => Time.parse('01-01-2001 10:00:00UTC').to_f - }} + let(:item) do + { + "class" => "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper", + "wrapped" => "TestClass", + "queue" => "default", + "args" => [{ + "job_class" => "TestJob", + "job_id" => "23e79d48-6966-40d0-b2d4-f7938463a263", + "queue_name" => "default", + "arguments" => ["Model", 1] + }], + "retry" => true, + "jid" => "efb140489485999d32b5504c", + "created_at" => Time.parse("01-01-2001 10:00:00UTC").to_f, + "enqueued_at" => Time.parse("01-01-2001 10:00:00UTC").to_f + } + end it "should wrap in a transaction with the correct params" do Appsignal.should_receive(:monitor_transaction).with( - 'perform_job.sidekiq', - :class => 'TestClass', - :method => 'perform', + "perform_job.sidekiq", + :class => "TestClass", + :method => "perform", :metadata => { - 'queue' => 'default' + "queue" => "default" }, - :params => ['Model', "1"], - :queue_start => Time.parse('01-01-2001 10:00:00UTC').to_f, - :queue_time => 60000.to_f + :params => ["Model", "1"], + :queue_start => Time.parse("01-01-2001 10:00:00UTC").to_f, + :queue_time => 60_000.to_f ) end end after do - Timecop.freeze(Time.parse('01-01-2001 10:01:00UTC')) do + Timecop.freeze(Time.parse("01-01-2001 10:01:00UTC")) do Appsignal::Hooks::SidekiqPlugin.new.call(worker, item, queue) do # nothing end end end @@ -83,11 +86,11 @@ Appsignal::Transaction.any_instance.should_receive(:set_error).with(error) end after do begin - Timecop.freeze(Time.parse('01-01-2001 10:01:00UTC')) do + Timecop.freeze(Time.parse("01-01-2001 10:01:00UTC")) do Appsignal::Hooks::SidekiqPlugin.new.call(worker, item, queue) do raise error end end rescue VerySpecificError @@ -96,16 +99,16 @@ end describe "#formatted_data" do let(:item) do { - 'foo' => 'bar', - 'class' => 'TestClass', + "foo" => "bar", + "class" => "TestClass" } end it "should only add items to the hash that do not appear in JOB_KEYS" do - plugin.formatted_metadata(item).should eq({'foo' => 'bar'}) + plugin.formatted_metadata(item).should eq("foo" => "bar") end end end describe Appsignal::Hooks::SidekiqHook do