<?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>Web Development Advice and Tips &#187; Testing</title>
	<atom:link href="http://blog.smartlogicsolutions.com/category/testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.smartlogicsolutions.com</link>
	<description>SmartLogic Solutions Blog</description>
	<lastBuildDate>Fri, 14 Jun 2013 14:26:03 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Adding Factory Girl steps to Turnip</title>
		<link>http://blog.smartlogicsolutions.com/2012/03/28/adding-factory-girl-steps-to-turnip/</link>
		<comments>http://blog.smartlogicsolutions.com/2012/03/28/adding-factory-girl-steps-to-turnip/#comments</comments>
		<pubDate>Wed, 28 Mar 2012 13:30:02 +0000</pubDate>
		<dc:creator>Dan Ivovich</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=1142</guid>
		<description><![CDATA[<p>Recently I&#8217;ve been trying out Turnip as an alternative to Cucumber. Turnip lets you run Gherkin tests inside RSpec. When using Factory Girl, the provided step definitions can be a huge help when setting up the preconditions for a scenario. Those step definitions do not work with Turnip due to differences from Cucumber in how [...]<div class="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2010/10/26/testpilot-rails-integration-testing-pattern/"     class="crp_title">TestPilot &#8211; Rails Integration Testing Pattern</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/02/21/using-rspec-macros-and-metadata/"     class="crp_title">Using RSpec Macros and Metadata</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/07/12/curlin-for-docs/"     class="crp_title">cURLin’ for Docs</a></li><li><a href="http://blog.smartlogicsolutions.com/2013/01/23/sinatra-oauth-workflow-use-this-to-speed-up-your-app-development/"     class="crp_title">Sinatra OAuth Workflow: Use This to Speed Up Your App&hellip;</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/09/17/rest-fest-3-things-i-learned/"     class="crp_title">REST Fest &#8211; 3 Things I Learned</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/" rel="nofollow">Contextual Related Posts</a></li></ul></div></p><p>The post <a href="http://blog.smartlogicsolutions.com/2012/03/28/adding-factory-girl-steps-to-turnip/">Adding Factory Girl steps to Turnip</a> appeared first on <a href="http://blog.smartlogicsolutions.com">Web Development Advice and Tips</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Recently I&#8217;ve been trying out <a href="https://github.com/jnicklas/turnip/">Turnip</a> as an alternative to <a href="https://github.com/cucumber/cucumber">Cucumber</a>. Turnip lets you run Gherkin tests inside RSpec. When using <a title="Factory Girl" href="https://github.com/thoughtbot/factory_girl" target="_blank">Factory Girl</a>, the provided step definitions can be a huge help when setting up the preconditions for a scenario. Those step definitions do not work with Turnip due to differences from Cucumber in how Turnip defines steps. It turns out that it is very easy to convert the step definitions that Factory Girl can create into step definitions that Turnip can understand.</p>
<p><span id="more-1142"></span></p>
<p>Factory Girl defines a function &#8220;convert_human_hash_to_attribute_hash&#8221; to process the Gherkin table steps. This needs to be available to RSpec examples as Turnip creates them from your Gherkin scenarios. So start by creating a file &#8220;spec/support/factory_girl_step_helpers.rb&#8221; and add &#8220;config.include FactoryGirlStepHelpers&#8221; in your &#8220;RSpec.configure&#8221; block. The contents of the file are in <a title="FactoryGirlStepHelpers" href="https://gist.github.com/2155058#file_factory_girl_step_helpers.rb" target="_blank">this gist</a>. I have not needed to modify this module from the one that in <a href="https://github.com/thoughtbot/factory_girl/blob/master/lib/factory_girl/step_definitions.rb" target="_blank">the default Factory Girl step definition file</a>.</p>
<p>The step definitions themselves require more significant modification. Lets look at how they are defined for Cucumber:</p>
<pre class="wp-code-highlight prettyprint">Given /^an? #{human_name} exists$/i do
  FactoryGirl.create(factory.name)
end</pre>
<p>The conversion of this one into a Turnip step is straightforward:</p>
<pre class="wp-code-highlight prettyprint">step &quot;a(n) #{human_name} exists&quot; do
  FactoryGirl.create(factory.name)
end</pre>
<p>The steps that handle a table with both the pluralized and singular versions is more complicated. The Cucumber step definition is:</p>
<pre class="wp-code-highlight prettyprint">Given /^the following (?:#{human_name}|#{human_name.pluralize}) exists?:?$/i do |table|
  table.hashes.each do |human_hash|
    attributes = convert_human_hash_to_attribute_hash(human_hash, factory.associations)
    FactoryGirl.create(factory.name, attributes)
  end
end</pre>
<p>Initially I tried to use Turnip&#8217;s ability to figure out &#8220;is/are&#8221; and &#8220;exist(s)&#8221; which looked like:</p>
<pre class="wp-code-highlight prettyprint">step &quot;the following #{human_name}/#{human_name.pluralize} exist(s):&quot; do |table|
  table.hashes.each do |human_hash|
    attributes = convert_human_hash_to_attribute_hash(human_hash, factory.associations)
    FactoryGirl.create(factory.name, attributes)
  end
end</pre>
<p>This didn&#8217;t work, it caused the table that was passed to the block to not be correct.<br />
The only solution was to create 2 different step definitions, one for pluralized form and one for the singular form.</p>
<p>The final file that creates the step definitions for every defined factory is listed in <a href="https://gist.github.com/2155058#file_factory_girl_steps.rb">this gist</a>.<br />
Simply place this file in &#8220;spec/acceptance/steps&#8221;</p>
<p>Now you can easily use steps like:</p>
<pre class="wp-code-highlight prettyprint">  Given 20 things exist
  Given the following things exist:
    | name  |
    | Ruby  |
    | Rails |
    | Blog  |</pre>
<p>Now enjoy easily setting up your test database using your factories from within your Turnip feature files!</p>
<div class="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2010/10/26/testpilot-rails-integration-testing-pattern/"     class="crp_title">TestPilot &#8211; Rails Integration Testing Pattern</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/02/21/using-rspec-macros-and-metadata/"     class="crp_title">Using RSpec Macros and Metadata</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/07/12/curlin-for-docs/"     class="crp_title">cURLin’ for Docs</a></li><li><a href="http://blog.smartlogicsolutions.com/2013/01/23/sinatra-oauth-workflow-use-this-to-speed-up-your-app-development/"     class="crp_title">Sinatra OAuth Workflow: Use This to Speed Up Your App&hellip;</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/09/17/rest-fest-3-things-i-learned/"     class="crp_title">REST Fest &#8211; 3 Things I Learned</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/" rel="nofollow">Contextual Related Posts</a></li></ul></div><p>The post <a href="http://blog.smartlogicsolutions.com/2012/03/28/adding-factory-girl-steps-to-turnip/">Adding Factory Girl steps to Turnip</a> appeared first on <a href="http://blog.smartlogicsolutions.com">Web Development Advice and Tips</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2012/03/28/adding-factory-girl-steps-to-turnip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using RSpec Macros and Metadata</title>
		<link>http://blog.smartlogicsolutions.com/2012/02/21/using-rspec-macros-and-metadata/</link>
		<comments>http://blog.smartlogicsolutions.com/2012/02/21/using-rspec-macros-and-metadata/#comments</comments>
		<pubDate>Tue, 21 Feb 2012 16:00:12 +0000</pubDate>
		<dc:creator>Sam Goldman</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=1070</guid>
		<description><![CDATA[<p>I have to hand it to you: you&#8217;re a great Rails developer! I just read through the code you&#8217;ve been writing for that new project and you&#8217;re doing it right. You&#8217;ve got fast, isolated tests with RSpec, integration tests in well-written Cucumber scenarios, and have you lost weight or are your controllers skinnier? Just one nit-pick, though—where [...]<div class="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2012/10/25/api-development/"     class="crp_title">API Development: Turning Controller Actions into Services</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/10/26/testpilot-rails-integration-testing-pattern/"     class="crp_title">TestPilot &#8211; Rails Integration Testing Pattern</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/07/12/curlin-for-docs/"     class="crp_title">cURLin’ for Docs</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/12/12/api-versioning-3-ways-to-architect-your-api-to-handle-versioned-requests/"     class="crp_title">API Versioning: 3 Ways to Architect Your API to Handle&hellip;</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/10/08/testing-ajax-with-testunit/"     class="crp_title">Testing AJAX with Test::Unit</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/" rel="nofollow">Contextual Related Posts</a></li></ul></div></p><p>The post <a href="http://blog.smartlogicsolutions.com/2012/02/21/using-rspec-macros-and-metadata/">Using RSpec Macros and Metadata</a> appeared first on <a href="http://blog.smartlogicsolutions.com">Web Development Advice and Tips</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>I have to hand it to you: you&#8217;re a great Rails developer! I just read through the code you&#8217;ve been writing for that new project and you&#8217;re doing it right. You&#8217;ve got fast, isolated tests with RSpec, integration tests in well-written Cucumber scenarios, and have you lost weight or are your controllers skinnier? Just one nit-pick, though—where are your controller specs?<br />
<span id="more-1070"></span><br />
If you follow best practices, I understand that it can seem unnecessary to test your controllers: they&#8217;re so small, they are all the same, and it&#8217;s pretty hard to get it wrong. Indeed, it would probably take longer to write the tests than it would to write the controller itself and in any event you already have integration tests that are covering most of the controller code.</p>
<p>Let me tell you why I still think you should write controller tests:</p>
<ul>
<li>They are very easy to write</li>
<li>They are mostly the same</li>
<li>Because they are mostly the same, we can refactor and make them even easier to write</li>
</ul>
<p>We all refactor our code, but it&#8217;s just as important to refactor our tests. The goal of refactoring is to facilitate reuse and increase clarity. Refactoring let&#8217;s us develop new abstractions upon which we can build complex logic. Our controllers are so lean and mean because they are benefitting from a very convenient abstraction: RESTful web services.</p>
<p>Chances are most of the controllers in your app have a lot of shared behaviors. They find, create, and update your models, set flash messages, redirect or render templates, and set status codes. Let&#8217;s take advantage of the shared behaviors to refactor our tests.</p>
<p>Put the following file into spec/support/controller_helpers.rb</p>
<pre class="wp-code-highlight prettyprint">module ControllerHelpers
  extend ActiveSupport::Concern

  module ClassMethods
    def self.define_action(action)
      define_method action do |*args, &amp;block|
        options = args.extract_options!
        options[:http_method] = action
        options[:controller_method] = args[0]
        args[0] = [action.to_s.upcase, &quot;#&quot; + options[:controller_method].to_s].join(&quot; &quot;)
        args &lt;&lt; options
        context(*args, &amp;block)
      end
    end

    define_action :get
    define_action :post
    define_action :put
    define_action :delete
    define_action :head
    define_action :options

    def it_should_flash(type, message)
      it &quot;should set the flash&quot; do
        do_request
        flash[type].should eq(message)
      end
    end

    def it_should_redirect_to(&amp;block)
      it &quot;should redirect&quot; do
        url = instance_eval(&amp;block)
        do_request
        response.should redirect_to(url)
      end
    end

    def it_should_render_template(template)
      it &quot;should render the #{template} template&quot; do
        do_request
        response.should render_template(template)
      end
    end
  end

  def do_request
    params = if respond_to?(:params) then send(:params) else nil end # of story
    send(example.metadata[:http_method], example.metadata[:controller_method], params)
  end
end

RSpec.configure do |config|
  config.include ControllerHelpers, :type =&gt; :controller
end</pre>
<p>Now we can write our controller specs easily. For example:</p>
<pre class="wp-code-highlight prettyprint">require &quot;spec_helper&quot;

describe FoosController do
  get :new do
    it_should_render_template :new
  end

  post :create do
    let(:params) { &quot;foo&quot; =&gt; { &quot;bar&quot; =&gt; &quot;baz&quot; } }
    let(:foo) { stub }

    before { Foo.stub!(:new).with(&quot;bar&quot; =&gt; &quot;baz&quot;).and_return(foo) }

    context &quot;successful create&quot; do
      before { foo.stub!(:save).and_return(true) }

      it_should_set_flash :success, &quot;Created foo.&quot;
      it_should_redirect_to { foos_url }
    end

    context &quot;failed create&quot; do
      before { foo.stub!(:save).and_return(false) }

      it_should_render_template :new
    end
  end
end</pre>
<p>Enjoy!</p>
<div class="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2012/10/25/api-development/"     class="crp_title">API Development: Turning Controller Actions into Services</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/10/26/testpilot-rails-integration-testing-pattern/"     class="crp_title">TestPilot &#8211; Rails Integration Testing Pattern</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/07/12/curlin-for-docs/"     class="crp_title">cURLin’ for Docs</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/12/12/api-versioning-3-ways-to-architect-your-api-to-handle-versioned-requests/"     class="crp_title">API Versioning: 3 Ways to Architect Your API to Handle&hellip;</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/10/08/testing-ajax-with-testunit/"     class="crp_title">Testing AJAX with Test::Unit</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/" rel="nofollow">Contextual Related Posts</a></li></ul></div><p>The post <a href="http://blog.smartlogicsolutions.com/2012/02/21/using-rspec-macros-and-metadata/">Using RSpec Macros and Metadata</a> appeared first on <a href="http://blog.smartlogicsolutions.com">Web Development Advice and Tips</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2012/02/21/using-rspec-macros-and-metadata/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>TestPilot &#8211; Rails Integration Testing Pattern</title>
		<link>http://blog.smartlogicsolutions.com/2010/10/26/testpilot-rails-integration-testing-pattern/</link>
		<comments>http://blog.smartlogicsolutions.com/2010/10/26/testpilot-rails-integration-testing-pattern/#comments</comments>
		<pubDate>Wed, 27 Oct 2010 02:21:55 +0000</pubDate>
		<dc:creator>Nick Gauthier</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=1008</guid>
		<description><![CDATA[<p>I&#8217;ve been thinking about ways to simplify rails integration testing. I wanted to see how well I could do it without cucumber and rspec. I decided to go pure minitest with capybara to help out. What emerged was the TestPilot pattern. Let&#8217;s check it out. Note: all of this code is runnable via the test-pilot-demo [...]<div class="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2012/03/28/adding-factory-girl-steps-to-turnip/"     class="crp_title">Adding Factory Girl steps to Turnip</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/08/20/testing-pdf-content-with-capybara/"     class="crp_title">Testing PDF Content with Capybara</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/10/08/testing-ajax-with-testunit/"     class="crp_title">Testing AJAX with Test::Unit</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/02/21/using-rspec-macros-and-metadata/"     class="crp_title">Using RSpec Macros and Metadata</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/10/25/api-development/"     class="crp_title">API Development: Turning Controller Actions into Services</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/" rel="nofollow">Contextual Related Posts</a></li></ul></div></p><p>The post <a href="http://blog.smartlogicsolutions.com/2010/10/26/testpilot-rails-integration-testing-pattern/">TestPilot &#8211; Rails Integration Testing Pattern</a> appeared first on <a href="http://blog.smartlogicsolutions.com">Web Development Advice and Tips</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been thinking about ways to simplify rails integration testing. I wanted to see how well I could do it without cucumber and rspec. I decided to go pure minitest with capybara to help out. What emerged was the TestPilot pattern. Let&#8217;s check it out.<br />
<span id="more-1008"></span><br />
Note: all of this code is runnable via the <a href="http://github.com/ngauthier/test-pilot-demo">test-pilot-demo</a> on github.</p>
<h4>Testing the Index</h4>
<p>This one is super simple. It&#8217;s just minitest and capybara:</p>
<pre class="wp-code-highlight prettyprint">
  test &quot;See the index&quot; do
    visit root_path
    assert_see &quot;Blog Posts&quot;
  end
</pre>
<p>You&#8217;ll notice I threw in &#8220;assert_see&#8221;. It&#8217;s a simple method that wraps some capybara code:</p>
<pre class="wp-code-highlight prettyprint">
  def assert_see(content)
    assert(page.has_content?(content), &quot;Expected page to contain \&quot;#{content}\&quot;, but it didn&#039;t&quot;)
  end
</pre>
<h4>Testing Create</h4>
<p>Now we&#8217;re getting into some real data business. These were my goals:</p>
<ol>
<li>Delegate filling in the form to a reusable helper</li>
<li>Make the assertion in helper</li>
<li>Deal with models like models, not like attribute hashes</li>
</ol>
<p>Here is my test code:</p>
<pre class="wp-code-highlight prettyprint">
  test &quot;Create a new post&quot; do
    BlogPilot do
      create(
        Blog.new(:title =&gt; &#039;a blog title&#039;, :body =&gt; &#039;a blog body&#039;)
      )
    end
  end
</pre>
<p>I delegating filling out the form to BlogPilot#create_blog. I also did it by passing in a blog object to be created. You&#8217;ll note there are no assertions. This was a personal choice. I wanted to write out my steps such that they are assumed to succeed. Any step that fails will fail the test.</p>
<p>So, what&#8217;s with this pilot business? Let&#8217;s check it out:</p>
<pre class="wp-code-highlight prettyprint">
class BlogPilot &lt; TestPilot::Core
  def create(blog)
    visit root_path
    fill_in &quot;Title&quot;, :with =&gt; blog.title
    fill_in &quot;Body&quot;, :with =&gt; blog.body
    click_button &#039;Create Post&#039;
    assert_on root_path
    assert_see blog.title
    assert_see blog.body
  end
end
</pre>
<p>That&#8217;s pretty straightforward! It&#8217;s just a capybara helper. You&#8217;ll note the step makes assertions. The only way the test can proceed is <b>if this step passes</b>. That way, we&#8217;ve also abstracted the notion of &#8220;successfully creating a blog&#8221; to a single place. So if we switch between divs, tables, and lists to display our blog, we <b>only change our expectations here</b>.</p>
<p>So what&#8217;s this TestPilot::Core business? There are two reasons I had to make TestPilot:</p>
<ol>
<li>I didn&#8217;t want tons of flat helpers (i.e. create_blog, create_comment, create_user)</li>
<li>I didn&#8217;t want to have to instantiate the pilot and keep calling it. I wanted &#8220;BlogPilot do &#8230; end&#8221;</li>
</ol>
<h4>TestPilot</h4>
<p>Two things should be going through your head right now:</p>
<ol>
<li>Wait a minute, he said <b>more simple</b>! How is introducing some new <em>framework</em> going to make this simpler?</li>
<li>HOW DO I GET THE GOODNESS IN ME</li>
</ol>
<p>Luckily, the answer to both questions is the same. This is test pilot:</p>
<pre class="wp-code-highlight prettyprint">
module TestPilot
  class Core &lt; ActionDispatch::IntegrationTest
    def initialize ; end # override new from inherited class
    def self.inherited(subclass)
      TestPilot::Dsl.send(:define_method, subclass.to_s) do |&amp;block|
        subclass.new.instance_eval(&amp;block)
      end
    end
  end
  module Dsl ; end
end
</pre>
<p>It&#8217;s not a gem. It barely deserves to be in lib. This could go <em>right in your test_helper.rb</em>. What&#8217;s going to break? There are <em>two lines</em> of real code in there. And if it breaks, guess what? It&#8217;s right there in test_helper, not in some gem you have to maintain your own fork of so you can have &#8220;Nick&#8217;s raspberry flavored test::pilot&#8221;.</p>
<h4>Where am I going?</h4>
<p>So what was my goal with this? My goal is to write code like this all day:</p>
<pre class="wp-code-highlight prettyprint">
test &quot;a logged in user can comment on another user&#039;s post&quot; do
  joe = Factory :user
  bob = Factory :user
  UserPilot do
    log_in joe
  end
  PostPilot do
    @post = create(Factory.build(:post))
  end
  UserPilot do
    log_out
    log_in bob
  end     
  CommentPilot do
    create(@post, Factory.build(:comment))
  end     
end
</pre>
<p>Notice I left out any assertions. I think it would be cool to have the pilot steps themselves assert a successful action, since you probably want to check for it every time anyways.</p>
<p>I enjoy that this gives me one of my favorite benefits of cucumber: <b>reusable steps</b>. But, I can carry around instance variables in a highly visible manner, and call specialized factories without creating a one-off step that obfuscates my codebase.</p>
<p>So what do you think? Would you rather code cucumber, rspec, raw test unit, test pilot? Or have I inspired you to roll your own?</p>
<p>Code: <a href="http://github.com/ngauthier/test-pilot-demo">test-pilot-demo</a>.</p>
<div class="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2012/03/28/adding-factory-girl-steps-to-turnip/"     class="crp_title">Adding Factory Girl steps to Turnip</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/08/20/testing-pdf-content-with-capybara/"     class="crp_title">Testing PDF Content with Capybara</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/10/08/testing-ajax-with-testunit/"     class="crp_title">Testing AJAX with Test::Unit</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/02/21/using-rspec-macros-and-metadata/"     class="crp_title">Using RSpec Macros and Metadata</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/10/25/api-development/"     class="crp_title">API Development: Turning Controller Actions into Services</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/" rel="nofollow">Contextual Related Posts</a></li></ul></div><p>The post <a href="http://blog.smartlogicsolutions.com/2010/10/26/testpilot-rails-integration-testing-pattern/">TestPilot &#8211; Rails Integration Testing Pattern</a> appeared first on <a href="http://blog.smartlogicsolutions.com">Web Development Advice and Tips</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2010/10/26/testpilot-rails-integration-testing-pattern/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Testing AJAX with Test::Unit</title>
		<link>http://blog.smartlogicsolutions.com/2010/10/08/testing-ajax-with-testunit/</link>
		<comments>http://blog.smartlogicsolutions.com/2010/10/08/testing-ajax-with-testunit/#comments</comments>
		<pubDate>Fri, 08 Oct 2010 19:58:17 +0000</pubDate>
		<dc:creator>Nick Gauthier</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=979</guid>
		<description><![CDATA[<p>If you want real end-to-end testing of a page with functioning AJAX, use Selenium. But I was interested in doing just a bit of JS speccing to make sure that the AJAX routes I called worked and that the data that came back fit the JS that I had written. So, I figured with a [...]<div class="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2010/10/26/testpilot-rails-integration-testing-pattern/"     class="crp_title">TestPilot &#8211; Rails Integration Testing Pattern</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/08/20/testing-pdf-content-with-capybara/"     class="crp_title">Testing PDF Content with Capybara</a></li><li><a href="http://blog.smartlogicsolutions.com/2013/05/29/troubleshooting-konacha-timeout-errors/"     class="crp_title">Troubleshooting Konacha Timeout Errors</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/12/12/api-versioning-3-ways-to-architect-your-api-to-handle-versioned-requests/"     class="crp_title">API Versioning: 3 Ways to Architect Your API to Handle&hellip;</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/02/21/using-rspec-macros-and-metadata/"     class="crp_title">Using RSpec Macros and Metadata</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/" rel="nofollow">Contextual Related Posts</a></li></ul></div></p><p>The post <a href="http://blog.smartlogicsolutions.com/2010/10/08/testing-ajax-with-testunit/">Testing AJAX with Test::Unit</a> appeared first on <a href="http://blog.smartlogicsolutions.com">Web Development Advice and Tips</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>If you want real end-to-end testing of a page with functioning AJAX, use Selenium. But I was interested in doing just a bit of JS speccing to make sure that the AJAX routes I called worked and that the data that came back fit the JS that I had written.</p>
<p>So, I figured with a little <a href="http://github.com/jnicklas/capybara">capybara</a> and a little <a href="http://github.com/cowboyd/therubyracer">therubyracer</a>, I could test my javascript with real route calls. Let&#8217;s check it out.<br />
<span id="more-979"></span></p>
<p>The Javascript I want to test:</p>
<pre class="wp-code-highlight prettyprint">var dataObject = {};
var getRemoteData = function() {
  $.getJSON(&#039;/remote_path.json&#039;, function(data) {
    dataObject = $.parseJSON(data);
  });
}
</pre>
<p>We will pretend that hitting /remote_path.json returns the following response in JSON:</p>
<pre class="wp-code-highlight prettyprint">
{ &quot;my_information&quot;: &quot;my response data&quot; }
</pre>
<p>I want to test:</p>
<ol>
<li>That /remote_path.json is accessible and returns information</li>
<li>That dataObject is populated with a Javascript Object containing the params I pass down</li>
</ol>
<p>Here is my commented testing code:</p>
<pre class="wp-code-highlight prettyprint">
  test &#039;get some information via ajax&#039; do
    # Create a new JS Context. :with =&gt; self means that
    # the global namespace is the current context
    js = V8::Context.new(:with =&gt; self)

    # Load up our JS file
    js.load(File.join(Rails.root, &#039;public&#039;, &#039;javascripts&#039;, &#039;application.js&#039;))

    # Define a mock method for getting JSON data
    def getJSON(url, callback)
      # When the JS wants some data, get it for real w/ capybara
      visit url
      # And call the JS function passed in (ruby =&gt; js)
      callback.call(page.body)
    end

    js.eval %{
      /* Mock out jQuery */
      var $ = {};

      /* Setup the mock in the right place (JS =&gt; ruby) */
      $.getJSON = getJSON; 

      /* Mock out jquery parseJSON to call ruby JSON.parse
         Since the args are the same, it is plug and play!
         (JS =&gt; ruby) */
      $.parseJSON = JSON.parse;

      /* Trigger our JS */
      getRemoteData();

      /* Assert what we expect (JS =&gt; ruby) */
      assert_equal(&quot; &quot;, dataObject.access_key);
    }
  end
</pre>
<p>This is not an example of an incredibly useful test, but I found the ability to bind back and forth easily between ruby and javascript to be <strong>mind-blowingly incredible</strong>. I mean, look at that last line, where I call assert and pass a javascript object to it!</p>
<p>Huge thanks to <strong><a href="http://github.com/cowboyd">Charles Lowell (cowboyd)</a></strong> for his hard work on <a href="http://github.com/cowboyd/therubyracer">therubyracer</a>.</p>
<p>Enjoy the weekend! </p>
<div class="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2010/10/26/testpilot-rails-integration-testing-pattern/"     class="crp_title">TestPilot &#8211; Rails Integration Testing Pattern</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/08/20/testing-pdf-content-with-capybara/"     class="crp_title">Testing PDF Content with Capybara</a></li><li><a href="http://blog.smartlogicsolutions.com/2013/05/29/troubleshooting-konacha-timeout-errors/"     class="crp_title">Troubleshooting Konacha Timeout Errors</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/12/12/api-versioning-3-ways-to-architect-your-api-to-handle-versioned-requests/"     class="crp_title">API Versioning: 3 Ways to Architect Your API to Handle&hellip;</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/02/21/using-rspec-macros-and-metadata/"     class="crp_title">Using RSpec Macros and Metadata</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/" rel="nofollow">Contextual Related Posts</a></li></ul></div><p>The post <a href="http://blog.smartlogicsolutions.com/2010/10/08/testing-ajax-with-testunit/">Testing AJAX with Test::Unit</a> appeared first on <a href="http://blog.smartlogicsolutions.com">Web Development Advice and Tips</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2010/10/08/testing-ajax-with-testunit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Timecop 0.3.4 Released</title>
		<link>http://blog.smartlogicsolutions.com/2009/12/07/timecop-0-3-4-released/</link>
		<comments>http://blog.smartlogicsolutions.com/2009/12/07/timecop-0-3-4-released/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 21:39:06 +0000</pubDate>
		<dc:creator>John Trupiano</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[TATFT]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[rubygem]]></category>
		<category><![CDATA[tatft]]></category>
		<category><![CDATA[timecop]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=794</guid>
		<description><![CDATA[<p>Timecop 0.3.4 has just been released. To install simply run: gem install timecop. Timecop is a RubyGem providing &#8220;time travel&#8221; and &#8220;time freezing&#8221; capabilities, making it dead simple to test time-dependent code. It provides a unified method to mock Time.now, Date.today, and DateTime.now in a single call. Documentation is hosted at RubyForge. The source code [...]<div class="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2010/09/07/nicks-highlights-from-ruby-hoedown/"     class="crp_title">Nick&#8217;s Highlights from Ruby Hoedown</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/06/22/railsconf-bohconf-2010-a-retrospective/"     class="crp_title">BohConf 2010: A Retrospective</a></li><li><a href="http://blog.smartlogicsolutions.com/2013/01/15/guide-to-application-development-infrastructure-pairing-and-ci-servers/"     class="crp_title">Guide to Application Development Infrastructure: Pairing and</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/10/08/testing-ajax-with-testunit/"     class="crp_title">Testing AJAX with Test::Unit</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/12/05/how-to-save-time-when-reformatting-dates-in-vim/"     class="crp_title">Vim Tip: How to Reformat Dates in 7 Steps</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/" rel="nofollow">Contextual Related Posts</a></li></ul></div></p><p>The post <a href="http://blog.smartlogicsolutions.com/2009/12/07/timecop-0-3-4-released/">Timecop 0.3.4 Released</a> appeared first on <a href="http://blog.smartlogicsolutions.com">Web Development Advice and Tips</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Timecop 0.3.4 has just been released.  To install simply run: <code>gem install timecop</code>.</p>
<p>Timecop is a RubyGem providing &#8220;time travel&#8221; and &#8220;time freezing&#8221; capabilities, making it dead simple to test time-dependent code.  It provides a unified method to mock Time.now, Date.today, and DateTime.now in a single call.</p>
<p>Documentation is hosted at <a href="http://johntrupiano.rubyforge.org/timecop/">RubyForge</a>.  The source code is hosted at <a href="http://github.com/jtrupiano/timecop">GitHub</a>.</p>
<p>Updates include:</p>
<p><span id="more-794"></span></p>
<p><strong>Maintenance</strong></p>
<ul>
<li>Fix various timezone-related issues.  Notably, when traveling to a DateTime<br />
    instance specified in a non-local timezone, convert provided DateTime<br />
    instance to a local instance and return that from DateTime.now.<br />
    Code contributed by Michaël Witrant [<a href="http://github.com/piglop">piglop</a>]
</li>
<li>Fix bug that would not allow Timecop to be used when Ruby&#8217;s &#8216;date&#8217;<br />
    library had not been previously loaded.<br />
    Code contributed by Tuomas Kareinen [<a href="http://github.com/tuomas">tuomas</a>]
</li>
<li>Fix bug when traveling to a DateTime across a DST boundary that<br />
    resulted in DateTime&#8217;s being off by an hour.
</li>
<li>Migrate argument parsing into Timecop::TimeStackItem to reduce the<br />
    responsibility of the Timecop class.
</li>
</ul>
<div class="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2010/09/07/nicks-highlights-from-ruby-hoedown/"     class="crp_title">Nick&#8217;s Highlights from Ruby Hoedown</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/06/22/railsconf-bohconf-2010-a-retrospective/"     class="crp_title">BohConf 2010: A Retrospective</a></li><li><a href="http://blog.smartlogicsolutions.com/2013/01/15/guide-to-application-development-infrastructure-pairing-and-ci-servers/"     class="crp_title">Guide to Application Development Infrastructure: Pairing and</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/10/08/testing-ajax-with-testunit/"     class="crp_title">Testing AJAX with Test::Unit</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/12/05/how-to-save-time-when-reformatting-dates-in-vim/"     class="crp_title">Vim Tip: How to Reformat Dates in 7 Steps</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/" rel="nofollow">Contextual Related Posts</a></li></ul></div><p>The post <a href="http://blog.smartlogicsolutions.com/2009/12/07/timecop-0-3-4-released/">Timecop 0.3.4 Released</a> appeared first on <a href="http://blog.smartlogicsolutions.com">Web Development Advice and Tips</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2009/12/07/timecop-0-3-4-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Timecop 0.3.0 Released</title>
		<link>http://blog.smartlogicsolutions.com/2009/09/20/timecop-0-3-0-released/</link>
		<comments>http://blog.smartlogicsolutions.com/2009/09/20/timecop-0-3-0-released/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 03:27:34 +0000</pubDate>
		<dc:creator>John Trupiano</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[TATFT]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[rubygem]]></category>
		<category><![CDATA[tatft]]></category>
		<category><![CDATA[timecop]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=704</guid>
		<description><![CDATA[<p>Timecop 0.3.0 has just been released. To install simply run: gem install timecop. Timecop is a RubyGem providing &#8220;time travel&#8221; and &#8220;time freezing&#8221; capabilities, making it dead simple to test time-dependent code. It provides a unified method to mock Time.now, Date.today, and DateTime.now in a single call. Documentation is on RubyForge. The source code is [...]<div class="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2010/10/08/testing-ajax-with-testunit/"     class="crp_title">Testing AJAX with Test::Unit</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/11/28/using-pull-requests-to-improve-code-quality-process-and-skills/"     class="crp_title">Using Pull Requests to Improve Code Quality, Process, and&hellip;</a></li><li><a href="http://blog.smartlogicsolutions.com/2013/03/27/cocoaconf-dc-5-highlights/"     class="crp_title">Looking Back on CocoaConf DC: 5 Highlights</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/06/22/railsconf-bohconf-2010-a-retrospective/"     class="crp_title">BohConf 2010: A Retrospective</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/12/05/how-to-save-time-when-reformatting-dates-in-vim/"     class="crp_title">Vim Tip: How to Reformat Dates in 7 Steps</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/" rel="nofollow">Contextual Related Posts</a></li></ul></div></p><p>The post <a href="http://blog.smartlogicsolutions.com/2009/09/20/timecop-0-3-0-released/">Timecop 0.3.0 Released</a> appeared first on <a href="http://blog.smartlogicsolutions.com">Web Development Advice and Tips</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Timecop 0.3.0 has just been released.  To install simply run: <code>gem install timecop</code>.</p>
<p>Timecop is a RubyGem providing &#8220;time travel&#8221; and &#8220;time freezing&#8221; capabilities, making it dead simple to test time-dependent code.  It provides a unified method to mock Time.now, Date.today, and DateTime.now in a single call.</p>
<p>Documentation is on <a href="http://johntrupiano.rubyforge.org/timecop/">RubyForge</a>.  The source code is hosted at <a href="http://github.com/jtrupiano/timecop">GitHub</a>.</p>
<p>Updates include:</p>
<p><strong>API</strong></p>
<ul>
<li>Completely remove Timecop#unset_all (deprecated by Timecop#return in 0.2.0)</li>
<li>Return Time.now from #freeze, #travel and #return  &#8212; code contributed by Keith Bennett (<a href="http://github.com/keithrbennett">keithrbennett</a>)</li>
</ul>
<p><strong>Maintenance</strong></p>
<ul>
<li>Fix bug that left Time#mock_time set in some instances</li>
<li>Upped build dependency to jeweler ~> 1.2.1</li>
<li>Don&#8217;t pollute top-level namespace with classes/constants</li>
</ul>
<p><strong>Documentation</strong></p>
<ul>
<li>Clearer examples in the README, better description in the gemspec</li>
<li>Improve RDoc</li>
</ul>
<div class="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2010/10/08/testing-ajax-with-testunit/"     class="crp_title">Testing AJAX with Test::Unit</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/11/28/using-pull-requests-to-improve-code-quality-process-and-skills/"     class="crp_title">Using Pull Requests to Improve Code Quality, Process, and&hellip;</a></li><li><a href="http://blog.smartlogicsolutions.com/2013/03/27/cocoaconf-dc-5-highlights/"     class="crp_title">Looking Back on CocoaConf DC: 5 Highlights</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/06/22/railsconf-bohconf-2010-a-retrospective/"     class="crp_title">BohConf 2010: A Retrospective</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/12/05/how-to-save-time-when-reformatting-dates-in-vim/"     class="crp_title">Vim Tip: How to Reformat Dates in 7 Steps</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/" rel="nofollow">Contextual Related Posts</a></li></ul></div><p>The post <a href="http://blog.smartlogicsolutions.com/2009/09/20/timecop-0-3-0-released/">Timecop 0.3.0 Released</a> appeared first on <a href="http://blog.smartlogicsolutions.com">Web Development Advice and Tips</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2009/09/20/timecop-0-3-0-released/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Sanitize Email to Preview HTML Emails Locally</title>
		<link>http://blog.smartlogicsolutions.com/2009/04/30/using-sanitize-email-to-preview-html-emails-locally/</link>
		<comments>http://blog.smartlogicsolutions.com/2009/04/30/using-sanitize-email-to-preview-html-emails-locally/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 13:26:04 +0000</pubDate>
		<dc:creator>Nick Gauthier</dc:creator>
				<category><![CDATA[ActionMailer]]></category>
		<category><![CDATA[Configuration]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=605</guid>
		<description><![CDATA[<p>John Trupiano has a great post to get you started with sanitize_email for Ruby on Rails. I wanted to preview my HTML emails without having to fill up my online email inboxes with tons of email (and then I&#8217;d have to make filters too). I also didn&#8217;t want to manage actually sending real email. So, [...]<div class="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2012/03/28/adding-factory-girl-steps-to-turnip/"     class="crp_title">Adding Factory Girl steps to Turnip</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/07/12/curlin-for-docs/"     class="crp_title">cURLin’ for Docs</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/10/26/testpilot-rails-integration-testing-pattern/"     class="crp_title">TestPilot &#8211; Rails Integration Testing Pattern</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/02/21/using-rspec-macros-and-metadata/"     class="crp_title">Using RSpec Macros and Metadata</a></li><li><a href="http://blog.smartlogicsolutions.com/2013/01/15/guide-to-application-development-infrastructure-pairing-and-ci-servers/"     class="crp_title">Guide to Application Development Infrastructure: Pairing and</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/" rel="nofollow">Contextual Related Posts</a></li></ul></div></p><p>The post <a href="http://blog.smartlogicsolutions.com/2009/04/30/using-sanitize-email-to-preview-html-emails-locally/">Using Sanitize Email to Preview HTML Emails Locally</a> appeared first on <a href="http://blog.smartlogicsolutions.com">Web Development Advice and Tips</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.smartlogicsolutions.com/wiki/John_Trupiano">John Trupiano</a> has <a href="http://blog.smartlogicsolutions.com/2009/04/25/reintroducing-sanitize_email-work-with-production-email-without-fear/">a great post</a> to get you started with <a href="http://github.com/jtrupiano/sanitize_email/tree/master">sanitize_email</a> for Ruby on Rails.</p>
<p>I wanted to preview my HTML emails without having to fill up my online email inboxes with tons of email (and then I&#8217;d have to make filters too). I also didn&#8217;t want to manage actually sending real email. So, I set up my machine for local delivery. Read on for instructions.<br />
<span id="more-605"></span><br />
I am running Ubuntu 9.04, however these instructions should be fine at least back to 8.04.</p>
<h3>Step 1 &#8211; Install Postfix</h3>
<p><code>sudo aptitude install postfix</code></p>
<p>During the install, choose &#8220;Local Delivery Only&#8221;</p>
<h3>Step 2 &#8211; Configure Evolution for Receiving Locally</h3>
<p>Open up Evolution &#8220;Applications->Internet->Evolution Mail&#8221;</p>
<p>Set up a new account and choose local delivery. When it asks you for a path, put in:</p>
<p><code>/var/mail/&lt;username&gt;</code></p>
<p>Note that this path may not exist if you&#8217;ve never received mail.</p>
<h3>Step 3 &#8211; Configure Sanitize Email</h3>
<p>In your rails test environment.rb put:</p>
<p><code>config.action_mailer.delivery_method = :sendmail</code></p>
<p>Then, in the initializer where you set up sanitize email:</p>
<p><code>ActionMailer::Base.sanitized_recipients = ["<username>@<hostname>"]<br />
ActionMailer::Base.local_environments = %w( test )</code></p>
<p>If you need to know your username or hostname, just open up a terminal. The command &#8220;whoami&#8221; will give you your username, and &#8220;hostname&#8221; will give you the hostname.</p>
<h3>Step 4 &#8211; Run your tests</h3>
<p>Now, run your rails tests. You <em>should</em> have a test for every email you send, and that should trigger them to be sent locally. You may have to tell Evolution to Send/Receive. Keep in mind your tests will probably fail because they will expect email to be in test mode.</p>
<h3>Step 5 &#8211; Set it back</h3>
<p>Remember, when you&#8217;re done previewing your email, reset config.action_mailer.delivery_method!</p>
<div class="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2012/03/28/adding-factory-girl-steps-to-turnip/"     class="crp_title">Adding Factory Girl steps to Turnip</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/07/12/curlin-for-docs/"     class="crp_title">cURLin’ for Docs</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/10/26/testpilot-rails-integration-testing-pattern/"     class="crp_title">TestPilot &#8211; Rails Integration Testing Pattern</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/02/21/using-rspec-macros-and-metadata/"     class="crp_title">Using RSpec Macros and Metadata</a></li><li><a href="http://blog.smartlogicsolutions.com/2013/01/15/guide-to-application-development-infrastructure-pairing-and-ci-servers/"     class="crp_title">Guide to Application Development Infrastructure: Pairing and</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/" rel="nofollow">Contextual Related Posts</a></li></ul></div><p>The post <a href="http://blog.smartlogicsolutions.com/2009/04/30/using-sanitize-email-to-preview-html-emails-locally/">Using Sanitize Email to Preview HTML Emails Locally</a> appeared first on <a href="http://blog.smartlogicsolutions.com">Web Development Advice and Tips</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2009/04/30/using-sanitize-email-to-preview-html-emails-locally/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Slow Actions in Rails Projects</title>
		<link>http://blog.smartlogicsolutions.com/2009/03/13/slow-actions-in-rails-projects/</link>
		<comments>http://blog.smartlogicsolutions.com/2009/03/13/slow-actions-in-rails-projects/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 20:08:34 +0000</pubDate>
		<dc:creator>Nick Gauthier</dc:creator>
				<category><![CDATA[Benchmarking]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=565</guid>
		<description><![CDATA[<p>MySQL&#8217;s slow query log is a very handy tool to detect which SQL queries are running slowly in a production app. So what about rails applications? Often, test data only contains a small amount of data. Over time more users use the site and generate more data. A page that usually renders in 100ms could [...]<div class="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2013/05/29/troubleshooting-konacha-timeout-errors/"     class="crp_title">Troubleshooting Konacha Timeout Errors</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/09/07/nicks-highlights-from-ruby-hoedown/"     class="crp_title">Nick&#8217;s Highlights from Ruby Hoedown</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/10/25/api-development/"     class="crp_title">API Development: Turning Controller Actions into Services</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/02/21/using-rspec-macros-and-metadata/"     class="crp_title">Using RSpec Macros and Metadata</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/09/11/nicks-highlights-from-windy-city-rails/"     class="crp_title">Nick&#8217;s Highlights from Windy City Rails</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/" rel="nofollow">Contextual Related Posts</a></li></ul></div></p><p>The post <a href="http://blog.smartlogicsolutions.com/2009/03/13/slow-actions-in-rails-projects/">Slow Actions in Rails Projects</a> appeared first on <a href="http://blog.smartlogicsolutions.com">Web Development Advice and Tips</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><a href="http://dev.mysql.com/doc/refman/5.1/en/slow-query-log.html">MySQL&#8217;s slow query log</a> is a very handy tool to detect which SQL queries are running slowly in a production app.</p>
<p>So what about rails applications? Often, test data only contains a small amount of data. Over time more users use the site and generate more data. A page that usually renders in 100ms could be taking 3-5 seconds, or more!</p>
<p>I present, <a href="http://github.com/ngauthier/slow-actions/tree/master">SlowActions</a>. The goal was to analyze a standard log file to detect actions that render slowly. It had to be easy to use and also not require modification of rails&#8217; logging mechanism. Observe:</p>
<pre class="wp-code-highlight prettyprint">  $&gt; slow-actions --actions development.log
             Cost    Average Max
  - UsersController : game_history (22 entries, 0% Error)
    Total:   11275.447 3642.437 12728.0
    Render:  7.20300 2.32700 17.2450
    DB:      10.5020 3.39200 10.0000

  - QuestionsController : refresh_index_table (89 entries, 0% Error)
    Total:   908.494 202.348 307.000
    Render:  0.00000 0.00000 0.00000
    DB:      32.5880 7.25800 10.0000
</pre>
<p>More info after the break &#8230;.<br />
<span id="more-565"></span></p>
<p>So, what are we looking at? These are the top two (because I cut off the rest) results for looking at all the log entries times sorted by their Cost. The first line is the Controller followed by the Action. In parenthesis is the number of entries in the log file and the percent of those entries that had an error.</p>
<p>The second line is the total time from request to the data being sent to the user. There is a column for Cost, Avg, and Max. Max is the maximum time this action ever took. Avg is the average amount of time the action took (not counting errors). Cost = Avg * Math.Log(# entries).</p>
<p>The Cost can be thought of as that action&#8217;s share of the slowness of the site. An action that is only run once a month and takes 5 seconds is not as bad as an action run 200 times per day that takes 1 second. The Log helps smooth things out a bit.</p>
<p>There are a bunch of filters that you can put on the command:</p>
<pre class="wp-code-highlight prettyprint">$&gt; slow-actions (--actions | --controllers | --sessions) log_file [log_file ...]
    You may also specify:
      --min-cost=FLOAT
      --min-avg=FLOAT
      --min-max=FLOAT
      --start-date=YYYY-MM-DD
      --end-date=YYYY-MM-DD
</pre>
<p>You can choose to output the actions and/or controllers (in a tree format) and/or the session ids (to see which users have it the worst, this is great to find out what is causing a slow action). You can also specify multiple log files, in case you rotate your logs.</p>
<p>You can choose a cutoff cost/avg/max, which means that you could make nice short little emails to yourself every night from your app.</p>
<p>You can also specify a date range, because after you fix a bug, you want to see what kind of effect it had.</p>
<p>I took care to put in some basic RDoc to help people use slow-actions in their own tests or tasks. For example, you could run this in irb:</p>
<pre class="wp-code-highlight prettyprint">require &#039;rubygems&#039;
require &#039;slow_actions&#039;
@sa = SlowActions.new
@sa.parse_file(&#039;/path/to/my/log&#039;)
puts @sa.print_actions</pre>
<p>Have I convinced you? Then get <a href="http://github.com/ngauthier/slow-actions/tree/master">SlowActions</a> off GitHub and download it and run it on your app, you&#8217;ll be surprised!</p>
<div class="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2013/05/29/troubleshooting-konacha-timeout-errors/"     class="crp_title">Troubleshooting Konacha Timeout Errors</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/09/07/nicks-highlights-from-ruby-hoedown/"     class="crp_title">Nick&#8217;s Highlights from Ruby Hoedown</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/10/25/api-development/"     class="crp_title">API Development: Turning Controller Actions into Services</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/02/21/using-rspec-macros-and-metadata/"     class="crp_title">Using RSpec Macros and Metadata</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/09/11/nicks-highlights-from-windy-city-rails/"     class="crp_title">Nick&#8217;s Highlights from Windy City Rails</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/" rel="nofollow">Contextual Related Posts</a></li></ul></div><p>The post <a href="http://blog.smartlogicsolutions.com/2009/03/13/slow-actions-in-rails-projects/">Slow Actions in Rails Projects</a> appeared first on <a href="http://blog.smartlogicsolutions.com">Web Development Advice and Tips</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2009/03/13/slow-actions-in-rails-projects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TATFT: Test Private Methods in C++</title>
		<link>http://blog.smartlogicsolutions.com/2009/02/16/tatft-test-private-methods-in-c/</link>
		<comments>http://blog.smartlogicsolutions.com/2009/02/16/tatft-test-private-methods-in-c/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 00:46:43 +0000</pubDate>
		<dc:creator>John Trupiano</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[TATFT]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=521</guid>
		<description><![CDATA[<p>It&#8217;s very rare that I do any C++ programming these days. However, one of my oldest customers continues to utilize a C++-based optimization/statistics framework that we helped them build many years ago. The project has a wonderful purpose, and we owe quite a bit to some of the first people to trust us (thank you [...]<div class="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2012/08/28/api-planning-and-proceeding-tell-me-what-youre-working-with/"     class="crp_title">API Planning and Proceeding: Tell Me What You’re Working&hellip;</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/10/08/testing-ajax-with-testunit/"     class="crp_title">Testing AJAX with Test::Unit</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/10/26/testpilot-rails-integration-testing-pattern/"     class="crp_title">TestPilot &#8211; Rails Integration Testing Pattern</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/07/12/curlin-for-docs/"     class="crp_title">cURLin’ for Docs</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/12/05/how-to-save-time-when-reformatting-dates-in-vim/"     class="crp_title">Vim Tip: How to Reformat Dates in 7 Steps</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/" rel="nofollow">Contextual Related Posts</a></li></ul></div></p><p>The post <a href="http://blog.smartlogicsolutions.com/2009/02/16/tatft-test-private-methods-in-c/">TATFT: Test Private Methods in C++</a> appeared first on <a href="http://blog.smartlogicsolutions.com">Web Development Advice and Tips</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>It&#8217;s very rare that I do any C++ programming these days.  However, one of my oldest customers continues to utilize a C++-based optimization/statistics framework that we helped them build many years ago.  The project has a <a href="http://jama.ama-assn.org/cgi/content/abstract/293/15/1883">wonderful purpose</a>, and we owe quite a bit to some of the first people to trust us (thank you Sommer and Dorry!).</p>
<p>As a Ruby programmer, I&#8217;ve come to love test-driven programming.  As such, I&#8217;ve made an effort recently to build a test-based workflow into this existing codebase (not always the easiest thing to do, applying a test-base to a large existing codebase).  Today I found myself in dire need of being able to test private functions in C++.  As a testament to the poor state of testing in other programming languages, many message boards/threads simply told me that I was testing the wrong thing (you should test the public API, not the private implementation).  Well, needless to say, this left me a bit uncomfortable.  The fact is, the majority of my code is tucked into private methods, and I&#8217;d be left with huge long-running end-to-end tests if I strictly followed this heuristic.</p>
<p>However, I came across one golden nugget, one of the most clever hacks I&#8217;ve seen in some time.  By utilizing pre-processor directives, we can temporarily override the meaning of private and protected in C++ code, essentially aliasing it to public.</p>
<pre class="wp-code-highlight prettyprint">
 #define protected public
 #define private   public
 #include &quot;TheClassHeaderUnderTest.h&quot;
 #undef protected
 #undef private
</pre>
<p>See what this is doing?  We wrap the class that we&#8217;ll be testing in pre-processor directives to interpret protected and private as an alias for public, essentially loading that class (when including the header file) as entirely public.  This allows me to access everything!  Private methods, private variables, you name it.  And now, just like in Ruby, it&#8217;s no holds barred, allowing me to poke and prod my objects without being wrapped on the wrist by the compiler.</p>
<p>Even better, these directives simply wrap your includes in your test files.  In other words, I don&#8217;t have to change my implementation to achieve this.</p>
<p>A clever hack, no matter the language or technology, is a clever hack.  And I absolutely love this hack.</p>
<p><strong>Credit</strong>: I discovered this technique as a comment on <a href="http://c2.com/cgi/wiki?ExtremeProgrammingTestingPrivateMethods">this wiki</a>.</p>
<div class="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2012/08/28/api-planning-and-proceeding-tell-me-what-youre-working-with/"     class="crp_title">API Planning and Proceeding: Tell Me What You’re Working&hellip;</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/10/08/testing-ajax-with-testunit/"     class="crp_title">Testing AJAX with Test::Unit</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/10/26/testpilot-rails-integration-testing-pattern/"     class="crp_title">TestPilot &#8211; Rails Integration Testing Pattern</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/07/12/curlin-for-docs/"     class="crp_title">cURLin’ for Docs</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/12/05/how-to-save-time-when-reformatting-dates-in-vim/"     class="crp_title">Vim Tip: How to Reformat Dates in 7 Steps</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/" rel="nofollow">Contextual Related Posts</a></li></ul></div><p>The post <a href="http://blog.smartlogicsolutions.com/2009/02/16/tatft-test-private-methods-in-c/">TATFT: Test Private Methods in C++</a> appeared first on <a href="http://blog.smartlogicsolutions.com">Web Development Advice and Tips</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2009/02/16/tatft-test-private-methods-in-c/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Properly Setting HTTP_REFERER in a Rails Integration Test for a File Upload</title>
		<link>http://blog.smartlogicsolutions.com/2009/02/03/properly-setting-http_referer-in-a-rails-integration-test-to-upload-file/</link>
		<comments>http://blog.smartlogicsolutions.com/2009/02/03/properly-setting-http_referer-in-a-rails-integration-test-to-upload-file/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 00:38:01 +0000</pubDate>
		<dc:creator>Greg Jastrab</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[file upload]]></category>
		<category><![CDATA[integration]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=495</guid>
		<description><![CDATA[<p>This one had me frustrated for the past hour. I&#8217;ve been writing integration tests for a Rails project and got stuck on an error when I was trying to test that a file upload worked successfully and asserted a redirection was occuring correctly, but ran into the following error: Expected response to be a &#60;:redirect&#62;, [...]<div class="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2012/02/21/using-rspec-macros-and-metadata/"     class="crp_title">Using RSpec Macros and Metadata</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/10/26/testpilot-rails-integration-testing-pattern/"     class="crp_title">TestPilot &#8211; Rails Integration Testing Pattern</a></li><li><a href="http://blog.smartlogicsolutions.com/2013/05/29/troubleshooting-konacha-timeout-errors/"     class="crp_title">Troubleshooting Konacha Timeout Errors</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/10/08/testing-ajax-with-testunit/"     class="crp_title">Testing AJAX with Test::Unit</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/08/20/testing-pdf-content-with-capybara/"     class="crp_title">Testing PDF Content with Capybara</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/" rel="nofollow">Contextual Related Posts</a></li></ul></div></p><p>The post <a href="http://blog.smartlogicsolutions.com/2009/02/03/properly-setting-http_referer-in-a-rails-integration-test-to-upload-file/">Properly Setting HTTP_REFERER in a Rails Integration Test for a File Upload</a> appeared first on <a href="http://blog.smartlogicsolutions.com">Web Development Advice and Tips</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>This one had me frustrated for the past hour.  I&#8217;ve been writing integration tests for a Rails project and got stuck on an error when I was trying to test that a file upload worked successfully and asserted a redirection was occuring correctly, but ran into the following error:</p>
<pre class="wp-code-highlight prettyprint">
Expected response to be a &lt;:redirect&gt;, but was &lt;500&gt;
&lt;&quot;No HTTP_REFERER was set in the request to this action, so
redirect_to :back could not be called successfully. If this
is a test, make sure to specify
request.env[\&quot;HTTP_REFERER\&quot;].&quot;&gt;
</pre>
<p>What a lovely error message to send me on a goose chase trying to set HTTP_REFERER directly on the @request as instructed.</p>
<h4>Did Not Work</h4>
<pre class="wp-code-highlight prettyprint">
@request.env[&quot;HTTP_REFERER&quot;] = &#039;/&#039;
post upload_path, { :file =&gt; fixture_file_upload(&quot;worddoc.docx&quot;, &quot;application/msword&quot;) },
  { :html =&gt; {:multipart =&gt; true} }
assert_redirected_to &#039;/&#039;, &#039;index&#039;
</pre>
<p>This continued to spit out the same error.  I finally stumbled across <a href="http://redsquirrel.com/cgi-bin/dave/2006/08/index.html">a post back from 2006</a> that held the answer.  The HTTP_REFERER is not set the same way in an integration test:</p>
<h4>Success!</h4>
<pre class="wp-code-highlight prettyprint">
post upload_path, { :file =&gt; fixture_file_upload(&quot;worddoc.docx&quot;, &quot;application/msword&quot;) },
  { :html =&gt; {:multipart =&gt; true}, :referer =&gt; &#039;/&#039; }
assert_redirected_to &#039;/&#039;, &#039;index&#039;
</pre>
<p>Hope that saves anyone else some time if you encounter this error.</p>
<div class="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2012/02/21/using-rspec-macros-and-metadata/"     class="crp_title">Using RSpec Macros and Metadata</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/10/26/testpilot-rails-integration-testing-pattern/"     class="crp_title">TestPilot &#8211; Rails Integration Testing Pattern</a></li><li><a href="http://blog.smartlogicsolutions.com/2013/05/29/troubleshooting-konacha-timeout-errors/"     class="crp_title">Troubleshooting Konacha Timeout Errors</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/10/08/testing-ajax-with-testunit/"     class="crp_title">Testing AJAX with Test::Unit</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/08/20/testing-pdf-content-with-capybara/"     class="crp_title">Testing PDF Content with Capybara</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/" rel="nofollow">Contextual Related Posts</a></li></ul></div><p>The post <a href="http://blog.smartlogicsolutions.com/2009/02/03/properly-setting-http_referer-in-a-rails-integration-test-to-upload-file/">Properly Setting HTTP_REFERER in a Rails Integration Test for a File Upload</a> appeared first on <a href="http://blog.smartlogicsolutions.com">Web Development Advice and Tips</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2009/02/03/properly-setting-http_referer-in-a-rails-integration-test-to-upload-file/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
