Rspec: 为 Sinatra 表单选择单选按钮?
Rspec: Selecting a radio button for Sinatra form?
我正在为 Sinatra 应用编写测试规范。我怎样才能让 rspec 单击我表单中的单选按钮?
<form action="/reports/new" method="POST">
<div class="form-group">
<label class="col-md-4 control-label" for="radios">Borough</label>
<div>
<label>
<input name="Brooklyn" id="borough_1" value="1" type="radio">Brooklyn</input>
</label>
<label>
<input name="Bronx" id="borough_2" value="2" type="radio">Bronx</input>
</label>
<label>
<input name="Manhattan" id="borough_3" value="3" type="radio">Manhattan</input>
</label>
<label>
<input name="Queens" id="borough_4" value="4" type="radio">Queens</input>
</label>
<label>
<input name="Staten Island" id="borough_5" value="5" type="radio">Staten Island</input>
</label>
<button value="Submit" type="submit">Submit</button>
</div>
</div>
</form>
编辑:我确实查看了这个资源,但它对我没有帮助:whosebug.com/questions/11483967/… 我试过了 choose('Manhattan')
。但是,我不断收到此错误:Failure/Error: choose('Manhattan') Capybara::ElementNotFound: Unable to find radio button "Manhattan"
好消息是 rspec 至少在寻找一个单选按钮。
visit '/reports/new'
fill_in(:title, :with => "Ben and Jerries Ice Cream")
fill_in(:business, :with => "Starbucks")
fill_in(:location, :with => "146 Rikers Street")
fill_in(:content, :with => "Some great food")
fill_in(:date, :with => "2016-09-12")
choose('Manhattan')
choose
通过 id、name 或 label 查找内容。来自文档:
#choose([locator], options) ⇒ Object
Find a radio button and mark it as checked. The radio button can be
found via name, id or label text.
确保:a) 水豚将 'reports/new' 和 b) 您的页面按预期呈现这些元素。例如,尝试自己转到 'reports/new' 并在控制台中选择该元素(假设您有 jQuery):
$('#borough_3');
或者直接在源码中寻找。
我正在为 Sinatra 应用编写测试规范。我怎样才能让 rspec 单击我表单中的单选按钮?
<form action="/reports/new" method="POST">
<div class="form-group">
<label class="col-md-4 control-label" for="radios">Borough</label>
<div>
<label>
<input name="Brooklyn" id="borough_1" value="1" type="radio">Brooklyn</input>
</label>
<label>
<input name="Bronx" id="borough_2" value="2" type="radio">Bronx</input>
</label>
<label>
<input name="Manhattan" id="borough_3" value="3" type="radio">Manhattan</input>
</label>
<label>
<input name="Queens" id="borough_4" value="4" type="radio">Queens</input>
</label>
<label>
<input name="Staten Island" id="borough_5" value="5" type="radio">Staten Island</input>
</label>
<button value="Submit" type="submit">Submit</button>
</div>
</div>
</form>
编辑:我确实查看了这个资源,但它对我没有帮助:whosebug.com/questions/11483967/… 我试过了 choose('Manhattan')
。但是,我不断收到此错误:Failure/Error: choose('Manhattan') Capybara::ElementNotFound: Unable to find radio button "Manhattan"
好消息是 rspec 至少在寻找一个单选按钮。
visit '/reports/new'
fill_in(:title, :with => "Ben and Jerries Ice Cream")
fill_in(:business, :with => "Starbucks")
fill_in(:location, :with => "146 Rikers Street")
fill_in(:content, :with => "Some great food")
fill_in(:date, :with => "2016-09-12")
choose('Manhattan')
choose
通过 id、name 或 label 查找内容。来自文档:
#choose([locator], options) ⇒ Object
Find a radio button and mark it as checked. The radio button can be found via name, id or label text.
确保:a) 水豚将 'reports/new' 和 b) 您的页面按预期呈现这些元素。例如,尝试自己转到 'reports/new' 并在控制台中选择该元素(假设您有 jQuery):
$('#borough_3');
或者直接在源码中寻找。