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

  • Home
  • SEARCH
  • 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 141039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:42:44+00:00 2026-05-11T07:42:44+00:00

I have a class defined in a file my Rails project’s lib dir that

  • 0

I have a class defined in a file my Rails project’s lib dir that will implement a bunch of utility functions as class methods. I’d like to write tests against those methods using Test::Unit and have them run as part of the project’s regular testing routine.

I tried sticking a file at the top level of the test dir…

require 'test_helper'  class UtilsTest < ActiveSupport::TestCase   should 'be true' do     assert false   end end 

…but that didn’t work. The test didn’t run.

What is the normal way to test code that is not one of the regular parts of Rails?

  • 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. 2026-05-11T07:42:45+00:00Added an answer on May 11, 2026 at 7:42 am

    You can put them in your units directory without any complications.

    My Library:

    [ cpm juno ~/apps/feedback ] cat lib/my_library.rb class MyLib   def look_at_me     puts 'I DO WEIRD STUFF'   end end 

    My Test:

    [ cpm juno ~/apps/feedback ] cat test/unit/fake_test.rb require 'test_helper'  class FakeTest < ActiveSupport::TestCase   # Replace this with your real tests.   def test_truth     require 'my_library'      puts 'RUNNING THIS NOW'     MyLib.new.look_at_me     assert true   end end 

    And running it:

    [ cpm juno ~/apps/feedback ] rake test:units (in /home/cpm/apps/feedback) /usr/bin/ruby1.8 -Ilib:test '/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb' 'test/unit/fake_test.rb' Loaded suite /usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader Started RUNNING THIS NOW I DO WEIRD STUFF . Finished in 0.254404 seconds.  1 tests, 1 assertions, 0 failures, 0 errors Loaded suite /var/lib/gems/1.8/bin/rake Started  Finished in 0.00094 seconds.  0 tests, 0 assertions, 0 failures, 0 errors 

    As long as it ends in _test.rb it should pick it up.

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

Sidebar

Related Questions

If I have the core of a class defined in one file as public
I have an actionscript file that defines a class that I would like to
I have the following members defined in a class that I'm trying to deserialise:
Let's say we have defined a CSS class that is being applied to various
I have a class with several template member functions that I would like to
If I have a class that includes a file with a constant like so:
I have a templated class defined (in part) as template <class T> MyClass {
I have a class with two methods defined in it. public class Routines {
Suppose I have an array of a objects of user defined class. Wanted to
I have a private const int defined in a C# class. I want compilation

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.