Rspec 使用capybara,如何使用page.should\u模板

Rspec 使用capybara,如何使用page.should\u模板,rspec,devise,rspec2,capybara,Rspec,Devise,Rspec2,Capybara,我有以下测试: 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 在我得到的日志

我有以下测试:

  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 "/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
1)身份验证流我可以注册Facebook
失败/错误:page.should呈现模板(“registrations/signup\u connect\u to\u facebook.html.erb”)
参数错误:
@请求必须是ActionDispatch::request
#./spec/requests/authentication_requests.rb:54:in'block(2级)in'
以1.11秒完成
1例,1例失败

验证呈现的模板的正确方法是什么?谢谢

我认为您遇到的问题是您在混合测试级别

如果要测试模板的呈现,请尝试执行常规rspec控制器测试

对于Capybara,您应该针对呈现模板的结果而不是模板的实际呈现进行断言。

在Capybara中

当前路径应==发布注释路径(post)

请参见此处: