I'm defining a feature to be used in a BDD workflow with tools such as Behat or Cucumber, using the Gherkin language. This is the feature definition so far:
Feature: Save Resource
In order to keep interesting resources that I want to view later
As a user
I need to be able to save new resources
Scenario: Saving a new resource
Given "http://google.com" is a valid link
When I insert "http://google.com" as the new resource link
And I insert "Google Search Engine" as the new resource title
Then I should see a confirmation message with the inserted link and title
When I accept
Then I should have 1 additional resource with the inserted link and title
Scenario: Aborting saving a new resource
Given "http://google.com" is a valid link
When I insert "http://google.com" as the new resource link
And I insert anything as the new resource title
Then I should see a confirmation message with the inserted link and title
When I abort
Then I should have the same number of resources as before
Scenario: Saving a resource with invalid link
Given "http://invalid.link" is an invalid link
When I insert "http://invalid.link" as the new resource link
And I insert anything as the new resource title
Then I should see a confirmation message with the inserted link and title
When I accept
Then I should see an error message telling me that the inserted link is invalid
Scenario: Saving a resource with already saved link
Given "http://google.com" is an already saved link
When I insert "http://google.com" as the new resource link
And I insert anything as the new resource title
Then I should see a confirmation message with the inserted link and title
When I accept
Then I should see an error message telling me that the inserted link already exists
As you can see, there's a lot of boilerplate repeated in several scenarios. I know I could define a Background
with a list of steps to be executed before all scenarios, where I could put all the steps up to the confirmation message, but if I did that, I wouldn't be able to distinguish among different links and titles that the user might have inserted.
Is it possible to define a background that is used only for certain, and not all, scenarios? Or maybe to concatenate two scenarios, for example requiring that a certain scenario (that I can reuse) is run before another? Or should I simply keep repeating the boilerplate?