Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 8b99df826c3b6cf56a1caaae5f931d50 > files > 394

ruby-actionpack-2.3.4-1mdv2010.0.noarch.rpm

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: ActionController::IntegrationTest</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">ActionController::IntegrationTest</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/lib/action_controller/integration_rb.html">
                lib/action_controller/integration.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                ActiveSupport::TestCase
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
An <a href="IntegrationTest.html">IntegrationTest</a> is one that spans
multiple controllers and actions, tying them all together to ensure they
work together as expected. It tests more completely than either unit or
functional tests do, exercising the entire stack, from the dispatcher to
the database.
</p>
<p>
At its simplest, you simply extend <a
href="IntegrationTest.html">IntegrationTest</a> and write your tests using
the get/post methods:
</p>
<pre>
  require &quot;#{File.dirname(__FILE__)}/test_helper&quot;

  class ExampleTest &lt; ActionController::IntegrationTest
    fixtures :people

    def test_login
      # get the login page
      get &quot;/login&quot;
      assert_equal 200, status

      # post the login and follow through to the home page
      post &quot;/login&quot;, :username =&gt; people(:jamis).username,
        :password =&gt; people(:jamis).password
      follow_redirect!
      assert_equal 200, status
      assert_equal &quot;/home&quot;, path
    end
  end
</pre>
<p>
However, you can also have multiple session instances open per test, and
even extend those instances with assertions and methods to create a very
powerful testing DSL that is specific for your application. You can even
reference any named routes you happen to have defined!
</p>
<pre>
  require &quot;#{File.dirname(__FILE__)}/test_helper&quot;

  class AdvancedTest &lt; ActionController::IntegrationTest
    fixtures :people, :rooms

    def test_login_and_speak
      jamis, david = login(:jamis), login(:david)
      room = rooms(:office)

      jamis.enter(room)
      jamis.speak(room, &quot;anybody home?&quot;)

      david.enter(room)
      david.speak(room, &quot;hello!&quot;)
    end

    private

      module CustomAssertions
        def enter(room)
          # reference a named route, for maximum internal consistency!
          get(room_url(:id =&gt; room.id))
          assert(...)
          ...
        end

        def speak(room, message)
          xml_http_request &quot;/say/#{room.id}&quot;, :message =&gt; message
          assert(...)
          ...
        end
      end

      def login(who)
        open_session do |sess|
          sess.extend(CustomAssertions)
          who = people(who)
          sess.post &quot;/login&quot;, :username =&gt; who.username,
            :password =&gt; who.password
          assert(...)
        end
      end
  end
</pre>

    </div>


   </div>


  </div>


    <!-- if includes -->
    <div id="includes">
      <h3 class="section-bar">Included Modules</h3>

      <div id="includes-list">
        <span class="include-name"><a href="Integration/Runner.html">Integration::Runner</a></span>
      </div>
    </div>

    <div id="section">





      


    <!-- if method_list -->


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>