我正在使用 rspec、rspec-rails、cucumber 和 webrat 开发 Rails。我正在尝试学习 BDD 和一般测试。我有一个这样的黄瓜场景:
Scenario: Questions List
Given quiz titled "Pearl Jam" has questions named "Corduroy, Dissident"
When I go to the experiment page for quiz titled "Pearl Jam"
Then I should see "Corduroy"
And I should see "Dissident"
我已经添加了第 1 步,在这里我正确地创建并保存了一个测验(我通过 puts 进行了测试)。现在我正在执行第 2 步。我在 paths.rb 中添加了一个新路径
when /^the experiment page for quiz titled "(.*)"$/i
new_quiz_experiment_path(Quiz.find_by_title($1))
由于某种原因find_by_title
不起作用。我收到此错误消息:
new_quiz_experiment_url failed to generate from {:quiz_id=>nil, :action=>"new", :controller=>"experiments"}, expected: {:action=>"new", :controller=>"experiments"}, diff: {:quiz_id=>nil} (ActionController::RoutingError)
我确定记录在那里,并正确保存;如果我插入
puts Quiz.find(1).title
我得到“珍珠果酱”。看起来find_by
不起作用,这很奇怪,因为黄瓜生成的文件包含以下示例:
# when /^(.*)'s profile page$/i
# user_profile_path(User.find_by_login($1))
我还尝试了一个更简单的 find 条件,它也不起作用。
任何想法?
在此先感谢,
戴维德