Skip to content

Commit 67d7b97

Browse files
committed
Check for puma and capybara when defining system tests
Rather than skipping the definition altogether define a fake module that warns about the dependencies.
1 parent 4b2d5e4 commit 67d7b97

File tree

4 files changed

+30
-23
lines changed

4 files changed

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

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)