On my page I have :
-->a form that scrapes the content of another website with a Ajax request made with ujs (remote: true):
<%= simple_form_for @listing, :url => listings_fetch_url, remote: true do |f| %>
<%= f.input :url %>
<%= f.button :submit, id: 'import_button' %>
<% end %>
-->another form that is populated by the scraping results from the form above
Manually it works...
However when I'm trying to automatically test it, it doesn't. Capybara finds the submit button, clicks on it but then it leaves me on a blank page.
Here is the code for the test:
feature "Listing import" do
scenario "fills in the form fields", js: true do
visit new_search_path
fill_in 'Url', :with => 'www.google.fr'
find('input#import_button').click
expect(page.body).to have_content 'query was'
end
end
The controller actions are the following:
def fetch
url = listing_params[:url]
@query = Query.new(ScraperService.new({url: url}).perform)
render :fill
end
# Renders an js.erb file
def fill
end
It seems like rspec with selenium can't render js.erb files?
Any help is appreciated!
EDIT
Thanks to @ThomasWalpole, I fixed an error 500 which was preventing Mechanize to scrape the web. The content is now scraped correctly but the problem remains: the page after clicking on the submit button becomes blank and the tests ends right afer. In the logs I have a lengthy message :
Could not log "render_template.action_view" event. NoMethodError: undefined method
example_group' for nil:NilClass ["/Users/Greg/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rspec-rails-3.6.0/lib/rspec/rails/view_rendering.rb:67:in
current_example_group'"
Query.new(ScraperService.new({url: url}).perform
make another request to the app, run in separate threads, etc? If so are you using :puma as your Capybara server (Capybara.server = :puma) ? – Thomas Walpolerequire 'webmock/rspec'
which was preventing Mechanize from accessing the web.Query.new...
isn't making another request to the app and doesn't run in a separate thread. Using Puma didn't change anything sadly. See my updated question please. – Greg