[rspec-users] Test for a gem/plugin?

Ashley Moran ashley.moran at patchspace.co.uk
Thu Dec 11 05:31:08 EST 2008


On 10 Dec 2008, at 17:40, James Byrne wrote:

> So, if I understand you correctly, then I should write features  
> somewhat
> like this:
>
> Scenario: A known user signs in successfully
>  Given a known user "myuser" with a password "myuserpassword"
>  When user "myuser" signs on with a password "myuserpassword"
>  Then user "myuser" is authenticated
>    And the user sees a sign in success message
>
> Scenario: A known user does not sign in successfully
>  Given a known user "myuser" with a password "myuserpassword"
>  When user "myuser" signs in with a password "anotherpassword"
>  Then user "myuser" is not authenticated
>    And the user sees a sign in failure message
>    And the user sees the sign in page
>
> And I should simply not worry about what is provided by authlogic,  
> other
> than the requisite behaviour as exhibited in this application.

That's how I (and many others here) tackle it.  But there's no need  
for the steps

   Then user "myuser" is authenticated

and

  Then user "myuser" is not authenticated

because these don't describe behaviour, they describe state.  The  
"sign in message" steps are what you really want.  And you can  
implement these as Matt described.  Since you've written steps that  
create the user (preferably through the app itself!), you could extend  
the step like this

   Given a known user "Mr Known User" with credentials "myuser" :  
"myuserpassword"

Then you already have the name to verify if you want to display a  
personalised message.  (On the other hand, putting too much data in  
the steps gets cumbersome; I tend to write them more like this:

   Scenario: A known user signs in successfully
     Given I am a registered user
     When I sign on with the correct credentials
     Then I should see a sign in success message

Even if internally I call out to steps more like the ones you wrote as  
examples.  Hope that doesn't muddy the waters though.

Ashley

-- 
http://www.patchspace.co.uk/
http://aviewfromafar.net/





More information about the rspec-users mailing list