Spinach with Placeholders

39 views
Skip to first unread message

Jeff Nyman

unread,
Dec 14, 2012, 6:49:39 AM12/14/12
to spina...@googlegroups.com
Greetings all.

I know that as part of its design approach Spinach does not allow the concept of regex (which I'm pretty much okay with) but also doesn't allow for placeholders, such as what Turnip provides. That's the part I'm less okay with -- although I'm still deciding on that, to be honest. I can see valid arguments on both sides of that debate.

Anyway, I was going to attempt a fork of Spinach just to see if I could put a placeholder concept in. Before I did so, I wanted to see if anyone had already started on this path or was actively working on such an approach. I see lots of forks on Github but it's difficult to tell if anyone is doing much with those forks.

Thanks.

- Jeff

Oriol Gual

unread,
Dec 14, 2012, 8:11:05 AM12/14/12
to spina...@googlegroups.com
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.

Cheers.

Jeff Nyman

unread,
Dec 14, 2012, 3:00:47 PM12/14/12
to spina...@googlegroups.com

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.

Oriol Gual

unread,
Dec 14, 2012, 3:26:46 PM12/14/12
to spina...@googlegroups.com
I understand you'd like to DRY on defining so many steps, but I would go against that.

What do you think of actually defining multiple steps, but the steps use a factory method to create the entity you need?

===============================
  Given (the base product is created by a clinical administrator) do
    create_entity("clinical administrator", "product")
  end

  Given (the base therapeutic area is created by a system administrator) do
    create_entity("system administrator", "therapeutic area")
  end

  def create_entity(author, type)
    on_view(LoginPage).login_as("system administrator")
    on(Navigation).go_to_list_page("therapeutic area")
    on(CreateEntity).enter_data_for("therapeutic area")
  end
===============================

Would this be OK?

Jeff Nyman

unread,
Dec 14, 2012, 4:01:30 PM12/14/12
to spina...@googlegroups.com

On Friday, December 14, 2012 2:26:46 PM UTC-6, Oriol Gual wrote:
 
What do you think of actually defining multiple steps, but the steps use a factory method to create the entity you need?

Would this be OK?

Yes, that seems to work perfectly well.

You gave me the shift in focus I needed! Much thanks.

Oriol Gual

unread,
Dec 14, 2012, 4:07:40 PM12/14/12
to spina...@googlegroups.com
Glad I could help :)
Reply all
Reply to author
Forward
0 new messages