<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>5Valleys Blog</title>
    <link>http://5Valleys.com/tags/#{params[:tag_id]/posts</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Rails, Software Development, Western Montana, and other incoherent ramblings.</description>
    <item>
      <title>ICandy</title>
      <description>At my day job we have several Rails apps that we've built and continue to maintain and enhance. We often add features that are usable in all of our applications, so although they're often initially developed in one app or another, they quickly get turned into plugins that we can share across all of our apps. &lt;a href='http://www.5valleys.com/posts/58-ICandy'&gt;continue...&lt;/a&gt;</description>
      <pubDate>Sat, 10 May 2008 16:19:04 +0000</pubDate>
      <link>http://www.5valleys.com/posts/58-ICandy</link>
      <author>jsgarvin</author>
      <category>ICandy</category>
      <category>Rails</category>
      <category>Testing</category>
    </item>
    <item>
      <title>ARID 0.5 Released</title>
      <description>I've just released ARID 0.5. This is a minor update with some small bug fixes and optimizations. &lt;a href='http://www.5valleys.com/posts/51-ARID-0-5-Released'&gt;continue...&lt;/a&gt;</description>
      <pubDate>Sun, 13 Apr 2008 19:07:00 +0000</pubDate>
      <link>http://www.5valleys.com/posts/51-ARID-0-5-Released</link>
      <author>jsgarvin</author>
      <category>Rails</category>
      <category>ARID</category>
      <category>Testing</category>
      <category>Ajax</category>
    </item>
    <item>
      <title>ARID 0.4 Release Party</title>
      <description>ARID has a new home of it's own on RubyForge, and version 0.4 and improved documentation is now available.

ARID (ActiveResourceIntegrationDSL) is a Ruby on Rails plugin providing methods for simple and DRY integration testing of conventions-compliant RESTful Rails applications.

This version contains significant changes to how test methods are formatted and is NOT backwards compatible with tests for
prior versions. &lt;a href='http://www.5valleys.com/posts/25-ARID-0-4-Release-Party'&gt;continue...&lt;/a&gt;</description>
      <pubDate>Sat, 13 Oct 2007 15:04:00 +0000</pubDate>
      <link>http://www.5valleys.com/posts/25-ARID-0-4-Release-Party</link>
      <author>jsgarvin</author>
      <category>Rails</category>
      <category>ARID</category>
      <category>Testing</category>
      <category>REST</category>
    </item>
    <item>
      <title>Keep your Integration Tests DRY with ARID (ActiveResourceIntegrationDsl)</title>
      <description>
I just released version 0.2 of ARID (ActiveResourceIntegrationDsl) [formerly known as RestfulCrudIntegrationTester].  I've been working with this on three different projects for the past week and so far am very happy with it.

Besides the name change, there's a couple major enhancements.
 &lt;a href='http://www.5valleys.com/posts/17-Keep-your-Integration-Tests-DRY-with-ARID-ActiveResourceIntegrationDsl-'&gt;continue...&lt;/a&gt;</description>
      <pubDate>Fri, 22 Jun 2007 20:02:23 +0000</pubDate>
      <link>http://www.5valleys.com/posts/17-Keep-your-Integration-Tests-DRY-with-ARID-ActiveResourceIntegrationDsl-</link>
      <author>jsgarvin</author>
      <category>Ruby</category>
      <category>Rails</category>
      <category>ARID</category>
      <category>Testing</category>
    </item>
    <item>
      <title>It Just Works</title>
      <description>When working with Rails full time, it's easy to grow accustomed to the fact that when you do things right, other things &quot;just work&quot; without you doing anything else. &lt;a href='http://www.5valleys.com/posts/16-It-Just-Works'&gt;continue...&lt;/a&gt;</description>
      <pubDate>Tue, 19 Jun 2007 19:45:49 +0000</pubDate>
      <link>http://www.5valleys.com/posts/16-It-Just-Works</link>
      <author>jsgarvin</author>
      <category>Rails</category>
      <category>REST</category>
      <category>ARID</category>
      <category>Testing</category>
    </item>
    <item>
      <title>First Plugin Released and Site Makeover</title>
      <description>Took a little time today to give the site a makeover, and fix some small bugs.  I still don't claim to have any eye for aesthetics, but I think this probably looks a lot nicer than before. Clean &amp; simple.

I also released my first public Rails plugin this morning (with the wildly clever name of RestfulCrudIntegrationTester), a whole 36 hours sooner than I thought I would yesterday.

I've just finally started delving into Integration Testing (yah, I know, I'm a little late to the party.) I was writing tests for two different projects (one at home and one at work) and noticed even though they were very different projects, I was duplicating a lot of low level integration test code. So... I extracted it out into a plugin.

Now, on both projects, and any others I use the plugin in, I can just say things like...

