2011-09-08 104 views
0

我已经定义了这一步:暧昧一步

Then /^the "([^"]*)" field(?: within (.*))? should be empty$/ do |field, parent| 
    with_scope(parent) do 
    field = find_field(field) 
    field_value = (field.tag_name == 'textarea') ? field.text : field.value 
    if field_value.respond_to? :should 
     field_value.to_s.should == '' 
    else 
     assert_equal('', field_value.to_s) 
    end 
    end 
end 

,当我跑我的情况也引发以下错误:

那么“城市”领域的“买房子”的形式内应该是买房子的‘内场“‘’城市的空#暧昧匹配’的形式应该是空”:

features/step_definitions/my_steps.rb:1:in `/^the "([^"]*)" field(?: within (.*))? should be empty$/' 
    features/step_definitions/web_steps.rb:35:in `/^(.*) within (.*[^:])$/' 

中提到的步骤是如下:

When /^(.*) within (.*[^:])$/ do |step, parent| 
    with_scope(parent) { When step } 
end 

所以,我有很多问题...

  • 怎么能可能定义我的步骤,无需匹配? When /^(.*) within (.*[^:])$/似乎绝对是不可避免的。

  • 然而,这一步不会引起歧义:

features/step_definitions/web_steps.rb:141

Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value| 
    with_scope(parent) do 
    field = find_field(field) 
    field_value = (field.tag_name == 'textarea') ? field.text : field.value 
    if field_value.respond_to? :should 
     field_value.should =~ /#{value}/ 
    else 
     assert_match(/#{value}/, field_value) 
    end 
    end 
end 
  • 我不能只是删除When /^(.*) within (.*[^:])$/一步?它是“系统”的一部分吗?我的意思是,它是/step_definitions/web_steps.rb,它配备了rake cucumber:install

回答

0

如果可以编辑web_steps.rb。实际上,最新版本的Cucumber建议完全删除它:

# TL;DR: YOU SHOULD DELETE THIS FILE 
# 
# This file was generated by Cucumber-Rails and is only here to get you a head start 
# These step definitions are thin wrappers around the Capybara/Webrat API that lets you 
# visit pages, interact with widgets and make assertions about page content. 
# If you use these step definitions as basis for your features you will quickly end up 
# with features that are: 
# 
# * Hard to maintain 
# * Verbose to read 
+0

谢谢。我不知道我是如何错过这个的:/ –