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
Update: you confuse functional and integration tests. Integration test doesn’t use
get, because there’s no controller action to test, instead you must usevisit(some url). Then you have to examine content of a page, not response code (latter is for functional tests). It may look like:In case you’ll need functional test, here’s an example: