From 73bb866d9a184596104a51ef27059fac6bb0ed54 Mon Sep 17 00:00:00 2001 From: Wyatt Ades Date: Tue, 14 May 2024 01:07:25 -0400 Subject: [PATCH] skip screenshots in rspec --- lib/cyperful.rb | 1 + lib/cyperful/framework_helper.rb | 7 +++++++ lib/cyperful/framework_injections.rb | 3 --- lib/cyperful/minitest.rb | 8 ++------ lib/cyperful/rspec.rb | 4 +++- test/dummy/Gemfile | 3 +-- 6 files changed, 14 insertions(+), 12 deletions(-) create mode 100644 lib/cyperful/framework_helper.rb diff --git a/lib/cyperful.rb b/lib/cyperful.rb index 2727d87..ae26744 100644 --- a/lib/cyperful.rb +++ b/lib/cyperful.rb @@ -65,5 +65,6 @@ def self.add_step_at_methods(*mods_or_methods) require "cyperful/test_parser" require "cyperful/ui_server" require "cyperful/driver" +require "cyperful/framework_helper" require "cyperful/framework_injections" require "cyperful/railtie" if defined?(Rails::Railtie) diff --git a/lib/cyperful/framework_helper.rb b/lib/cyperful/framework_helper.rb new file mode 100644 index 0000000..d2dc586 --- /dev/null +++ b/lib/cyperful/framework_helper.rb @@ -0,0 +1,7 @@ +module Cyperful::FrameworkHelper + # Disable default screenshot on failure b/c we handle them ourselves. + # https://github.com/rails/rails/blob/v7.0.1/actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb#L156 + def take_failed_screenshot + nil + end +end diff --git a/lib/cyperful/framework_injections.rb b/lib/cyperful/framework_injections.rb index 2c004c9..8d25bb7 100644 --- a/lib/cyperful/framework_injections.rb +++ b/lib/cyperful/framework_injections.rb @@ -65,9 +65,6 @@ def initialize(...) # hide the "Chrome is being controlled by automated test software" infobar driver_opts.args.delete("--enable-automation") driver_opts.exclude_switches << "enable-automation" - - pp args: driver_opts.args, - exclude_switches: driver_opts.exclude_switches end end end diff --git a/lib/cyperful/minitest.rb b/lib/cyperful/minitest.rb index 44b1649..b43fad9 100644 --- a/lib/cyperful/minitest.rb +++ b/lib/cyperful/minitest.rb @@ -3,6 +3,8 @@ module Cyperful::Minitest # rubocop:disable Style/ClassAndModuleChildren module SystemTestHelper + include Cyperful::FrameworkHelper + def setup Cyperful.setup(self.class, self.method_name) super @@ -16,12 +18,6 @@ def teardown Cyperful.teardown(error) super end - - # Disable default screenshot on failure b/c we handle them ourselves. - # https://github.com/rails/rails/blob/main/actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb#L156 - def take_failed_screenshot - nil - end end end diff --git a/lib/cyperful/rspec.rb b/lib/cyperful/rspec.rb index 7449a57..74a5012 100644 --- a/lib/cyperful/rspec.rb +++ b/lib/cyperful/rspec.rb @@ -2,6 +2,8 @@ module Cyperful::Rspec def self.configure(rspec_conf) + rspec_conf.include(Cyperful::FrameworkHelper) + rspec_conf.before(:example, type: :system) do # e.g. class = `RSpec::ExampleGroups::MyTest` # e.g. full_description = "my_test can visit root" @@ -11,7 +13,7 @@ def self.configure(rspec_conf) rspec_conf.after(:example, type: :system) do example = RSpec.current_example - error = example.exception + error = example.exception # may be nil # if error.is_a?(RSpec::Expectations::ExpectationNotMetError) # error = error.error diff --git a/test/dummy/Gemfile b/test/dummy/Gemfile index cac769e..f17f50a 100644 --- a/test/dummy/Gemfile +++ b/test/dummy/Gemfile @@ -44,8 +44,7 @@ group :test do gem "capybara" gem "selenium-webdriver" - # manually load test-frameworks since we support multiple - gem "rspec-rails" + gem "rspec-rails" # should we require=false this? gem "cyperful", path: "../..", require: false end