Skip to content

Instantly share code, notes, and snippets.

@Claudia108
Forked from rrgayhart/1602-testing-homework.markdown
Last active July 3, 2016 20:12
Show Gist options
  • Save Claudia108/9b64eaa129035a2ff627f563946f801f to your computer and use it in GitHub Desktop.
Save Claudia108/9b64eaa129035a2ff627f563946f801f to your computer and use it in GitHub Desktop.
Testing Homework

Testing Homework - Rails/JS

  • Choose one of the following tracks:

  • Skim/Read through the associated links

  • Attempt to hook up and implement unit or feature js tests in your IdeaBox or this sample idea-bin project

  • Fork this gist

  • Respond with:

    Your experience implementing

    I had huge trouble with getting selenium up and running. I updated the selenium gem, I used approaches from stack overflow to configure selenium differently in the spec_helper. Only after downgrading firefox to the prior version (46 instead of the current 47), the driver worked and I could run my tests. I still ran into some issues that made me change my design of the page. Rspec/selenium wouldn't recognize glyphicons inside of button tags. I had to change them to a tags for rspec to run the test properly.

    Were you successful?

    Yes, I was successful and I could test every feature I implemented with js. It was great to see what worked on the actual browser page and what didn't but it didn't help so much figuring out where the test failed. The message from rspec was still the best source for debugging. And the test suite gets really slow with this browser. I am thinking of trying a headless browser next time to see the difference.

    Links to commits on Github or copy and pasted code snippits of a test
    RSpec.feature "user changes quality of idea" do
    scenario "user upvotes idea", js: true do
      idea = create(:idea)
    
      visit '/'
    
      expect(page).to have_content("swill")
    
      within("#idea-#{idea.id}") do
        find(".upvote").click
      end
    
      expect(page).to have_current_path('/')
      expect(page).to have_content("plausible")
    
      within("#idea-#{idea.id}") do
        find(".upvote").click
      end
    
      expect(page).to have_content("genius")
    
      within("#idea-#{idea.id}") do
        find(".upvote").click
      end
    
      expect(page).to have_content("genius")
    end
    
    RSpec.feature "user deletes idea", :js => true do
      scenario "they no longer see the idea on the page" do
        create_list(:idea, 3)
        idea = Idea.first
    
        visit '/'
    
        within("li:first-child") {
          expect(page).to have_content(idea.title)
          expect(page).to have_content(idea.body)
    
          find(".delete-idea").click
          wait_for_ajax
          expect(page).not_to have_content(idea.title)
          expect(page).not_to have_content(idea.body)
        }
    end
    

end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment