rubytestingcucumberpicklemachinist

How to use named Machinist blueprints in Cucumber with Pickle


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?


Solution

  • 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.