[rspec-users] Test for a gem/plugin?
Matt Wynne
matt at mattwynne.net
Wed Dec 10 09:54:02 EST 2008
On 9 Dec 2008, at 19:06, James Byrne wrote:
> I have decided that for now I am going to use the authlogic gem to
> provide authentication for the project I am creating. The question
> arises, since authentication is a user feature request and since it is
> to be satisfied through the use of a gem (not a plugin) then should
> one
> test for the availability of the gem or not?
>
> Secondly, given that a gem is providing the authentication logic
> (and is
> not my code which therefore should not be tested by me) then what
> should
> one test for with respect to the specific implementation? The
> existence
> of particular attributes? The existence of a users model?
>
> Does one write step definitions (assuming rspec) like:
>
> When /users are authenticated/ do
> #TODO: This does not work even when the model class exists.
> User.should exist
> end
>
> When /authentication by authlogic/ do
> #TODO: Find out how to test for a loaded gem within an application
> end
If you're working at the level of Cucumber features, I would stay well
away from implementation details like the particular technology you're
using for authentication.
Remember this is called Behaviour Driven Development[1] for a reason.
You're focussing on specifying the desired *behaviour* of the system.
How you chose to satisfy the user's need for that behaviour is an
entirely separate matter.
A large benefit of having Acceptance Tests, IMO, is that you could
radically change your implementation under the hood, such as switching
to a different authentication mechanism, and the features would still
be valid. You might have to code up some of your steps a little
differently, but as long as the users want the same thing from the
system, the features should not have to change in the slightest.
[1]http://dannorth.net/introducing-bdd
Matt Wynne
http://blog.mattwynne.net
http://www.songkick.com
More information about the rspec-users
mailing list