Rails test "IX" Integration testing integration test

Source: Internet
Author: User
Tags http request

Opening

Today we're going to familiarize ourselves with rails ' integration testing integration test.

Brief introduction

Integration testing is primarily about testing the interactions between multiple controller, and testing the more important workflows in the application to verify that these workflows are in line with the expected assumptions.

Unlike unit tests and functional tests, they are automatically added. Integration testing needs to be added manually, and rails provides a command

Rails Generate Integration_test

You can create integration tests in the Test/integration folder by command.

$ rails Generate integration_test user_flows 
      exists  test/integration/ 
      create  Test/integration/user _flows_test.rb

Let's take a look at some of the common help methods used in integration testing.

Https

Returns true if the session is simulating an HTTPS request.

https!

Allows you to simulate HTTPS requests.

host!

Allows you to set the host name in the next request.

redirect?

Returns true if the last request was a jump.

follow_redirect!

followed by a jump response

Request_via_redirect (Http_method, path, [parameters], [headers])

Sends an HTTP request to the specified path, optionally parameters, optional headers, and then a jump.

Post_via_redirect (path, [parameters], [headers])

Send a POST request to the path you specify, optional parameters, optional headers, and then a jump.

Get_via_redirect (path, [parameters], [headers])

Sends a GET request to the specified path, optionally parameters, optionally headers, followed by a jump.

Put_via_redirect (path, [parameters], [headers])

Sends the PUT request to the specified path, optionally parameters, optional headers, and then a jump.

Delete_via_redirect (path, [parameters], [headers])

Sends a delete request to the specified path, optionally parameters, optional headers, and then a jump.

Open_session

To open a new session

Example

Let's add some code to the test/integration/user_flows_test.rb of the integrated test file that we created.

Require ' Test_helper '
     
class Userflowstest < Actiondispatch::integrationtest 
  include Factorygirl::syntax: : Methods 
     
  def test_admin_login_and_browse_posts 
    user = Factorygirl.create (: user_valid) Get 
     
    "/signin"
    assert_response (Post_via_redirect) 
     
    ("Sessions", {:user=>{:email=> User.email,:p assword => User.password}}) 
    assert_equal '/', path 
    assert_equal ' sign in successfully ', Flash[:notice] get 
     
    ' admin/ Posts "
    Assert_response" 
    assert assigns (:p osts) End 
     

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/project/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.