Note that there are some explanatory texts on larger screens.

plurals
  1. PORspec test failing when output indicates it should pass
    primarykey
    data
    text
    <p>~~~~~~~~~~~~~~~ <strong>Edit/Update</strong> ~~~~~~~~~~~~~~~</p> <p>Ok, I fixed the tests that were failing to pass by appending a ".to_s" to each user.password_digest in the change blocks. I assume this is working because before user.password_digest was sort of like a pointer, and calling "to_s" forces the test to compare the string values. If anyone can explain why the test compares the pointer and not the value, please enlighten me.</p> <p>After adding the .to_s calls (added everywhere I was expecting a user attribute to change), Failure #3 is still occurring (and a new failure, actually, but I'm sure it's caused by the same issue causing Failure #3). Any ideas why the test "correct user with correct password should change email" isn't catching the change action that happens correctly in the browser?</p> <p>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</p> <p>I'm trying to validate behavior of a form to update a user's profile (change email and/or password). 3 of my tests are failing, and I can't figure out why. Take a look at the console output when I run the tests...</p> <pre><code>Failures: 1) User Pages Edit page correct user updates password with incorrect password should not change password Failure/Error: expect { click_button "Save" }.not_to change{ user.password_digest } result should not have changed, but did change from "$2a$10$Xrg1SHSyDmK5Of9HrjgYAuzkJzKk7HeaVjj4ZT9Ldz2R9BNji3D2S" to "$2a$10$Xrg1SHSyDmK5Of9HrjgYAuzkJzKk7HeaVjj4ZT9Ldz2R9BNji3D2S" # ./spec/requests/user_pages_spec.rb:135:in `block (6 levels) in &lt;top (required)&gt;' 2) User Pages Edit page correct user updates password with confirmation mismatch should not change password Failure/Error: expect { click_button "Save" }.not_to change{ user.password_digest } result should not have changed, but did change from "$2a$10$bm2viuIuNCRIEEWe/qYVAOVl0r0EW7Y/1CqalKUwgR.ht/wVtQ8Zi" to "$2a$10$bm2viuIuNCRIEEWe/qYVAOVl0r0EW7Y/1CqalKUwgR.ht/wVtQ8Zi" # ./spec/requests/user_pages_spec.rb:147:in `block (6 levels) in &lt;top (required)&gt;' 3) User Pages Edit page correct user updates email with correct password should change email Failure/Error: expect { click_button "Save" }.to change{ user.email }.to(new_email) result should have been changed to "new_email@example.com", but is now "person_7@example.com" # ./spec/requests/user_pages_spec.rb:121:in `block (6 levels) in &lt;top (required)&gt;' Finished in 2.99 seconds 8 examples, 3 failures </code></pre> <p>Failures #1 &amp; 2 should be passing, right? The before and after strings match, and they're expected not to change! What could be going on here?</p> <p>Furthermore, I can't figure out why failure #3 is happening.</p> <p>The code works as expected in the browser. Could it have something to do with AJAX? The update action the form is hitting doesn't redirect_to anything -- it just renders the page again with flash notices. I'm a Rails newbie so I'm probably missing something obvious.</p> <p>The form:</p> <pre><code>&lt;%= form_tag user_path(params[:id]), method: :put do %&gt; &lt;%= label_tag :email %&gt; &lt;%= text_field_tag :email, params[:email] || @user.email %&gt; &lt;%= label_tag :new_password %&gt; &lt;%= password_field_tag :new_password %&gt; &lt;%= label_tag :new_password_confirmation, "Confirm new password" %&gt; &lt;%= password_field_tag :new_password_confirmation %&gt; &lt;%= label_tag :password %&gt; &lt;%= password_field_tag :password %&gt; &lt;%= submit_tag "Save", class: "btn btn-primary pull-down" %&gt; &lt;% end %&gt; </code></pre> <p>The tests spec (unrelated tests removed for clarity):</p> <pre><code>require 'spec_helper' describe "User Pages" do subject { page } describe "Edit page" do let(:user) { FactoryGirl.create(:user) } describe "correct user" do before do log_in user # helper method that logs the user in, a la Michael Hartl tutorial visit edit_user_path(user) end it { current_path.should == edit_user_path(user) } it { should have_selector('title', text: 'Edit') } it { should_not have_content('not authorized') } describe "updates email" do let(:new_email) { "new_email@example.com" } before { fill_in 'Email', with: new_email } describe "with incorrect password" do it "should not change email" do expect { click_button "Save" }.not_to change{ user.email } end end describe "with correct password" do before { fill_in 'Password', with: user.password } it "should change email" do expect { click_button "Save" }.to change{ user.email }.to(new_email) end end end describe "updates password" do describe "with incorrect password" do before do fill_in 'New password', with: 'newpassword' fill_in 'Confirm new password', with: 'newpassword' end it "should not change password" do expect { click_button "Save" }.not_to change{ user.password_digest } end end describe "with confirmation mismatch" do before do fill_in 'New password', with: 'newpassword' fill_in 'Confirm new password', with: 'password' fill_in 'Password', with: user.password end it "should not change password" do expect { click_button "Save" }.not_to change{ user.password_digest } end end describe "with correct password" do before do fill_in 'New password', with: 'newpassword' fill_in 'Confirm new password', with: 'newpassword' fill_in 'Password', with: user.password end it "should change password" do expect { click_button "Save" }.to change{ user.password_digest } end end end end end end </code></pre> <p>Relevant gem versions: Rails 3.2.9, Capybara 1.1.2, FactoryGirl 4.1.0</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.
    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