Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7440847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:54:54+00:00 2026-05-29T10:54:54+00:00

I have a class called RemoteError with a self.fatal method on it. This methods

  • 0

I have a class called RemoteError with a self.fatal method on it. This methods job is basically to catch an exception, send the details of the exception to a server and then propagate the exception in order to kill the program.

class RemoteError
  def initialize(label, error)
    @label = label
    @error = error
  end

  def self.fatal(label, error)
    object = new(label, error)
    object.send
    raise error
  end

  def send
    # send the error to the server
  end
end

I’m trying to write tests for the RemoteError.fatal method. This is difficult because of the call to raise within the method. Every time I run my tests, raise obviously raises an exception and I can’t test that send was called.

  describe "fatal" do
    it "should send a remote error" do
      error = stub
      RemoteError.stub(:new) { error }
      error.should_receive(:send)

      RemoteError.fatal(stub, stub)
    end
  end

Is there a way that I can stub or somehow circumvent raise for this specific test?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:54:55+00:00Added an answer on May 29, 2026 at 10:54 am

    You could wrap the method that raises the error in a lambda…

    it "should send a remote error" do
      ...
    
      lambda { RemoteError.fatal(stub, stub) }.should raise_error(error)
    end    
    

    This essentially allows the method to be called, and you get the return value or raised error from it, which you then assert against with .should raise_error(error). This also makes is so that if no error is raised from that call, the test will fail normally.

    To say it another way, you don’t need, nor want, to stub raise. Simply wrap it in a lambda and your code will continue to execute, you should be able to make sure that your message is sent, and your test won’t exit/crash.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class called XMLtoXML.java and this is one of it's methods... import
I have a class called CategoryViewController and its viewDidLoad method calls this method: -
I have a class called EventConsumer which defines an event EventConsumed and a method
I have this class called Table: class Table { public string Name { get
i have this class called MemoryManager, it is supposed to implement a simple smart
I have a class called Path for which there are defined about 10 methods,
I have a class called UserInfo that contains details about a given user. There
I have one class called Person that basically looks like: public class Person {
I have a class called IssuesView which implements INotifyPropertyChanged . This class holds an
I have class called Chicken and in Chicken I have some methods, so in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.