<?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>Mindtonic &#187; Ruby</title>
	<atom:link href="http://blog.mindtonic.net/category/development/ruby-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mindtonic.net</link>
	<description>Thoughts on Music and Application Development</description>
	<lastBuildDate>Fri, 30 Jul 2010 18:08:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Using Authlogic with Cucumber</title>
		<link>http://blog.mindtonic.net/using_authlogic_with_cucumber/</link>
		<comments>http://blog.mindtonic.net/using_authlogic_with_cucumber/#comments</comments>
		<pubDate>Sun, 27 Jun 2010 21:37:40 +0000</pubDate>
		<dc:creator>mindtonic</dc:creator>
				<category><![CDATA[Cucumber]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Shoulda]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Authlogic]]></category>
		<category><![CDATA[RSpec]]></category>
		<category><![CDATA[Test::Unit]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://blog.mindtonic.net/?p=146</guid>
		<description><![CDATA[I have created a set of Authlogic behavior steps to use in my Cucumber tests.  These steps cover most of your basic functionality and provide some helper functions that you can use in your other step definitions.  The Cucumber feature definitions cover the major elements of authentication: logging in, logging out and the presence of a UserSession. http://github.com/mindtonic/AuthLogic-Cucumber-Steps]]></description>
			<content:encoded><![CDATA[<p>I have been working with <a title="Cucumber BDD" href="http://cukes.info/">Cucumber</a> lately and have been retrofitting one of my main projects <a title="sumuv.com" href="http://sumuv.com">Sumuv.com</a> with appropriate behavioral tests.  We have a fully functional test suite written with <a href="http://github.com/thoughtbot/shoulda">Shoulda</a> and Test::Unit, so I am not particularly interested in translating the unit and functional tests to RSpec.</p>
<div style="float: right; padding: 10px; margin: 5px; border: groove 1px #000;text-align:center;"><img src="http://maggiesfarm.anotherdotcom.com/uploads/cucumber.jpg" alt="" /><br />
<strong>This is the vegetable you are looking for.</strong></div>
<p>I figured that since the Cucumber BDD tests are completely different than the Shoulda unit and functional tests, I could just slip my Cucumber steps right on in.  It does seem a little strange to be writing the functional tests in Test::Unit and the behavioral steps in RSpec.  In the future I will probably follow <a href="http://robots.thoughtbot.com/post/701863189/shoulda-rails3-and-beyond">the Shoulda train</a> and move to RSpec exclusively, but I am enjoying the differences in the two platforms on this particular retrofit.</p>
<p>While I am mentioning the Shoulda train, I really enjoyed <a href="http://robots.thoughtbot.com/">Thoughtbot&#8217;s</a> post &#8220;<a title="This should_change Your Mind" href="http://robots.thoughtbot.com/post/731871832/this-should-change-your-mind">This should_change Your Mind</a>&#8220;.  Their very simple explanations of the difference between behavioral testing and functional testing created a clear distinction in my mind.  It was the golden nugget of wisdom I had been looking for.</p>
<p>I have been a big fan of <a href="http://www.binarylogic.com/">Binary Logic&#8217;s</a> <a href="http://github.com/binarylogic/authlogic">Authlogic</a> gem for handling site authentication and user sessions.  I love the clean interface and versatility.  A lot of forethought went in to make this an elegant interface on top of some pretty robust and secure code.</p>
<p>As a result of this work, I have created a set of Authlogic behavior steps to use in my Cucumber tests.  These steps cover most of your basic functionality and provide some helper functions that you can use in your other step definitions.  The Cucumber feature definitions cover the major elements of authentication: logging in, logging out and the presence of a UserSession.</p>
<p>I will continue to improve the quality and coverage of these features.  I plan to include a set of features to cover user registration.  I offer this here because I find it useful for my other projects.  If you find it helpful too, please let me know!</p>
<p><strong><a title="AuthLogic Cucumber Steps" href="http://github.com/mindtonic/AuthLogic-Cucumber-Steps">http://github.com/mindtonic/AuthLogic-Cucumber-Steps</a></strong></p>
<textarea cols="40" rows="10" name="code" class="Ruby"># Authlogic ~ Cucumber Authentication Steps

Before do
	include Authlogic::TestCase
	activate_authlogic
end

#
# Helper Methods available to other steps
#

def create_user(login)
  @current_user = User.create!(
    :login => login,
    :password => 'generic',
    :password_confirmation => 'generic',
    :email => "#{login}@example.com"
  )
end

def login_user
  visit "/login" 
  fill_in("login", :with => @current_user.login) 
  fill_in("password", :with => 'generic') 
  click_button("Login")
end

def logout_user
  session = UserSession.find
  session.destroy if session
end

def user_session
  @session ||= UserSession.find
end

#
# Cucumber Assertions
#

Given /^I am the user "(.*)"$/ do |login|
  create_user login
end

Given /^I am logged in as "(.*)"$/ do |login|
  create_user login
  login_user
end

Given /^I am not logged in$/ do
  logout_user
end

When /^I Log In$/ do
  login_user
end

When /^I logout$/ do
  logout_user
end

Then /^there should be a session$/ do
  user_session
  @session.should_not be nil
end

Then /^there should not be a session$/ do
  user_session
  @session.should be nil
end

Then /^the user should be "([^"]*)"$/ do |login| #"
  user_session
  @session.user.login.should be == login
end
</textarea>
	<!-- WordPress Code Snippet -->
	<script type="text/javascript" src="http://blog.mindtonic.net/wp-content/plugins/wordpress-code-snippet/js/shCore.js"></script><script type="text/javascript" src="http://blog.mindtonic.net/wp-content/plugins/wordpress-code-snippet/js/shBrushRuby.js"></script>
	<link type="text/css" rel="stylesheet" href="http://blog.mindtonic.net/wp-content/plugins/wordpress-code-snippet/css/SyntaxHighlighter.css"/>
	
	<script language="javascript">
	dp.SyntaxHighlighter.ClipboardSwf = 'http://blog.mindtonic.net/wp-content/plugins/wordpress-code-snippet/js/clipboard.swf';
	dp.SyntaxHighlighter.HighlightAll('code');
	</script>
	<!-- End WordPress Code Snippet -->
	]]></content:encoded>
			<wfw:commentRss>http://blog.mindtonic.net/using_authlogic_with_cucumber/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calculating The Number Of Months Between Two Dates In Ruby</title>
		<link>http://blog.mindtonic.net/calculating-the-number-of-months-between-two-dates-in-ruby/</link>
		<comments>http://blog.mindtonic.net/calculating-the-number-of-months-between-two-dates-in-ruby/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 18:08:44 +0000</pubDate>
		<dc:creator>mindtonic</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blog.mindtonic.net/?p=114</guid>
		<description><![CDATA[My research led me here: http://www.francisfish.com/getting_the_number_of_months_between_two_dates_in_rubyrails.htm def months_between( startdate = Time.now, enddate = Time.now ) (enddate.month - startdate.month) + 12 * (enddate.year - startdate.year) end dp.SyntaxHighlighter.ClipboardSwf = 'http://blog.mindtonic.net/wp-content/plugins/wordpress-code-snippet/js/clipboard.swf'; dp.SyntaxHighlighter.HighlightAll('code');]]></description>
			<content:encoded><![CDATA[<p>My research led me here: <a href="http://www.francisfish.com/getting_the_number_of_months_between_two_dates_in_rubyrails.htm">http://www.francisfish.com/getting_the_number_of_months_between_two_dates_in_rubyrails.htm</a></p>
<textarea cols="40" rows="10" name="code" class="Ruby">def months_between( startdate = Time.now, enddate = Time.now )
  (enddate.month - startdate.month) + 12 * (enddate.year - startdate.year) 
end</textarea>
	<!-- WordPress Code Snippet -->
	<script type="text/javascript" src="http://blog.mindtonic.net/wp-content/plugins/wordpress-code-snippet/js/shCore.js"></script><script type="text/javascript" src="http://blog.mindtonic.net/wp-content/plugins/wordpress-code-snippet/js/shBrushRuby.js"></script>
	<link type="text/css" rel="stylesheet" href="http://blog.mindtonic.net/wp-content/plugins/wordpress-code-snippet/css/SyntaxHighlighter.css"/>
	
	<script language="javascript">
	dp.SyntaxHighlighter.ClipboardSwf = 'http://blog.mindtonic.net/wp-content/plugins/wordpress-code-snippet/js/clipboard.swf';
	dp.SyntaxHighlighter.HighlightAll('code');
	</script>
	<!-- End WordPress Code Snippet -->
	]]></content:encoded>
			<wfw:commentRss>http://blog.mindtonic.net/calculating-the-number-of-months-between-two-dates-in-ruby/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
