Skip to content

Commit 140af82

Browse files
committed
Use capybara-mechanize for smoke tests
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.
1 parent bd3880c commit 140af82

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ end
8686
group :test do
8787
gem "capybara", "~> 3.40"
8888
gem "capybara-email"
89+
gem "capybara-mechanize"
8990
gem "cuprite", "~> 0.15"
9091
gem "faker"
9192
gem "rspec"

Gemfile.lock

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ GEM
120120
capybara-email (3.0.2)
121121
capybara (>= 2.4, < 4.0)
122122
mail
123+
capybara-mechanize (1.13.0)
124+
capybara (>= 3.0.0, < 4)
125+
mechanize (~> 2.8.5)
123126
choice (0.2.0)
124127
coderay (1.1.3)
125128
concurrent-ruby (1.3.4)
@@ -152,6 +155,7 @@ GEM
152155
actionmailer (>= 5.0)
153156
devise (>= 4.6)
154157
diff-lcs (1.5.1)
158+
domain_name (0.6.20240107)
155159
dotenv (2.8.1)
156160
dotenv-rails (2.8.1)
157161
dotenv (= 2.8.1)
@@ -208,6 +212,8 @@ GEM
208212
hashie (5.0.0)
209213
html-attributes-utils (1.0.2)
210214
activesupport (>= 6.1.4.4)
215+
http-cookie (1.0.8)
216+
domain_name (~> 0.5)
211217
i18n (1.14.6)
212218
concurrent-ruby (~> 1.0)
213219
inflection (1.0.0)
@@ -225,6 +231,7 @@ GEM
225231
kramdown-parser-gfm (1.1.0)
226232
kramdown (~> 2.0)
227233
language_server-protocol (3.17.0.3)
234+
logger (1.6.5)
228235
logstop (0.3.1)
229236
loofah (2.22.0)
230237
crass (~> 1.0.2)
@@ -243,7 +250,22 @@ GEM
243250
rack (>= 2.1.4.1)
244251
marcel (1.0.2)
245252
matrix (0.4.2)
253+
mechanize (2.8.5)
254+
addressable (~> 2.8)
255+
domain_name (~> 0.5, >= 0.5.20190701)
256+
http-cookie (~> 1.0, >= 1.0.3)
257+
mime-types (~> 3.0)
258+
net-http-digest_auth (~> 1.4, >= 1.4.1)
259+
net-http-persistent (>= 2.5.2, < 5.0.dev)
260+
nokogiri (~> 1.11, >= 1.11.2)
261+
rubyntlm (~> 0.6, >= 0.6.3)
262+
webrick (~> 1.7)
263+
webrobots (~> 0.1.2)
246264
method_source (1.0.0)
265+
mime-types (3.6.0)
266+
logger
267+
mime-types-data (~> 3.2015)
268+
mime-types-data (3.2025.0107)
247269
mini_mime (1.1.5)
248270
minitest (5.25.1)
249271
msgpack (1.6.0)
@@ -252,6 +274,9 @@ GEM
252274
mutex_m (0.2.0)
253275
net-http (0.4.1)
254276
uri
277+
net-http-digest_auth (1.4.1)
278+
net-http-persistent (4.0.5)
279+
connection_pool (~> 2.2)
255280
net-imap (0.4.10)
256281
date
257282
net-protocol
@@ -438,6 +463,8 @@ GEM
438463
ruby-graphviz (1.2.5)
439464
rexml
440465
ruby-progressbar (1.13.0)
466+
rubyntlm (0.6.5)
467+
base64
441468
semantic_logger (4.15.0)
442469
concurrent-ruby (~> 1.0)
443470
sentry-rails (5.19.0)
@@ -529,6 +556,7 @@ GEM
529556
crack (>= 0.3.2)
530557
hashdiff (>= 0.4.0, < 2.0.0)
531558
webrick (1.8.1)
559+
webrobots (0.1.2)
532560
websocket-driver (0.7.6)
533561
websocket-extensions (>= 0.1.0)
534562
websocket-extensions (0.1.5)
@@ -548,6 +576,7 @@ PLATFORMS
548576
arm64-darwin-21
549577
arm64-darwin-23
550578
x86_64-darwin-21
579+
x86_64-darwin-24
551580
x86_64-linux
552581

553582
DEPENDENCIES
@@ -556,6 +585,7 @@ DEPENDENCIES
556585
bootsnap
557586
capybara (~> 3.40)
558587
capybara-email
588+
capybara-mechanize
559589
console1984 (~> 0.1.29)
560590
cssbundling-rails
561591
cuprite (~> 0.15)

spec/system/smoke_spec.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@
22
require "spec_helper"
33
require "capybara/rspec"
44
require "capybara/cuprite"
5+
require 'capybara/mechanize'
56

6-
Capybara.javascript_driver = :cuprite
77
Capybara.always_include_port = false
88

9-
RSpec.describe "Smoke test", type: :system, js: true, smoke_test: true do
9+
Capybara.register_driver :mechanize do |_|
10+
Capybara::Mechanize::Driver.new(proc {})
11+
end
12+
13+
RSpec.describe "Smoke test", type: :system, smoke_test: true, driver: :mechanize do
14+
before do
15+
Capybara.app_host = ENV["HOSTING_DOMAIN"]
16+
end
17+
1018
it "works as expected" do
1119
when_i_am_authorized_as_a_support_user
1220
when_i_visit_the_start_page
@@ -45,7 +53,7 @@
4553
end
4654

4755
it "/health/all returns 200" do
48-
page.visit("#{ENV["HOSTING_DOMAIN"]}/health/all")
56+
page.visit("/health/all")
4957
expect(page.status_code).to eq(200)
5058
end
5159

@@ -102,9 +110,10 @@ def then_i_see_the_start_page
102110
end
103111

104112
def when_i_am_authorized_as_a_support_user
105-
page.driver.basic_authorize(
113+
page.driver.browser.agent.add_auth(
114+
ENV["HOSTING_DOMAIN"],
106115
ENV["SUPPORT_USERNAME"],
107-
ENV["SUPPORT_PASSWORD"],
116+
ENV["SUPPORT_PASSWORD"]
108117
)
109118
end
110119

@@ -155,6 +164,6 @@ def when_i_press_the_start_button
155164
end
156165

157166
def when_i_visit_the_start_page
158-
page.visit("#{ENV["HOSTING_DOMAIN"]}/start")
167+
page.visit("/start")
159168
end
160169
end

0 commit comments

Comments
 (0)