Skip to content

Commit

Permalink
Use capybara-webmock to avoid external requests
Browse files Browse the repository at this point in the history
The images from OpenStreetMap take a while to load, sometimes even
causing Net::ReadTimeout errors if the internet connection is slow. It's
happened a lot recently on Travis builds.

Using capybara-webmock we guarantee the test suite doesn't fail due to
network issues.
  • Loading branch information
javierm committed Sep 7, 2019
1 parent 1f0a4cd commit 8bb5462
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ end

group :test do
gem "capybara", "~> 2.17.0"
gem "capybara-webmock", "~> 0.5.3"
gem "coveralls", "~> 0.8.22", require: false
gem "database_cleaner", "~> 1.7.0"
gem "email_spec", "~> 2.1.0"
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (>= 2.0, < 4.0)
capybara-webmock (0.5.3)
capybara (>= 2.4, < 4)
rack (>= 1.4)
rack-proxy (>= 0.6.0)
selenium-webdriver (~> 3.0)
childprocess (0.9.0)
ffi (~> 1.0, >= 1.0.11)
chronic (0.10.2)
Expand Down Expand Up @@ -389,6 +394,8 @@ GEM
rack (>= 0.4)
rack-attack (5.0.1)
rack
rack-proxy (0.6.5)
rack
rack-test (0.6.3)
rack (>= 1.0)
rails (5.0.7.2)
Expand Down Expand Up @@ -584,6 +591,7 @@ DEPENDENCIES
capistrano-rails (~> 1.4.0)
capistrano3-delayed-job (~> 1.7.3)
capybara (~> 2.17.0)
capybara-webmock (~> 0.5.3)
ckeditor (~> 4.2.3)
cocoon (~> 1.2.9)
coffee-rails (~> 4.2.2)
Expand Down
4 changes: 3 additions & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@

Capybara.register_driver :headless_chrome do |app|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: { args: %w(headless no-sandbox window-size=1200,600) }
chromeOptions: {
args: %W[headless no-sandbox window-size=1200,600 proxy-server=127.0.0.1:#{Capybara::Webmock.port_number}]
}
)

Capybara::Selenium::Driver.new(
Expand Down
8 changes: 8 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@
end
end

config.before(:each, type: :feature) do
Capybara::Webmock.start
end

config.after(:suite) do
Capybara::Webmock.stop
end

config.after(:each, :page_driver) do
page.driver.reset!
end
Expand Down

0 comments on commit 8bb5462

Please sign in to comment.