开发者

With capybara, how to use page.should render_template

开发者 https://www.devze.com 2023-04-01 01:28 出处:网络
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\'

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 Fa开发者_StackOverflow社区cebook
     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


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.


In Capybara

current_path.should == post_comments_path(post)

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号