[rspec-users] What's the best way to test inherited behavior?
Hongli Lai
hongli at plan99.net
Thu Oct 9 15:35:42 EDT 2008
Pat Maddox wrote:
> I've written [1] about using shared example groups to do this sort of
> things. You're already using them :) but maybe you can still get
> something out of that post.
>
> What specifically don't you like about this solution?
What Matt proposed is very nice. :) I was struggling with finding a good
way to name my specs.
However, by calling the shared example "a server" I can still end up
with weird names:
describe FrameworkSpawner
describe "when in conservative spawning mode"
before :each do
..
end
it_should_behave_like "an AbstractServer"
end
describe "when in smart spawning mode"
before :each do
end
it_should_behave_like "an AbstractServer"
end
end
So I can end up with a weird sentence like:
"FrameworkSpawner when in smart spawning mode an AbstractServer raises
AlreadyStarted if the child process is still running"
Shared example groups *are* a blessing. Just the constructed sentences
bother me sometimes. :) I'm also wondering whether it's a good idea to
test my child classes like this, or whether I should test the parent
class separately, and not test the child classes for the parent class's
behaviors.
More information about the rspec-users
mailing list