<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: How to test flash.now in Rails</title>
	<atom:link href="http://randomba.org/2008/04/how-to-test-flashnow-in-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://randomba.org/2008/04/how-to-test-flashnow-in-rails/</link>
	<description>Programming, Ruby, Rails, and other random things.</description>
	<pubDate>Thu, 20 Nov 2008 22:36:15 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: olegueret</title>
		<link>http://randomba.org/2008/04/how-to-test-flashnow-in-rails/#comment-71</link>
		<dc:creator>olegueret</dc:creator>
		<pubDate>Wed, 17 Sep 2008 14:11:10 +0000</pubDate>
		<guid isPermaLink="false">http://randomba.org/index.php/2008/04/17/how-to-test-flashnow-in-rails/#comment-71</guid>
		<description>Since Rails 2.1 you can simply do:


def test_create_with_empty_email_sets_error_in_flash
  post :create
  assert_not_nil flash[:error]
end


(from Carlos Brando's free book: Ruby On Rails 2.1 - What's new)</description>
		<content:encoded><![CDATA[<p>Since Rails 2.1 you can simply do:</p>
<p>def test_create_with_empty_email_sets_error_in_flash<br />
  post :create<br />
  assert_not_nil flash[:error]<br />
end</p>
<p>(from Carlos Brando&#8217;s free book: Ruby On Rails 2.1 - What&#8217;s new)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Emmanuel Oga</title>
		<link>http://randomba.org/2008/04/how-to-test-flashnow-in-rails/#comment-55</link>
		<dc:creator>Emmanuel Oga</dc:creator>
		<pubDate>Fri, 20 Jun 2008 05:21:35 +0000</pubDate>
		<guid isPermaLink="false">http://randomba.org/index.php/2008/04/17/how-to-test-flashnow-in-rails/#comment-55</guid>
		<description>Funny thing, I remember having problems testing flashes with rspec also (I think my problem was with flash.now[:something], not with flash[:...], but, anyway....)

In the end I ended doing something like:


class SomeController &#60; ApplicationController
  def some_action
    ...
    flash_now(:notice, "hello")
  end

private
  def flash_now(key, something)
    flash.now[key] = something
  end
end


Then I could spec the action with something like

it "should blah blah"
  ...
  controller.should_receive(:flash_now).with(:notice, "Hello")
end


May not be the best example (you can argue now the problem is testing flash_now method :) ) but what I try to say is that sometimes is easier to change a little the code to make it more "testable".</description>
		<content:encoded><![CDATA[<p>Funny thing, I remember having problems testing flashes with rspec also (I think my problem was with flash.now[:something], not with flash[:...], but, anyway&#8230;.)</p>
<p>In the end I ended doing something like:</p>
<p>class SomeController &lt; ApplicationController<br />
  def some_action<br />
    &#8230;<br />
    flash_now(:notice, &#8220;hello&#8221;)<br />
  end</p>
<p>private<br />
  def flash_now(key, something)<br />
    flash.now[key] = something<br />
  end<br />
end</p>
<p>Then I could spec the action with something like</p>
<p>it &#8220;should blah blah&#8221;<br />
  &#8230;<br />
  controller.should_receive(:flash_now).with(:notice, &#8220;Hello&#8221;)<br />
end</p>
<p>May not be the best example (you can argue now the problem is testing flash_now method <img src='http://randomba.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ) but what I try to say is that sometimes is easier to change a little the code to make it more &#8220;testable&#8221;.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
