views:

171

answers:

2

I noticed this little tid-bit in the readme for pickle:

(The latest version of pickle supports multiple blueprints, for earlier versions of machinist use pickle <= 0.1.10)

I'm running in to a situation where I want to create a user with admin privileges. I've got two machinist blueprints:

User.blueprint do
  first_name
  last_name
  email
  password { "password" }
  password_confirmation { "password" }
  state "active"
end

User.blueprint(:super_admin) do
  roles { ["super-admin", "moderator"] }
end

Rather than creating a custom step for myself to create the super-admin user, I was wondering if there's a way to do it using Pickle.

Using the following will use the normal pickle step and reference the basic machinist User blueprint:

Given a user exists with first_name: "Test", last_name: "Man"

The question is, how do I say that I want a super-admin user?

+1  A: 

Not sure how this would be done in Pickle, with the very similar gem Cucumber Factory you could create a super-admin user like this:

Given there is a user (super admin) with the first name "Test" and the last name "Man"
henning-koch
Thanks Henning, I wasn't aware of this gem's existence. I'll have to give it a go next time I start up another project.
Chris
A: 

So it turns out that creating named Machinist blueprints in Pickle is pretty simple:

Given a super admin user exists with first_name: "Test", last_name: "Man"

This line will call the same pickle step, but Pickle is intelligent enough to map the text "super admin user" to the User.blueprint(:super_admin) factory.

It's such an obvious method that I really should have just tried it before asking. The documentation for Pickle doesn't explicitly mention the syntax for doing this anywhere, only that it's possible to do. So now we know.

Chris