我正在学习如何用 cucumber/webrat 编写测试。我的测试场景之一设置为测试表单验证(将字段留空)。奇怪的是,我没有填写fill_in
的字段被设置为字段的name
属性。这仅在我运行 cucumber 时发生,在使用浏览器时不会发生。
我正在使用的步骤很简单:
When /^I submit the form$/ do
# Not filling in the 'Name' field here
fill_in 'Description', :with => 'This is a description'
click_button 'Save'
end
运行使用上述步骤的场景后,我可以看到文本字段“名称”设置为“名称”而不是为空。如果我在该字段中填写空格或nil
:
fill_in 'Name', :with => ''
我正在测试的表格很简单:
<form action="/item/create" method="post">
<div>
<label for="ItemName">Name</label>
<input type="text" name="name" id="ItemName" />
</div>
<div>
<label for="ItemDescription">Description</label>
<textarea name="description" id="ItemDescription"></textarea>
</div>
<input type="submit" value="Save" />
</form>
知道为什么会这样吗?