All threads / Warden and System Tests are driving me insane.
Ask A Question


You’re not receiving notifications from this thread.

Warden and System Tests are driving me insane.

Niklas Nson asked in Testing

Im using Warden for authentication and are now trying to write system test. But when I run a system test I get the following error:

Failure/Error: if current_user.admin?
  undefined method `admin?' for nil:NilClass 

Meaning current_user is not set. How to fix this? I have set up so I can do controller tests with Warden and that works. But I can not figure this out and I don't find any documentation with working code.

Please help me out, I'm going crazy!


module SigninHelper
  def sign_in_as(user)
    visit signin_path
    fill_in 'authentications_email', with:
    fill_in 'authentications_password', with: user.password
    click_button 'Logga in'

  def sign_out
    click_link "Logga ut"

exempel testcase:

require 'rails_helper'
require 'pry'

RSpec.describe "UserEdits", type: :system do
  let(:user) { Fabricate(:confirmed_user) }

  it "should update a users email" do 
    visit user_url(user.guid)
    click_link 'Ändra medlemsuppgifter'
    fill_in 'user_email', with: ""
    expect {
      click_button 'Uppdatera uppgifter'
    }.to change { }

I was trying to use "driven_by :rack_test" when changing to driven_by :selenium_chrome_headless it works as expected.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 62,791+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2022 GoRails, LLC. All rights reserved.