I’ve got a greenfield Rails 3.2 app that I cannot get the first step-def to work. My cucumber-rails is (1.3.0), factory_girl_rails (3.1.0). They are both in the test environment. As per good cucumber practices, this app has NO model, generator or views written yet. I’m waiting for the nudge from the testing to drive what needs to be done.
Here is the first feature:
Background:
Given a School "Murfree High School" exists
Here’s the step definition.rb
Given /^a School "([^"]*)" exists$/ do
#Factory(:school) #fails
school = FactoryGirl.create(:school)
end
Here is my spec/factories.rb
require 'factory_girl'
FactoryGirl.define do
factory :school do
name "Murfree High School"
end
end
So I get a mismatch error because I want to make that step definition a general step so I can swap in any name of a school. BUT the point of a factory I thought is to nail down a record generation so that I can reuse that factory in other definitions, and perhaps grow it as the number of fields grow. Normally my step def would be Given /^a School “([^”]*)” exists$/ do |name| but there is no where to put that argument when I have a factory ready to go generate that test record. If I remove the quotes around the name of the high school in the feature so that this definition is “tied” to that factory, I get a yellow response from cucumber. Which begs the question: since I don’t have a model to generate into, why didn’t I receive a red error msg?
What am I overlooking in reconciling factoryGirl and a generic step definition in cucumber?
FactoryGirl includes a set of step definitions, one of which will automatically create a step called
a school exists with a name of "([^"]+)". See http://robots.thoughtbot.com/post/284805810/gimme-three-steps for the original announcement.PS: I also created a copy of the FG step definition module which does exactly the same thing, only also creates instance variables based on the name of the factory being generated. In your case, the instance variable
@schoolwould be created.