Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rspec/Capybara-测试时选择表单应触发Onchange事件_Ruby On Rails_Testing_Selenium_Rspec_Capybara - Fatal编程技术网

Ruby on rails Rspec/Capybara-测试时选择表单应触发Onchange事件

Ruby on rails Rspec/Capybara-测试时选择表单应触发Onchange事件,ruby-on-rails,testing,selenium,rspec,capybara,Ruby On Rails,Testing,Selenium,Rspec,Capybara,我是TDD的新手,实际上我是在测试之前编写代码的。代码本身工作正常,并且从主页面应用onChange事件。但是,在测试时,即使选择了不同的选项作为所选选项(因此该选项确实发生了更改),onchange事件似乎在测试时没有实际触发,并且它保持在同一页上。它表示预期的:“/ctscans/index”,得到:“/”(使用==) 欢迎光临 require 'spec_helper' describe "Welcome Page" do before {visit root_path}

我是TDD的新手,实际上我是在测试之前编写代码的。代码本身工作正常,并且从主页面应用onChange事件。但是,在测试时,即使选择了不同的选项作为所选选项(因此该选项确实发生了更改),onchange事件似乎在测试时没有实际触发,并且它保持在同一页上。它表示预期的:“/ctscans/index”,得到:“/”(使用==)

欢迎光临

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>
@path[0]),:onchange=>“gotoNewPage()””%>
函数gotoNewPage(){
if(document.getElementById('procedure').value){
window.location.href=document.getElementById('procedure')。值;
}
}

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

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

嗯,好吧,我添加了它,得到了一个Selenium::WebDriver:错误(找不到Firefox二进制文件(os=macosx)。请确保计算机上安装了Firefox。在搜索此问题的答案后,似乎大多数文章都有一个功能/support/env.rb和/或使用cucumber。您对此了解吗?假设您安装了Firefox,请将
require'capybara/rspec'
添加到您的
spec\u helper
中。cucumber应该没有必要.是的,我做到了,谢谢。我现在必须让无头浏览工作。你用过PhantomJS+Ghost吗?不,我不熟悉这些。