Justin,
You might reconsider that generic "user."
On 3/17/14, 11:57 PM, Justin Holzer wrote:
> I am just getting started out with writing specs using Gherkin. I think
> it's great, but there is one case in particular where I am unsure of
> what the best practice is, and was hoping you all (the wonderful
> Cucumber community), could lend some advice.
>
> I have a feature in which most, but not all, of the scenarios are
> dependent on the following "Given" conditions:
>
> * The user must be authenticated
> * The feature must be enabled for the group that the user belongs to
> * The user must also be granted explicit permissions to access the
feature
>
> I have created scenarios to provide examples of what should happen in
> the cases where each one of the above conditions is not met...
>
> |
> Scenario: The user cannot access feature X because they are not
authenticated
> Given that the user is not authenticated
> When they attempt to access feature X
> Then they receive an unauthorized error
When an unauthenticated user attempts to access feature X
Then they receive an unauthorized error
>
> Scenario: The user cannot access feature X because it is disabled for
their
> group
> Given that the user is authenticated
> And feature X is disabled for their group
> When they attempt to access feature X
> Then they receive an unauthorized error
Given feature X is disabled for group "UnuthorizedGroup"
When an authenticated user of group "UnuthorizedGroup" attempts to
access feature X
...
BTW, what is "an unauthorized error?" Is that an error that's not
allowed? ;-) Phrasing and word choice matters.
>
> Scenario: The user cannot access feature X because they are not granted
> permission to access it
> Given that the user is authenticated
> And feature X is enabled for their group
> And the user is not granted permission to access feature X
> When they attempt to access feature X
> Then the receive an unauthorized notification
> |
>
> The first scenario above will be the only scenario in which the user is
> not authenticated/signed in. Is it truly necessary to reiterate that the
> user is authenticated in every other scenario? Can the fact that the
> user is authenticated safely be assumed in all scenarios other than the
> first? If not, is there a better way to indicate that it applies to all
> scenarios, except for one, without explicitly repeating it again and
again?
Another approach would be to create one feature file for access control,
and another for use of the feature itself.
>
> It also feels like the way that I have written the above scenarios is
> implying the order in which the conditions should be checked, which is
> not what I want to imply at all. These are high level requirements after
> all, not technical design documents.
>
> Similarly, for all scenarios other than the 3 mentioned above, it will
> be a "Given" that the user is authenticated, they have the feature
> enabled for their group, and they have permission to access it. Again,
> will it really be necessary to repeat these facts for every scenario
> (other than the 3 mentioned above)?
>
> I feel like I'm missing something, as I'm sure others have encountered
> cases similar to mine. Is there a better/DRY-er way to write scenarios
> like the ones I describe? Any suggestions would be greatly appreciated!
What are the other scenarios for the feature? I would concentrate on
those, first, and then worry about the authentication and authorization.
I find it easier to make meaningful scenarios when the user is trying to
do more than get beyond an error message.
- George
--
----------------------------------------------------------------------
* George Dinwiddie *
http://blog.gdinwiddie.com
Software Development
http://www.idiacomputing.com
Consultant and Coach
http://www.agilemaryland.org
----------------------------------------------------------------------