黄瓜:rails 动态查找在 paths.rb 中不起作用
我正在使用 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,我在其中正确创建并保存了测验(我通过 put 进行了测试)。 现在我正在执行第 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))
我还尝试了一个更简单的条件查找,它也不起作用。
有什么想法吗?
预先感谢,
达维德
I am working on rails with rspec, rspec-rails, cucumber and webrat.
I am trying to learn BDD and testing in general.
I have a cucumber scenario like this:
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"
I have alrady added step 1, where I create and save a quiz correctly (I tested through puts).
Now I am working on step 2. I am adding a new path in paths.rb
when /^the experiment page for quiz titled "(.*)"$/i
new_quiz_experiment_path(Quiz.find_by_title($1))
For some reason find_by_title
does not work. I get this error message:
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)
I am sure the record is there, and correctly saved; if I insert
puts Quiz.find(1).title
I get "Pearl Jam". Looks like find_by
is not working, which is quite weird since the cucumber generated file contains this example:
# when /^(.*)'s profile page$/i
# user_profile_path(User.find_by_login($1))
I also tried a simpler find first with conditions, it doesn't work either.
Any idea?
Thanks in advance,
Davide
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢 ryanb 的建议,我能够找到该错误,该错误位于
基本上我已经不一致地解析了此步骤;我已在第一个正则表达式中插入了引号,因此该图块被保存,因为
我想我已经学到了两件事:
!
的方法来更具表现力错误消息。Thanks to ryanb's suggestion I was able to find the bug, which was in
Basically I had parsed this step inconsisetntly; I had inserted the quotation marks in the 1st regex, so the tile got saved as
I guess I've lerned two things:
!
for more expressive error messages.