[Ruby] A sensible approach to organization of hooks, helper methods, etc?

41 views
Skip to first unread message

David Troyer

unread,
May 20, 2013, 4:10:49 PM5/20/13
to cu...@googlegroups.com
Currently my primary work project's support/env.rb is a mess. It is a free for all of hooks, helper methods, with little in the way of convention or standard. Step files are similar with their own hooks and helper methods strewn about.

Has anyone come up with a decent abstract model for organizing all of this? I'm tempted to create a support/hooks.rb for ALL hooks, since order can sometimes matter. As for helper methods and the like, I'm not sure where to start. I can see using some modules for namespacing but this is a large project and I want things to remain or become usable and findable.

Thanks for your thoughts,

David Troyer

Matt Wynne

unread,
May 22, 2013, 2:05:06 PM5/22/13
to cu...@googlegroups.com
My general principle is to try to put nothing into env.rb unless I absolutely have to. I try to think about cohesion, so I'll put things that tend to change together in the same file. That means that if I have hooks and helpers for authentication, for example, I'll put both into features/support/authentication.rb. My capybara configuration lives in features/support/capybara.rb

I think anything you can do to break up your env.rb is a help though. Just start at the bottom, pulling things out into separate files. When everything's in the same file it's hard to see the dependencies, but you'll thank yourself for spending an hour or two trying to clean it up.

The other thing, which might be quite uncomfortable to confront, is that if your Cukes feel like a sprawling mess, perhaps the application you're testing has too many responsibilities? Could it be broken up into smaller projects that can be tested separately?


Reply all
Reply to author
Forward
0 new messages