有了水豚,如何使用page.should render_template

发布于 2024-12-02 07:44:24 字数 1268 浏览 0 评论 0原文

我有以下测试:

  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

验证模板已渲染的正确方法是什么?谢谢

I have the following test:

  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

In the logs I get:

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

Problem is the test fails:

 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

What is the right method to validate the the template was rendered? Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧情勿念 2024-12-09 07:44:24

我认为你遇到的问题是你混合了测试级别。

如果您想测试模板的渲染,请尝试执行正常的 rspec 控制器测试。

使用 Capybara,您应该针对渲染模板的结果而不是模板的实际渲染进行断言。

I think the problem you're having is that you're mixing levels of testing.

If you want to test rendering of a template, try doing a normal rspec controller test.

With Capybara, you should be asserting against the result of rendering the template rather than the actual rendering of the template.

诗笺 2024-12-09 07:44:24

在水豚中

current_path.should == post_comments_path(post)

https://github.com/jnicklas/capybara#navigating< /a>

In Capybara

current_path.should == post_comments_path(post)

https://github.com/jnicklas/capybara#navigating

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文