我正在使用非常好的结果的黄瓜和工厂女孩,但我发现语法有点强迫。
假设我的模型有合适的工厂,我想要一个通用的黄瓜帮手/步骤
Given a model exists
When I visit the model's edit page
我知道该步骤的一部分会进入页面,但是知道#{模型}引用的实例将会在edit_model_path(@model)中找到我正在寻找的内容。
一如既往,非常感谢您的帮助。
答案 0 :(得分:0)
传递一个字符串来表示类...所以对于类Thing,使用字符串'thing'。一旦你迈出这一步,你应该好好去,我想......
您可以使用班级名称来构建编辑页面的URL。实际上,您可以使用以下代码从类名称中获取类的常量:
my_model = "thing".classify.constantize
my_instance = my_model.find(...)
我认为这会让你足够概括一步,不是吗?
答案 1 :(得分:0)
您正在寻找的是pickle,它为您提供了确切的功能。将gem添加到Gemfile后,运行rails g pickle --paths --email
命令,可以编写
# 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
有关路径的问题,您可以执行此操作(请记住生成器中的--paths
选项)
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"
中的更多示例