Using Authlogic with Cucumber
Posted: June 27th, 2010 | Author: mindtonic | Filed under: Cucumber, Ruby, Shoulda, Testing | Tags: Authlogic, Cucumber, RSpec, Test::Unit, testing | No Comments »I have been working with Cucumber lately and have been retrofitting one of my main projects Sumuv.com with appropriate behavioral tests. We have a fully functional test suite written with Shoulda and Test::Unit, so I am not particularly interested in translating the unit and functional tests to RSpec.

This is the vegetable you are looking for.
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 the Shoulda train and move to RSpec exclusively, but I am enjoying the differences in the two platforms on this particular retrofit.
While I am mentioning the Shoulda train, I really enjoyed Thoughtbot’s post “This should_change Your Mind“. 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.
I have been a big fan of Binary Logic’s Authlogic 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.
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.
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!
http://github.com/mindtonic/AuthLogic-Cucumber-Steps
Leave a Reply