Note that there are some explanatory texts on larger screens.

plurals
  1. POsigned_in? function not working in Chapter 8-9 of Rails Tutorial (Hartl)
    primarykey
    data
    text
    <p>I have one rspec test failing.</p> <pre><code> 1) User pages edit with valid information should have link "Sign out", {:href=&gt;"/signout"} Failure/Error: it { should have_link('Sign out', href: signout_path) } expected #has_link?("Sign out", {:href=&gt;"/signout"}) to return true, got false # ./spec/requests/user_pages_spec.rb:80:in `block (4 levels) in &lt;top (required)&gt;' </code></pre> <p>The test looks to see if a 'Sign out' link is present in the header after signing in. The code works in a browser but not in rspec. The spec in question is aligned with the Hartl tutorial:</p> <pre><code>describe "User pages" do subject { page } ... describe "edit" do let(:user) { FactoryGirl.create(:user) } before { visit edit_user_path(user) } ... describe "with valid information" do let(:new_name) { "New Name" } let(:new_email) { "new@example.com"} before do fill_in "Name", with: new_name fill_in "Email", with: new_email fill_in "Password", with: user.password fill_in "Confirm Password", with: user.password click_button "Save changes" end it { should have_title(new_name) } it { should have_selector('div.alert.alert-success') } it { should have_link('Sign out', href: signout_path) } specify { expect(user.reload.name).to eq new_name } specify { expect(user.reload.email).to eq new_email } end end end </code></pre> <p>The following code is the header template being tested (also follows the Hartl Rails tutorial). I've run some tests (using <code>puts</code>) and found out that after logging in, the <code>signed_in?</code> function is returning false to rspec (while returning true when tested in the browser). </p> <pre><code> &lt;% if signed_in? %&gt; &lt;li&gt;&lt;%= link_to "Users", '#' %&gt;&lt;/li&gt; &lt;li id="fat-menu" class="dropdown"&gt; &lt;a href="#" class="dropdown-toggle" data-toggle="dropdown"&gt; Account &lt;b class="caret"&gt;&lt;/b&gt; &lt;/a&gt; &lt;ul class="dropdown-menu"&gt; &lt;li&gt;&lt;%= link_to "Profile", current_user %&gt;&lt;/li&gt; &lt;li&gt;&lt;%= link_to "Settings", edit_user_path(current_user) %&gt;&lt;/li&gt; &lt;li class="divider"&gt;&lt;/li&gt; &lt;li&gt; &lt;%= link_to "Sign out", signout_path, method: "delete" %&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;% else %&gt; &lt;li&gt;&lt;%= link_to "Sign in", signin_path %&gt;&lt;/li&gt; &lt;% end %&gt; </code></pre> <p>It appears this is a problem with rspec and I haven't been able to figure out what to do to remedy.</p> <p>Thanks in advance for your help.</p>
    singulars
    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.
 

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