It is technically possible to change your examples to group the fruits in a single scenario. Each of the steps would have to:
- Take the string of fruits
- Split them on the comma (assuming no fruits have a comma in them)
- Perform the action for each fruit
For example, your "Then I should see info" would look like:
Then /I should see the (.*) info/ do |fruit_array|
fruits = fruit_array.split(',').map(&:strip)
fruits_on_page = ['apple', 'banana', 'grape']
fruits.all? do |fruit|
fruits_on_page.should include fruit
end
end
In terms of whether it is a good idea or not, I believe the recommendation would be to use your first approach with each individual fruit being an example. The reason being that having just one assertion per test (scenario) is easier to understand and debug. However, there could be reasons to combine the tests. For example, if each example takes an hour to run, perhaps you would save time by combining them. If there is an interaction with fruits, then it might make sense to combine them to test that interaction. Another reason for not changing it, is that while your scenarios might look dryer, you step definitions are now more complicated. As well, making multiple assertions in a step can be bad since only the first failed assertion is reported (though there are hacks to address this).