1

i'm using a before filter: authenticate_user! on my pages. I have cucumber tests that test behaviour on these pages, they're now failing because i don't have an authenticated user, what is the simplest way to make these tests pass? short of having to create a user each time and log him in? is there a way? i've tested that the page is not accessible if the user is not logged in, i dont want to have to test this each time i add a test for the page

using rails 3 , devise 1.2, cucumber

newbie_86
  • 4,520
  • 17
  • 58
  • 89

1 Answers1

2

You should write a reusable set of cucumber steps to log your user in for your tests. This is the way Devise explicitly suggests in their readme for testing that a user is logged in and has a proper session.

You can create reusable cucumber steps, so you only need to write the steps to log a user in once, then you can just do:

Given a valid user is logged in
When ...

There's a lot more info on using cucumber this way online, but if you want a simple example I found this one in the answer to this question.

Community
  • 1
  • 1
Brett Bender
  • 19,388
  • 2
  • 38
  • 46
  • @ Brett Bender - would you create a new user and log him in in the Given a valid user is logged in step? – newbie_86 Apr 13 '11 at 08:03
  • Waht i'm trying to avoid is creating a user over and over again. ideally, i'd like to create him once and then use the same user across tests, is that possible with cucumber? – newbie_86 Apr 13 '11 at 08:33
  • You will likely want to tag your tests that require a user be present in the database, and use a before hook to make sure the user is created before your test runs. See the wiki page about hooks: https://github.com/aslakhellesoy/cucumber/wiki/Hooks – Brett Bender Apr 13 '11 at 15:05