[rspec-users] Common setup code and naming specifications
Bob Cotton
bob.cotton at rallydev.com
Thu Jan 4 18:34:14 EST 2007
"David Chelimsky" <dchelimsky at gmail.com> writes:
> 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
> end
> end
>
> context "..." do
> include MyHelpers
> setup do
> set_logged_in
> end
> end
>
What about:
module LoggedIn
def setup
session[:logged_in] = true
end
end
context "..." do
include LoggedIn
end
A little less typing, and just as clear.
-Bob
>>
>> 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.
>
> David
>
>> 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
>>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
--
Bob Cotton
Test Architect -- Rally Software -- rallydev.com
http://www.testarchitecture.com/blog
More information about the rspec-users
mailing list