Note that there are some explanatory texts on larger screens.

plurals
  1. POTesting Views that use Devise with RSpec
    primarykey
    data
    text
    <p>I am trying to get a previously passing rspec "view spec" to pass after adding Devise's <code>user_signed_in?</code> method to the view template in question. The template looks something like this:</p> <pre><code>&lt;% if user_signed_in? %&gt; Welcome back. &lt;% else %&gt; Please sign in. &lt;% endif %&gt; </code></pre> <p>The view spec that <em>was</em> passing looks something like this:</p> <pre><code>require "spec_helper" describe "home/index.html.erb" do it "asks you to sign in if you are not signed in" do render rendered.should have_content('Please sign in.') end end </code></pre> <p>The error it produces after adding the call to <code>user_signed_in?</code> is:</p> <pre><code> 1) home/index.html.erb asks you to sign in if you are not signed in Failure/Error: render ActionView::Template::Error: undefined method `authenticate' for nil:NilClass # ./app/views/home/index.html.erb:1:in `_app_views_home_index_html_erb__1932916999377371771_70268384974540' # ./spec/views/home/index.html.erb_spec.rb:6:in `block (2 levels) in &lt;top (required)&gt;' </code></pre> <p>There are plenty of references to this error around the web, but I have yet to find an answer descriptive enough that I can get my test passing again. I believe the problem has something to do with the view (which is being testing in isolation from any models/controllers) not having some key Devise infrastructure available. Your suggestions are appreciated.</p> <p>Also, once the test passes, how would I test the other path (user already signed in)? I presume it will be very similar. Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload