我正在編寫Sinatra應用程序的測試規範。我怎樣才能讓rspec點擊我表格中的單選按鈕?Rspec:爲Sinatra表單選擇一個單選按鈕?
<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>
編輯:我沒有檢查這個資源,但它並沒有幫助我:stackoverflow.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')
你到目前爲止嘗試過什麼?有[幾](http://stackoverflow.com/questions/27430074/how-to-click-radio-button-with-capybara-in-ruby-on-rails-app)[答案](http:// stackoverflow.com/questions/11483967/selecting-a-radio-button-with-rspec)[available](http://stackoverflow.com/questions/21085057/capybara-chooseradio-button-not-working)與一個快速谷歌搜索;你有沒有研究過這些實驗? –
我沒看看這個資源:http://stackoverflow.com/questions/11483967/selecting-a-radio-button-with-rspec?noredirect=1&lq=1 我試過'選擇('曼哈頓')'。然而,我一直得到這個錯誤: '''失敗/錯誤:選擇('曼哈頓') 水豚:: ElementNotFound: 無法找到單選按鈕「曼哈頓」''' –
@Joel B,請添加細節你的最後一條評論對你的問題,它將在未來幫助我們。 – eeeeeean