Skip to content

Commit 1a7202d

Browse files
committed
Check for puma and capybara when defining system tests (#1893)
* Check for puma and capybara when defining system tests Rather than skipping the definition altogether define a fake module that warns about the dependencies. * If we can't load system_test_case for some reason we cant run system tests As per @mockdeep's conversation in #1889 other dependencies might not allow us to even load system_test_case so we fallback to our original strategy for now.
1 parent 9688432 commit 1a7202d

File tree

4 files changed

+33
-24
lines changed

4 files changed

+33
-24
lines changed

lib/rspec/rails/configuration.rb

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,7 @@ def self.add_test_type_configurations(config)
4949
config.include RSpec::Rails::ViewExampleGroup, :type => :view
5050
config.include RSpec::Rails::FeatureExampleGroup, :type => :feature
5151
config.include RSpec::Rails::Matchers
52-
53-
if ActionPack::VERSION::STRING >= "5.1"
54-
begin
55-
require 'puma'
56-
require 'capybara'
57-
config.include RSpec::Rails::SystemExampleGroup, :type => :system
58-
# rubocop:disable Lint/HandleExceptions
59-
rescue LoadError
60-
# rubocop:enable Lint/HandleExceptions
61-
end
62-
end
52+
config.include RSpec::Rails::SystemExampleGroup, :type => :system
6353
end
6454

6555
# @private

lib/rspec/rails/example.rb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,4 @@
88
require 'rspec/rails/example/model_example_group'
99
require 'rspec/rails/example/job_example_group'
1010
require 'rspec/rails/example/feature_example_group'
11-
if ActionPack::VERSION::STRING >= "5.1"
12-
begin
13-
require 'puma'
14-
require 'capybara'
15-
require 'rspec/rails/example/system_example_group'
16-
# rubocop:disable Lint/HandleExceptions
17-
rescue LoadError
18-
# rubocop:enable Lint/HandleExceptions
19-
end
20-
end
11+
require 'rspec/rails/example/system_example_group'

lib/rspec/rails/example/system_example_group.rb

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
1-
if ActionPack::VERSION::STRING >= "5.1"
2-
require 'action_dispatch/system_test_case'
1+
can_load_system_tests = false
2+
begin
3+
require 'puma'
4+
require 'capybara'
5+
if ActionPack::VERSION::STRING >= "5.1"
6+
require 'action_dispatch/system_test_case'
7+
can_load_system_tests = true
8+
end
9+
# rubocop:disable Lint/HandleExceptions
10+
rescue LoadError
11+
# rubocop:enable Lint/HandleExceptions
12+
end
13+
14+
if !can_load_system_tests
15+
module RSpec
16+
module Rails
17+
module SystemExampleGroup
18+
extend ActiveSupport::Concern
19+
20+
included do
21+
abort """
22+
System test integration requires Rails >= 5.1 and has a hard
23+
dependency on `puma` and `capybara`, please add these to your
24+
Gemfile before attempting to use system tests.
25+
"""
26+
end
27+
end
28+
end
29+
end
30+
else
331
module RSpec
432
module Rails
533
# @api public

spec/rspec/rails/example/system_example_group_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require "spec_helper"
22
module RSpec::Rails
3-
if defined?(SystemExampleGroup)
3+
if ActionPack::VERSION::STRING >= "5.1"
44
RSpec.describe SystemExampleGroup do
55
it_behaves_like "an rspec-rails example group mixin", :system,
66
'./spec/system/', '.\\spec\\system\\'

0 commit comments

Comments
 (0)