[rspec-users] Common setup code and naming specifications

David Chelimsky dchelimsky at gmail.com
Thu Jan 4 18:12:18 EST 2007

On 1/4/07, Tobias Grimm <listaccount at e-tobi.net> wrote:
> Hello!
> I have a lot of contexts for testing Rails controllers, that must do
> something like 'session[:logged_in] = true' in their setup. How can this
> be refactored? In unit tests I would simply create a
> LoggedInControllerTest base class, that all my functional tests would
> derive from.

module MyHelpers
  def set_logged_in
    session[:logged_in] = true

context "..." do
  include MyHelpers
  setup do

> And another small question:
> In my controller specifications I often have to decide whether to write:
> specify "should provide the first ten items in @items and three pages in
> @pages when passing no :page parameter to the :list action"
> or
> specify "should provide the first ten items and three pages when not
> selecting a specific page"

Definitely the latter. These names should be how the customer would
talk about requirements, not how developers would - UNLESS you're
writing a framework for developers and developers ARE your customers.


> So the decision is, whether to explicitly name parameters, return values
> and actions or to use a more abstract phrase. How do you handle this?
> Sorry, might be a stupid question, but I'm, still trying to get the
> right "feeling" for BDD-style testing.
> bye,
> Tobias
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list