<?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>Nobody Listens Anyway &#187; shoulda</title>
	<atom:link href="http://www.justinball.com/tag/shoulda/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.justinball.com</link>
	<description>Life is an optimization issue</description>
	<lastBuildDate>Sat, 31 Jul 2010 16:47:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0-alpha</generator>
		<item>
		<title>Interesting testing issue with Rails 2.3.3</title>
		<link>http://www.justinball.com/2009/07/24/interesting-testing-issue-with-rails-2-3-3/</link>
		<comments>http://www.justinball.com/2009/07/24/interesting-testing-issue-with-rails-2-3-3/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 18:14:02 +0000</pubDate>
		<dc:creator>Justin Ball</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[shoulda]]></category>
		<category><![CDATA[template not foudn]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.justinball.com/?p=1094</guid>
		<description><![CDATA[I'm not sure if this applies to all the versions of Rails, but right now I'm using the latest 2.3.3.  I'm using shoulda to do testing and my code looks like this:
&#160;
    context &#34;GET show&#34; do
      setup do
        @feed [...]]]></description>
			<content:encoded><![CDATA[<p>I'm not sure if this applies to all the versions of Rails, but right now I'm using the latest 2.3.3.  I'm using shoulda to do testing and my code looks like this:</p>
<pre class="ruby">&nbsp;
    context <span style="color:#996600;">&quot;GET show&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      setup <span style="color:#9966CC; font-weight:bold;">do</span>
        <span style="color:#0066ff; font-weight:bold;">@feed</span> = Factory<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:feed</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        get <span style="color:#ff3333; font-weight:bold;">:show</span>, <span style="color:#ff3333; font-weight:bold;">:id</span> =&gt; <span style="color:#0066ff; font-weight:bold;">@feed</span>.<span style="color:#9900CC;">to_param</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
      should_not_set_the_flash
      should_respond_with <span style="color:#ff3333; font-weight:bold;">:success</span>
      should_render_template <span style="color:#ff3333; font-weight:bold;">:show</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;</pre>
<p>The method I am testing looks like this:</p>
<pre class="ruby">&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> show
    <span style="color:#0066ff; font-weight:bold;">@feed</span> = Feed.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:id</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@entries</span> = <span style="color:#0066ff; font-weight:bold;">@feed</span>.<span style="color:#9900CC;">entries</span>
    respond_to <span style="color:#9966CC; font-weight:bold;">do</span> |format|
      <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">pjs</span> <span style="color:#006600; font-weight:bold;">&#123;</span> debugger; render <span style="color:#ff3333; font-weight:bold;">:template</span> =&gt; <span style="color:#996600;">'feeds/show'</span>, <span style="color:#ff3333; font-weight:bold;">:layout</span> =&gt; <span style="color:#0000FF; font-weight:bold;">false</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
      <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">json</span> <span style="color:#006600; font-weight:bold;">&#123;</span> render <span style="color:#ff3333; font-weight:bold;">:json</span> =&gt; <span style="color:#0066ff; font-weight:bold;">@feed</span>.<span style="color:#9900CC;">as_json</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
      <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">html</span> <span style="color:#006600; font-weight:bold;">&#123;</span> render <span style="color:#ff3333; font-weight:bold;">:template</span> =&gt; <span style="color:#996600;">'feeds/show'</span>, <span style="color:#ff3333; font-weight:bold;">:layout</span> =&gt; params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:layout</span><span style="color:#006600; font-weight:bold;">&#93;</span> || <span style="color:#0000FF; font-weight:bold;">true</span>  <span style="color:#006600; font-weight:bold;">&#125;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;</pre>
<p>The result of running this test is:<br />
<strong>Missing template feeds/show.erb in view path app/views</strong></p>
<p>That is very irritating.</p>
<p>I found that if I change the order as below everything works fine:</p>
<pre class="ruby">&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> show
    <span style="color:#0066ff; font-weight:bold;">@feed</span> = Feed.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:id</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@entries</span> = <span style="color:#0066ff; font-weight:bold;">@feed</span>.<span style="color:#9900CC;">entries</span>
    respond_to <span style="color:#9966CC; font-weight:bold;">do</span> |format|
      <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">html</span> <span style="color:#006600; font-weight:bold;">&#123;</span> render <span style="color:#ff3333; font-weight:bold;">:template</span> =&gt; <span style="color:#996600;">'feeds/show'</span>, <span style="color:#ff3333; font-weight:bold;">:layout</span> =&gt; params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:layout</span><span style="color:#006600; font-weight:bold;">&#93;</span> || <span style="color:#0000FF; font-weight:bold;">true</span>  <span style="color:#006600; font-weight:bold;">&#125;</span>
      <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">pjs</span> <span style="color:#006600; font-weight:bold;">&#123;</span> debugger; render <span style="color:#ff3333; font-weight:bold;">:template</span> =&gt; <span style="color:#996600;">'feeds/show'</span>, <span style="color:#ff3333; font-weight:bold;">:layout</span> =&gt; <span style="color:#0000FF; font-weight:bold;">false</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
      <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">json</span> <span style="color:#006600; font-weight:bold;">&#123;</span> render <span style="color:#ff3333; font-weight:bold;">:json</span> =&gt; <span style="color:#0066ff; font-weight:bold;">@feed</span>.<span style="color:#9900CC;">as_json</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;</pre>
<p>I can also change the test and explicitly list the format:</p>
<pre class="ruby">&nbsp;
    context <span style="color:#996600;">&quot;GET show&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      setup <span style="color:#9966CC; font-weight:bold;">do</span>
        <span style="color:#0066ff; font-weight:bold;">@feed</span> = Factory<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:feed</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        get <span style="color:#ff3333; font-weight:bold;">:show</span>, <span style="color:#ff3333; font-weight:bold;">:id</span> =&gt; <span style="color:#0066ff; font-weight:bold;">@feed</span>.<span style="color:#9900CC;">to_param</span>, <span style="color:#ff3333; font-weight:bold;">:format</span> =&gt; <span style="color:#996600;">'html'</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
      should_not_set_the_flash
      should_respond_with <span style="color:#ff3333; font-weight:bold;">:success</span>
      should_render_template <span style="color:#ff3333; font-weight:bold;">:show</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;</pre>
<p>I'm guessing that is the appropriate way to deal with things.  It appears that the test doesn't send in 'html' as a default format.   I might add that this test lives inside a Rails engine.  I'm not sure if that affects things, but I figure that I would list this issue here in case anyone else runs into the same problem or in case I forget how to deal with this which is quite likely.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.justinball.com/2009/07/24/interesting-testing-issue-with-rails-2-3-3/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Shoulda Craps out on Rails 2.2.2</title>
		<link>http://www.justinball.com/2008/12/20/shoulda-craps-out-on-rails-222/</link>
		<comments>http://www.justinball.com/2008/12/20/shoulda-craps-out-on-rails-222/#comments</comments>
		<pubDate>Sun, 21 Dec 2008 01:14:47 +0000</pubDate>
		<dc:creator>Justin Ball</dc:creator>
				<category><![CDATA[Funny]]></category>
		<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[shoulda]]></category>

		<guid isPermaLink="false">http://www.justinball.com/2008/12/20/shoulda-craps-out-on-rails-222/</guid>
		<description><![CDATA[I tried the latest shoulda on luvfoo a while back and it died on the internationalization stuff so we gave up.  Turns out that with the new internationalization in Rails 2.2.2 shoulda is dying again.  I know the code is free and shoulda really is a great project, but I think this shows [...]]]></description>
			<content:encoded><![CDATA[<p>I tried the latest shoulda on luvfoo a while back and it died on the internationalization stuff so we gave up.  Turns out that <a href="http://gusg.us/code/ruby/rails-2_2-headaches-1">with the new internationalization in Rails 2.2.2 shoulda is dying again.</a>  I know the code is free and shoulda really is a great project, but I think this shows why you have to be very careful about what 3rd party projects you include in your software.  All of us using shoulda are now in a holding pattern until we get an update.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.justinball.com/2008/12/20/shoulda-craps-out-on-rails-222/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Shoulda to test login &#8211; should_require_login</title>
		<link>http://www.justinball.com/2008/10/02/using-shoulda-to-test-login-should_require_login/</link>
		<comments>http://www.justinball.com/2008/10/02/using-shoulda-to-test-login-should_require_login/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 15:57:49 +0000</pubDate>
		<dc:creator>Justin Ball</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[shoulda]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.justinball.com/?p=781</guid>
		<description><![CDATA[I've had my problems with shoulda, but one very powerful component of the testing framework is the ability to create macros.  Here's one that checks to make sure a user has to be logged in to access an action.  Put it into test/shoulda_macros/authentication.rb.  (You can name the file anything you want I [...]]]></description>
			<content:encoded><![CDATA[<p>I've had my problems with shoulda, but one very powerful component of the testing framework is the ability to create macros.  Here's one that checks to make sure a user has to be logged in to access an action.  Put it into test/shoulda_macros/authentication.rb.  (You can name the file anything you want I just thought authentication.rb made sense)</p>
<pre class="ruby">&nbsp;
<span style="color:#6666ff; font-weight:bold;">Test::Unit::TestCase</span>.<span style="color:#9900CC;">class_eval</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">should_require_login</span><span style="color:#006600; font-weight:bold;">&#40;</span>*actions<span style="color:#006600; font-weight:bold;">&#41;</span>
    actions.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> |action|
      should <span style="color:#996600;">&quot;Require login for '#{action}' action&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
        get<span style="color:#006600; font-weight:bold;">&#40;</span>action<span style="color:#006600; font-weight:bold;">&#41;</span>
        assert_redirected_to<span style="color:#006600; font-weight:bold;">&#40;</span>login_url<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&lt;/ruby&gt;
&nbsp;
<span style="color:#9966CC; font-weight:bold;">Then</span> inside your controller test <span style="color:#9966CC; font-weight:bold;">do</span> something like this:
&lt;pre lang=<span style="color:#996600;">&quot;ruby&quot;</span>&gt;
<span style="color:#9966CC; font-weight:bold;">class</span> UserControllerTest &lt; <span style="color:#6666ff; font-weight:bold;">ActionController::TestCase</span>
  should_require_login <span style="color:#ff3333; font-weight:bold;">:edit</span>, <span style="color:#ff3333; font-weight:bold;">:update</span>, <span style="color:#ff3333; font-weight:bold;">:destroy</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.justinball.com/2008/10/02/using-shoulda-to-test-login-should_require_login/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Shoulda Doesn&#8217;t like &#8216;Status&#8217;</title>
		<link>http://www.justinball.com/2008/07/25/shoulda-doesnt-like-status/</link>
		<comments>http://www.justinball.com/2008/07/25/shoulda-doesnt-like-status/#comments</comments>
		<pubDate>Fri, 25 Jul 2008 22:41:31 +0000</pubDate>
		<dc:creator>Justin Ball</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[shoulda]]></category>

		<guid isPermaLink="false">http://www.justinball.com/?p=586</guid>
		<description><![CDATA[One of the models in a project I am working on right now ends in 'status'.  Rails handles that just find but in my tests I started noticing an odd error:

test: Lookup should belong_to lookup_status. (LookupTest):
NameError: uninitialized constant LookupStatu

The Shoulda test looks like this:

   should_belong_to :lookup_status

Nothing to complicated there.  Should recognizes [...]]]></description>
			<content:encoded><![CDATA[<p>One of the models in a project I am working on right now ends in 'status'.  Rails handles that just find but in my tests I started noticing an odd error:</p>
<p><code><br />
test: Lookup should belong_to lookup_status. (LookupTest):<br />
NameError: uninitialized constant LookupStatu<br />
</code></p>
<p>The Shoulda test looks like this:<br />
<code><br />
   should_belong_to :lookup_status<br />
</code></p>
<p>Nothing to complicated there.  Should recognizes the relationship just find but when it tries to find a class it goes looking for LookupStatu.  I fixed this by adding the the class name to the relationship thus:</p>
<p><code><br />
belongs_to :lookup_status, :class_name => 'LookupStatus'<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.justinball.com/2008/07/25/shoulda-doesnt-like-status/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shoulda, assert_sent_email and Unreal Users</title>
		<link>http://www.justinball.com/2008/07/24/shoulda-assert_sent_email-and-unreal-users/</link>
		<comments>http://www.justinball.com/2008/07/24/shoulda-assert_sent_email-and-unreal-users/#comments</comments>
		<pubDate>Thu, 24 Jul 2008 20:27:41 +0000</pubDate>
		<dc:creator>Justin Ball</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[assert_sent_email]]></category>
		<category><![CDATA[shoulda]]></category>

		<guid isPermaLink="false">http://www.justinball.com/?p=583</guid>
		<description><![CDATA[I have been banging my head against a problem in my testing.  Using the UI everything worked as expected, but my tests were failing when I tried to see if emails were being sent in a specific case.
Here's the test I was trying to run using Shoulda:

context "reset password for user that has not [...]]]></description>
			<content:encoded><![CDATA[<p>I have been banging my head against a problem in my testing.  Using the UI everything worked as expected, but my tests were failing when I tried to see if emails were being sent in a specific case.</p>
<p>Here's the test I was trying to run using Shoulda:<br />
<code><br />
context "reset password for user that has not been activated" do<br />
    setup do<br />
        @email = users(:not_activated_user).email<br />
        @emails.clear<br />
        # this code should send out a reset password email after setting up a password reset code.<br />
        post :create, :reset_password => {:email => users(:not_activated_user).email}<br />
    end</p>
<p>    should "send reset notification email" do<br />
        assert_sent_email do |email|<br />
            email.subject =~ /You have requested to change your/ &&<br />
            email.to.include?(@email) &&<br />
            email.body.include?("You requested that your #{GlobalConfig.application_name} password be reset, but your account is not yet active.")<br />
        end<br />
    end</p>
<p>    should_set_the_flash_to(/A password reset link has been sent to your email address/i)<br />
    should_redirect_to "login_path"</p>
<p>end<br />
</code></p>
<p>Here's the yml file I was using:<br />
<code><br />
quentin:<br />
	  login: quentin<br />
	  email: quentin@example.com<br />
	  newsletter: 1<br />
	  notify_of_events: 1<br />
	  terms_of_service: 1<br />
	  salt: 7e3041ebc2fc05a40c60028e2c4901a81035d3cd<br />
	  crypted_password: 00742970dc9e6319f8019fd54864d3ea740f04b1 # test<br />
	  activation_code: 8f24789ae988411ccf33ab0c30fe9106fab32e9b<br />
	  activated_at: <%= 5.days.ago.to_s :db %><br />
	  password_reset_code: 8f24789ae3484122cf33ab0c3ffe9106fab334de</p>
<p>not_activated_user:<br />
	  login: not_activated_user<br />
	  email: not_activated_user@example.com<br />
	  newsletter: 0<br />
	  notify_of_events: 0<br />
	  terms_of_service: 1<br />
	  salt: 7e3041ebc2fc05a40c60028e2c4901a81035d3cd<br />
	  crypted_password: 00742970dc9e6319f8019fd54864d3ea740f04b1 # test<br />
	  activation_code: 9f24789ae988411ccf33ab0c30fe9106fab32e9a<br />
	  password_reset_code: 8f24789ae3484122cf33ab0c3ffe9106fab334de<br />
</code></p>
<p>For some reason the email part of the test failed every time.  I finally changed my code to this:</p>
<p><code><br />
context "reset password for user that has not been activated" do<br />
    setup do<br />
        user = create_user<br />
        @email = user.email<br />
        @emails.clear<br />
        post :create, :reset_password => {:email => @email}<br />
     end</p>
<p>    should "send reset notification email" do<br />
        assert_sent_email do |email|<br />
            email.subject =~ /You have requested to change your/ &&<br />
            email.to.include?(@email) &&<br />
            email.body.include?("You requested that your #{GlobalConfig.application_name} password be reset, but your account is not yet active.")<br />
        end<br />
    end</p>
<p>    should_set_the_flash_to(/A password reset link has been sent to your email address/i)<br />
    should_redirect_to "login_path"</p>
<p>end<br />
</code> </p>
<p>create_user creates a user in the database instead of using the users from the users.yml file.  Using this method everything started working.  I have found that frequently I have better luck with my tests if I create real users.  I am sure there is a good reason for this, but I am stopping my research at knowing that I need to create users or other object when the tests don't work as expected.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.justinball.com/2008/07/24/shoulda-assert_sent_email-and-unreal-users/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tip for Testing Email with Ruby on Rails and Shoulda</title>
		<link>http://www.justinball.com/2008/07/24/tip-for-testing-email-with-ruby-on-rails-and-shoulda/</link>
		<comments>http://www.justinball.com/2008/07/24/tip-for-testing-email-with-ruby-on-rails-and-shoulda/#comments</comments>
		<pubDate>Thu, 24 Jul 2008 06:39:51 +0000</pubDate>
		<dc:creator>Justin Ball</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[assert_sent_email]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[shoulda]]></category>

		<guid isPermaLink="false">http://www.justinball.com/?p=580</guid>
		<description><![CDATA[Shoulda comes with a great method for testing email called 'assert_sent_email'.  (If you try it and get a method missing error update Shoulda.  Not that anyone wouldn't know to just do that).  No matter what you use to test email as long as you are in test mode your emails will be [...]]]></description>
			<content:encoded><![CDATA[<p>Shoulda comes with a great method for testing email called 'assert_sent_email'.  (If you try it and get a method missing error update Shoulda.  Not that anyone wouldn't know to just do that).  No matter what you use to test email as long as you are in test mode your emails will be placed into an array accessible using:<br />
<code><br />
ActionMailer::Base.deliveries<br />
</code></p>
<p>This is due to this line in test.rb found in the environments folder:<br />
<code><br />
config.action_mailer.delivery_method = :test<br />
</code></p>
<p>Now here's the tip.  You might think you are really smart if you take advantage of the fact that Rails has a very handy initializers folder and put a file in there called mail.rb that contains all your email settings.</p>
<p>DON'T do it.  That initializer will override your test settings and the email specific tests will always fail.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.justinball.com/2008/07/24/tip-for-testing-email-with-ruby-on-rails-and-shoulda/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
