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


views / welcome / 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>

最佳答案

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

describe "with Ctscan selected", js: true do ...

关于ruby-on-rails - Rspec/Capybara-选择表单在测试时应触发Onchange事件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18348974/

10-13 02:07