2012-12-13 31 views
0
Failures: 

1) User pages signup with valid information edit with invalid information 
Failure/Error: before { click_button "Save changes" } 
AbstractController::ActionNotFound: 
    The action 'update' could not be found for UsersController 
# (eval):2:in `click_button' 
# ./spec/requests/user_pages_spec.rb:105:in `block (6 levels) in <top (required)>' 

Finished in 1.13 seconds 
62 examples, 1 failure 

Failed examples: 

rspec ./spec/requests/user_pages_spec.rb:107 # User pages signup with valid information edit with invalid information 

我爲此感到它沒有看到我的users_controller.rb我的更新動作但是它的存在:失敗的測試9

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 


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


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


def update 
@user = User.find(params[:id]) 
if @user.update_attributes(params[:user]) 
    flash[:success] = "Profile updated" 
    sign_in @user 
    redirect_to @user 
else 
    render 'edit' 
end 
end 

我莫名其妙地結束了兩個編輯行動,但如果我刪除其中的一個,我可以讓測試運行。我認爲我遇到的麻煩中有99%是隨處可見的,並在錯誤的地方插入新的行爲。感謝您的幫助

回答

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

有一個雙end這裏。這結束了class UsersController。只要刪除所有這些行,你應該沒問題。

+0

三江源是非常有意義!我剛剛刪除了重複編輯操作的雙端,並添加了一個結尾,它通過了!但是,我可以請你看看我的user_pages_spec嗎?我也遇到了失敗的測試,我希望它的內容也很簡單。 http://pastebin.com/a7tScj4s再次感謝! – jfoutch

+0

這是一個失敗:1)用戶頁面註冊有效信息 失敗/錯誤:fill_in「密碼」,與:user.password NameError: 未定義的局部變量或方法'用戶'爲# #./spec/requests/user_pages_spec.rb:119:in ' – jfoutch

+0

我沒有太多經驗與測試。爲此提出一個新問題可能是一個好主意。從你添加的粘貼的外觀和錯誤:你沒有在你的測試中定義'user'。這應該是一個變量,我最好的猜測是它應該出自FactoryGirl類。 –

2

你首先必須匹配每一端。你可能被卸下這會已經引起了UserController類結束,因爲在你的行動結束外的第一個編輯操作的第二個編輯動作...

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 

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

    def update 
    @user = User.find(params[:id]) 
    if @user.update_attributes(params[:user]) 
     flash[:success] = "Profile updated" 
     sign_in @user 
     redirect_to @user 
    else 
     render 'edit' 
    end 
    end 
end 
+0

是的,這是問題的感謝。我有點掙扎。你偶然看到我的user_pages_spec有類似的問題嗎? http://pastebin.com/a7tScj4s – jfoutch

+0

跟蹤這一點的最好方法是實際上只是遵循Tab鍵模式,並且在創建時總是關閉一個模塊。對於每一個都有結束 –

+0

感謝您的提示! – jfoutch