<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>LetRails &#187; 测试</title>
	<atom:link href="http://www.letrails.cn/archives/category/test/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.letrails.cn</link>
	<description></description>
	<lastBuildDate>Sat, 06 Aug 2011 07:02:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>Rails Cookie测试</title>
		<link>http://www.letrails.cn/archives/how-to-test-rails-cookie/</link>
		<comments>http://www.letrails.cn/archives/how-to-test-rails-cookie/#comments</comments>
		<pubDate>Sat, 19 Jul 2008 07:57:31 +0000</pubDate>
		<dc:creator>yuanyi</dc:creator>
				<category><![CDATA[测试]]></category>

		<guid isPermaLink="false">http://www.letrails.cn/archives/how-to-test-rails-cookie</guid>
		<description><![CDATA[如果你在某个action中对Cookie进行了设置，然后你又打算对你设置的cookie进行测试，那么你可能会遇到麻烦，不妨看看下面这段代码： class CookiesController &#160;&#160;def update &#160;&#160;&#160;&#160;cookies[:name] = 'demo' &#160;&#160;end end describe CookiesController &#160;&#160;it "should update cookies[:name] to 'demo'" do &#160;&#160;&#160;&#160;request.cookies[:name] = 'test' &#160;&#160;&#160;&#160;put :update &#160;&#160;&#160;&#160;request.cookies[:name].should == 'demo' &#160;&#160;end end 如果你运行上面的测试，将会得到一个：expected &#8216;demo&#8217; got &#8216;test&#8217;，这是怎么回事，cookie设置失败了？实际上这是正确的，之所以产生这样的结果是因为我们对Rails的Cookie机制不了解，首先我们需要区分request.cookies和Controller中的cookies，request.cookies是用于模拟客户端发送的 cookie的，它是一个Hash对象，因此我们可以像使用hash那样使用它： >> request.cookies[:name] = &#8216;test&#8217; >> request.cookies[:name] test 但是Controller中的cookies则不同，它是一个ActionController::CookieJar对象，这个cookies对象实际上保存了2个cookie集合：incoming cookie和outgoing cookie。incoming cookie就是客户请求中所携带的cookie（也就是request.cookies），而outgoing cookie则是在请求处理完后将被设置回客户端的cookie。 因此尽管我们使用了[]=方法来设置cookie，但因为cookies对象重载了[]与[]=方法： []方法返回的是incoming cookie，也就是request中携带的cookie 而[]=方法设置的却是outgoing cookie，它只对下一个请求起作用，也就是说它会被包含在下一个请求的incoming cookie中。 因此设置controller cookies，我们只能得到： >> [...]<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="升级到Rails 3 Beta" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fupgrade-to-rails-3-beta%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fhow-to-test-rails-cookie%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">升级到Rails 3 Beta</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Rails性能优化简明指南" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Frails-performance-optimization-guide%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fhow-to-test-rails-cookie%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/08/3251308.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Rails性能优化简明指南</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Rails2.0新特性介绍（ 下）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F07-11-23-rails20-features%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fhow-to-test-rails-cookie%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/08/3251634.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Rails2.0新特性介绍（ 下）</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Shanghai on Rails 7.26线下活动" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fshanghai-on-rails-726-meeting%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fhow-to-test-rails-cookie%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/09/3251440.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Shanghai on Rails 7.26线下活动</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>如果你在某个action中对Cookie进行了设置，然后你又打算对你设置的cookie进行测试，那么你可能会遇到麻烦，不妨看看下面这段代码：</p>
<p class="code"><code class="ruby">class CookiesController<br />
&nbsp;&nbsp;def update<br />
&nbsp;&nbsp;&nbsp;&nbsp;cookies[:name] = 'demo'<br />
&nbsp;&nbsp;end<br />
end<br />
describe CookiesController<br />
&nbsp;&nbsp;it "should update cookies[:name] to 'demo'" do<br />
&nbsp;&nbsp;&nbsp;&nbsp;request.cookies[:name] = 'test'<br />
&nbsp;&nbsp;&nbsp;&nbsp;put :update<br />
&nbsp;&nbsp;&nbsp;&nbsp;request.cookies[:name].should == 'demo'<br />
&nbsp;&nbsp;end<br />
end<br />
</code></p>
<p>如果你运行上面的测试，将会得到一个：expected &#8216;demo&#8217; got &#8216;test&#8217;，这是怎么回事，cookie设置失败了？实际上这是正确的，之所以产生这样的结果是因为我们对Rails的Cookie机制不了解，首先我们需要区分request.cookies和Controller中的cookies，request.cookies是用于模拟客户端发送的 cookie的，它是一个Hash对象，因此我们可以像使用hash那样使用它：</p>
<p>>> request.cookies[:name] = &#8216;test&#8217;<br />
>> request.cookies[:name]<br />
test</p>
<p>但是Controller中的cookies则不同，它是一个ActionController::CookieJar对象，这个cookies对象实际上保存了2个cookie集合：incoming cookie和outgoing cookie。incoming cookie就是客户请求中所携带的cookie（也就是request.cookies），而outgoing cookie则是在请求处理完后将被设置回客户端的cookie。</p>
<p>因此尽管我们使用了[]=方法来设置cookie，但因为cookies对象重载了[]与[]=方法：</p>
<ol>
<li> []方法返回的是incoming cookie，也就是request中携带的cookie</li>
<li>而[]=方法设置的却是outgoing cookie，它只对下一个请求起作用，也就是说它会被包含在下一个请求的incoming cookie中。</li>
</ol>
<p>因此设置controller cookies，我们只能得到：</p>
<p>>> cookies[:name] = &#8216;test&#8217;<br />
>> cookies[:name]<br />
nil</p>
<p>如果你需要测试cookies是否设置成功，那么一个简单的方法，就是将controller中的cookies替换成一个hash，比如：</p>
<p class="code"><code class="ruby"><br />
describe CookiesController<br />
&nbsp;&nbsp;it "should update cookies[:name] to 'demo'" do<br />
&nbsp;&nbsp;&nbsp;&nbsp;request.cookies[:name] = 'test'<br />
&nbsp;&nbsp;&nbsp;&nbsp;@cookies = {}<br />
&nbsp;&nbsp;&nbsp;&nbsp;controller.stub!(:cookies).and_return(@cookies)<br />
&nbsp;&nbsp;&nbsp;&nbsp;put :update<br />
&nbsp;&nbsp;&nbsp;&nbsp;@cookies[:name].should == 'demo'<br />
&nbsp;&nbsp;end<br />
end</code></p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="升级到Rails 3 Beta" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fupgrade-to-rails-3-beta%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fhow-to-test-rails-cookie%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">升级到Rails 3 Beta</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Rails性能优化简明指南" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Frails-performance-optimization-guide%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fhow-to-test-rails-cookie%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/08/3251308.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Rails性能优化简明指南</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Rails2.0新特性介绍（ 下）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F07-11-23-rails20-features%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fhow-to-test-rails-cookie%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/08/3251634.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Rails2.0新特性介绍（ 下）</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Shanghai on Rails 7.26线下活动" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fshanghai-on-rails-726-meeting%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fhow-to-test-rails-cookie%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/09/3251440.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Shanghai on Rails 7.26线下活动</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://www.letrails.cn/archives/how-to-test-rails-cookie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>quietbacktrace: 让Test::Unit不再唐僧</title>
		<link>http://www.letrails.cn/archives/quietbacktrace-make-test-unit-output-more-cleaner/</link>
		<comments>http://www.letrails.cn/archives/quietbacktrace-make-test-unit-output-more-cleaner/#comments</comments>
		<pubDate>Thu, 20 Dec 2007 09:11:10 +0000</pubDate>
		<dc:creator>Yuanyi ZHANG</dc:creator>
				<category><![CDATA[测试]]></category>

		<guid isPermaLink="false">http://www.letrails.cn/archives/quietbacktrace-%e8%ae%a9testunit%e4%b8%8d%e5%86%8d%e5%94%90%e5%83%a7</guid>
		<description><![CDATA[如果你使用Test:Unit，那么你是否经常会为了它过于唐僧的错误输出而烦恼不已？就像下面这样： 1) Failure: test_should_be_create(ForumCommentsControllerTest) method assert_block in assertions.rb at line 48 method _wrap_assertion in assertions.rb at line 495 method assert_block in assertions.rb at line 46 method test_should_be_create in forum_comments_controller_test.rb at line 38 method __send__ in test_case_adapter.rb at line 19 method run in test_case_adapter.rb at line 19 method run in testsuite.rb at line 34 method each [...]<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="在test:unit中应用BDD" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-09-using-bdd-in-test-unit%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fquietbacktrace-make-test-unit-output-more-cleaner%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">在test:unit中应用BDD</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Rails Cookie测试" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fhow-to-test-rails-cookie%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fquietbacktrace-make-test-unit-output-more-cleaner%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Rails Cookie测试</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Ruby 1.9正式发布" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fruby-1-9-released%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fquietbacktrace-make-test-unit-output-more-cleaner%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/08/3251554.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Ruby 1.9正式发布</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Railsbench简明指南(0.9.2)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F18%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fquietbacktrace-make-test-unit-output-more-cleaner%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/08/3251762.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Railsbench简明指南(0.9.2)</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>如果你使用Test:Unit，那么你是否经常会为了它过于唐僧的错误输出而烦恼不已？就像下面这样：</p>
<p class="code"><code>  1) Failure:<br />
test_should_be_create(ForumCommentsControllerTest)<br />
method assert_block in assertions.rb at line 48<br />
method _wrap_assertion in assertions.rb at line 495<br />
method assert_block in assertions.rb at line 46<br />
method test_should_be_create in forum_comments_controller_test.rb at line 38<br />
method __send__ in test_case_adapter.rb at line 19<br />
method run in test_case_adapter.rb at line 19<br />
method run in testsuite.rb at line 34<br />
method each in testsuite.rb at line 33<br />
method run in testsuite.rb at line 33<br />
method run in testsuite.rb at line 34<br />
method each in testsuite.rb at line 33<br />
method run in testsuite.rb at line 33<br />
method run_suite in testrunnermediator.rb at line 46<br />
method start_mediator in testrunner.rb at line 67<br />
method start in testrunner.rb at line 41<br />
method run in testrunnerutilities.rb at line 29<br />
method run in autorunner.rb at line 216<br />
method run in autorunner.rb at line 12<br />
at top level in unit.rb at line 278<br />
at top level in forum_comments_controller_test.rb at line 63<br />
response is not a redirection to all of the options supplied (redirection is &lt;{"action"=&gt;"show", "id"=&gt;1, "controller"=&gt;"forums"}&gt;), difference: &lt;{"id"=&gt;"post-2"}&gt;</code></p>
<p><a href="http://www.thoughtbot.com">thoughtbot</a>提供的<a href="http://giantrobots.thoughtbot.com/2007/12/3/shhh-your-test-unit-backtraces-are-too-noisy">quietbacktrace</a> gem或许可以帮你减轻一些痛苦：</p>
<p class="code"><code>$ sudo gem install quietbacktrace</code></p>
<p>要在Rails中使用quietbacktrace，你需要将它解包到vendor目录：</p>
<p class="code"><code class="ruby">cd rails-app-folder/vendor/gems<br />
gem unpack quietbacktrace</code></p>
<p>然后在config/environments/test.rb 中添加：</p>
<p class="code"><code class="ruby">require 'quietbacktrace'</code></p>
<p>然后再在test/test_helper.rb中添加：</p>
<p class="code"><code class="ruby">class Test::Unit::TestCase<br />
&nbsp;&nbsp;self.backtrace_silencers &lt;&lt; :rails_vendor<br />
&nbsp;&nbsp;self.backtrace_filters   &lt;&lt; :rails_root<br />
end</code></p>
<p>好了，现在再次运行测试，你会发现，上面冗长无比的输出已经变成了下面的样子：</p>
<p class="code"><code>1) Failure:<br />
test_should_be_create(ForumCommentsControllerTest)<br />
at top level in forum_comments_controller_test.rb at line 38<br />
at top level in forum_comments_controller_test.rb at line 63<br />
response is not a redirection to all of the options supplied (redirection is &lt;{"action"=&gt;"show", "id"=&gt;1, "controller"=&gt;"forums"}&gt;), difference: &lt;{"id"=&gt;"post-2"}&gt;</code></p>
<p>当然，如果你偶尔想要回首下往日的艰苦岁月，那也很简单，只需要在test/test_helper.rb中添加：</p>
<p class="code"><code class="ruby">class Test::Unit::TestCase<br />
&nbsp;&nbsp;self.quiet_backtrace = false<br />
end</code></p>
<p>再对着天空大喊一句：薄弱波罗蜜，一切就都恢复原样了，更多信息，请看<a href="http://giantrobots.thoughtbot.com/2007/12/3/shhh-your-test-unit-backtraces-are-too-noisy">这里</a>。</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="在test:unit中应用BDD" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-09-using-bdd-in-test-unit%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fquietbacktrace-make-test-unit-output-more-cleaner%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">在test:unit中应用BDD</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Rails Cookie测试" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fhow-to-test-rails-cookie%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fquietbacktrace-make-test-unit-output-more-cleaner%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Rails Cookie测试</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Merb: Rails的替代者？" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-07-merb-framework%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fquietbacktrace-make-test-unit-output-more-cleaner%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/08/3251636.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Merb: Rails的替代者？</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="NetBeans IDE: Windows平台最好的Ruby IDE" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F15%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fquietbacktrace-make-test-unit-output-more-cleaner%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/08/3251498.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">NetBeans IDE: Windows平台最好的Ruby IDE</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://www.letrails.cn/archives/quietbacktrace-make-test-unit-output-more-cleaner/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>在test:unit中应用BDD</title>
		<link>http://www.letrails.cn/archives/11-09-using-bdd-in-test-unit/</link>
		<comments>http://www.letrails.cn/archives/11-09-using-bdd-in-test-unit/#comments</comments>
		<pubDate>Fri, 09 Nov 2007 11:40:25 +0000</pubDate>
		<dc:creator>Yuanyi ZHANG</dc:creator>
				<category><![CDATA[测试]]></category>

		<guid isPermaLink="false">http://www.letrails.cn/archives/11-09-using-bdd-in-test-unit</guid>
		<description><![CDATA[techno-weenie.net提供了两个插件simple_bdd和test_spec_on_rails，可以让你在test:unit中应用BDD而不需安装rspec，如果再加上mocha，test:unit与rspec就只存在语法的差异了。 安装： script/plugin install http://svn.techno-weenie.net/projects/plugins/simply_bdd/ script/plugin install http://svn.techno-weenie.net/projects/plugins/test_spec_on_rails/ 使用： 1. simple_bdd: context "New User" do &#160;&#160;def setup &#160;&#160;end &#160;&#160;specify "should be invalid without a username" do &#160;&#160;end end 这相当于： class NewUserTest &#60; Test::Unit::TestCase &#160;&#160;def setup &#160;&#160;end &#160;&#160;def test_should_be_invalid_without_a_username &#160;&#160;end end test_spec_on_rails: #model @user.should.validate @user.should.be.validated #Redirection response.should.be.redirected # assert_response :redirect response.should.redirect foo_url(@foo) # assert_redirected_to foo_url(@foo) should.redirect_to [...]<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fquietbacktrace-make-test-unit-output-more-cleaner%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-09-using-bdd-in-test-unit%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">quietbacktrace: 让Test::Unit不再唐僧</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F16%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-09-using-bdd-in-test-unit%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Rails应用性能优化3</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fyslow-intro%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-09-using-bdd-in-test-unit%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">使用YSlow提升应用性能</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F17%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-09-using-bdd-in-test-unit%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Rails应用性能优化4</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p><a href="http://techno-weenie.net">techno-weenie.net</a>提供了两个插件simple_bdd和test_spec_on_rails，可以让你在test:unit中应用BDD而不需安装rspec，如果再加上<a href="http://mocha.rubyforge.org/">mocha</a>，test:unit与rspec就只存在语法的差异了。</p>
<p>安装：</p>
<p class="code"><code>script/plugin install http://svn.techno-weenie.net/projects/plugins/simply_bdd/<br />
script/plugin install http://svn.techno-weenie.net/projects/plugins/test_spec_on_rails/</code></p>
<p>使用：</p>
<p>1. simple_bdd:</p>
<p class="code"><code class="ruby">context "New User" do<br />
&nbsp;&nbsp;def setup<br />
&nbsp;&nbsp;end<br />
&nbsp;&nbsp;specify "should be invalid without a username" do<br />
&nbsp;&nbsp;end<br />
end</code></p>
<p>这相当于：</p>
<p class="code"><code class="ruby">class NewUserTest &lt; Test::Unit::TestCase<br />
&nbsp;&nbsp;def setup<br />
&nbsp;&nbsp;end<br />
&nbsp;&nbsp;def test_should_be_invalid_without_a_username<br />
&nbsp;&nbsp;end<br />
end</code></p>
<p>test_spec_on_rails:</p>
<p class="code"><code class="ruby">#model<br />
@user.should.validate<br />
@user.should.be.validated<br />
#Redirection<br />
response.should.be.redirected           # assert_response :redirect<br />
response.should.redirect foo_url(@foo)  # assert_redirected_to foo_url(@foo)<br />
should.redirect_to :action =&gt; 'show'    # because "response" is optional</code></p>
<p>更多请<a href="http://svn.techno-weenie.net/projects/plugins/test_spec_on_rails/README">参看README.</a></p>
<p>另外<a href="http://dust.rubyforge.org/">DUST</a>也提供和simple_bdd类似的功能。</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fquietbacktrace-make-test-unit-output-more-cleaner%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-09-using-bdd-in-test-unit%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">quietbacktrace: 让Test::Unit不再唐僧</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F16%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-09-using-bdd-in-test-unit%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Rails应用性能优化3</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fyslow-intro%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-09-using-bdd-in-test-unit%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">使用YSlow提升应用性能</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F17%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-09-using-bdd-in-test-unit%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Rails应用性能优化4</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://www.letrails.cn/archives/11-09-using-bdd-in-test-unit/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>RSpec进阶指南（三）：Mocking</title>
		<link>http://www.letrails.cn/archives/11-07-advanced-rspec-tutorials-mocking/</link>
		<comments>http://www.letrails.cn/archives/11-07-advanced-rspec-tutorials-mocking/#comments</comments>
		<pubDate>Wed, 07 Nov 2007 15:03:33 +0000</pubDate>
		<dc:creator>Yuanyi ZHANG</dc:creator>
				<category><![CDATA[测试]]></category>

		<guid isPermaLink="false">http://www.letrails.cn/archives/11-07-advanced-rspec-tutorials-mocking</guid>
		<description><![CDATA[让我们先来看一个例子，假设我们要测试这个action： def comment &#160;&#160;@post = Post.find(params[:id]) &#160;&#160;@comment = Comment.new(params[:comment]) &#160;&#160;respond_to do &#124;format&#124; &#160;&#160;&#160;&#160;if @comment.save &#38;&#38; @post.comments.concat(@comment) &#160;&#160;&#160;&#160;&#160;&#160;flash[:notice] = 'Comment was successfully updated.' &#160;&#160;&#160;&#160;&#160;&#160;format.html { redirect_to post_path(@blogger, @post) } &#160;&#160;&#160;&#160;&#160;&#160;format.xml { head k } &#160;&#160;&#160;&#160;else &#160;&#160;&#160;&#160;&#160;&#160;flash[:notice] = 'Error saving comment.' &#160;&#160;&#160;&#160;&#160;&#160;format.html { redirect_to post_path(@blogger, @post) } &#160;&#160;&#160;&#160;&#160;&#160;format.xml { render ml =&#62; @comment.errors.to_xml } &#160;&#160;&#160;&#160;end &#160;&#160;end end [...]<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-02-advanced-rspec-tutorials-basics%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-07-advanced-rspec-tutorials-mocking%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec进阶指南(2): 基础知识</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fadvanced-rspec-tutorials-rspec-scaffold%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-07-advanced-rspec-tutorials-mocking%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec进阶指南(1): rspec_scaffold</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Frspec-story-tutorials%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-07-advanced-rspec-tutorials-mocking%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec Story简介</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F20%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-07-advanced-rspec-tutorials-mocking%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec简明指南</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>让我们先来看一个例子，假设我们要测试这个action：</p>
<p class="code"><code class="ruby">def comment<br />
&nbsp;&nbsp;@post = Post.find(params[:id])<br />
&nbsp;&nbsp;@comment = Comment.new(params[:comment])<br />
&nbsp;&nbsp;respond_to do |format|<br />
&nbsp;&nbsp;&nbsp;&nbsp;if @comment.save &amp;&amp; @post.comments.concat(@comment)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flash[:notice] = 'Comment was successfully updated.'<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format.html { redirect_to post_path(@blogger, @post) }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format.xml  { head <img src='http://www.letrails.cn/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> k }<br />
&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flash[:notice] = 'Error saving comment.'<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format.html { redirect_to post_path(@blogger, @post) }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format.xml  { render <img src='http://www.letrails.cn/wp-includes/images/smilies/icon_mad.gif' alt=':x' class='wp-smiley' /> ml =&gt; @comment.errors.to_xml }<br />
&nbsp;&nbsp;&nbsp;&nbsp;end<br />
&nbsp;&nbsp;end<br />
end</code></p>
<p>我需要确保我能够对帖子发布评论：</p>
<p class="code"><code class="ruby">it "should add comments to the post" do<br />
&nbsp;&nbsp;post = posts(:one)<br />
&nbsp;&nbsp;comment_count = post.comments.size<br />
&nbsp;&nbsp;post :comment, :id =&gt; 1, :comment =&gt; {:title =&gt; 'test', :body =&gt; 'very nice!'}<br />
&nbsp;&nbsp;post.reload<br />
&nbsp;&nbsp;post.comments.size.should == comment_count + 1<br />
&nbsp;&nbsp;flash[:notice].should match(/success/i)<br />
&nbsp;&nbsp;response.should redirect_to(posts_path(@blogger, @post))<br />
end</code></p>
<p>看起来不错？但这个测试例实际测试了许多不该它来测试的东西，它应该只测试action，但是它却连同model也一并测试了，并且它还依赖于fixtures。</p>
<p>我们可以使用一个mock object来代替真是的post对象：</p>
<p class="code"><code class="ruby">post = mock_model(Post)</code></p>
<p>现在我们需要关注comment的第一行：</p>
<p class="code"><code class="ruby">@post = Post.find(params[:id])</code></p>
<p>我希望这一行在测试时得到执行，但是不用测试，我也知道这行代码肯定是工作正常的，因此，我现在要做的就是让这行代码返回我在上面创建的那个mock object：</p>
<p class="code"><code class="ruby">Post.should_receive(:find).and_return(post)</code></p>
<p>或者这样：</p>
<p class="code"><code class="ruby">Post.stub!(:find).and_return(post)</code></p>
<p>但 是请注意，should_receive和stub!虽然都可以让Post.find返回我的mock object，但是他们的区别却是巨大的，如果我调用了stub!，但是却没有调用Post.find，stub!不会抱怨什么，因为它是个老实人，但是 should_receive就不用，如果我告诉should_receive我会调用Post.find，但却没调用，那问题就来了，它会抱怨为何我不 守信用，并抛出一个异常来警告我。</p>
<p>但是跟在他们后面的and_return的作用却是完全相同的，它让你mock或者stub的方法返回你传递给它的任何参数。</p>
<p>接下来，我需要对comment做同样的事情：</p>
<p class="code"><code class="ruby">comment = mock_model(Comment)<br />
Comment.should_receive(:new).with({:title =&gt; 'comment title', :body =&gt; 'comment body'}).and_return(comment)</code></p>
<p>接下来我需要关注这条语句：</p>
<p class="code"><code class="ruby">if @comment.save &amp;&amp; @post.comments.concat(@comment)</code></p>
<p>同上面一样：</p>
<p class="code"><code class="ruby">comment.should_receive(:save).and_return(true)<br />
post.comments.should_receive(:concat).and_return(comment)</code></p>
<p>下面我需要测试flash及redirect：</p>
<p class="code"><code class="ruby">flash[:notice].should match(/success/i)<br />
response.should redirect_to(posts_path(blogger, post))</code></p>
<p>现在，还剩下最后一件事情：这个action必须使用blogger变量来进行重定向，这里我使用instance_variable_set来完成这个工作：</p>
<p class="code"><code class="ruby">blogger = mock_model(User)<br />
@controller.instance_variable_set(:@blogger, blogger)</code></p>
<p>基本就是这样，下面是将部分代码放入before中的完整代码：</p>
<p class="code"><code class="ruby">describe PostsController, "comment", :behaviour_type =&gt; :controller, do<br />
&nbsp;&nbsp;before do<br />
&nbsp;&nbsp;&nbsp;&nbsp;@post = mock_model(Post)<br />
&nbsp;&nbsp;&nbsp;&nbsp;Post.should_receive(:find).and_return(@post)<br />
&nbsp;&nbsp;&nbsp;&nbsp;@comment = mock_model(Comment)<br />
&nbsp;&nbsp;&nbsp;&nbsp;Comment.should_receive(:new).with.({:title =&gt; 'comment title', :body =&gt; 'comment body'}).and_return(@comment)<br />
&nbsp;&nbsp;&nbsp;&nbsp;@blogger = mock_model(User)<br />
&nbsp;&nbsp;&nbsp;&nbsp;@controller.instance_variable_set(:@blogger, @blogger)<br />
&nbsp;&nbsp;end<br />
&nbsp;&nbsp;it "should add comments to the post" do<br />
&nbsp;&nbsp;&nbsp;&nbsp;@comment.should_receive(:save).and_return(true)<br />
&nbsp;&nbsp;&nbsp;&nbsp;@post.comments.should_receive(:concat).and_return(@comment)<br />
&nbsp;&nbsp;&nbsp;&nbsp;post :comment, :id =&gt; @post.id, :comment =&gt; {:title =&gt; 'comment title', :body =&gt; 'comment body'}<br />
&nbsp;&nbsp;&nbsp;&nbsp;flash[:notice].should match(/success/i)<br />
&nbsp;&nbsp;&nbsp;&nbsp;response.should redirect_to(posts_path(@blogger, @post))<br />
&nbsp;&nbsp;end<br />
end</code></p>
<p>相关帖子：</p>
<ul>
<li><a href="http://www.letrails.cn/archives/advanced-rspec-tutorials-rspec-scaffold">RSpec进阶指南(1): rspec_scaffold</a></li>
<li><a href="http://www.letrails.cn/archives/11-02-advanced-rspec-tutorials-basics">RSpec进阶指南(2): 基础知识</a></li>
</ul>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-02-advanced-rspec-tutorials-basics%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-07-advanced-rspec-tutorials-mocking%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec进阶指南(2): 基础知识</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fadvanced-rspec-tutorials-rspec-scaffold%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-07-advanced-rspec-tutorials-mocking%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec进阶指南(1): rspec_scaffold</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Frspec-story-tutorials%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-07-advanced-rspec-tutorials-mocking%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec Story简介</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F20%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-07-advanced-rspec-tutorials-mocking%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec简明指南</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://www.letrails.cn/archives/11-07-advanced-rspec-tutorials-mocking/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RSpec进阶指南(2): 基础知识</title>
		<link>http://www.letrails.cn/archives/11-02-advanced-rspec-tutorials-basics/</link>
		<comments>http://www.letrails.cn/archives/11-02-advanced-rspec-tutorials-basics/#comments</comments>
		<pubDate>Fri, 02 Nov 2007 08:18:31 +0000</pubDate>
		<dc:creator>Yuanyi ZHANG</dc:creator>
				<category><![CDATA[测试]]></category>

		<guid isPermaLink="false">http://www.letrails.cn/archives/11-02-advanced-rspec-tutorials-basics</guid>
		<description><![CDATA[下面是RSpec测试的一些基础语法，这些都是会运行通过的测试例: Strings: 'foo'.should == 'foo' 'foo'.should === 'foo' 'foo'.should_not equal('foo') ''.should be_empty 'foo with bar'.should include('with') 'http://fr.ivolo.us'.should match(/http:\/\/.+/i) nil.should be_nil Numbers: 100.should &#60; 200 200.should &#62;= 100 (200 - 100).should == 100 # (100 - 80) is less than 21 100.should be_close(80,21) Arrays: [1,2,3].should have(3).items [].should be_empty [1,2,3].should include(2) Hashes: {}.should be_empty {:post =&#62; {:title [...]<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fadvanced-rspec-tutorials-rspec-scaffold%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-02-advanced-rspec-tutorials-basics%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec进阶指南(1): rspec_scaffold</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-07-advanced-rspec-tutorials-mocking%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-02-advanced-rspec-tutorials-basics%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec进阶指南（三）：Mocking</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Frspec-story-tutorials%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-02-advanced-rspec-tutorials-basics%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec Story简介</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F20%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-02-advanced-rspec-tutorials-basics%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec简明指南</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>下面是RSpec测试的一些基础语法，这些都是会运行通过的测试例:</p>
<p><strong>Strings:</strong></p>
<p class="code"><code class="ruby">'foo'.should == 'foo'<br />
'foo'.should === 'foo'<br />
'foo'.should_not equal('foo')<br />
''.should be_empty<br />
'foo with bar'.should include('with')<br />
'http://fr.ivolo.us'.should match(/http:\/\/.+/i)<br />
nil.should be_nil</code></p>
<p><strong>Numbers:</strong></p>
<p class="code"><code class="ruby">100.should &lt; 200<br />
200.should &gt;= 100<br />
(200 - 100).should == 100</code></p>
<p class="code"><code class="ruby"># (100 - 80) is less than 21<br />
100.should be_close(80,21)</code></p>
<p><strong>Arrays:</strong></p>
<p class="code"><code class="ruby">[1,2,3].should have(3).items<br />
[].should be_empty<br />
[1,2,3].should include(2)</code></p>
<p><strong>Hashes:</strong></p>
<p class="code"><code class="ruby">{}.should be_empty<br />
{:post =&gt; {:title =&gt; 'test'}}.should have_key(:post)<br />
{:post =&gt; {:title =&gt; 'test'}}.should_not have_key(:title)<br />
false.should be_false<br />
true.should be_true</code></p>
<p><strong>Records:</strong></p>
<p class="code"><code class="ruby"># assuming  @post = Post.new(:title =&gt; 'test')<br />
@post.should be_instance_of(Post)<br />
@post.should respond_to(:title)</code></p>
<p>相关文章：</p>
<ul>
<li><a href="http://www.letrails.cn/archives/advanced-rspec-tutorials-rspec-scaffold">RSpec进阶指南(1): rspec_scaffold</a></li>
<li><a href="http://www.letrails.cn/archives/20">RSpec简明指南</a></li>
</ul>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fadvanced-rspec-tutorials-rspec-scaffold%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-02-advanced-rspec-tutorials-basics%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec进阶指南(1): rspec_scaffold</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-07-advanced-rspec-tutorials-mocking%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-02-advanced-rspec-tutorials-basics%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec进阶指南（三）：Mocking</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Frspec-story-tutorials%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-02-advanced-rspec-tutorials-basics%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec Story简介</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F20%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-02-advanced-rspec-tutorials-basics%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec简明指南</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://www.letrails.cn/archives/11-02-advanced-rspec-tutorials-basics/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RSpec进阶指南(1): rspec_scaffold</title>
		<link>http://www.letrails.cn/archives/advanced-rspec-tutorials-rspec-scaffold/</link>
		<comments>http://www.letrails.cn/archives/advanced-rspec-tutorials-rspec-scaffold/#comments</comments>
		<pubDate>Mon, 08 Oct 2007 15:59:41 +0000</pubDate>
		<dc:creator>Yuanyi ZHANG</dc:creator>
				<category><![CDATA[测试]]></category>

		<guid isPermaLink="false">http://www.letrails.cn/archives/rspec%e8%bf%9b%e9%98%b6%e6%8c%87%e5%8d%971-rspec_scaffold</guid>
		<description><![CDATA[不同于前面那篇入门性的指南（如果还没读过，建议先阅读那篇文章然后再回来），这一系列将涵盖RSpec在Rails中的使用以及一些高级主题，来自我的同事Josh Stephenson，这是第一篇。 要使用RSpec来测试你的Rails应用，有一个比较简单的方法，使用rspec_scaffold生成器来代替scaffold_resource（Rails2.0中已更名为scaffold）。 $ ./script/generate rspec_scaffold post title:string body:text author:integer created_at:datetime updated_at:datetime &#160;&#160;&#160;&#160;&#160;exists app/models/ &#160;&#160;&#160;&#160;&#160;exists app/controllers/ &#160;&#160;&#160;&#160;&#160;exists app/helpers/ &#160;&#160;&#160;&#160;&#160;create app/views/posts &#160;&#160;&#160;&#160;&#160;create spec/controllers/ &#160;&#160;&#160;&#160;&#160;create spec/models/ &#160;&#160;&#160;&#160;&#160;create spec/helpers/ &#160;&#160;&#160;&#160;&#160;create spec/fixtures/ &#160;&#160;&#160;&#160;&#160;create spec/views/posts &#160;&#160;&#160;&#160;&#160;create spec/controllers/posts_controller_spec.rb &#160;&#160;&#160;&#160;&#160;create app/controllers/posts_controller.rb &#160;&#160;&#160;&#160;&#160;create spec/helpers/posts_helper_spec.rb &#160;&#160;&#160;&#160;&#160;create app/helpers/posts_helper.rb &#160;&#160;&#160;&#160;&#160;create app/views/posts/index.rhtml &#160;&#160;&#160;&#160;&#160;create app/views/posts/show.rhtml &#160;&#160;&#160;&#160;&#160;create app/views/posts/new.rhtml &#160;&#160;&#160;&#160;&#160;create app/views/posts/edit.rhtml &#160;&#160;&#160;&#160;&#160;create app/models/post.rb &#160;&#160;&#160;&#160;&#160;create spec/fixtures/posts.yml &#160;&#160;&#160;&#160;&#160;create spec/models/post_spec.rb &#160;&#160;&#160;&#160;&#160;create spec/views/posts/edit.rhtml_spec.rb &#160;&#160;&#160;&#160;&#160;create [...]<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-02-advanced-rspec-tutorials-basics%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fadvanced-rspec-tutorials-rspec-scaffold%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec进阶指南(2): 基础知识</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Frspec-story-tutorials%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fadvanced-rspec-tutorials-rspec-scaffold%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec Story简介</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-07-advanced-rspec-tutorials-mocking%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fadvanced-rspec-tutorials-rspec-scaffold%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec进阶指南（三）：Mocking</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F20%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fadvanced-rspec-tutorials-rspec-scaffold%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec简明指南</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>不同于前面<a href="http://www.letrails.cn/archives/20">那篇入门性的指南</a>（如果还没读过，建议先阅读那篇文章然后再回来），这一系列将涵盖RSpec在Rails中的使用以及一些高级主题，来自我的同事<a href="http://fr.ivolo.us/">Josh Stephenson</a>，这是第一篇。</p>
<p>要使用RSpec来测试你的Rails应用，有一个比较简单的方法，使用rspec_scaffold生成器来代替scaffold_resource（Rails2.0中已更名为scaffold）。</p>
<p class="code"><code class="ruby">$  ./script/generate rspec_scaffold post title:string body:text author:integer created_at:datetime updated_at:datetime<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exists  app/models/<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exists  app/controllers/<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exists  app/helpers/<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create  app/views/posts<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create  spec/controllers/<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create  spec/models/<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create  spec/helpers/<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create  spec/fixtures/<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create  spec/views/posts<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create  spec/controllers/posts_controller_spec.rb<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create  app/controllers/posts_controller.rb<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create  spec/helpers/posts_helper_spec.rb<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create  app/helpers/posts_helper.rb<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create  app/views/posts/index.rhtml<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create  app/views/posts/show.rhtml<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create  app/views/posts/new.rhtml<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create  app/views/posts/edit.rhtml<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create  app/models/post.rb<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create  spec/fixtures/posts.yml<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create  spec/models/post_spec.rb<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create  spec/views/posts/edit.rhtml_spec.rb<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create  spec/views/posts/index.rhtml_spec.rb<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create  spec/views/posts/new.rhtml_spec.rb<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create  spec/views/posts/show.rhtml_spec.rb<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create  db/migrate<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create  db/migrate/001_create_posts.rb<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;route  map.resources :posts</code></p>
<p>就像你看到的，rspec_scaffold会为你生成model，controller，helper，views以及其它一些辅助的spec文件。让我们先来看看spec/models/post_spec.rb吧：</p>
<p class="code"><code class="ruby"># this is called a context (or a describe block)<br />
require File.dirname(__FILE__) + '/../spec_helper'<br />
describe Post do<br />
&nbsp;&nbsp;before(:each) do<br />
&nbsp;&nbsp;&nbsp;&nbsp;@post = Post.new<br />
&nbsp;&nbsp;end<br />
&nbsp;&nbsp;# this is called an example:<br />
&nbsp;&nbsp;it "should be valid" do<br />
&nbsp;&nbsp;&nbsp;&nbsp;@post.should be_valid<br />
&nbsp;&nbsp;end<br />
end</p>
<p>首先，我们需要注意，所有的specs都拥有behaviour_type属性，spec使用它来确定需要加载哪些spec helpers，我们可以通过下面的语句来指定它：</p>
<p class="code"><code class="ruby">describe Post, "a useful comment", :behaviour_type =&gt; :model do</code></p>
<p>这将会加载测试model所需的helpers，让我们继续回到post_spec.rb，这段代码其实没有任何意义，因为post model什么也没有做，所以让我们先来给post model加一些validations：</p>
<p class="code"><code class="ruby">class Post &lt; ActiveRecord::Base<br />
&nbsp;&nbsp;validates_presence_of :title<br />
&nbsp;&nbsp;validates_presence_of :body<br />
&nbsp;&nbsp;validates_uniqueness_of :title<br />
end</code></p>
<p>一些人可能认为测试validations没什么用，因为几乎可以肯定它们肯定是工作正常的，但是作为应用的最底层代码，我还是愿意对它们的行为进行检查，以确保它们符合我的预期：</p>
<p class="code"><code class="ruby">describe Post do<br />
&nbsp;&nbsp;before(:each) do<br />
&nbsp;&nbsp;&nbsp;&nbsp;@post = Post.new(valid_post_hash) # grabs the hash below<br />
&nbsp;&nbsp;end<br />
&nbsp;&nbsp;it "should be valid" do<br />
&nbsp;&nbsp;&nbsp;&nbsp;@post.should be_valid<br />
&nbsp;&nbsp;end<br />
&nbsp;&nbsp;it "should not be valid without a title" do<br />
&nbsp;&nbsp;&nbsp;&nbsp;@post.title = ''<br />
&nbsp;&nbsp;&nbsp;&nbsp;@post.should_not be_valid<br />
&nbsp;&nbsp;end<br />
&nbsp;&nbsp;it "should not be valid without a body" do<br />
&nbsp;&nbsp;&nbsp;&nbsp;@post.body = ''<br />
&nbsp;&nbsp;&nbsp;&nbsp;@post.should_not be_valid<br />
&nbsp;&nbsp;end<br />
&nbsp;&nbsp;def valid_post_hash<br />
&nbsp;&nbsp;&nbsp;&nbsp;{:title =&gt; 'test', :body =&gt; 'test body'}<br />
&nbsp;&nbsp;end<br />
end</p>
<p>尽管RSpec的可读性并不是很好，但我认为至少上面这段代码写的相当清楚，应该不需要再进行解释，不过对于几个比较特殊的方法还是要说明一下：</p>
<p class="code"><code class="ruby">&nbsp;&nbsp;before(:all) do<br />
&nbsp;&nbsp;# 会在所有example运行前被调用一次<br />
&nbsp;&nbsp;end<br />
&nbsp;&nbsp;before do<br />
&nbsp;&nbsp;# 与before(:each)相同，会在每个example运行前被调用一次<br />
&nbsp;&nbsp;end<br />
&nbsp;&nbsp;after(:each) do<br />
&nbsp;&nbsp;# 会在每个example运行完后被调用一次<br />
&nbsp;&nbsp;&nbsp;&nbsp;@post.destroy unless @post.new_record?<br />
&nbsp;&nbsp;end<br />
&nbsp;&nbsp;after(:all) do<br />
&nbsp;&nbsp;&nbsp;&nbsp;# 会在所有examples运行完之后被调用一次<br />
&nbsp;&nbsp;&nbsp;&nbsp;Post.destroy_all<br />
&nbsp;&nbsp;end</code></p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-02-advanced-rspec-tutorials-basics%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fadvanced-rspec-tutorials-rspec-scaffold%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec进阶指南(2): 基础知识</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Frspec-story-tutorials%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fadvanced-rspec-tutorials-rspec-scaffold%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec Story简介</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-07-advanced-rspec-tutorials-mocking%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fadvanced-rspec-tutorials-rspec-scaffold%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec进阶指南（三）：Mocking</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F20%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fadvanced-rspec-tutorials-rspec-scaffold%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec简明指南</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://www.letrails.cn/archives/advanced-rspec-tutorials-rspec-scaffold/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mock工具： Mocha还是FlexMock</title>
		<link>http://www.letrails.cn/archives/57/</link>
		<comments>http://www.letrails.cn/archives/57/#comments</comments>
		<pubDate>Wed, 29 Aug 2007 13:55:42 +0000</pubDate>
		<dc:creator>Yuanyi ZHANG</dc:creator>
				<category><![CDATA[测试]]></category>

		<guid isPermaLink="false">http://www.letrails.cn/archives/57</guid>
		<description><![CDATA[简介 Mocha和FlexMock是两个比较流行的针对Rails单元测试的Mock工具， Mocha： 作者：James， Ben, Chris 以及 Paul 许可：MIT License SVN：svn://rubyforge.org/var/svn/mocha/trunk 文档：http://mocha.rubyforge.org/ FlexMock： 作者：Jim Weirich 许可：类BSD License SVN：svn://rubyforge.org/var/svn/mocha/trunk 文档：flexmock.rubyforge.org 安装 Mocha： $ gem install mocha $ script/plugin install svn://rubyforge.org/var/svn/mocha/trunk FlexMock： $ gem install flexmock 使用 Mocha： # Mocking a class method product = Product.new Product.expects(:find).with(1).returns(product) assert_equal product, Product.find(1) FlexMock： product = Product.new flexmock(Product).should_receive(:find).with(1).and_return(product) assert_equal product, [...]<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="RSpec进阶指南（三）：Mocking" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-07-advanced-rspec-tutorials-mocking%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F57%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">RSpec进阶指南（三）：Mocking</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="rcov: ruby代码覆盖率工具" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F51%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F57%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/08/3251581.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">rcov: ruby代码覆盖率工具</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="JRuby1.0发布" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F14%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F57%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/08/3251519.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">JRuby1.0发布</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="RailsLogVisualizer现在支持Windows" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F32%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F57%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/08/3251814.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">RailsLogVisualizer现在支持Windows</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p><strong>简介</strong></p>
<p>Mocha和FlexMock是两个比较流行的针对Rails单元测试的Mock工具，</p>
<p>Mocha：<br />
<strong>作者：</strong><a href="http://blog.floehopper.org/">James</a>， <a href="http://www.reevoo.com/blogs/bengriffiths">Ben</a>, <a href="http://blog.seagul.co.uk/">Chris</a> 以及 <a href="http://po-ru.com/">Paul</a><br />
<strong>许可：</strong>MIT License</p>
<p><strong>SVN：</strong>svn://rubyforge.org/var/svn/mocha/trunk<br />
<strong>文档：</strong><a href="http://mocha.rubyforge.org/">http://mocha.rubyforge.org/</a></p>
<p>FlexMock：<br />
<strong>作者：</strong>Jim Weirich<br />
<strong>许可：</strong>类BSD License<br />
<strong>SVN：</strong>svn://rubyforge.org/var/svn/mocha/trunk</p>
<p><strong>文档：</strong><a href="http://flexmock.rubyforge.org/">flexmock.rubyforge.org</a></p>
<p><strong>安装</strong></p>
<p>Mocha：</p>
<p class="code"><code>$ gem install mocha<br />
$ script/plugin install svn://rubyforge.org/var/svn/mocha/trunk</code></p>
<p>FlexMock：</p>
<p class="code"><code>$ gem install flexmock</code></p>
<p>使用</p>
<p>Mocha：</p>
<p class="code"><code class="ruby"># Mocking a class method<br />
product = Product.new<br />
Product.expects(:find).with(1).returns(product)<br />
assert_equal product, Product.find(1)</code></p>
<p>FlexMock：</p>
<p class="code"><code class="ruby">product = Product.new<br />
flexmock(Product).should_receive(:find).with(1).and_return(product)<br />
assert_equal product, Product.find(1)</code></p>
<p>这里只是一个简单的比较，<a href="http://www.slideshare.net/">SlideShare</a>上专门有一个幻灯<a href="http://www.slideshare.net/viget/mockfight-flexmock-vs-mocha/">对Mocha和FlexMock的方方面面进行了比较</a>，最后的结论是，两者的功能基本相同，差异只在于语法，所以不必担心选择一个会失掉另一个的某些功能，喜欢哪个语法就用哪个好了，我比较喜欢Mocha的语法。</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="RSpec进阶指南（三）：Mocking" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-07-advanced-rspec-tutorials-mocking%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F57%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">RSpec进阶指南（三）：Mocking</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="sortable column headers: 表格数据排序插件" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F5%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F57%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/08/3251861.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">sortable column headers: 表格数据排序插件</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Rails插件： RAV" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F56%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F57%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/08/3251650.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Rails插件： RAV</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="在Rails中创建多对多映射" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F34%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F57%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/08/3251550.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">在Rails中创建多对多映射</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://www.letrails.cn/archives/57/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>使用SQLite in memory提高测试代码效率</title>
		<link>http://www.letrails.cn/archives/55/</link>
		<comments>http://www.letrails.cn/archives/55/#comments</comments>
		<pubDate>Thu, 23 Aug 2007 16:21:01 +0000</pubDate>
		<dc:creator>Yuanyi ZHANG</dc:creator>
				<category><![CDATA[性能]]></category>
		<category><![CDATA[数据库]]></category>
		<category><![CDATA[测试]]></category>

		<guid isPermaLink="false">http://www.letrails.cn/archives/55</guid>
		<description><![CDATA[对于需要进行持续集成的大型项目来说，运行测试代码的花费就显得尤为重要，Chris Roos在这篇帖子里介绍了一种通过使用SQLite数据库来 提高测试代码运行效率的方法。 首先你需要安装SQLite3以及sqlite3-ruby gem，然后修改database.yml： test: adapter: sqlite3 database: ":memory:" 但是这样有一个问题，由于SQLite数据库保存在内存中，因此必须在每次执行单元测试之前首先生成数据库的大纲，不过不用担心，Chris Roos已经提供了一段现成的代码，将它加到你的environment.rb就可以了： def in_memory_database? &#160;&#160;ENV["RAILS_ENV"] == "test" and &#160;&#160;ActiveRecord::Base.connection.class == ActiveRecord::ConnectionAdapters::SQLite3Adapter and &#160;&#160;Rails::Configuration.new.database_configuration['test']['database'] == ':memory:' end if in_memory_database? &#160;&#160;puts "creating sqlite in memory database" &#160;&#160;load "#{RAILS_ROOT}/db/schema.rb" # use db agnostic schema by default &#160;&#160;# ActiveRecord::Migrator.up('db/migrate') # use migrations end 不过要注意，以上代码最好加在”# Include your application configuration below”这一行之后，因为说不准后面的配置有可能就会用到数据库。 [...]<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="使用Flog测试你的Ruby代码复杂度" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F62%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F55%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/08/3251517.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用Flog测试你的Ruby代码复杂度</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Rails Cookie测试" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fhow-to-test-rails-cookie%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F55%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Rails Cookie测试</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="rcov: ruby代码覆盖率工具" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F51%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F55%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/08/3251581.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">rcov: ruby代码覆盖率工具</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Bash提示符显示Git分支" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fshow-git-branch-in-bash-prompt%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F55%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/05/15/8702104.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Bash提示符显示Git分支</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p><a href="http://lilac.greatweb.cn/rails/wp-admin/post-new.php">对于需要进行持续集成的大型项目来说，运行测试代码的花费就显得尤为重要，</a><a href="http://blog.seagul.co.uk/" title="Chris Roos" id="qlfp">Chris Roos</a>在<a href="http://blog.seagul.co.uk/articles/2006/02/08/in-memory-sqlite-database-for-rails-testing" title="这篇帖子里" id="di-q">这篇帖子里</a>介绍了一种通过使用SQLite数据库来 提高测试代码运行效率的方法。</p>
<p>首先你需要安装<a href="http://www.sqlite.org/download.html" title="SQLite3" id="yh2a">SQLite3</a>以及sqlite3-ruby gem，然后修改database.yml：</p>
<p class="code"><code class="ruby">test:<br />
adapter: sqlite3<br />
database: ":memory:"</code></p>
<p>但是这样有一个问题，由于SQLite数据库保存在内存中，因此必须在每次执行单元测试之前首先生成数据库的大纲，不过不用担心，<a href="http://blog.seagul.co.uk/" title="Chris Roos" id="qlfp">Chris Roos</a>已经提供了一段现成的代码，将它加到你的environment.rb就可以了：</p>
<p class="code"><code class="ruby"><br />
def in_memory_database?<br />
&nbsp;&nbsp;ENV["RAILS_ENV"] == "test" and<br />
&nbsp;&nbsp;ActiveRecord::Base.connection.class == ActiveRecord::ConnectionAdapters::SQLite3Adapter and<br />
&nbsp;&nbsp;Rails::Configuration.new.database_configuration['test']['database'] == ':memory:'<br />
end<br />
if in_memory_database?<br />
&nbsp;&nbsp;puts "creating sqlite in memory database"<br />
&nbsp;&nbsp;load "#{RAILS_ROOT}/db/schema.rb" # use db agnostic schema by default<br />
&nbsp;&nbsp;#  ActiveRecord::Migrator.up('db/migrate') # use migrations<br />
end</code></p>
<p>不过要注意，以上代码最好加在”# Include your application configuration below”这一行之后，因为说不准后面的配置有可能就会用到数据库。</p>
<p>这段代码使用db/schema.rb来初始化数据库，因此你最好先执行下面这条命令，以保证schema.rb与数据库保持同步(当然你也可以使用db:migrate)：</p>
<p class="code"><code class="ruby">rake db:migrate:dump</code></p>
<p>现在在执行下rake test，看看速度是不是快了不少，下面是我找的一个小测试程序的运行结果：</p>
<p>sqlite in memory:<br />
unit tests: 0.14s<br />
functional tests: 0.59s</p>
<p>mysql:<br />
unit tests: 1.16s<br />
functional tests: 1.81s</p>
<p>如果你觉得这样还是有些麻烦，不要紧，<a href="http://nubyonrails.com/">Geoffrey Grosenbach</a>已经为你准备好了一个<a href="http://nubyonrails.com/articles/2006/06/01/san-francisco-sqlite3-memory-tests-asteroids" title="插件" id="j44:">插件</a>，你只需要动手改一下database.yml就成了。</p>
<p><strong>更新：如果不想每次都看到那一堆数据库创建信息，那么只需在加载schema.rb之前，将ActiveRecord::Schema.verbose置为false即可：</strong></p>
<p class="code"><code class="ruby">if in_memory_database?<br />
&nbsp;&nbsp;verbose = ActiveRecord::Schema.verbose<br />
&nbsp;&nbsp;ActiveRecord::Schema.verbose = false<br />
&nbsp;&nbsp;puts "creating sqlite in memory database"<br />
&nbsp;&nbsp;load "#{RAILS_ROOT}/db/schema.rb" # use db agnostic schema by default<br />
&nbsp;&nbsp;ActiveRecord::Schema.verbose = verbose<br />
end</code></p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="使用Flog测试你的Ruby代码复杂度" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F62%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F55%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/08/3251517.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用Flog测试你的Ruby代码复杂度</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Rails Cookie测试" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fhow-to-test-rails-cookie%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F55%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Rails Cookie测试</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="rcov: ruby代码覆盖率工具" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F51%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F55%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/03/08/3251581.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">rcov: ruby代码覆盖率工具</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Bash提示符显示Git分支" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fshow-git-branch-in-bash-prompt%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F55%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/05/15/8702104.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Bash提示符显示Git分支</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://www.letrails.cn/archives/55/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>rcov: ruby代码覆盖率工具</title>
		<link>http://www.letrails.cn/archives/51/</link>
		<comments>http://www.letrails.cn/archives/51/#comments</comments>
		<pubDate>Sun, 19 Aug 2007 15:24:41 +0000</pubDate>
		<dc:creator>Yuanyi ZHANG</dc:creator>
				<category><![CDATA[测试]]></category>

		<guid isPermaLink="false">http://www.letrails.cn/archives/51</guid>
		<description><![CDATA[简介 rcov是一个用于诊断Ruby代码覆盖率的工具，它最主要的用途就是用于确定单元测试是否覆盖到了所有代码，rcov使用一个经过优化的C运行时，因此性能相当惊人，同时它还提供多种格式的输出。 安装 $ gem install rcov 使用 rcov的使用相当简单： $ rcov test/*.rb 如果使用rspec，由于rcov不支持从命令行调用spec，因此你必须在测试代码中包含这一行： require 'spec' 下面的截图来自rcov的官方主页（Total coverage将空行也计算在内，而Code coverage则去除了空行）： 你还可以通过链接直接查看单个文件的覆盖率： 更多信息参看这里。<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fruby-1-9-released%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F51%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Ruby 1.9正式发布</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fruby-metaclass-tutorials%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F51%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Ruby Metaclass详解</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Ftenpay-ruby-plugin-update%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F51%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">财付通Ruby插件更新</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Froxy-a-ruby-proxy-library%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F51%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Roxy: Ruby代理库</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p><strong>简介</strong></p>
<p>rcov是一个用于诊断Ruby代码覆盖率的工具，它最主要的用途就是用于确定单元测试是否覆盖到了所有代码，rcov使用一个经过优化的C运行时，因此性能相当惊人，同时它还提供多种格式的输出。</p>
<p><strong>安装</strong></p>
<p class="code"><code>$ gem install rcov</code></p>
<p><strong>使用</strong></p>
<p>rcov的使用相当简单：</p>
<p class="code"><code>$ rcov test/*.rb</code></p>
<p>如果使用rspec，由于rcov不支持从命令行调用spec，因此你必须在测试代码中包含这一行：</p>
<p class="code"><code class="ruby">require 'spec'</code></p>
<p>下面的截图来自rcov的官方主页（Total coverage将空行也计算在内，而Code coverage则去除了空行）：</p>
<p class="img"><img src="http://eigenclass.org/hiki.rb?c=plugin;plugin=attach_download;p=rcov;file_name=typo-summary.png" /></p>
<p>你还可以通过链接直接查看单个文件的覆盖率：</p>
<p class="img"><img src="http://eigenclass.org/hiki.rb?c=plugin;plugin=attach_download;p=rcov;file_name=typo-detailed.png" /></p>
<p>更多信息参看<a href="http://eigenclass.org/hiki/rcov">这里</a>。</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fruby-1-9-released%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F51%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Ruby 1.9正式发布</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fruby-metaclass-tutorials%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F51%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Ruby Metaclass详解</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Ftenpay-ruby-plugin-update%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F51%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">财付通Ruby插件更新</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Froxy-a-ruby-proxy-library%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F51%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Roxy: Ruby代理库</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://www.letrails.cn/archives/51/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RSpec简明指南</title>
		<link>http://www.letrails.cn/archives/20/</link>
		<comments>http://www.letrails.cn/archives/20/#comments</comments>
		<pubDate>Wed, 20 Jun 2007 13:15:42 +0000</pubDate>
		<dc:creator>Yuanyi ZHANG</dc:creator>
				<category><![CDATA[指南]]></category>
		<category><![CDATA[测试]]></category>

		<guid isPermaLink="false">http://www.letrails.cn/archives/20</guid>
		<description><![CDATA[这是David Chelimsky写的一篇RSpec简明指南，原文在这里。 简介 要了解RSpec，我们首先需要了解什么是行为驱动开发（Behaviour Driven Development，简称BDD），BDD是一种融合了可接受性测试驱动计划（Acceptance Test Driven Planning），域驱动设计（Domain Driven Design）以及测试驱动开发（Test Driven Development，简称TDD）的敏捷开发模型。RSpec为BDD开发提供TDD支持。 你可以简单的将RSpec看作一个传统的单元测试框架，但我们更愿意将它看成是一种领域特定语言（Domain Specific Language，以下简称DSL），它的主要作用就是描述我们对系统执行某个样例(example)的期望行为(behavior)。 这篇指南遵从TDD思想，但是我们将使用行为（behavior）和样例（example）来代替测试例（test case）和测试方法（test method），想知道我们为什么采用这样的术语，请参看Dan North, Dave Astels, 以及 Brian Marick 的相关文章。 安装 目前RSpec的最新版本是1.0.5，需要Ruby184以上版本，可以通过下面这条命令安装： # gem install rspec 准备工作 整篇指南都围绕一个例子展开，因此在开始前，你最好先为这个例子建个目录： $ mkdir rspec_tutorial $ cd rspec_tutorial 开始 我们首先要了解的是RSpec DSL的&#8221;describe&#8221;与&#8221;it&#8221;方法，这两个方法有很多其它的名字（但是我们不推荐使用它们），我们之所以使用这样的命名，只是想让你站在行为（behavior）而不是结构（structure）的角度进行思考。 创建名为user_spec.rb的文件： describe User do end describe方法创建一个Behavior实例，所以你可以将&#8221;describe User&#8221;理解为&#8221;描述用户的行为（describe the behaviour of the User [...]<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fadvanced-rspec-tutorials-rspec-scaffold%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F20%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec进阶指南(1): rspec_scaffold</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-07-advanced-rspec-tutorials-mocking%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F20%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec进阶指南（三）：Mocking</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-02-advanced-rspec-tutorials-basics%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F20%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec进阶指南(2): 基础知识</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Frspec-story-tutorials%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F20%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec Story简介</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>这是<a href="http://blog.davidchelimsky.net/">David Chelimsky</a>写的一篇RSpec简明指南，原文在<a href="http://blog.davidchelimsky.net/articles/2007/05/14/an-introduction-to-rspec-part-i">这里</a>。</p>
<p><font size="5"><b>简介</b></font></p>
<p>要了解RSpec，我们首先需要了解什么是行为驱动开发（Behaviour Driven Development，简称BDD），BDD是一种融合了可接受性测试驱动计划（Acceptance Test Driven Planning），域驱动设计（Domain Driven Design）以及测试驱动开发（Test Driven Development，简称TDD）的敏捷开发模型。RSpec为BDD开发提供TDD支持。</p>
<p>你可以简单的将RSpec看作一个传统的单元测试框架，但我们更愿意将它看成是一种领域特定语言（Domain Specific Language，以下简称DSL），它的主要作用就是描述我们对系统执行某个样例(example)的期望行为(behavior)。</p>
<p>这篇指南遵从TDD思想，但是我们将使用行为（behavior）和样例（example）来代替测试例（test case）和测试方法（test method），想知道我们为什么采用这样的术语，请参看<a href="http://dannorth.net/tags/agile/bdd/">Dan North</a>, <a href="http://daveastels.com/articles/2005/07/05/a-new-look-at-test-driven-development">Dave Astels</a>, 以及 <a href="http://exampler.com/">Brian Marick</a> 的相关文章。</p>
<p><font size="5"><b>安装</b></font></p>
<p>目前RSpec的最新版本是1.0.5，需要Ruby184以上版本，可以通过下面这条命令安装：</p>
<p class="code"><code># gem install rspec</code></p>
<p><font size="5"><b>准备工作</b></font></p>
<p>整篇指南都围绕一个例子展开，因此在开始前，你最好先为这个例子建个目录：</p>
<p class="code"><code>$ mkdir rspec_tutorial<br />
$ cd rspec_tutorial</code></p>
<p><font size="5"><b>开始</b></font></p>
<p>我们首先要了解的是RSpec DSL的&#8221;describe&#8221;与&#8221;it&#8221;方法，这两个方法有很多其它的名字（但是我们不推荐使用它们），我们之所以使用这样的命名，只是想让你站在行为（behavior）而不是结构（structure）的角度进行思考。</p>
<p>创建名为user_spec.rb的文件：</p>
<p class="code"><code>describe User do<br />
end</code></p>
<p>describe方法创建一个Behavior实例，所以你可以将&#8221;describe User&#8221;理解为&#8221;描述用户的行为（describe the behaviour of the User class）&#8221;，或许这个方法叫做“<br />
describe_the_behaviour_of”会更合适些，但这实在太冗长了，所以我们决定只选取第一个单词describe来作为这个方法的名字。</p>
<p>现在你可以在shell中试试这条命令：</p>
<p class="code"><code>$ spec user_spec.rb</code></p>
<p>spec命令有很多选项，但大部分超出了本指南的范围，如果你感兴趣，可以只输入spec而不带任何参数来查看帮助信息。</p>
<p>让我们接着回到上面那条命令，它应该会产生下面的输出：</p>
<p class="code"><code>./user_spec.rb:1: uninitialized constant User (NameError)</code></p>
<p>这是因为我们还没有创建User类，也就是说我们要描述的东西不存在，因此我们需要再创建一个user.rb来定义我们所要描述的对象：</p>
<p class="code"><code class="ruby">class User<br />
end</code></p>
<p>并在user_spec.rb中包含它：</p>
<p class="code"><code class="ruby">require 'user'<br />
describe User do<br />
end</code></p>
<p>现在再次运行spec命令：</p>
<p class="code"><code>$ spec user_spec.rb<br />
Finished in 6.0e-06 seconds<br />
0 examples, 0 failures</code></p>
<p>这个输出是说我们还没有定义样例，所以现在我们就来定义一个：</p>
<p class="code"><code class="ruby">describe User do<br />
&nbsp;&nbsp;it "should be in any roles assigned to it" do<br />
&nbsp;&nbsp;end<br />
end</code></p>
<p>it方法返回一个Example实例，因此我们可以将it方法理解成“用户行为的一个样例”。</p>
<p>再次运行spec：</p>
<p class="code"><code>$ spec user_spec.rb --format specdoc<br />
User<br />
- should be in any roles assigned to it<br />
Finished in 0.022865 seconds<br />
1 example, 0 failures</code></p>
<p>specdoc参数格式化行为（describe方法创建的对象）以及样例（it方法创建的对象）的名字然后输出，这种格式来自于TestDox，一个为JUnit测试例及方法提供相似报告的工具。</p>
<p>现在我们开始增加Ruby代码：</p>
<p class="code"><code class="ruby">describe User do<br />
&nbsp;&nbsp;it "should be in any roles assigned to it" do<br />
&nbsp;&nbsp;&nbsp;&nbsp;user.should be_in_role("assigned role")<br />
&nbsp;&nbsp;end<br />
end</code></p>
<p>这句话的意思是User应该能够胜任所有分配给他的角色，那么事实是这样么？让我们运行spec试试看：</p>
<p class="code"><code>$ spec user_spec.rb --format specdoc<br />
User<br />
- should be in any roles assigned to it (ERROR - 1)<br />
1)<br />
NameError in &#8216;User should be in any roles assigned to it&#8217;<br />
undefined local variable or method `user&#8217; for #<#<Class:0x14ed15c>:0&#215;14ecdd8><br />
./user_spec.rb:6:<br />
Finished in 0.017956 seconds<br />
1 example, 1 failure</code></p>
<p>又出错了，是的，但在继续之前，让我们先仔细看看这段出错信息：</p>
<ul>
<li>&#8220;ERROR -1)&#8221;告诉我们&#8221;should be in any roles assigned to it&#8221;这个样例出错了</li>
<li>&#8220;1)&#8221;则为我们详细描述了这个错误，当样例很多时，你就会发现这个编号非常有用</li>
</ul>
<p>还有一点需要注意：这段信息没有给出RSpec代码的backtrace，如果你需要它，可以通过&#8211;backtrace选项来获取。</p>
<p>下面，我们继续我们的例子，上面的错误是因为我们没有创建User对象，那我们就创建一个：</p>
<p class="code"><code class="ruby">describe User do<br />
&nbsp;&nbsp;it "should be in any roles assigned to it" do<br />
&nbsp;&nbsp;&nbsp;&nbsp;user = User.new<br />
&nbsp;&nbsp;&nbsp;&nbsp;user.should be_in_role("assigned role")<br />
&nbsp;&nbsp;end<br />
end</code></p>
<p class="code"><code>$ spec user_spec.rb --format specdoc<br />
User<br />
- should be in any roles assigned to it (ERROR - 1)<br />
1)<br />
NoMethodError in &#8216;User should be in any roles assigned to it&#8217;<br />
undefined method `in_role?&#8217; for #<User:0x14ec8ec><br />
./user_spec.rb:7:<br />
Finished in 0.020779 seconds<br />
1 example, 1 failure</code></p>
<p>还是失败，不过这次是因为User对象缺少role_in?方法，修改user.rb:</p>
<p class="code"><code class="ruby">class User<br />
&nbsp;&nbsp;def in_role?(role)<br />
&nbsp;&nbsp;end</code></p>
<p class="code"><code>$ spec user_spec.rb --format specdoc<br />
User<br />
- should be in any roles assigned to it (FAILED - 1)<br />
1)<br />
&#8216;User should be in any roles assigned to it&#8217; FAILED<br />
expected in_role?(&#8221;assigned role&#8221;) to return true, got nil<br />
./user_spec.rb:7:<br />
Finished in 0.0172110000000001 seconds<br />
1 example, 1 failure</code></p>
<p>虽然又失败了，但我们的第一个目标其实已经达到了，我们得到了一段更有意义的错误描述&#8221;User should be in any roles assigned to it&#8221;。</p>
<p>让这段代码避免失败很简单：</p>
<p class="code"><code class="ruby">class User<br />
&nbsp;&nbsp;def in_role?(role)<br />
&nbsp;&nbsp;&nbsp;&nbsp;true<br />
&nbsp;&nbsp;end</code></p>
<p class="code"><code>$ spec user_spec.rb --format specdoc<br />
User<br />
- should be in any roles assigned to it<br />
Finished in 0.018173 seconds<br />
1 example, 0 failures</code></p>
<p>现在终于通过了，但是让我们再来看看这段代码：</p>
<p class="code"><code class="ruby">describe User do<br />
&nbsp;&nbsp;it "should be in any roles assigned to it" do<br />
&nbsp;&nbsp;&nbsp;&nbsp;user = User.new<br />
&nbsp;&nbsp;&nbsp;&nbsp;user.should be_in_role("assigned role")<br />
&nbsp;&nbsp;end<br />
end</code></p>
<p>我们可以将这个样例理解成“用户应该接受所有分配给他的角色”，但问题是我们还没有分给他角色呢？</p>
<p class="code"><code class="ruby">describe User do<br />
&nbsp;&nbsp;it "should be in any roles assigned to it" do<br />
&nbsp;&nbsp;&nbsp;&nbsp;user = User.new<br />
&nbsp;&nbsp;&nbsp;&nbsp;user.assign_role("assigned role")<br />
&nbsp;&nbsp;&nbsp;&nbsp;user.should be_in_role("assigned role")<br />
&nbsp;&nbsp;end<br />
end</code></p>
<p>这段代码又会引发一个错误，因为User并没有assign_role这个方法：</p>
<p class="code"><code class="ruby">class User<br />
&nbsp;&nbsp;def in_role?(role)<br />
&nbsp;&nbsp;&nbsp;&nbsp;true<br />
&nbsp;&nbsp;end<br />
&nbsp;&nbsp;def assign_role(role)<br />
&nbsp;&nbsp;end<br />
end</code></p>
<p class="code"><code>$ spec user_spec.rb --format specdoc<br />
User<br />
- should be in any roles assigned to it<br />
Finished in 0.018998 seconds<br />
1 example, 0 failures</code></p>
<p>样例再次通过，但是我们的任务还没结束，只要你再回头看看我们目前的代码，就会发现这个User的行为与我们的目标还有距离。</p>
<p>现在，我们只是解决了“用户必须接受所有分配给他的角色”，但是还有一个问题就是”用户不应该接受没有分配给他的角色“。所以我们需要为用户行为再增加一个样例：</p>
<p class="code"><code class="ruby">describe User do<br />
&nbsp;&nbsp;it "should be in any roles assigned to it" do<br />
&nbsp;&nbsp;&nbsp;&nbsp;user = User.new<br />
&nbsp;&nbsp;&nbsp;&nbsp;user.assign_role("assigned role")<br />
&nbsp;&nbsp;&nbsp;&nbsp;user.should be_in_role("assigned role")<br />
&nbsp;&nbsp;end<br />
&nbsp;&nbsp;it &#8220;should NOT be in any roles not assigned to it&#8221; do<br />
&nbsp;&nbsp;&nbsp;&nbsp;user = User.new<br />
&nbsp;&nbsp;&nbsp;&nbsp;user.should_not be_in_role(&#8221;unassigned role&#8221;)<br />
&nbsp;&nbsp;end<br />
end</code></p>
<p class="code"><code>$ spec user_spec.rb --format specdoc<br />
User<br />
- should be in any roles assigned to it<br />
- should NOT be in any roles not assigned to it (FAILED - 1)<br />
1)<br />
&#8216;User should NOT be in any roles not assigned to it&#8217; FAILED<br />
expected in_role?(&#8221;unassigned role&#8221;) to return false, got true<br />
./user_spec.rb:12:<br />
Finished in 0.019014 seconds<br />
2 examples, 1 failure</code></p>
<p>失败了，用户接受了没有分给他的角色，这需要我们对User的实现做些改动：</p>
<p class="code"><code class="ruby">class User<br />
&nbsp;&nbsp;def in_role?(role)<br />
&nbsp;&nbsp;&nbsp;&nbsp;role == "assigned role"<br />
&nbsp;&nbsp;end<br />
&nbsp;&nbsp;def assign_role(role)<br />
&nbsp;&nbsp;end<br />
end</code></p>
<p>现在，一切都搞定了，但是我们的代码与样例有些重复（它们都使用了&#8221;assigned role&#8221;），因此，有必要对User类进行重构：</p>
<p class="code"><code class="ruby">class User<br />
&nbsp;&nbsp;def in_role?(role)<br />
&nbsp;&nbsp;&nbsp;&nbsp;role == @role<br />
&nbsp;&nbsp;end<br />
&nbsp;&nbsp;def assign_role(role)<br />
&nbsp;&nbsp;&nbsp;&nbsp;@role = role<br />
&nbsp;&nbsp;end<br />
end</code></p>
<p>随后，让我们再来测试一下：</p>
<p class="code"><code>$ spec user_spec.rb --format specdoc<br />
User<br />
- should be in any roles assigned to it<br />
- should NOT be in any roles not assigned to it<br />
Finished in 0.018199 seconds<br />
2 examples, 0 failures</code></p>
<p>事情就这么结束了么？你可能还有些疑惑，因为我们甚至可以将一个数字分配给用户，但这与&#8221;用户应该接受任何分配给他的角色&#8221;是吻合的，所以，这时候我们应该征求下我们的客户的意见，“每个用户在同一时间只能担当一个角色吗？”，如果客户的回答是Yes，那么很幸运，我们不需要对我们的代码进行改动，而只需对样例的描述进行一些修改，但如果客户的回答是No，那我们恐怕还得再做些工作。</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">无觅猜您也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Fadvanced-rspec-tutorials-rspec-scaffold%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F20%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec进阶指南(1): rspec_scaffold</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-07-advanced-rspec-tutorials-mocking%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F20%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec进阶指南（三）：Mocking</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F11-02-advanced-rspec-tutorials-basics%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F20%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec进阶指南(2): 基础知识</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.letrails.cn%2Farchives%2Frspec-story-tutorials%2F&from=http%3A%2F%2Fwww.letrails.cn%2Farchives%2F20%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">RSpec Story简介</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://www.letrails.cn/archives/20/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

