diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..ab03e96 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,21 @@ +inherit_gem: + betterlint: + - config/default.yml + +inherit_mode: + merge: + - Exclude + +AllCops: + TargetRubyVersion: 3.0 + NewCops: enable + +Rails/EnvironmentVariableAccess: + Enabled: false + +RSpec/IndexedLet: + Enabled: false + +Style/FrozenStringLiteralComment: + Exclude: + - 'gemfiles/*' diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..ff365e0 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.1.3 diff --git a/Appraisals b/Appraisals index fa93d7e..2681b48 100644 --- a/Appraisals +++ b/Appraisals @@ -1,3 +1,5 @@ +# frozen_string_literal: true + appraise 'rspec-3.9' do gem 'rspec', '~> 3.9.0' end diff --git a/Gemfile b/Gemfile index 5d6c9b8..60b3130 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,10 @@ +# frozen_string_literal: true + source 'https://rubygems.org' -# Specify your gem's dependencies in rspec-fortify.gemspec gemspec + +gem 'appraisal' +gem 'betterlint' +gem 'rspec' +gem 'tty-command' diff --git a/Guardfile b/Guardfile index e6c7593..c9fe0d1 100644 --- a/Guardfile +++ b/Guardfile @@ -1,5 +1,7 @@ -guard 'rspec', :version => 2, :cli => '-c -f d' do +# frozen_string_literal: true + +guard 'rspec', version: 2, cli: '-c -f d' do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } - watch('spec/spec_helper.rb') { "spec" } + watch('spec/spec_helper.rb') { 'spec' } end diff --git a/Rakefile b/Rakefile old mode 100644 new mode 100755 index 37c6ddb..8b37144 --- a/Rakefile +++ b/Rakefile @@ -1,12 +1,11 @@ #!/usr/bin/env rake +# frozen_string_literal: true + require 'bundler/setup' -require "bundler/gem_tasks" +require 'bundler/gem_tasks' -begin - require 'rspec/core/rake_task' +require 'rspec/core/rake_task' - RSpec::Core::RakeTask.new(:spec) +RSpec::Core::RakeTask.new(:spec) - task :default => :spec -rescue LoadError -end +task default: :spec diff --git a/gemfiles/rspec_3.10.gemfile b/gemfiles/rspec_3.10.gemfile index 1c4ab36..fc4a94b 100644 --- a/gemfiles/rspec_3.10.gemfile +++ b/gemfiles/rspec_3.10.gemfile @@ -1,7 +1,12 @@ +# frozen_string_literal: true + # This file was generated by Appraisal source "https://rubygems.org" +gem "appraisal" +gem "betterlint" gem "rspec", "~> 3.10.0" +gem "tty-command" gemspec path: "../" diff --git a/gemfiles/rspec_3.10.gemfile.lock b/gemfiles/rspec_3.10.gemfile.lock index 7c27bb8..975a5b4 100644 --- a/gemfiles/rspec_3.10.gemfile.lock +++ b/gemfiles/rspec_3.10.gemfile.lock @@ -7,14 +7,51 @@ PATH GEM remote: https://rubygems.org/ specs: + activesupport (7.1.3.2) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + minitest (>= 5.1) + mutex_m + tzinfo (~> 2.0) appraisal (2.5.0) bundler rake thor (>= 0.14.0) + ast (2.4.2) + base64 (0.2.0) + betterlint (1.10.1) + rubocop (~> 1.62.0) + rubocop-performance (~> 1.21.0) + rubocop-rails (~> 2.24.0) + rubocop-rake (~> 0.6.0) + rubocop-rspec (~> 2.28.0) + bigdecimal (3.1.7) + concurrent-ruby (1.2.3) + connection_pool (2.4.1) diff-lcs (1.5.1) + drb (2.2.1) + i18n (1.14.4) + concurrent-ruby (~> 1.0) + json (2.7.2) + language_server-protocol (3.17.0.3) + minitest (5.22.3) + mutex_m (0.2.0) + parallel (1.24.0) + parser (3.3.1.0) + ast (~> 2.4.1) + racc pastel (0.8.0) tty-color (~> 0.5) + racc (1.7.3) + rack (3.0.10) + rainbow (3.1.1) rake (13.2.1) + regexp_parser (2.9.0) + rexml (3.2.6) rspec (3.10.0) rspec-core (~> 3.10.0) rspec-expectations (~> 3.10.0) @@ -28,10 +65,48 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.10.0) rspec-support (3.10.3) + rubocop (1.62.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.31.3) + parser (>= 3.3.1.0) + rubocop-capybara (2.20.0) + rubocop (~> 1.41) + rubocop-factory_bot (2.25.1) + rubocop (~> 1.41) + rubocop-performance (1.21.0) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rails (2.24.1) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 1.33.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rake (0.6.0) + rubocop (~> 1.0) + rubocop-rspec (2.28.0) + rubocop (~> 1.40) + rubocop-capybara (~> 2.17) + rubocop-factory_bot (~> 2.22) + rubocop-rspec_rails (~> 2.28) + rubocop-rspec_rails (2.28.3) + rubocop (~> 1.40) + ruby-progressbar (1.13.0) thor (1.3.1) tty-color (0.6.0) tty-command (0.10.1) pastel (~> 0.8) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + unicode-display_width (2.5.0) PLATFORMS arm64-darwin-22 @@ -39,6 +114,7 @@ PLATFORMS DEPENDENCIES appraisal + betterlint rspec (~> 3.10.0) rspec-fortify! tty-command diff --git a/gemfiles/rspec_3.11.gemfile b/gemfiles/rspec_3.11.gemfile index 61f07c2..7e43058 100644 --- a/gemfiles/rspec_3.11.gemfile +++ b/gemfiles/rspec_3.11.gemfile @@ -1,7 +1,12 @@ +# frozen_string_literal: true + # This file was generated by Appraisal source "https://rubygems.org" +gem "appraisal" +gem "betterlint" gem "rspec", "~> 3.11.0" +gem "tty-command" gemspec path: "../" diff --git a/gemfiles/rspec_3.11.gemfile.lock b/gemfiles/rspec_3.11.gemfile.lock index 8327ee8..6348a72 100644 --- a/gemfiles/rspec_3.11.gemfile.lock +++ b/gemfiles/rspec_3.11.gemfile.lock @@ -7,14 +7,51 @@ PATH GEM remote: https://rubygems.org/ specs: + activesupport (7.1.3.2) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + minitest (>= 5.1) + mutex_m + tzinfo (~> 2.0) appraisal (2.5.0) bundler rake thor (>= 0.14.0) + ast (2.4.2) + base64 (0.2.0) + betterlint (1.10.1) + rubocop (~> 1.62.0) + rubocop-performance (~> 1.21.0) + rubocop-rails (~> 2.24.0) + rubocop-rake (~> 0.6.0) + rubocop-rspec (~> 2.28.0) + bigdecimal (3.1.7) + concurrent-ruby (1.2.3) + connection_pool (2.4.1) diff-lcs (1.5.1) + drb (2.2.1) + i18n (1.14.4) + concurrent-ruby (~> 1.0) + json (2.7.2) + language_server-protocol (3.17.0.3) + minitest (5.22.3) + mutex_m (0.2.0) + parallel (1.24.0) + parser (3.3.1.0) + ast (~> 2.4.1) + racc pastel (0.8.0) tty-color (~> 0.5) + racc (1.7.3) + rack (3.0.10) + rainbow (3.1.1) rake (13.2.1) + regexp_parser (2.9.0) + rexml (3.2.6) rspec (3.11.0) rspec-core (~> 3.11.0) rspec-expectations (~> 3.11.0) @@ -28,10 +65,48 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.11.0) rspec-support (3.11.1) + rubocop (1.62.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.31.3) + parser (>= 3.3.1.0) + rubocop-capybara (2.20.0) + rubocop (~> 1.41) + rubocop-factory_bot (2.25.1) + rubocop (~> 1.41) + rubocop-performance (1.21.0) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rails (2.24.1) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 1.33.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rake (0.6.0) + rubocop (~> 1.0) + rubocop-rspec (2.28.0) + rubocop (~> 1.40) + rubocop-capybara (~> 2.17) + rubocop-factory_bot (~> 2.22) + rubocop-rspec_rails (~> 2.28) + rubocop-rspec_rails (2.28.3) + rubocop (~> 1.40) + ruby-progressbar (1.13.0) thor (1.3.1) tty-color (0.6.0) tty-command (0.10.1) pastel (~> 0.8) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + unicode-display_width (2.5.0) PLATFORMS arm64-darwin-22 @@ -39,6 +114,7 @@ PLATFORMS DEPENDENCIES appraisal + betterlint rspec (~> 3.11.0) rspec-fortify! tty-command diff --git a/gemfiles/rspec_3.12.gemfile b/gemfiles/rspec_3.12.gemfile index 561a9cd..54cce98 100644 --- a/gemfiles/rspec_3.12.gemfile +++ b/gemfiles/rspec_3.12.gemfile @@ -1,7 +1,12 @@ +# frozen_string_literal: true + # This file was generated by Appraisal source "https://rubygems.org" +gem "appraisal" +gem "betterlint" gem "rspec", "~> 3.12.0" +gem "tty-command" gemspec path: "../" diff --git a/gemfiles/rspec_3.12.gemfile.lock b/gemfiles/rspec_3.12.gemfile.lock index 3d4151c..68eaf1b 100644 --- a/gemfiles/rspec_3.12.gemfile.lock +++ b/gemfiles/rspec_3.12.gemfile.lock @@ -7,14 +7,51 @@ PATH GEM remote: https://rubygems.org/ specs: + activesupport (7.1.3.2) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + minitest (>= 5.1) + mutex_m + tzinfo (~> 2.0) appraisal (2.5.0) bundler rake thor (>= 0.14.0) + ast (2.4.2) + base64 (0.2.0) + betterlint (1.10.1) + rubocop (~> 1.62.0) + rubocop-performance (~> 1.21.0) + rubocop-rails (~> 2.24.0) + rubocop-rake (~> 0.6.0) + rubocop-rspec (~> 2.28.0) + bigdecimal (3.1.7) + concurrent-ruby (1.2.3) + connection_pool (2.4.1) diff-lcs (1.5.1) + drb (2.2.1) + i18n (1.14.4) + concurrent-ruby (~> 1.0) + json (2.7.2) + language_server-protocol (3.17.0.3) + minitest (5.22.3) + mutex_m (0.2.0) + parallel (1.24.0) + parser (3.3.1.0) + ast (~> 2.4.1) + racc pastel (0.8.0) tty-color (~> 0.5) + racc (1.7.3) + rack (3.0.10) + rainbow (3.1.1) rake (13.2.1) + regexp_parser (2.9.0) + rexml (3.2.6) rspec (3.12.0) rspec-core (~> 3.12.0) rspec-expectations (~> 3.12.0) @@ -28,10 +65,48 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) rspec-support (3.12.2) + rubocop (1.62.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.31.3) + parser (>= 3.3.1.0) + rubocop-capybara (2.20.0) + rubocop (~> 1.41) + rubocop-factory_bot (2.25.1) + rubocop (~> 1.41) + rubocop-performance (1.21.0) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rails (2.24.1) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 1.33.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rake (0.6.0) + rubocop (~> 1.0) + rubocop-rspec (2.28.0) + rubocop (~> 1.40) + rubocop-capybara (~> 2.17) + rubocop-factory_bot (~> 2.22) + rubocop-rspec_rails (~> 2.28) + rubocop-rspec_rails (2.28.3) + rubocop (~> 1.40) + ruby-progressbar (1.13.0) thor (1.3.1) tty-color (0.6.0) tty-command (0.10.1) pastel (~> 0.8) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + unicode-display_width (2.5.0) PLATFORMS arm64-darwin-22 @@ -39,6 +114,7 @@ PLATFORMS DEPENDENCIES appraisal + betterlint rspec (~> 3.12.0) rspec-fortify! tty-command diff --git a/gemfiles/rspec_3.13.gemfile b/gemfiles/rspec_3.13.gemfile index be287d5..7ec1349 100644 --- a/gemfiles/rspec_3.13.gemfile +++ b/gemfiles/rspec_3.13.gemfile @@ -1,7 +1,12 @@ +# frozen_string_literal: true + # This file was generated by Appraisal source "https://rubygems.org" +gem "appraisal" +gem "betterlint" gem "rspec", "~> 3.13.0" +gem "tty-command" gemspec path: "../" diff --git a/gemfiles/rspec_3.13.gemfile.lock b/gemfiles/rspec_3.13.gemfile.lock index c873fb0..31115d9 100644 --- a/gemfiles/rspec_3.13.gemfile.lock +++ b/gemfiles/rspec_3.13.gemfile.lock @@ -7,14 +7,51 @@ PATH GEM remote: https://rubygems.org/ specs: + activesupport (7.1.3.2) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + minitest (>= 5.1) + mutex_m + tzinfo (~> 2.0) appraisal (2.5.0) bundler rake thor (>= 0.14.0) + ast (2.4.2) + base64 (0.2.0) + betterlint (1.10.1) + rubocop (~> 1.62.0) + rubocop-performance (~> 1.21.0) + rubocop-rails (~> 2.24.0) + rubocop-rake (~> 0.6.0) + rubocop-rspec (~> 2.28.0) + bigdecimal (3.1.7) + concurrent-ruby (1.2.3) + connection_pool (2.4.1) diff-lcs (1.5.1) + drb (2.2.1) + i18n (1.14.4) + concurrent-ruby (~> 1.0) + json (2.7.2) + language_server-protocol (3.17.0.3) + minitest (5.22.3) + mutex_m (0.2.0) + parallel (1.24.0) + parser (3.3.1.0) + ast (~> 2.4.1) + racc pastel (0.8.0) tty-color (~> 0.5) + racc (1.7.3) + rack (3.0.10) + rainbow (3.1.1) rake (13.2.1) + regexp_parser (2.9.0) + rexml (3.2.6) rspec (3.13.0) rspec-core (~> 3.13.0) rspec-expectations (~> 3.13.0) @@ -28,10 +65,48 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) rspec-support (3.13.1) + rubocop (1.62.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.31.3) + parser (>= 3.3.1.0) + rubocop-capybara (2.20.0) + rubocop (~> 1.41) + rubocop-factory_bot (2.25.1) + rubocop (~> 1.41) + rubocop-performance (1.21.0) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rails (2.24.1) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 1.33.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rake (0.6.0) + rubocop (~> 1.0) + rubocop-rspec (2.28.0) + rubocop (~> 1.40) + rubocop-capybara (~> 2.17) + rubocop-factory_bot (~> 2.22) + rubocop-rspec_rails (~> 2.28) + rubocop-rspec_rails (2.28.3) + rubocop (~> 1.40) + ruby-progressbar (1.13.0) thor (1.3.1) tty-color (0.6.0) tty-command (0.10.1) pastel (~> 0.8) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + unicode-display_width (2.5.0) PLATFORMS arm64-darwin-22 @@ -39,6 +114,7 @@ PLATFORMS DEPENDENCIES appraisal + betterlint rspec (~> 3.13.0) rspec-fortify! tty-command diff --git a/gemfiles/rspec_3.9.gemfile b/gemfiles/rspec_3.9.gemfile index 4212c75..5915605 100644 --- a/gemfiles/rspec_3.9.gemfile +++ b/gemfiles/rspec_3.9.gemfile @@ -1,7 +1,12 @@ +# frozen_string_literal: true + # This file was generated by Appraisal source "https://rubygems.org" +gem "appraisal" +gem "betterlint" gem "rspec", "~> 3.9.0" +gem "tty-command" gemspec path: "../" diff --git a/gemfiles/rspec_3.9.gemfile.lock b/gemfiles/rspec_3.9.gemfile.lock index fd326d3..a6cc3e4 100644 --- a/gemfiles/rspec_3.9.gemfile.lock +++ b/gemfiles/rspec_3.9.gemfile.lock @@ -7,14 +7,51 @@ PATH GEM remote: https://rubygems.org/ specs: + activesupport (7.1.3.2) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + minitest (>= 5.1) + mutex_m + tzinfo (~> 2.0) appraisal (2.5.0) bundler rake thor (>= 0.14.0) + ast (2.4.2) + base64 (0.2.0) + betterlint (1.10.1) + rubocop (~> 1.62.0) + rubocop-performance (~> 1.21.0) + rubocop-rails (~> 2.24.0) + rubocop-rake (~> 0.6.0) + rubocop-rspec (~> 2.28.0) + bigdecimal (3.1.7) + concurrent-ruby (1.2.3) + connection_pool (2.4.1) diff-lcs (1.5.1) + drb (2.2.1) + i18n (1.14.4) + concurrent-ruby (~> 1.0) + json (2.7.2) + language_server-protocol (3.17.0.3) + minitest (5.22.3) + mutex_m (0.2.0) + parallel (1.24.0) + parser (3.3.1.0) + ast (~> 2.4.1) + racc pastel (0.8.0) tty-color (~> 0.5) + racc (1.7.3) + rack (3.0.10) + rainbow (3.1.1) rake (13.2.1) + regexp_parser (2.9.0) + rexml (3.2.6) rspec (3.9.0) rspec-core (~> 3.9.0) rspec-expectations (~> 3.9.0) @@ -28,10 +65,48 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) rspec-support (3.9.4) + rubocop (1.62.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.31.3) + parser (>= 3.3.1.0) + rubocop-capybara (2.20.0) + rubocop (~> 1.41) + rubocop-factory_bot (2.25.1) + rubocop (~> 1.41) + rubocop-performance (1.21.0) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rails (2.24.1) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 1.33.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rake (0.6.0) + rubocop (~> 1.0) + rubocop-rspec (2.28.0) + rubocop (~> 1.40) + rubocop-capybara (~> 2.17) + rubocop-factory_bot (~> 2.22) + rubocop-rspec_rails (~> 2.28) + rubocop-rspec_rails (2.28.3) + rubocop (~> 1.40) + ruby-progressbar (1.13.0) thor (1.3.1) tty-color (0.6.0) tty-command (0.10.1) pastel (~> 0.8) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + unicode-display_width (2.5.0) PLATFORMS arm64-darwin-22 @@ -39,6 +114,7 @@ PLATFORMS DEPENDENCIES appraisal + betterlint rspec (~> 3.9.0) rspec-fortify! tty-command diff --git a/lib/rspec/fortify.rb b/lib/rspec/fortify.rb index 2f4f7cf..1c628b2 100644 --- a/lib/rspec/fortify.rb +++ b/lib/rspec/fortify.rb @@ -1,52 +1,52 @@ +# frozen_string_literal: true + require 'rspec/core' require 'rspec/fortify/version' require 'rspec_ext/rspec_ext' module RSpec class Fortify - def self.setup + def self.setup # rubocop:disable Metrics/AbcSize RSpec.configure do |config| - config.add_setting :clear_lets_on_failure, :default => true - config.add_setting :default_retry_count, :default => 1 - config.add_setting :default_sleep_interval, :default => 0 - config.add_setting :display_try_failure_messages, :default => true - config.add_setting :exponential_backoff, :default => false + config.add_setting :clear_lets_on_failure, default: true + config.add_setting :default_retry_count, default: 1 + config.add_setting :default_sleep_interval, default: 0 + config.add_setting :display_try_failure_messages, default: true + config.add_setting :exponential_backoff, default: false config.add_setting :retry_on_failure, default: main? || pr? config.add_setting :retry_on_failure_count, default: 2 config.add_setting :retry_on_success, default: pr? && changed_specs.size < 30 config.add_setting :retry_on_success_count, default: 10 - config.add_setting :verbose_retry, :default => true + config.add_setting :verbose_retry, default: true # retry based on example metadata - config.add_setting :retry_count_condition, :default => ->(_) { nil } + config.add_setting :retry_count_condition, default: ->(_) {} # If a list of exceptions is provided and 'retry' > 1, we only retry if # the exception that was raised by the example is NOT in that list. Otherwise # we ignore the 'retry' value and fail immediately. # # If no list of exceptions is provided and 'retry' > 1, we always retry. - config.add_setting :exceptions_to_hard_fail, :default => [] + config.add_setting :exceptions_to_hard_fail, default: [] # If a list of exceptions is provided and 'retry' > 1, we only retry if # the exception that was raised by the example is in that list. Otherwise # we ignore the 'retry' value and fail immediately. # # If no list of exceptions is provided and 'retry' > 1, we always retry. - config.add_setting :exceptions_to_retry, :default => [] + config.add_setting :exceptions_to_retry, default: [] # Callback between retries - config.add_setting :retry_callback, :default => nil + config.add_setting :retry_callback, default: nil - config.around :each do |example| - example.run_with_retry - end + config.around :each, &:run_with_retry end end attr_reader :context, :ex - def initialize(ex, opts = {}) - @ex = ex + def initialize(example, opts = {}) + @ex = example @ex.metadata.merge!(opts) current_example.attempts ||= 0 end @@ -55,7 +55,7 @@ def current_example @current_example ||= RSpec.current_example end - def retry_count + def retry_count # rubocop:disable Metrics/AbcSize if retry_on_success? RSpec.configuration.retry_on_success_count elsif retry_on_failure? @@ -82,28 +82,30 @@ def attempts=(val) end def clear_lets - !ex.metadata[:clear_lets_on_failure].nil? ? - ex.metadata[:clear_lets_on_failure] : - RSpec.configuration.clear_lets_on_failure + if ex.metadata[:clear_lets_on_failure].nil? + RSpec.configuration.clear_lets_on_failure + else + ex.metadata[:clear_lets_on_failure] + end end def sleep_interval if ex.metadata[:exponential_backoff] - 2**(current_example.attempts-1) * ex.metadata[:retry_wait] + (2**(current_example.attempts - 1)) * ex.metadata[:retry_wait] else - ex.metadata[:retry_wait] || - RSpec.configuration.default_sleep_interval + ex.metadata[:retry_wait] || + RSpec.configuration.default_sleep_interval end end def exceptions_to_hard_fail ex.metadata[:exceptions_to_hard_fail] || - RSpec.configuration.exceptions_to_hard_fail + RSpec.configuration.exceptions_to_hard_fail end def exceptions_to_retry ex.metadata[:exceptions_to_retry] || - RSpec.configuration.exceptions_to_retry + RSpec.configuration.exceptions_to_retry end def verbose_retry? @@ -114,7 +116,7 @@ def display_try_failure_messages? RSpec.configuration.display_try_failure_messages? end - def run + def run # rubocop:disable Metrics/PerceivedComplexity, Metrics/AbcSize, Metrics/CyclomaticComplexity loop do RSpec.configuration.formatters.each { |f| f.retry(ex) if f.respond_to? :retry } if attempts.positive? @@ -142,9 +144,7 @@ def run break end - if exceptions_to_retry.any? && ex.exception && !exception_exists_in?(exceptions_to_retry, ex.exception) - break - end + break if exceptions_to_retry.any? && ex.exception && !exception_exists_in?(exceptions_to_retry, ex.exception) if verbose_retry? && display_try_failure_messages? && retry_on_failure? && (attempts != retry_count) exception_strings = @@ -172,21 +172,21 @@ def run # borrowed from ActiveSupport::Inflector def ordinalize(number) - if (11..13).include?(number.to_i % 100) + if (11..13).cover?(number.to_i % 100) "#{number}th" else case number.to_i % 10 - when 1; "#{number}st" - when 2; "#{number}nd" - when 3; "#{number}rd" - else "#{number}th" + when 1 then "#{number}st" + when 2 then "#{number}nd" + when 3 then "#{number}rd" + else "#{number}th" end end end def exception_exists_in?(list, exception) list.any? do |exception_klass| - exception.is_a?(exception_klass) || exception_klass === exception + exception.is_a?(exception_klass) || exception_klass === exception # rubocop:disable Style/CaseEquality end end @@ -229,7 +229,7 @@ def should_retry? end def cast_to_boolean(value) - if value.nil? || %w(false f 0 no n).include?(value.to_s.downcase) + if value.nil? || %w(false f 0 no n).include?(value.to_s.downcase) # rubocop:disable Style/IfWithBooleanLiteralBranches false else true diff --git a/lib/rspec/fortify/formatter.rb b/lib/rspec/fortify/formatter.rb index 4619398..b956d97 100644 --- a/lib/rspec/fortify/formatter.rb +++ b/lib/rspec/fortify/formatter.rb @@ -1,56 +1,65 @@ +# frozen_string_literal: true + require 'rspec/core/formatters/base_text_formatter' -class RSpec::Fortify::Formatter < RSpec::Core::Formatters::BaseTextFormatter - RSpec::Core::Formatters.register self, :example_passed +module RSpec + module Fortify + class Formatter < RSpec::Core::Formatters::BaseTextFormatter + RSpec::Core::Formatters.register self, :example_passed - def initialize(output) - super(output) - @tries = Hash.new { |h, k| h[k] = { successes: 0, tries: 0 } } - end + def initialize(output) + super(output) + @tries = Hash.new { |h, k| h[k] = { successes: 0, tries: 0 } } + end - def seed(_); end + def seed(_); end - def message(_message); end + def message(_message); end - def close(_); end + def close(_); end - def dump_failures(_); end + def dump_failures(_); end - def dump_pending(_); end + def dump_pending(_); end - def dump_summary(notification) - summary = "\nRSpec Fortify Summary:\n" - @tries.each do |key, retry_data| - next if retry_data[:successes] < 1 || retry_data[:tries] <= 1 - summary += "\t#{key.location}: #{key.full_description}: passed at attempt #{retry_data[:tries]}\n" - end - retried = @tries.count { |_, v| v[:tries] > 1 && v[:successes] > 0 } - summary += "\n\t#{retried} of #{notification.example_count} tests passed with retries.\n" - summary += "\t#{notification.failure_count} tests failed all retries.\n" - output.puts summary - end + def dump_summary(notification) # rubocop:disable Metrics/AbcSize + summary = "\nRSpec Fortify Summary:\n" + @tries.each do |key, retry_data| + next if retry_data[:successes] < 1 || retry_data[:tries] <= 1 - def example_passed(notification) - increment_success notification.example - end + summary += "\t#{key.location}: #{key.full_description}: passed at attempt #{retry_data[:tries]}\n" + end + retried = @tries.count { |_, v| v[:tries] > 1 && (v[:successes]).positive? } + summary += "\n\t#{retried} of #{notification.example_count} tests passed with retries.\n" + summary += "\t#{notification.failure_count} tests failed all retries.\n" + output.puts summary + end - def retry(example) - increment_tries example - end + def example_passed(notification) + increment_success notification.example + end - private + def retry(example) + increment_tries example + end - def increment_success(example) - # debugger - previous = @tries[example] - @tries[example] = { - successes: previous[:successes] + 1, tries: previous[:tries] + 1 } - end + private - def increment_tries(example) - # debugger - previous = @tries[example] - @tries[example] = { - successes: previous[:successes], tries: previous[:tries] + 1 } + def increment_success(example) + # debugger + previous = @tries[example] + @tries[example] = { + successes: previous[:successes] + 1, tries: previous[:tries] + 1 + } + end + + def increment_tries(example) + # debugger + previous = @tries[example] + @tries[example] = { + successes: previous[:successes], tries: previous[:tries] + 1 + } + end + end end end diff --git a/lib/rspec/fortify/version.rb b/lib/rspec/fortify/version.rb index 98694a5..ba39cb4 100644 --- a/lib/rspec/fortify/version.rb +++ b/lib/rspec/fortify/version.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + module RSpec class Fortify - VERSION = "1.0.0.pre" + VERSION = '1.0.0.pre' end end diff --git a/lib/rspec_ext/rspec_ext.rb b/lib/rspec_ext/rspec_ext.rb index 3fd0fc3..35b7b95 100644 --- a/lib/rspec_ext/rspec_ext.rb +++ b/lib/rspec_ext/rspec_ext.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module RSpec module Core class Example diff --git a/rspec-fortify.gemspec b/rspec-fortify.gemspec index ee82785..6fe2e8a 100644 --- a/rspec-fortify.gemspec +++ b/rspec-fortify.gemspec @@ -1,22 +1,22 @@ -# -*- encoding: utf-8 -*- -require File.expand_path('../lib/rspec/fortify/version', __FILE__) +# frozen_string_literal: true -Gem::Specification.new do |gem| - gem.authors = ['Yusuke Mito', 'Michael Glass', 'Devin Burnette'] - gem.email = ["devin@betterment.com"] - gem.description = %q{retry intermittently failing rspec examples} - gem.summary = %q{retry intermittently failing rspec examples} - gem.homepage = "https://github.com/Betterment/rspec-fortify" - gem.license = "MIT" +require 'English' +require File.expand_path('lib/rspec/fortify/version', __dir__) - gem.files = `git ls-files`.split($\) - gem.executables = [] - gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) - gem.name = "rspec-fortify" - gem.require_paths = ["lib"] - gem.version = RSpec::Fortify::VERSION - gem.add_runtime_dependency(%{rspec-core}, '>3.9') - gem.add_development_dependency %q{appraisal} - gem.add_development_dependency %q{rspec} - gem.add_development_dependency %q{tty-command} +Gem::Specification.new do |spec| + spec.authors = ['Yusuke Mito', 'Michael Glass', 'Devin Burnette'] + spec.email = ['devin@betterment.com'] + spec.description = 'retry intermittently failing rspec examples' + spec.summary = 'retry intermittently failing rspec examples' + spec.homepage = 'https://github.com/Betterment/rspec-fortify' + spec.license = 'MIT' + spec.metadata['rubygems_mfa_required'] = 'true' + + spec.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR) + spec.executables = [] + spec.name = 'rspec-fortify' + spec.require_paths = ['lib'] + spec.version = RSpec::Fortify::VERSION + spec.required_ruby_version = '>= 3.0' + spec.add_runtime_dependency 'rspec-core', '>3.9' end diff --git a/spec/fixtures/bad_test.rb b/spec/fixtures/bad_test.rb index 8d2fb1f..cc2bf6d 100644 --- a/spec/fixtures/bad_test.rb +++ b/spec/fixtures/bad_test.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -RSpec.describe 'Bad Test Example' do +RSpec.describe 'Bad Test Example' do # rubocop:disable RSpec/FilePath let(:foo) { false } it 'is a bad test' do diff --git a/spec/fixtures/flaky_test.rb b/spec/fixtures/flaky_test.rb index 855da0b..73d4cf4 100644 --- a/spec/fixtures/flaky_test.rb +++ b/spec/fixtures/flaky_test.rb @@ -1,13 +1,15 @@ +# frozen_string_literal: true + require 'spec_helper' -RSpec.describe 'Flaky Test Example' do - before(:all) do - $try_counter = 0 +RSpec.describe 'Flaky Test Example' do # rubocop:disable RSpec/FilePath + before(:all) do # rubocop:disable RSpec/BeforeAfterAll + $try_counter = 0 # rubocop:disable Style/GlobalVars end it 'fails on the third try' do - $try_counter += 1 + $try_counter += 1 # rubocop:disable Style/GlobalVars - expect($try_counter).not_to eq(3), "Intentionally failing on the third try" + expect($try_counter).not_to eq(3), 'Intentionally failing on the third try' # rubocop:disable Style/GlobalVars end end diff --git a/spec/fixtures/good_test.rb b/spec/fixtures/good_test.rb index ff5cdb7..c8a8e40 100644 --- a/spec/fixtures/good_test.rb +++ b/spec/fixtures/good_test.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -RSpec.describe 'Good Test Example' do +RSpec.describe 'Good Test Example' do # rubocop:disable RSpec/FilePath let(:foo) { true } it 'is a good test' do diff --git a/spec/lib/rspec/fortify_spec.rb b/spec/lib/rspec/fortify_spec.rb index a287f59..6ba1bc5 100644 --- a/spec/lib/rspec/fortify_spec.rb +++ b/spec/lib/rspec/fortify_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'tty-command' @@ -16,19 +18,19 @@ end it 'retries bad test examples the configured failed retry amount' do - out, _err = cmd.run!('bundle exec rspec spec/fixtures/bad_test.rb', env:) + out, _err = cmd.run!('bundle exec rspec spec/fixtures/bad_test.rb', env: env) expect(out).to include('2nd try') expect(out).not_to include('10th try') end it 'runs good test examples once' do - out, _err = cmd.run!('bundle exec rspec spec/fixtures/good_test.rb', env:) + out, _err = cmd.run!('bundle exec rspec spec/fixtures/good_test.rb', env: env) expect(out).to include('1st try') expect(out).not_to include('2nd try') end it 'runs flaky test examples once' do - out, _err = cmd.run!('bundle exec rspec spec/fixtures/flaky_test.rb', env:) + out, _err = cmd.run!('bundle exec rspec spec/fixtures/flaky_test.rb', env: env) expect(out).to include('1st try') expect(out).not_to include('2nd try') end @@ -43,19 +45,19 @@ end it 'retries bad test examples the configured failed retry amount' do - out, _err = cmd.run!('bundle exec rspec spec/fixtures/bad_test.rb', env:) + out, _err = cmd.run!('bundle exec rspec spec/fixtures/bad_test.rb', env: env) expect(out).to include('2nd try') expect(out).not_to include('10th try') end it 'runs good test examples once' do - out, _err = cmd.run!('bundle exec rspec spec/fixtures/good_test.rb', env:) + out, _err = cmd.run!('bundle exec rspec spec/fixtures/good_test.rb', env: env) expect(out).to include('1st try') expect(out).not_to include('2nd try') end it 'runs flaky test examples once' do - out, _err = cmd.run!('bundle exec rspec spec/fixtures/flaky_test.rb', env:) + out, _err = cmd.run!('bundle exec rspec spec/fixtures/flaky_test.rb', env: env) expect(out).to include('1st try') expect(out).not_to include('2nd try') end @@ -75,19 +77,19 @@ end it 'retries bad test examples the configured failed retry amount' do - out, _err = cmd.run!('bundle exec rspec spec/fixtures/bad_test.rb', env:) + out, _err = cmd.run!('bundle exec rspec spec/fixtures/bad_test.rb', env: env) expect(out).to include('2nd try') expect(out).not_to include('10th try') end it 'runs good test examples once' do - out, _err = cmd.run!('bundle exec rspec spec/fixtures/good_test.rb', env:) + out, _err = cmd.run!('bundle exec rspec spec/fixtures/good_test.rb', env: env) expect(out).to include('1st try') expect(out).not_to include('2nd try') end it 'runs flaky test examples once' do - out, _err = cmd.run!('bundle exec rspec spec/fixtures/flaky_test.rb', env:) + out, _err = cmd.run!('bundle exec rspec spec/fixtures/flaky_test.rb', env: env) expect(out).to include('1st try') expect(out).not_to include('2nd try') end @@ -104,18 +106,18 @@ end it 'retries bad test examples the configured failed retry amount' do - out, _err = cmd.run!('bundle exec rspec spec/fixtures/bad_test.rb', env:) + out, _err = cmd.run!('bundle exec rspec spec/fixtures/bad_test.rb', env: env) expect(out).to include('1st try') expect(out).not_to include('2nd try') end it 'retries good test examples the configured success retry amount' do - out, _err = cmd.run!('bundle exec rspec spec/fixtures/good_test.rb', env:) + out, _err = cmd.run!('bundle exec rspec spec/fixtures/good_test.rb', env: env) expect(out).to include('10th try') end it 'retries flaky test examples until they flake' do - out, _err = cmd.run!('bundle exec rspec spec/fixtures/flaky_test.rb', env:) + out, _err = cmd.run!('bundle exec rspec spec/fixtures/flaky_test.rb', env: env) expect(out).to include('2nd try') end end @@ -131,19 +133,19 @@ end it 'retries bad test examples the configured failed retry amount' do - out, _err = cmd.run!('bundle exec rspec spec/fixtures/bad_test.rb', env:) + out, _err = cmd.run!('bundle exec rspec spec/fixtures/bad_test.rb', env: env) expect(out).to include('2nd try') expect(out).not_to include('10th try') end it 'runs good test examples once' do - out, _err = cmd.run!('bundle exec rspec spec/fixtures/good_test.rb', env:) + out, _err = cmd.run!('bundle exec rspec spec/fixtures/good_test.rb', env: env) expect(out).to include('1st try') expect(out).not_to include('2nd try') end it 'runs flaky test examples once' do - out, _err = cmd.run!('bundle exec rspec spec/fixtures/flaky_test.rb', env:) + out, _err = cmd.run!('bundle exec rspec spec/fixtures/flaky_test.rb', env: env) expect(out).to include('1st try') expect(out).not_to include('2nd try') end @@ -161,19 +163,19 @@ end it 'runs bad test examples once' do - out, _err = cmd.run!('bundle exec rspec spec/fixtures/bad_test.rb', env:) + out, _err = cmd.run!('bundle exec rspec spec/fixtures/bad_test.rb', env: env) expect(out).to include('1st try') expect(out).not_to include('2nd try') end it 'runs good test examples once' do - out, _err = cmd.run!('bundle exec rspec spec/fixtures/good_test.rb', env:) + out, _err = cmd.run!('bundle exec rspec spec/fixtures/good_test.rb', env: env) expect(out).to include('1st try') expect(out).not_to include('2nd try') end it 'runs flaky test examples once' do - out, _err = cmd.run!('bundle exec rspec spec/fixtures/flaky_test.rb', env:) + out, _err = cmd.run!('bundle exec rspec spec/fixtures/flaky_test.rb', env: env) expect(out).to include('1st try') expect(out).not_to include('2nd try') end @@ -188,19 +190,19 @@ end it 'runs bad test examples once' do - out, _err = cmd.run!('bundle exec rspec spec/fixtures/bad_test.rb', env:) + out, _err = cmd.run!('bundle exec rspec spec/fixtures/bad_test.rb', env: env) expect(out).to include('1st try') expect(out).not_to include('2nd try') end it 'runs good test examples once' do - out, _err = cmd.run!('bundle exec rspec spec/fixtures/good_test.rb', env:) + out, _err = cmd.run!('bundle exec rspec spec/fixtures/good_test.rb', env: env) expect(out).to include('1st try') expect(out).not_to include('2nd try') end it 'runs flaky test examples once' do - out, _err = cmd.run!('bundle exec rspec spec/fixtures/flaky_test.rb', env:) + out, _err = cmd.run!('bundle exec rspec spec/fixtures/flaky_test.rb', env: env) expect(out).to include('1st try') expect(out).not_to include('2nd try') end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c5ab267..f9db90a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + require 'rspec/fortify'