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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:56:44+00:00 2026-05-31T10:56:44+00:00

I have an Rspec test for a helper method which requires access to my

  • 0

I have an Rspec test for a helper method which requires access to my current_user method provided by Devise. The issue is when I use the login_user macro in my tests for helpers they don’t work!

Here is what my test looks like:

describe 'follow_link' do
  before :each do
    login_user
  end

  it "display 'follow' if the curren_user is not following" do
    user = Factory :user
    helper.follow_link(user).should == 'Follow'
  end
end

But it fails with this:

Failure/Error: login_user
 NoMethodError:
   undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_2:0x007faf8c680090>
# ./spec/support/macros.rb:4:in `login_user'
# ./spec/helpers/users_helper_spec.rb:29:in `block (3 levels) in <top (required)>'

And that macro looks like this:

def login_user
  @user = Factory(:user)
  visit new_user_session_path

  # fill in sign in form
  within("#main_container") do
    fill_in "user[email]", with: @user.email
    fill_in "user[password]", with: @user.password
    click_button "Sign in"
  end
end

I’ve required:

require 'spec_helper'

in my test and everything but that method still isn’t available.

  • 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-31T10:56:46+00:00Added an answer on May 31, 2026 at 10:56 am

    Friend ‘visit’ is the method of Capybara which is used for writing integration test cases.

    For writing RSpec unit test cases you need to stub the current_user method call and focus on the functionality of the helper method.

    describe 'follow_link' do
      before :each do
       @user = Factory :user
       helper.stub(:current_user).and_return(@user)
      end
    
      it "display 'follow' if the curren_user is not following" do
        helper.follow_link(@user).should == 'Follow'
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using a helper class with an rspec test, I can't see to use
I have problems to get rspec running properly to test validates_inclusion_of my migration looks
I have the following RSpec example which is passing: describe UsersController do it should
I've got an rspec test which looks something like this: require 'require_all' require_rel '../spec_helper'
I have just installed Rspec and Rspec-rails. When i try to run the test,
I have written some Rspec test cases in my spec/models/season_spec.rb file. They are as:-
I try test my view with Rspec. In my view, I have a Decorator
I'm trying to use capybara with rspec to test my rails app. I've simplified
In my ApplicationController I have a method defined as a helper method: helper_method :some_method_here
i will use RSpec with Factory girl in my Rails3 Project. I have installed

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.