|
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 |
| 1 | +module RSpec |
| 2 | + module Rails |
| 3 | + # @api public |
| 4 | + # Container class for system tests |
| 5 | + module SystemExampleGroup |
| 6 | + extend ActiveSupport::Concern |
| 7 | + include RSpec::Rails::RailsExampleGroup |
| 8 | + include RSpec::Rails::Matchers::RedirectTo |
| 9 | + include RSpec::Rails::Matchers::RenderTemplate |
| 10 | + include ActionDispatch::Integration::Runner |
| 11 | + include ActionDispatch::Assertions |
| 12 | + include ActionController::TemplateAssertions |
13 | 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 |
| - """ |
| 14 | + # @private |
| 15 | + module BlowAwayAfterTeardownHook |
| 16 | + # @private |
| 17 | + def after_teardown |
26 | 18 | end
|
27 | 19 | end
|
28 |
| - end |
29 |
| - end |
30 |
| -else |
31 |
| - module RSpec |
32 |
| - module Rails |
33 |
| - # @api public |
34 |
| - # Container class for system tests |
35 |
| - module SystemExampleGroup |
36 |
| - extend ActiveSupport::Concern |
37 |
| - include RSpec::Rails::RailsExampleGroup |
38 |
| - include ActionDispatch::Integration::Runner |
39 |
| - include ActionDispatch::Assertions |
40 |
| - include RSpec::Rails::Matchers::RedirectTo |
41 |
| - include RSpec::Rails::Matchers::RenderTemplate |
42 |
| - include ActionController::TemplateAssertions |
43 |
| - |
44 |
| - include ActionDispatch::IntegrationTest::Behavior |
45 | 20 |
|
46 |
| - # @private |
47 |
| - module BlowAwayAfterTeardownHook |
48 |
| - # @private |
49 |
| - def after_teardown |
50 |
| - end |
51 |
| - end |
| 21 | + # for the SystemTesting Screenshot situation |
| 22 | + def passed? |
| 23 | + RSpec.current_example.exception.nil? |
| 24 | + end |
52 | 25 |
|
53 |
| - original_after_teardown = ::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown.instance_method(:after_teardown) |
| 26 | + # @private |
| 27 | + def method_name |
| 28 | + @method_name ||= [ |
| 29 | + self.class.name.underscore, |
| 30 | + RSpec.current_example.description.underscore, |
| 31 | + rand(1000) |
| 32 | + ].join("_").gsub(/[\/\.:, ]/, "_") |
| 33 | + end |
54 | 34 |
|
55 |
| - include ::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown |
56 |
| - include ::ActionDispatch::SystemTesting::TestHelpers::ScreenshotHelper |
57 |
| - include BlowAwayAfterTeardownHook |
| 35 | + # Delegates to `Rails.application`. |
| 36 | + def app |
| 37 | + ::Rails.application |
| 38 | + end |
58 | 39 |
|
59 |
| - # for the SystemTesting Screenshot situation |
60 |
| - def passed? |
61 |
| - RSpec.current_example.exception.nil? |
| 40 | + included do |other| |
| 41 | + begin |
| 42 | + require 'capybara' |
| 43 | + require 'action_dispatch/system_test_case' |
| 44 | + # rubocop:disable Lint/HandleExceptions |
| 45 | + rescue LoadError |
| 46 | + # rubocop:enable Lint/HandleExceptions |
| 47 | + abort """ |
| 48 | + System test integration requires Rails >= 5.1 and has a hard |
| 49 | + dependency on a webserver and `capybara`, please add capybara to |
| 50 | + your Gemfile and configure a webserver (e.g. `Capybara.server = |
| 51 | + :webrick`) before attempting to use system tests. |
| 52 | + """.gsub(/[\n\s]+/,' ').strip |
62 | 53 | end
|
63 | 54 |
|
64 |
| - # @private |
65 |
| - def method_name |
66 |
| - @method_name ||= [ |
67 |
| - self.class.name.underscore, |
68 |
| - RSpec.current_example.description.underscore, |
69 |
| - rand(1000) |
70 |
| - ].join("_").gsub(/[\/\.:, ]/, "_") |
71 |
| - end |
| 55 | + original_after_teardown = |
| 56 | + ::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown.instance_method(:after_teardown) |
72 | 57 |
|
73 |
| - # Delegates to `Rails.application`. |
74 |
| - def app |
75 |
| - ::Rails.application |
76 |
| - end |
| 58 | + other.include ActionDispatch::IntegrationTest::Behavior |
| 59 | + other.include ::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown |
| 60 | + other.include ::ActionDispatch::SystemTesting::TestHelpers::ScreenshotHelper |
| 61 | + other.include BlowAwayAfterTeardownHook |
77 | 62 |
|
78 |
| - included do |
79 |
| - attr_reader :driver |
| 63 | + attr_reader :driver |
80 | 64 |
|
81 |
| - if ActionDispatch::SystemTesting::Server.respond_to?(:silence_puma=) |
82 |
| - ActionDispatch::SystemTesting::Server.silence_puma = true |
83 |
| - end |
| 65 | + if ActionDispatch::SystemTesting::Server.respond_to?(:silence_puma=) |
| 66 | + ActionDispatch::SystemTesting::Server.silence_puma = true |
| 67 | + end |
84 | 68 |
|
85 |
| - def initialize(*args, &blk) |
86 |
| - super(*args, &blk) |
87 |
| - @driver = nil |
88 |
| - end |
| 69 | + def initialize(*args, &blk) |
| 70 | + super(*args, &blk) |
| 71 | + @driver = nil |
| 72 | + end |
89 | 73 |
|
90 |
| - def driven_by(*args, &blk) |
91 |
| - @driver = ::ActionDispatch::SystemTestCase.driven_by(*args, &blk).tap(&:use) |
92 |
| - end |
| 74 | + def driven_by(*args, &blk) |
| 75 | + @driver = ::ActionDispatch::SystemTestCase.driven_by(*args, &blk).tap(&:use) |
| 76 | + end |
93 | 77 |
|
94 |
| - before do |
95 |
| - # A user may have already set the driver, so only default if driver |
96 |
| - # is not set |
97 |
| - driven_by(:selenium) unless @driver |
98 |
| - @routes = ::Rails.application.routes |
99 |
| - end |
| 78 | + before do |
| 79 | + # A user may have already set the driver, so only default if driver |
| 80 | + # is not set |
| 81 | + driven_by(:selenium) unless @driver |
| 82 | + @routes = ::Rails.application.routes |
| 83 | + end |
100 | 84 |
|
101 |
| - after do |
102 |
| - orig_stdout = $stdout |
103 |
| - $stdout = StringIO.new |
104 |
| - begin |
105 |
| - original_after_teardown.bind(self).call |
106 |
| - ensure |
107 |
| - myio = $stdout |
108 |
| - RSpec.current_example.metadata[:extra_failure_lines] = myio.string |
109 |
| - $stdout = orig_stdout |
110 |
| - end |
| 85 | + after do |
| 86 | + orig_stdout = $stdout |
| 87 | + $stdout = StringIO.new |
| 88 | + begin |
| 89 | + original_after_teardown.bind(self).call |
| 90 | + ensure |
| 91 | + myio = $stdout |
| 92 | + RSpec.current_example.metadata[:extra_failure_lines] = myio.string |
| 93 | + $stdout = orig_stdout |
111 | 94 | end
|
112 | 95 | end
|
113 | 96 | end
|
|
0 commit comments