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 6978055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:42:23+00:00 2026-05-27T17:42:23+00:00

I made this code and i try to test it with minitest, but it

  • 0

I made this code and i try to test it with minitest, but it seems that i am not using the right syntax for an exception :/

def my_method(a,b=10)
  begin
    a/b
  rescue
    raise 'bla'
  end
end

describe 'my test' do
  it "must divide" do
    my_method(6,3).must_equal(2)
  end

  it "can't divide by zero and raise bla" do
    my_method(6,0).must_raise 'bla'
  end

  it "must divide by 10 if there is only one arg" do
    my_method(10).must_equal(1)
  end
end

Output :

Run options: –seed 30510

Running tests:

..E

Finished tests in 0.001000s, 3000.0000 tests/s, 2000.0000 assertions/s.

1) Error:
test_0002_can_t_divide_by_zero_and_raise_bla(my test):
RuntimeError: bla
essai.rb:9:in my_method'
essai.rb:19:in
test_0002_can_t_divide_by_zero_and_raise_bla’

3 tests, 2 assertions, 0 failures, 1 errors, 0 skips

The second test raise me an error, can somebody help me ?

  • 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-27T17:42:23+00:00Added an answer on May 27, 2026 at 5:42 pm

    You should call must_raise on proc, not on method call result:

    require 'minitest/autorun'
    
    def my_method(a,b=10)
      begin
        a/b
      rescue
        raise 'bla'
      end
    end
    
    describe 'my test' do
      it "must divide" do
        my_method(6,3).must_equal(2)
      end
    
      it "can't divide by zero and raise bla" do
        div_by_zero = lambda { my_method(6,0) }
        div_by_zero.must_raise RuntimeError
        error = div_by_zero.call rescue $!
        error.message.must_equal 'bla'
      end
    
      it "must divide by 10 if there is only one arg" do
        my_method(10).must_equal(1)
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made this code with jQuery to fade images ( but not the one
Hey. I know this is not a 'refactor my code' site but I made
I am pretty new at C# and .NET, but I've made this code to
Ok. I've made this awe-crap-code Exporting table to XLS (but still no idea how
I made some sample code to try wxNotebook, but the new inserted pages remain
How can I improve this code? What has made this long winded is the
i made a windows service & add project installer.in which only contain this code.
I have roughly the following code. Could this be made nicer or more efficient?
I made this little Cocoa app with a WebView that displays Google Maps in
The project I'm working on is slightly more complicated but I made this simple

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.