2012-09-03 24 views
2

我遵循[Michael Hartl的教程] [1]並在第7章中做了練習,現在有4個錯誤,我無法弄清楚如何修復我。當我手動測試生產應用程序時,錯誤根本不存在。所以我不知道我的文字發展是否有什麼問題,但我完全失去了知識,所以我想我會在這裏發帖,看看我的全部noobness是否使我失明......感謝您的幫助!Ruby on Rails教程 - 獲取錯誤,拉出我的頭髮

這裏的4個錯誤消息我得到:

Failures: 

    1) signup with invalid information after submission 
    Failure/Error: it { should have_selector('title', text: "Sign up") } 
     expected css "title" with text "Sign up" to return something 
    # ./spec/requests/user_pages_spec.rb:38:in `block (4 levels) in <top (required)>' 

    2) signup with invalid information after submission 
    Failure/Error: it { should have_content('error') } 
     expected there to be content "error" in "after submission" 
    # ./spec/requests/user_pages_spec.rb:39:in `block (4 levels) in <top (required)>' 

    3) signup after saving the user 
    Failure/Error: it { should have_selector('title', text: user.name) } 
    NoMethodError: 
     undefined method `name' for nil:NilClass 
    # ./spec/requests/user_pages_spec.rb:60:in `block (3 levels) in <top (required)>' 

    4) signup after saving the user 
    Failure/Error: it { should have_selector('div.alert.alert-success', text: 'Welcome') } 
     expected css "div.alert.alert-success" with text "Welcome" to return something 
    # ./spec/requests/user_pages_spec.rb:61:in `block (3 levels) in <top (required)>' 

Finished in 6.8 seconds 
10 examples, 4 failures 

Failed examples: 

rspec ./spec/requests/user_pages_spec.rb:38 # signup with invalid information after submission 
rspec ./spec/requests/user_pages_spec.rb:39 # signup with invalid information after submission 
rspec ./spec/requests/user_pages_spec.rb:60 # signup after saving the user 
rspec ./spec/requests/user_pages_spec.rb:61 # signup after saving the user 

這裏是我的user_pages_spec.rb代碼:

require 'spec_helper' 

    require 'spec_helper' 

    describe "User pages" do 

     subject { page } 

     describe "signup page" do 
     before { visit signup_path } 

     it { should have_selector('h1', text: 'Sign up') } 
     it { should have_selector('title', text: full_title('Sign up')) } 
     end 

     describe "profile page" do 
     let(:user) { FactoryGirl.create(:user) } 
     before { visit user_path(user) } 

     it { should have_selector('h1', text: user.name) } 
     it { should have_selector('title', text: user.name) } 
    end 
    end 

     describe "signup" do 

     before { visit signup_path } 

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

     describe "with invalid information" do 
      it "should not create a user" do 
      expect { click_button submit }.not_to change(User, :count) 
      end 


      describe "after submission" do 
       before { click_button submit } 

       it { should have_selector('title', text: "Sign up") } 
       it { should have_content('error') } 
      end 
     end 

     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 "Confirmation", with: "foobar" 
      end 

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

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

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


    [1]: http://ruby.railstutorial.org/ 

這裏有一個觀點/用戶模板代碼/show.html.erb

<% provide(:title, @user.name) %> 
<div class="row"> 
    <aside class="span4"> 
    <section> 
     <h1> 
     <%= gravatar_for @user %> 
     <%= @user.name %> 

     </h1> 
    </section> 
    </aside> 
</div> 

,然後這裏的users_controller.rb

class UsersController < ApplicationController 

    def show 
    @user = User.find(params[:id]) 
    end 

    def new 
    @user = User.new 
    end 

def create 
    @user = User.new(params[:user]) 
    if @user.save 
     sign_in @user 
     flash[:success] = "Welcome to the Sample App!" 
     redirect_to @user 
    else 
     render 'new' 
    end 
    end 

end 
+1

嗨,歡迎來到Stack Overflow。請注意用四個空格適當地格式化您的帖子,以獲得代碼和終端輸出。謝謝! –

+1

如果沒有看到應用程序的其他代碼,很難調試此問題。你能把它放在GitHub上嗎? –

+1

當然,這是Github上的一個鏈接 - https://github.com/nfriend21/sample_app – nfriend21

回答

2

你們都還好吧,

我不知道如果沒有回答我的問題是某種在這個論壇菜鳥痛苦的開始,但之後差不多24小時,睡個好覺,我解決了這個問題!

經過幾次G搜索,我發現我可以通過在錯誤的地方「結束」來阻止某些變量通過。事實證明,我在這裏做了兩個主要領域。一旦我找到並修復這些錯誤,所有的錯誤都消失了。

我現在就拍拍自己的背部。我希望這能夠幫助未來遇到同樣問題的所有新手。