⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_assert_select.rb

📁 ruby on rails web敏捷开发之路第二版 源代码
💻 RB
字号:
#---# Excerpted from "Agile Web Development with Rails, 2nd Ed."# We make no guarantees that this code is fit for any purpose. # Visit http://www.pragmaticprogrammer.com/titles/rails2 for more book information.#---require File.dirname(__FILE__) + '/../test_helper'require 'application'# Re-raise errors caught by the controller.class DummyController < ApplicationController  def rescue_action(e)     raise e   endenddef create_fixtures(*names)endclass DummyControllerTest < Test::Unit::TestCase  HTML = %{    <html>   <head>     <title>Pragprog Books Online Store</title>     <!-- ... -->   </head>   <body id="store">     <div id="banner">       <img src="/images/logo.png"> Pragmatic Bookshelf     </div>     <div id="columns">       <div id="side">         <div id="cart">           <div class="cart-title">Your Cart</div>           <table>             <tr>               <td>1&times;</td>               <td>Pragmatic Project Automation</td>               <td class="item-price">$29.95</td>             </tr>             <tr>               <td>1&times;</td>               <td>Pragmatic Unit Testing (C#)</td>               <td class="item-price">$27.75</td>             </tr>             <tr class="total-line">               <td colspan="2">Total</td>               <td class="total-cell">$57.70</td>             </tr>           </table>           <form method="post" action="/store/checkout" class="button-to">             <div>               <input type="submit" value="Checkout">             </div>           </form>           <form method="post" action="/store/empty_cart" class="button-to">             <div>               <input type="submit" value="Empty cart">             </div>           </form>         </div>         <a href="http://www....">Home</a><br>         <a href="http://www..../faq">Questions</a><br>         <a href="http://www..../news">News</a><br>         <a href="http://www..../contact">Contact</a><br>       </div>       <div id="main">         <h1>Your Pragmatic Catalog</h1>         <div class="entry">           <img src="/images/auto.jpg">           <h3>Pragmatic Project Automation</h3>           <p><em>Pragmatic Project Automation</em> shows you how to           improve the consistency and repeatability of your project's           procedures using automation to reduce risk and errors.</p>           <p>Simply put, we're going to put this thing called a           computer to work for you doing the mundane (but important)           project stuff. That means you'll have more time and energy           to do the really exciting---and difficult---stuff, like           writing quality code.</p>           <div class="price-line">            <p></p>             <span class="price">$29.95</span>              <!-- ... -->           </div>         </div>         <!-- ... -->       </div>     </div>   </body>   </html>}  def setup_with_fixtures  end    def setup    @controller = DummyController.new    @request    = ActionController::TestRequest.new    @response   = ActionController::TestResponse.new    @response.body = HTML  end    def teardown_without_fixtures  end    def test_one    assert_select "title"    assert_select "title", "Pragprog Books Online Store"    assert_select "title", /Online/ end  def test_cart_long   assert_select "div#cart"   assert_select "div#cart table tr", 3   assert_select "div#cart table tr.total-line td:last-of-type", "$57.70"  end    def test_xx   p(css_select("div :first-child").map(&:name)) end def test_cart       assert_select "div#cart" do      assert_select "table" do        assert_select "tr", :count => 3        assert_select "tr.total-line td:last-of-type", "$57.70"      end    end  endend

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -