I'm using cucumber and factory girl with very good results, but I'm finding that the syntax is a little bit forced.
Assuming there are valid factories for my model, I'd like a generic cucumber helper/step
Given a model exists
When I visit the model's edit page
I know the portion of the step going to the page but having the step know that #{the model} is referi开发者_开发知识库ng to an instance would that would go in edit_model_path(@model) is what I'm looking for.
As always, thanks very much for the help.
Pass the a string in representing the class...so for the class Thing, use the string 'thing'. Once you have this in a step you should be good to go, I'd think...
You could probably use the class name to build up the URL to your edit page. You can actually get the class constant from it's name using this code :
my_model = "thing".classify.constantize
my_instance = my_model.find(...)
I think this would let you generalize the step enough, no?
What you're looking for is pickle, it gives you that exact functionality. After you've added the gem to your Gemfile you run the rails g pickle --paths --email
command you can write steps like
# assuming you have an User class and a Factory for that model
Given a user exists
And another user exists with role: "admin"
# later
Then a user should exist with name: "Fred"
And that user should be activated # this uses rspec predicate matchers
For your question about paths you can do this (remember the --paths
option in the generator)
Scenario: Show product
Given a product exists with name: "Milk", price: "2.99"
When I go to the show page for that product
Then I should see "Milk" within "h1"
And I should see "$2.99"
More examples in the readme file and in this railscast
精彩评论