Sha256: 9f276bf8218c0459eca0241759d5d5a9e76dec89cfb8c3ed9f7632a60c4a6870

Contents?: true

Size: 1.51 KB

Versions: 12

Compression:

Stored size: 1.51 KB

Contents

require "rake"

describe Appsignal::Hooks::RakeHook do
  let(:task) { Rake::Task.new("task:name", Rake::Application.new) }
  before(:context) do
    Appsignal.config = project_fixture_config
    expect(Appsignal.active?).to be_truthy
    Appsignal::Hooks.load_hooks
  end

  describe "#execute" do
    context "without error" do
      it "creates no transaction" do
        expect(Appsignal::Transaction).to_not receive(:create)
      end

      it "calls the original task" do
        expect(task).to receive(:execute_without_appsignal).with("foo")
      end

      after { task.execute("foo") }
    end

    context "with error" do
      let(:error) { VerySpecificError.new }
      let(:transaction) { background_job_transaction }
      before do
        task.enhance { raise error }

        expect(Appsignal::Transaction).to receive(:create).with(
          kind_of(String),
          Appsignal::Transaction::BACKGROUND_JOB,
          kind_of(Appsignal::Transaction::GenericRequest)
        ).and_return(transaction)
      end

      it "sets the action" do
        expect(transaction).to receive(:set_action).with("task:name")
      end

      it "sets the error" do
        expect(transaction).to receive(:set_error).with(error)
      end

      it "completes the transaction and stops" do
        expect(transaction).to receive(:complete).ordered
        expect(Appsignal).to receive(:stop).with("rake").ordered
      end

      after do
        expect { task.execute("foo") }.to raise_error VerySpecificError
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
appsignal-2.3.1 spec/lib/appsignal/hooks/rake_spec.rb
appsignal-2.3.0 spec/lib/appsignal/hooks/rake_spec.rb
appsignal-2.3.0.beta.3 spec/lib/appsignal/hooks/rake_spec.rb
appsignal-2.3.0.beta.2 spec/lib/appsignal/hooks/rake_spec.rb
appsignal-2.3.0.beta.1 spec/lib/appsignal/hooks/rake_spec.rb
appsignal-2.2.1 spec/lib/appsignal/hooks/rake_spec.rb
appsignal-2.2.0 spec/lib/appsignal/hooks/rake_spec.rb
appsignal-2.2.0.beta.1 spec/lib/appsignal/hooks/rake_spec.rb
appsignal-2.1.2 spec/lib/appsignal/hooks/rake_spec.rb
appsignal-2.1.1 spec/lib/appsignal/hooks/rake_spec.rb
appsignal-2.1.1.beta.1 spec/lib/appsignal/hooks/rake_spec.rb
appsignal-2.1.0 spec/lib/appsignal/hooks/rake_spec.rb