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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:52:30+00:00 2026-06-10T13:52:30+00:00

Like most people, I have learned Rails before Ruby and now I would like

  • 0

Like most people, I have learned Rails before Ruby and now I would like to get a better knowledge of Ruby.
I am making some scripts and I would like to test them.
I was surprised by the fact that you can’t use Rails’ test syntax in plain ruby scripts. The following code does not work:

require "test/unit"
class MyTest < Test::Unit::TestCase
  test "one plus one should be equal to two" do
    assert_equal 1 + 1, 2
  end
end

# Error: wrong number of arguments (1 for 2) (ArgumentError)

You have to use this code instead:

require "test/unit"
class MyTest < Test::Unit::TestCase
  def one_plus_one_should_be_equal_to_two
    assert_equal 1 + 1, 2
  end
end

Which seems less readable to me.
Is it possible to use the "declarative" syntax in plain Ruby scripts?

  • 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-06-10T13:52:32+00:00Added an answer on June 10, 2026 at 1:52 pm

    According to Rails’ APIs, the test method is defined inside ActiveSupport::Testing::Declarative module and uses a sort of metaprogramming to add new test methods.

    If you don’t already have the Rails gem installed, you can just install the activesupport gem:

    gem install activesupport
    

    Now you just have to require it and make your class inherit from ActiveSupport::TestCase.
    Here is the complete code:

    require "test/unit"
    require "active_support"
    class MyTest < ActiveSupport::TestCase
      test "one plus one should be equal to two" do
        assert_equal 1 + 1, 2
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a document which contains references to some other documents. Like most people,
We have a basic service that some people use but most people want their
Here is the lay of the land. Like most people I have my domain
Like most *nix people, I tend to play with my tools and get them
It looks like this template tag works like a charm for most people: http://blog.localkinegrinds.com/2007/09/06/digg-style-pagination-in-django/
I have a particular web application that like most others, has to account for
I do some stuff with XMLSerializer class. Like a most of beginners I face
What's the most most ruby-like way of converting from an Array like [:one, 1,
Like most people I use SWFObject to embed Flash (swf) files to my Web
Like most people new to Git, I've had my share of confusion trying to

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.