2011-08-30 61 views
3

我有以下測試:隨着水豚,如何使用page.should render_template

it "I can Sign Up with Facebook" do 

    visit new_user_registration_path 

    click_link_or_button 'Sign up with Facebook' 

    # Validate 
    page.should render_template("registrations/signup_connect_to_facebook.html.erb") 

    end 

在日誌中我得到:

Started GET "https://stackoverflow.com/users/auth/facebook/callback" for 127.0.0.1 at 2011-08-30 13:26:04 -0700 
    Processing by AuthenticationsController#create as HTML 
    Authentication Load (0.8ms) SELECT "authentications".* FROM "authentications" WHERE "authentications"."provider" = 'facebook' AND "authentications"."uuid" = '13' LIMIT 1 
AuthenticationsController - Route D 
Rendered registrations/signup_connect_to_facebook.html.erb (0.7ms) 
Completed 200 OK in 111ms (Views: 3.4ms | ActiveRecord: 2.7ms) 
    SQL (0.3ms) ROLLBACK 

問題是測試失敗:

1) authentication flows I can Sign Up with Facebook 
    Failure/Error: page.should render_template("registrations/signup_connect_to_facebook.html.erb") 
    ArgumentError: 
     @request must be an ActionDispatch::Request 
    # ./spec/requests/authentication_requests.rb:54:in `block (2 levels) in <top (required)>' 

Finished in 1.11 seconds 
1 example, 1 failure 

什麼是驗證模板被渲染的正確方法?謝謝

+2

在這裏看到:http://www.ruby-forum.com/topic/216322 – zetetic

回答

10

我認爲你遇到的問題是你混合測試的水平。

如果要測試模板的渲染,請嘗試執行正常的rspec控制器測試。

對於Capybara,您應該聲明模板的渲染結果而不是模板的實際渲染。