new_session_as('jon','Exc3l1ent_p@s5w0rd!') do |jon|
  jon.updates_article(1,{:article =&gt; {:subject =&gt; 'New Subject'}})
end

And then the Plugin will go try to login as that user (using the sessions_controller), and exercise both the edit and update actions in the articles_controller, as well as confirm that the edit form has the correct action, method, and input elements for a RESTful update.

Note, that the plugin is only for very RESTful controllers (if you didn't get that already), and it makes a few big assumptions on how your Rails app works. I tried to make sure the assumptions followed Rails conventions as much as possible.
 
Some of the initial code came from Jamis Buck's post on the subject from over a year ago, (yah, yah, late to the party) so thanks to Jamis for getting me started on the right path.

Strangly, as long as Integration Testing has been around, I didn't find any existing plugins to provide this kind of basic framework. So, I'm hoping I didn't waste time reinventing the wheel, and instead have found an unfilled need and provided a worthwhile contribution to the Rails community. Time will tell on that.

Here's the complete README file from the 0.1 version of plugin.

RestfulCrudIntegrationTester
============================
Provides a framework of common integration
tests for RESTful CRUD interactions.

How To Use
==========
class ArticleTest &lt; ActionController::IntegrationTest
  include RestfulCrudIntegrationTester
  
  def test_some_article_functionality
  	new_session_as('jonnyg','testing123') do |jon|
      params = {
      	:article =&gt; {
      		:title =&gt; 'Foo Bites Bar',
      		:content =&gt; 'Bar was bitten by Foo yesterday.' 
      	}
      }
      jon.creates_story(params)
      params = {:article =&gt; {:title =&gt; 'Bar Bitten Badly'}}
      jon.updates_story(1,params)
      jon.reads_story(1)
      jon.deletes_story(1)
    end
  end
end

Assumptions
===========
The plugin makes certain assumptions about your application.
Some of these can be bypassed or overridden if your app does
not conform.

* you have appropriate map.resources lines in your routes.rb
	for any controllers you intend to test with these methods.
* sessions_path helper method returns the path to a controller
	that controls user logins. (Provided automatically by
	Rails if you have a sessions_controller and routes.rb
	includes &quot;map.resources :sessions&quot;.)
	@ Override by adding your own sessions_path method to
	application_helper
	
* your sessions controller accepts parameters in the form of...
	{:user =&gt; {:username =&gt; 'xxx', :password =&gt; 'yyy'}}
	@ Override by providing your own new_session_as method
		that generates an appropriate session for your app
		with the user provided.

Provided Methods
================
-Create Sessions-
-----------------
new_session:
	creates generic session (i.e. user not logged into your site).
	
	#example
	new_session do |guest|
		#guest.does_things here
	end
	
new_session_as:
	creates session as user with provided username and password.
	
	***assumes that you have a 'sessions_controller' and that it
	takes params in the form of... 
	{:user =&gt; {:username =&gt; 'xxx', :password =&gt; 'yyy'}}
	
-Do CRUD-
---------
All CRUD tasks can be passed a block to do additional assertions
sess.reads_():
	performs a GET to _path()
	asserts a :success response
	yields if you passed a block containing more assertions
	
sess.creates_():
	performs a GET to new__path
	asserts a :success response
	asserts page contains a form with a _path action
		and a 'post' method.
	asserts form contains appropriately named input elements
		for each of the  you provided.
		i.e. 'person[first_name]'
	performs a POST to _path passing 
	yields if you passed a block containing more assertions
	if you did NOT pass a block
		asserts a :redirect response
		follows redirect
		asserts a :success response
	
	
sess.updates_(,)
	performs a GET to edit__path()
	asserts a :success response
	asserts page contains a form with a _path action
		and a 'post' method.
        asserts form contains a hidden input field named '_method'
    	        and a value of 'put'.
	asserts form contains appropriately named input elements
		for each of the  you provided.
		i.e. 'person[first_name]'
	performs a PUT to _path passing 
	yields if you passed a block containing more assertions
	if you did NOT pass a block
		asserts a :redirect response
		follows redirect
		asserts a :success response
		
sess.deletes_():
	performs a DELETE to _path()
	yields if you passed a block containing more assertions
	if you did NOT pass a block
		asserts a :redirect response
		follows redirect
		asserts a :success response
 &lt;a href='http://www.5valleys.com/posts/15-First-Plugin-Released-and-Site-Makeover'&gt;continue...&lt;/a&gt;</description>
      <pubDate>Sat, 16 Jun 2007 19:16:19 +0000</pubDate>
      <link>http://www.5valleys.com/posts/15-First-Plugin-Released-and-Site-Makeover</link>
      <author>jsgarvin</author>
      <category>Testing</category>
      <category>Rails</category>
      <category>ARID</category>
      <category>Ruby</category>
    </item>
  </channel>
</rss>
