Sivarg

You know what really grinds my gears ?

[UPDATE] : Unfortunately, I have really odd results with this method. I'll post the right method when I find it ! Sorry !

Recently, I decided to give a chance to Authlogic. Authlogic is a very powerful auth framework. I must admin I miss the simplicity of Clearance, but nevermind.

Authlogic has a lot of doc, including for testing. Anyway, the testing doc is only about Test::Unit, and I mostly use cucumber + shoulda currently.

If you want to test authlogic with cucumber, just add to your step file (features/steps/authentication_steps.rb in my case) :

Before do
include Authlogic::TestCase
activate_authlogic
end
And that's all !

Now, you can write a step like :


Given /^I am a signed in user$/ do
@user = Factory(:user) # or use fixtures, mocks, whatever !
assert @user_session = UserSession.create(@user)
assert_equal controller.session["user_credentials"], @user.persistence_token
end
and that's ALL. Don't require anything, config.gem is already loading everything for you.

Can't understand why this simple wasn't on the net before :)

Happy testing !

0 comments:

About this blog

A nice techno-tale !