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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:45:29+00:00 2026-05-16T05:45:29+00:00

When using a helper class with an rspec test, I can’t see to use

  • 0

When using a helper class with an rspec test, I can’t see to use the .should be_false idiom. It’s okay in a function defined in a helper .rb file, but when it’s within a class the be_false symbol is not found. Example below — why doesn’t this work? How can I use be_false et al in a helper?

It seems possible that it’s intentional that assertions like this only work in tests themselves. I have helpers which can fail due to eg. network comms problems which are actually bona-fide test failures since the network comms my helpers use are part of the system under test. How should I make my tests fail gracefully inside a helper class?

Results

$ spec ./test.rb 
helper_foo 1
helper_foo 2
helper_foo 3
FunctionFoo 1
F

1)
NameError in 'my_test should test that helper classes can use should be_false etc'
undefined local variable or method `be_false' for #<HelperFoo:0x2b265f7adc98>
./helper.rb:13:in `FunctionFoo'
./test.rb:13:

Finished in 0.004536 seconds

1 example, 1 failure

test.rb

require "helper.rb"

describe "my_test" do
    it "should test that helper classes can use should be_false etc" do

        (1 == 1).should be_true
        (2 == 1).should be_false

        helper_foo()

        instance = HelperFoo.new()
        instance.FunctionFoo
    end
  end

helper.rb

def helper_foo
    puts "helper_foo 1"
    (1==2).should be_false
    puts "helper_foo 2"
    (2==2).should be_true
    puts "helper_foo 3"
end

class HelperFoo
    def FunctionFoo
        puts "FunctionFoo 1"
        (1==2).should be_false
        puts "FunctionFoo 2"
        (2==2).should be_true
        puts "FunctionFoo 3"
    end
end
  • 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-16T05:45:30+00:00Added an answer on May 16, 2026 at 5:45 am

    Expectations like be_true are only available in the context of an it block. When you call a method on HelperFoo.new, it’s no longer executed in the context of whatever magical class it operates on.

    You should read up on instance_eval to understand what an evaluation context is.

    Also if you need to define RSpec examples externally, you should use Shared Example Groups.

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

Sidebar

Related Questions

I am using a helper class in my app, to access a database and
For convenience, I am using a helper class that allow to display a wait
Hi all im using a sqlite helper class, but i have a little problem
I am trying to insert into my database table using the database helper class.
I currently have a helper class that I am using to obfuscate a static
I currently have a class file with the following enumeration: using System; namespace Helper
I'm using a helper class to build my hyperlink. The markup looks like this:
I am using a ado.net helper class from Here . I don't know how
I'm using ASP.NET MVC 3. I've wriiten a helper class as follows: public static
I am using Js helper class and i have successfully implement this.I am using

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.