将 Cucumber 用于 BDD (CS169.x1@edX) 时,会返回以下消息以响应“cucumber features/filter_movie_list.feature”的执行:
When I uncheck the following ratings: G, PG-13 # features/step_definitions/movie_steps.rb:44
Undefined step: "When I uncheck "ratings_G"" (Cucumber::Undefined)
./features/step_definitions/movie_steps.rb:52:in `block (2 levels) in <top (required)>'
./features/step_definitions/movie_steps.rb:49:in `each'
./features/step_definitions/movie_steps.rb:49:in `/I (un)?check the following ratings: (.*)/'
features/filter_movie_list.feature:30:in `When I uncheck the following ratings: G, PG-13'
...
You can implement step definitions for undefined steps with these snippets:
When /^When I uncheck "(.*?)"$/ do |arg1|
pending # express the regexp above with the code you wish you had
end
有问题的特定配置在“features/filter_movie_list.feature”中有一个声明性步骤,它说:
当我取消选中以下评级时:G、PG-13
尝试在“features/step_definitions/movie_steps.rb”中实现声明性步骤(以重用“features/step_definitions/web_steps.rb”的命令步骤),如下所示:
When /I (un)?check the following ratings: (.*)/ do |uncheck, rating_list|
step "When I uncheck \"ratings_G\""
和一个有效的 'features/step_definitions/web_steps.rb' 文件(即,在 gem 安装后由 'rails generate cucumber_rails_training_wheels:install' 创建的文件),具有如下命令式默认步骤:
When /^(?:|I )uncheck "([^"]*)"$/ do |field|
check(field)
end
此外,Cucumber 似乎可以访问 'features/step_definitions/web_steps.rb',因为添加When I uncheck "ratings_G"
到 'features/step_definitions/movie_steps.rb' 成功;有人知道可能导致这种行为的原因吗?声明性步骤的实现甚至已被简化,因此不会发生变量替换......