2

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>

1 Answer 1

4

You haven't indicated that the spec needs to use a javascript driver. Try

describe "with Ctscan selected", js: true do ...
Sign up to request clarification or add additional context in comments.

4 Comments

hmm, ok I added that and I'm getting a Selenium::WebDriver:Error (Could not find Firefox binary (os=macosx). Make sure Firefox is installed on the machine. After searching for answers on this, it seems that most of theses have a features/support/env.rb and/or use cucumber. Would you know anything about this?
Assuming you do have Firefox installed, add require 'capybara/rspec' to your spec_helper. Cucumber shouldn't be necessary.
Yeah, I did that thanks. I just have to get Headless browsing working now. HAve you used PhantomJS + Ghost to do this
No, I'm not familiar with those.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.