[rspec-users] Common setup code and naming specifications
Bob Cotton
bob.cotton at rallydev.com
Thu Jan 4 22:42:48 EST 2007
Bryan Liles <bryan at osesm.com> writes:
> On Jan 4, 2007, at 6:34 PM, Bob Cotton wrote:
>
>>
>> What about:
>>
>> module LoggedIn
>> def setup
>> session[:logged_in] = true
>> end
>> end
>>
>> context "..." do
>> include LoggedIn
>> end
>>
>
> With this method, don't you lose access to setup? Seems like a lot
> to lose just to gain a a login mixin.
Sorry, LoggedIn should have been a class:
class One
def setup
puts "in setup one"
end
end
context "context with inherit" do
inherit One
setup do
puts "in context setup"
end
specify "some specify" do
puts "in specify"
end
end
$ spec foo_spec..rb
in setup one
in context setup
in specify
.
I do agree with David, that some duplication in test code is ok. It
would be easy to get the LoggedIn class buried up the inheritance
hierarchy where it can't be seen.
But if it's the only superclass of the context, and it's visible, and
it named correctly, this will save you some typing.
-Bob
--
Bob Cotton
Test Architect -- Rally Software -- rallydev.com
http://www.testarchitecture.com/blog
More information about the rspec-users
mailing list