On Friday, December 14, 2012 7:11:05 AM UTC-6, Oriol Gual wrote:
Hi Jeff,
There has been some discussion about this (see
https://github.com/codegram/spinach/issues/94) and right now the consensus is that it won't be part of Spinach itself. You could try though with a plugin that extends Spinach features.
No problem! I know that this is a specific design choice for Spinach and I respect that. I'm actually curious about this notion. For example, in my tests we have need of creating a lot of entities in our system. So we'll have statements like this:
the base product is created by a clinical administrator
the base therapeutic area is created by a system administrator
the base indication is created
the base plan is created
the base study is created
And so on. The idea is that these are contexts that are established because we create all data on the fly. If a specific role is not mentioned (as in the last three), then we default to a basic user. Now in Cucumber I originally used what some people hate: regex. I did this:
Given (/^the base (.*) is created(?: by a (.*))?$/) do |entity, role|
Obviously that's pretty hard on the eyes. :) But it does nicely allow me to keep things DRY because then I have steps in that When method like this:
on_view(LoginPage).login_as(role)
on(Navigation).go_to_list_page(entity)
on(CreateEntity).enter_data_for(entity)
The fact that I can have an optional part to the matcher means that I can let the business write things as they want. I'm not sure that Placeholders would be any better or worse than regex. So here's my question to the Spinach crew: how would you do the above? Would you just have one matcher for each possible phrase? In that case, it means each Given method would have to have very similar logic in place. So, it would be like this:
===============================
Given (the base product is created by a clinical administrator) do
on_view(LoginPage).login_as("clinical administrator")
on(Navigation).go_to_list_page("product")
on(CreateEntity).enter_data_for("product")
end
Given (the base therapeutic area is created by a system administrator) do
on_view(LoginPage).login_as("system administrator")
on(Navigation).go_to_list_page("therapeutic area")
on(CreateEntity).enter_data_for("therapeutic area")
end
===============================
But that seems like I'm adding a lot of bloat and duplication since I don't have a way to DRY it up without regex or placeholders. But maybe I'm thinking of it wrong.