2014-09-04 43 views
-2

已更新但仍無法使用!Rails教程9.6.5遇到問題,無法通過測試

更新 - 我以爲我已經包含了我正在使用的Rspec測試,但我沒有。他們現在包括在內

我提出了改變,但它仍然沒有通過。返回的失敗測試給出的唯一提示是它只是沒有達到測試的目標。它似乎沒有給出任何線索爲什麼...

我無法讓我的測試通過更改代碼後,按照清單9.49和9.50。我有一種感覺,我錯過了某處的細節,但我似乎無法找到它。這裏是我的代碼:

edit.html.erb 本頁面應該呈現共享「領域」,這已被重構作爲活動的一部分。

<% provide(:title, "Edit user") %> 
    <h1>Update your profile</h1> 

    <div class="row"> 
     <div class="span6 offset3"> 
      <%= form_for(@user) do |f| %> 
       <%= render 'fields', f: f %> 
       <%= f.submit "Save changes", class: "btn btn-large btn-primary" %> 
      <% end %> 

      <%= gravatar_for @user %> 
      <a href="http://gravatar.com/emails" target="_blank">change</a> 
     </div> 
    </div> 

new.html.erb 本頁面應該呈現共享「領域」,這已被重構作爲活動的一部分。

<% provide(:title, 'Sign up') %> 
    <h1>Sign Up</h1> 

    <div class="row"> 
     <div class="span6 offset3"> 
      <%= form_for(@user) do |f| %> 
       <%= render 'fields', f: f %> 
       <%= f.submit "Create my account", class: "btn btn-large btn-primary" %> 
      <% end %> 
     </div> 
    </div> 

_fields.html.erb 本頁面已經被重構。我有一種感覺,這個錯誤與此有關,但我不確定。

<%= render 'shared/error_messages' %> 

    <%= f.label :name %> 
    <%= f.text_field :name %> 

    <%= f.label :email %> 
    <%= f.text_field :email %> 

    <%= f.label :passsword %> 
    <%= f.password_field :password %> 

    <%= f.label :password_confirmation, "Confirm Password" %> 
    <%= f.password_field :password_confirmation %> 

下面是保持失敗的RSpec的測試:

describe "signup page" do 
    before { visit signup_path } 

    it { should have_content('Sign Up') } 
    it { should have_title(full_title('Sign up')) } 
end 

describe "signup" do 
    before { visit signup_path } 

    let(:submit) { "Create my account" } 

    describe "with valid information" do 
     before do 
      fill_in "Name",     with: "Example User" 
      fill_in "Email",     with: "[email protected]" 
      fill_in "Password",    with: "foobar" 
      fill_in "Confirm Password",  with: "foobar" 
     end 

     it "should create a user" do 
      expect { click_button submit }.to change(User, :count).by(1) 
     end 

     describe "after saving the user" do 
      before { click_button submit } 
      let(:user) { User.find_by(email: '[email protected]') } 

      it { should have_link('Sign out') } 
      it { should have_title(user.name) } 
      it { should have_selector('div.alert.alert-success', text: 'Welcome') } 
     end 
    end 
end 

describe "edit" do 
    let(:user) { FactoryGirl.create(:user) } 
    before do 
     sign_in user 
     visit edit_user_path(user) 
    end 

    describe "with valid information" do 
     let(:new_name) { "New Name" } 
     let(:new_email) { "[email protected]" } 
     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 

這裏是我失敗的測試:

Failures: 

1) UserPages signup with valid information should create a user 
    Failure/Error: expect { click_button submit }.to change(User, :count).by(1) 
    count should have been changed by 1, but was changed by 0 
# ./spec/requests/user_pages_spec.rb:85:in `block (4 levels) in <top (required)>' 

2) UserPages signup with valid information after saving the user 
    Failure/Error: it { should have_link('Sign out') } 
    expected #has_link?("Sign out") to return true, got false 
# ./spec/requests/user_pages_spec.rb:92:in `block (5 levels) in <top (required)>' 

3) UserPages signup with valid information after saving the user 
    Failure/Error: it { should have_selector('div.alert.alert-success', text: 'Welcome') } 
    expected #has_selector?("div.alert.alert-success", {:text=>"Welcome"}) to return true, got false 
# ./spec/requests/user_pages_spec.rb:94:in `block (5 levels) in <top (required)>' 

    4) UserPages signup with valid information after saving the user 
    Failure/Error: it { should have_title(user.name) } 
    NoMethodError: 
    undefined method `name' for nil:NilClass 
    # ./spec/requests/user_pages_spec.rb:93:in `block (5 levels) in <top (required)>' 

> 5) UserPages edit with valid information 
>  Failure/Error: it { should have_selector('div.alert.alert-success') } 
>  expected #has_selector?("div.alert.alert-success") to return true, got false 
>  # ./spec/requests/user_pages_spec.rb:138:in `block (4 levels) in <top (required)>' 
> 
> 6) UserPages edit with valid information 
>  Failure/Error: specify { expect(user.reload.name).to eq new_name } 
>  
>  expected: "New Name" 
>   got: "Person 65" 
>  
>  (compared using ==) 
>  # ./spec/requests/user_pages_spec.rb:140:in `block (4 levels) in <top (required)>' 
> 
> 7) UserPages edit with valid information 
>  Failure/Error: it { should have_title(new_name) } 
>  expected #has_title?("New Name") to return true, got false 
>  # ./spec/requests/user_pages_spec.rb:137:in `block (4 levels) in <top (required)>' 
> 
> 8) UserPages edit with valid information 
>  Failure/Error: specify { expect(user.reload.email).to eq new_email } 
>  
>  expected: "[email protected]" 
>   got: "[email protected]" 
>  
>  (compared using ==) 
>  # ./spec/requests/user_pages_spec.rb:141:in `block (4 levels) in <top (required)>' 
> 
>Finished in 6.01 seconds 
>88 examples, 8 failures 
> 
>Failed examples: 
> 
>rspec ./spec/requests/user_pages_spec.rb:84 # UserPages signup with valid information should >create a user 
>rspec ./spec/requests/user_pages_spec.rb:93 # UserPages signup with valid information after >saving the user 
>rspec ./spec/requests/user_pages_spec.rb:92 # UserPages signup with valid information after >saving the user 
>rspec ./spec/requests/user_pages_spec.rb:94 # UserPages signup with valid information after >saving the user 
>rspec ./spec/requests/user_pages_spec.rb:138 # UserPages edit with valid information 
>rspec ./spec/requests/user_pages_spec.rb:140 # UserPages edit with valid information 
>rspec ./spec/requests/user_pages_spec.rb:137 # UserPages edit with valid information 
>rspec ./spec/requests/user_pages_spec.rb:141 # UserPages edit with valid information 
> 
>Randomized with seed 6990 
+0

確認!!確認密碼。 – sevenseacat 2014-09-04 01:08:42

+0

更新了建議的更改,但仍未通過。返回的失敗測試給出的唯一提示是它只是沒有達到測試的目標。它似乎沒有給出任何線索爲什麼。 – 2014-09-04 17:29:15

回答

1

看一看你_fields.html.erb

更改<%= f.label :passsword %><%= f.label :password %>(強調「密碼」中S的數量。)

+0

謝謝!我知道這是小事,但我無法弄清楚。 – 2014-09-04 21:01:31

相關問題