1

我是 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>
4

1 回答 1

3

您没有指出规范需要使用 javascript 驱动程序。尝试

describe "with Ctscan selected", js: true do ...
于 2013-08-21T05:20:41.640 回答