我是TDD的新手,实际上我在测试之前编写了代码。代码本身工作正常,并且从主页面中应用onChange事件。但是,在测试时,即使选择了不同的选项作为选择的选项(因此选项确实发生了变化),似乎onchange事件在测试时不是实际触发器,并且它保持在同一页面上。它表示预期:“/ ctscans / index“,得到:”/“(使用==)
welcome_spec.rb
require 'spec_helper'
describe "Welcome Page" do
before {visit root_path}
subject{page}
describe "with Ctscan selected" do
before {select("CT Scan", :from => "procedure")}
it {should have_select('procedure', :selected => 'CT Scan')}
it "redirects to" do
select 'MRI', :from => 'procedure'
current_path.should == ctscans_index_path
end
end
end
视图/欢迎/ index.html.erb
<%=select_tag(:procedure, options_for_select(@paths, :selected => @paths[0]),:onchange => "gotoNewPage()")%>
<script type="text/javascript">
function gotoNewPage() {
if (document.getElementById('procedure').value){
window.location.href = document.getElementById('procedure').value;
}
}
</script>
答案 0 :(得分:3)
您还没有表明规范需要使用javascript驱动程序。尝试
describe "with Ctscan selected", js: true do ...