How do I include SessionsHelper methods into my specs files?
like current_user and sign_in
Currently I am getting undefined local variable or method `current_user’ for #RSpec::Core::ExampleGroup::Nested_1:0x007ffd4391ac60
require "spec_helper"
include SessionsHelper
describe "Groups" do
it "signed in user should be able to create a group", :js => true do
@user = User.create(name:"ankur",email:"ankothari@gmail.com",password:"akk322",password_confirmation:"akk322")
subject{@user}
visit '/'
click_link "Log In"
fill_in "session_email",with: @user.email
fill_in "session_password",with:@user.password
within("#login-content") do
click_button "Login"
end
# fill_in "creategroupinput", with: "Electronics"
expect do
xhr :post, user_groups_path(@user), groups: { name:"Electronics" }
end.to change(@user.groups, :count).by(1)
# # expect{click_button "Create"}.to change{user.groups.count}.by(1)
# expect{click_button "Create Group"}.to change{user.groups.count}.by(1)
end
@ankur_kothari, the error you’re getting means the current_user is nil, which means the login probably didn’t work. Also, it looks like you’re mixing capybara and xhr, which might use a different session. Thats where you’ll want to investigate.
As an aside, when you paste code, can you try to make it better formatted? Properly spaced and indented? That’ll help us be able to read it and help you.