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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:13:53+00:00 2026-06-01T14:13:53+00:00

I have to write integration test case for my one feature listing page and

  • 0

I have to write integration test case for my one feature listing page and that feature index method has code like below

def index
  @food_categories = current_user.food_categories
end

Now when i try to write a test case for this it throws an error

'undefined method features for nil class' because it can not get the current user

Now what i have do is below
I have write the login process in the before each statement and then write the test case for the features listing page

Can you please let me know that how i can get the current_user ?

FYI, I have used devise gem and working on integration test case with Rspec

Here is my spec file
And here is my food_categories_spec.rb

  • 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-01T14:13:54+00:00Added an answer on June 1, 2026 at 2:13 pm

    Update: you confuse functional and integration tests. Integration test doesn’t use get, because there’s no controller action to test, instead you must use visit (some url). Then you have to examine content of a page, not response code (latter is for functional tests). It may look like:

    visit '/food_categories'
    page.should have_content 'Eggs'
    page.should have_content 'Fats and oils'
    

    In case you’ll need functional test, here’s an example:

    # spec/controllers/your_controller_spec.rb
    describe YourController do
    
      before do
        @user = FactoryGirl.create(:user)
        sign_in @user
      end
    
      describe "GET index" do
    
        before do
          get :index
        end
    
        it "is successful" do
          response.should be_success
        end
    
        it "assings user features" do
          assigns(:features).should == @user.features
        end
      end
    end
    
    # spec/spec_helper.rb
    RSpec.configure do |config|
      #...
      config.include Devise::TestHelpers, :type => :controller
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an old asp.net application that has no unit tests, integration tests, component
I am trying ot write an integration test for one of my controller classes
I suspect that I will shortly have a need to write an integration library
I have some integration tests that test the processing of USB data from a
I would like to write some integration test for my application. I wasn't able
I'm writing a simple web app in PHP that needs to have write access
I have to write a Matlab script that does this: The input is 2
In one of my Django projects I have a suite of unit tests that
I have a class API which has full code coverage and uses DI to
So say I'm doing TDD and I write a test like this: public void

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.