Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chadellison/3466e43da0104ef8e7d3351198d389bd to your computer and use it in GitHub Desktop.
Save chadellison/3466e43da0104ef8e7d3351198d389bd 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
    • Were you successful?
    • Links to commits on Github or copy and pasted code snippits of a test
@chadellison
Copy link
Author

My experience implementing the feature tests was painful as warned. I gave it a solid three hours trying a variety of different things. I believe I have everything setup correctly in my rails helper and feature tests. I was so close to getting it to work; so I thought. I installed firefox and adjusted versions of the selenium gem. After getting everything setup correctly my current version of firefox is not working with the capybara selenium web driver. If I have time, I will have another go at it.

I was unsuccessful.

snippets:
module WaitForAjax
def wait_for_ajax
Timeout.timeout(Capybara.default_max_wait_time) do
loop until finished_all_ajax_requests?
end
end

def finished_all_ajax_requests?
  page.evaluate_script('jQuery.active').zero?
end

end

RSpec.configure do |config|
config.include WaitForAjax, type: :feature
end
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end

config.before(:each) do
DatabaseCleaner.strategy = :transaction
end

config.before(:each, :js => true) do
DatabaseCleaner.strategy = :truncation
end

config.before(:each) do
DatabaseCleaner.start
end

config.after(:each) do
DatabaseCleaner.clean
end

Snippet from test:
scenario "User sees ideas", js: true do

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