Skip to content

Commit

Permalink
Use capybara-mechanize for smoke tests
Browse files Browse the repository at this point in the history
The behaviour of the default capybara driver starts the rack application
and launches chrome, which is slow.

Smoke tests target a remote deployed environment so those are not
needed. Use capybara-mechanize to make remote requests only.
  • Loading branch information
saliceti committed Jan 16, 2025
1 parent bd3880c commit 571b229
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ end
group :test do
gem "capybara", "~> 3.40"
gem "capybara-email"
gem "capybara-mechanize"
gem "cuprite", "~> 0.15"
gem "faker"
gem "rspec"
Expand Down
30 changes: 30 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ GEM
capybara-email (3.0.2)
capybara (>= 2.4, < 4.0)
mail
capybara-mechanize (1.13.0)
capybara (>= 3.0.0, < 4)
mechanize (~> 2.8.5)
choice (0.2.0)
coderay (1.1.3)
concurrent-ruby (1.3.4)
Expand Down Expand Up @@ -152,6 +155,7 @@ GEM
actionmailer (>= 5.0)
devise (>= 4.6)
diff-lcs (1.5.1)
domain_name (0.6.20240107)
dotenv (2.8.1)
dotenv-rails (2.8.1)
dotenv (= 2.8.1)
Expand Down Expand Up @@ -208,6 +212,8 @@ GEM
hashie (5.0.0)
html-attributes-utils (1.0.2)
activesupport (>= 6.1.4.4)
http-cookie (1.0.8)
domain_name (~> 0.5)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
inflection (1.0.0)
Expand All @@ -225,6 +231,7 @@ GEM
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
language_server-protocol (3.17.0.3)
logger (1.6.5)
logstop (0.3.1)
loofah (2.22.0)
crass (~> 1.0.2)
Expand All @@ -243,7 +250,22 @@ GEM
rack (>= 2.1.4.1)
marcel (1.0.2)
matrix (0.4.2)
mechanize (2.8.5)
addressable (~> 2.8)
domain_name (~> 0.5, >= 0.5.20190701)
http-cookie (~> 1.0, >= 1.0.3)
mime-types (~> 3.0)
net-http-digest_auth (~> 1.4, >= 1.4.1)
net-http-persistent (>= 2.5.2, < 5.0.dev)
nokogiri (~> 1.11, >= 1.11.2)
rubyntlm (~> 0.6, >= 0.6.3)
webrick (~> 1.7)
webrobots (~> 0.1.2)
method_source (1.0.0)
mime-types (3.6.0)
logger
mime-types-data (~> 3.2015)
mime-types-data (3.2025.0107)
mini_mime (1.1.5)
minitest (5.25.1)
msgpack (1.6.0)
Expand All @@ -252,6 +274,9 @@ GEM
mutex_m (0.2.0)
net-http (0.4.1)
uri
net-http-digest_auth (1.4.1)
net-http-persistent (4.0.5)
connection_pool (~> 2.2)
net-imap (0.4.10)
date
net-protocol
Expand Down Expand Up @@ -438,6 +463,8 @@ GEM
ruby-graphviz (1.2.5)
rexml
ruby-progressbar (1.13.0)
rubyntlm (0.6.5)
base64
semantic_logger (4.15.0)
concurrent-ruby (~> 1.0)
sentry-rails (5.19.0)
Expand Down Expand Up @@ -529,6 +556,7 @@ GEM
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
webrick (1.8.1)
webrobots (0.1.2)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
Expand All @@ -548,6 +576,7 @@ PLATFORMS
arm64-darwin-21
arm64-darwin-23
x86_64-darwin-21
x86_64-darwin-24
x86_64-linux

DEPENDENCIES
Expand All @@ -556,6 +585,7 @@ DEPENDENCIES
bootsnap
capybara (~> 3.40)
capybara-email
capybara-mechanize
console1984 (~> 0.1.29)
cssbundling-rails
cuprite (~> 0.15)
Expand Down
21 changes: 15 additions & 6 deletions spec/system/smoke_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@
require "spec_helper"
require "capybara/rspec"
require "capybara/cuprite"
require 'capybara/mechanize'

Capybara.javascript_driver = :cuprite
Capybara.always_include_port = false

RSpec.describe "Smoke test", type: :system, js: true, smoke_test: true do
Capybara.register_driver :mechanize do |app|
Capybara::Mechanize::Driver.new(proc {})
end

RSpec.describe "Smoke test", type: :system, smoke_test: true, driver: :mechanize do
before do
Capybara.app_host = ENV["HOSTING_DOMAIN"]
end

it "works as expected" do
when_i_am_authorized_as_a_support_user
when_i_visit_the_start_page
Expand Down Expand Up @@ -45,7 +53,7 @@
end

it "/health/all returns 200" do
page.visit("#{ENV["HOSTING_DOMAIN"]}/health/all")
page.visit("/health/all")
expect(page.status_code).to eq(200)
end

Expand Down Expand Up @@ -102,9 +110,10 @@ def then_i_see_the_start_page
end

def when_i_am_authorized_as_a_support_user
page.driver.basic_authorize(
page.driver.browser.agent.add_auth(
ENV["HOSTING_DOMAIN"],
ENV["SUPPORT_USERNAME"],
ENV["SUPPORT_PASSWORD"],
ENV["SUPPORT_PASSWORD"]
)
end

Expand Down Expand Up @@ -155,6 +164,6 @@ def when_i_press_the_start_button
end

def when_i_visit_the_start_page
page.visit("#{ENV["HOSTING_DOMAIN"]}/start")
page.visit("/start")
end
end

0 comments on commit 571b229

Please sign in to comment.