Upload
michael-reinsch
View
546
Download
0
Embed Size (px)
Citation preview
capybara acceptance testing
scenario "publish event" do visit event_url(event) click_on "Publish Event" expect(event.reload).to be_published end
scenario "publish event", js: true do visit event_url(event) click_on "Publish Event" expect(event.reload).to be_published end
scenario "publish event", js: true do visit event_url(event) click_on "Publish Event" expect(event.reload).to be_published end
!
scenario "publish event", js: true do visit event_url(event) click_on "Publish Event" expect(event.reload).to be_published end
!Failure/Error: expect(event.reload).to be_published
rspec process
rspec process
rails server process
spawns
rspec process
rails server process
spawns
browser process
spawns / sends
commands
rspec process
rails server process
spawns
browser process
spawns / sends
commands
http requests
scenario "publish event", js: true do visit event_url(event) click_on "Publish Event" expect(page).to have_content("Registration: Open") expect(event.reload).to be_published end
scenario "publish event", js: true do visit event_url(event) click_on "Publish Event" expect(page).to have_content("Registration: Open") expect(event.reload).to be_published end
"
scenario "publish event", js: true do visit event_url(event) click_on "Publish Event" expect(page).to have_content("Registration: Open") expect(event.reload).to be_published end
Failure/Error: Unable to find matching line from backtrace ActiveRecord::StatementInvalid: PG::TRDeadlockDetected: ERROR: deadlock detected DETAIL: Process 7186 waits for AccessShareLock on relation 16570 of database 16396; blocked by process 7274. Process 7274 waits for AccessExclusiveLock on relation 17012 of database 16396; blocked by process 7186.
#
ajax
vs.
database_cleaner
# in spec/spec_helper.rb
config.append_after(:each) do Rails.logger.debug("======= cleaning DB") DatabaseCleaner.clean end
module RSpecLoggerListener extend self
def start(notification) Rails.logger.info("\n\n====== Starting new test run") end def stop(notification) Rails.logger.info("\n\n====== Test run finished") end def example_started(notification) Rails.logger.info("\n\n====== START #{notification.example.full_description}") end def example_passed(notification) Rails.logger.info("====== PASSED #{notification.example.full_description}") end def example_failed(notification) Rails.logger.info("====== FAILED #{notification.example.full_description}") end def example_pending(notification) Rails.logger.info("====== PENDING #{notification.example.full_description}") end end
RSpec.configuration.reporter.register_listener( RSpecLoggerListener, :start, :stop, :example_started, :example_passed, :example_failed, :example_pending)
get it from: https://gist.github.com/mreinsch/2c8dbb01e51c32c3c5c8
module CapybaraHelperMethods def wait_for_ajax counter = 0 while !finished_all_ajax_requests? counter += 1 sleep 0.2 raise "AJAX request took too long." if counter >= (Capybara.default_wait_time * 5) end end
def finished_all_ajax_requests? active = page.evaluate_script <<-SCRIPT.strip.gsub(/\s+/,' ') (function () { if (typeof jQuery != 'undefined') { return jQuery.active; } else { console.error("jQuery was undefined on " + document.URL + " - will retry..."); return -1; } })() SCRIPT
active && active.zero? end end
RSpec.configuration.include CapybaraHelperMethods, :type => :feature
based on https://coderwall.com/p/aklybw/wait-for-ajax-with-capybara-2-0
scenario "publish event", js: true do visit event_url(event) click_on "Publish Event" expect(page).to have_content("Registration: Open") expect(event.reload).to be_published wait_for_ajax end
"
Beware of the async!
Michael [email protected] github / twitter: mreinsch