New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing error handling #15

Closed
adarsh opened this Issue May 27, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@adarsh

adarsh commented May 27, 2015

This is pretty difficult now. Anyone else find a good way to test the rescue_from behavior in ActiveJob?

DelayedJob has a nice error method hook:

def error(job, exception)
    ExceptionService.notify(exception)
end

Maybe it's worth adding this to ActiveJob?

@isaacseymour

This comment has been minimized.

Show comment
Hide comment
@isaacseymour

isaacseymour May 27, 2015

Contributor

I think you could write something like:

class MyError < StandardError; end

class MyJob < ActiveJob::Base
  rescue_from(MyError) { |error| ExceptionService.notify(error) }

  def perform
    "nothing to see here"
  end
end

it "shouts about errors" do
  expect(ExceptionService).to receive(:notify).with(exception)
  allow_any_instance_of(MyJob).to receive(:perform).and_raise(MyError.new("sad times"))
  MyJob.perform_now
end
Contributor

isaacseymour commented May 27, 2015

I think you could write something like:

class MyError < StandardError; end

class MyJob < ActiveJob::Base
  rescue_from(MyError) { |error| ExceptionService.notify(error) }

  def perform
    "nothing to see here"
  end
end

it "shouts about errors" do
  expect(ExceptionService).to receive(:notify).with(exception)
  allow_any_instance_of(MyJob).to receive(:perform).and_raise(MyError.new("sad times"))
  MyJob.perform_now
end
@adarsh

This comment has been minimized.

Show comment
Hide comment
@adarsh

adarsh May 27, 2015

Nice! Thank you @isaacseymour! I always forget about allow_any_instance_of.

I feel like this is now off-topic and I'm going to close it in favor of a patch to Rails. Feel free to re-open if someone feels like an error matcher would be helpful for these jobs.

adarsh commented May 27, 2015

Nice! Thank you @isaacseymour! I always forget about allow_any_instance_of.

I feel like this is now off-topic and I'm going to close it in favor of a patch to Rails. Feel free to re-open if someone feels like an error matcher would be helpful for these jobs.

@adarsh adarsh closed this May 27, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment