I'm using datatables in my application , and the records are loaded to the table by ajax. Now I'm writing tests for the page of my datatable and have to wait untill the records are loaded. I configured capybara webkit and put js: true in my test. but when I run the test i get this error
Failure/Error: raise ActionController::RoutingError, "No route matches [#{env['REQUEST_METHOD']}] #{env['PATH_INFO'].inspect}"
ActionController::RoutingError:
No route matches [GET] "/images/sort_both.png"
In my browser i checked the console , and I don't get this errors, all images are found.
this is my configuration of webkit
Capybara.javascript_driver = :webkit
Capybara::Webkit.configure do |config|
config.raise_javascript_errors = false
end
i'm using wait_for_ajax method
def wait_for_ajax
Timeout.timeout(Capybara.default_max_wait_time) do
loop do
active = page.evaluate_script('jQuery.active')
break if active == 0
end
end
end
and this is my test
scenario 'check pending contributions', js: true do
login_as analyst, scope: :analyst
visit '/analyst/contributions'
wait_for_ajax
expect(page).to have_content "#{contribution.user_name}"
end
And now I want to fix this routing error , or just ignore it because I just want to test the logic, not js errors.
That error isn't a JS error, it's an error raised by your server when an asset is requested. You can probably tell your test to ignore the error by setting Capybara.raise_server_errors = false
, however the better solution would be to fix your asset pipeline so that all assets are getting correctly served in the test environment. Odds are that you have previously precompiled the assets in the test environment and that a left over manifest file is preventing it from recompiling newly added assets. You can fix that by running something like
RAILS_ENV=test rake assets:clobber
Additionally, assuming the #{contribution.user_name}
text is being loaded via the ajax call there is no need for the wait_for_ajax
method call since have_content
will already wait/retry.