2011-09-08 141 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

謝謝。我不知道我是如何錯過這個的:/ –