黄瓜的暧昧步骤

时间:2011-09-08 14:47:15

标签: regex cucumber

我已经定义了这一步:

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

1 个答案:

答案 0 :(得分: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