Skip to content

Commit 7634998

Browse files
author
Sam Phippen
committed
Refactor system test implementation to be good
1 parent d79b4f7 commit 7634998

File tree

1 file changed

+16
-37
lines changed

1 file changed

+16
-37
lines changed

lib/rspec/rails/example/system_example_group.rb

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,30 @@ module Rails
55
# @api public
66
# Container class for request spec functionality.
77
module SystemExampleGroup
8-
extend ActiveSupport::Concern
9-
include RSpec::Rails::RailsExampleGroup
10-
include ActionDispatch::Integration::Runner
11-
include ActionDispatch::Assertions
12-
include RSpec::Rails::Matchers::RedirectTo
13-
include RSpec::Rails::Matchers::RenderTemplate
14-
include ActionController::TemplateAssertions
15-
16-
include ActionDispatch::IntegrationTest::Behavior
17-
18-
module BlowAwayAfterTeardownHook
19-
def after_teardown
20-
end
21-
end
8+
# In rails system test inherits from integration test.
9+
# RequestExampleGroup wraps that, so we just include it here
10+
include RSpec::Rails::RequestExampleGroup
2211

2312
original_after_teardown = ::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown.instance_method(:after_teardown)
2413

25-
include ::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown
26-
include ::ActionDispatch::SystemTesting::TestHelpers::ScreenshotHelper
27-
include BlowAwayAfterTeardownHook
28-
29-
# for the SystemTesting Screenshot situation
30-
def passed?
31-
RSpec.current_example.exception.nil?
32-
end
33-
14+
module SystemTestHooks
15+
include ::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown
16+
include ::ActionDispatch::SystemTesting::TestHelpers::ScreenshotHelper
17+
# for the SystemTesting Screenshot situation
18+
def passed?
19+
RSpec.current_example.exception.nil?
20+
end
3421

35-
# Delegates to `Rails.application`.
36-
def app
37-
::Rails.application
22+
def after_teardown
23+
end
3824
end
25+
include SystemTestHooks
3926

4027
included do
41-
def driven_by(*args, &blk)
42-
@driver = ::ActionDispatch::SystemTestCase.driven_by(*args, &blk).tap { |d|
43-
d.use
44-
}
45-
end
28+
attr_reader :driver
4629

47-
def driver
48-
@driver
30+
def driven_by(*args, &blk)
31+
@driver = ::ActionDispatch::SystemTestCase.driven_by(*args, &blk).tap(&:use)
4932
end
5033

5134
before do
@@ -56,10 +39,6 @@ def driver
5639
after do
5740
original_after_teardown.bind(self).call
5841
end
59-
60-
around do |ex|
61-
ex.run
62-
end
6342
end
6443
end
6544
end

0 commit comments

Comments
 (0)