【发布时间】:2014-06-23 15:05:40
【问题描述】:
我开始用黄瓜做 BDD。
我的第一个场景是这样写的
Scenario: ...
Given I am on the new event page
And I fill in "title" with "tata"
通过这些步骤
Given /^I am on (.+)$/ do |page_name|
visit("/event/new")
end
When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
fill_in(field.gsub(' ', '_'), :with => value)
end
效果很好,很好。 现在,我想使用发送功能访问一个页面。所以我把第一步改成这样。
Given /^I am on (.+)$/ do |page_name|
self.send("new_event_path".to_sym)
end
页面已找到,但由于未找到某个元素,fill_in 不起作用。
Unable to find field "title" (Capybara::ElementNotFound)
我不明白为什么它不能与发送功能一起使用?
【问题讨论】:
-
“我在”的第二个实现不会访问任何内容,它只是评估 URI 并将其丢弃。
-
添加您知道比第一个解决方案更通用的解决方案吗?我在这里看到了这个解决方案:github.com/cucumber/cucumber-rails-training-wheels/blob/master/…
-
好的,我只需要访问一下(path_to(my_page))