Tuesday, 20 August 2013

Rspec/Capybara - Select Form should trigger Onchange event when testing

Rspec/Capybara - Select Form should trigger Onchange event when testing

I'm new to TDD and I actually wrote the code before the tests. The code
itself works fine and from the main page the onChange event applies.
However, when testing, even though a different option is chosen as the
selected option(so the option does change), it seems that the onchange
event is not actualled trigger when testing and it stays on the same
page.it says expected: "/ctscans/index", got: "/" (using ==)
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>

No comments:

Post a Comment