diff --git a/.rubocop_rspec_base.yml b/.rubocop_rspec_base.yml index af024e8c53..4af70a17fc 100644 --- a/.rubocop_rspec_base.yml +++ b/.rubocop_rspec_base.yml @@ -69,10 +69,6 @@ LineLength: MethodLength: Max: 15 -# Who cares what we call the argument for binary operator methods? -BinaryOperatorParameterName: - Enabled: false - PercentLiteralDelimiters: PreferredDelimiters: '%': () # double-quoted string @@ -115,195 +111,16 @@ StringLiterals: Style/SpecialGlobalVars: Enabled: false -Style/TrailingCommaInLiteral: - Enabled: false - -Style/TrailingCommaInArguments: - Enabled: false - TrivialAccessors: AllowDSLWriters: true AllowPredicates: true ExactNameMatch: true -Style/ParallelAssignment: - Enabled: false - -Layout/EmptyLineBetweenDefs: - Enabled: false - -Layout/FirstParameterIndentation: - Enabled: false - -Naming/ConstantName: - Enabled: false - -Style/ClassCheck: - Enabled: false - -Style/ConditionalAssignment: - Enabled: false - -Style/EmptyMethod: - Enabled: false - -Style/FormatStringToken: - Enabled: false - Style/GuardClause: Enabled: false -Style/IdenticalConditionalBranches: - Enabled: false - Style/IfUnlessModifier: Enabled: false -Style/IfUnlessModifierOfIfUnless: - Enabled: false - -Style/MethodMissing: - Enabled: false - -Style/MixinUsage: - Enabled: false - -Style/MultipleComparison: - Enabled: false - -Style/MutableConstant: - Enabled: false - -Style/NestedModifier: - Enabled: false - -Style/NestedParenthesizedCalls: - Enabled: false - -Style/NumericPredicate: - Enabled: false - -Style/RedundantParentheses: - Enabled: false - -Style/StringLiteralsInInterpolation: - Enabled: false - Style/SymbolArray: Enabled: false - -Style/SymbolProc: - Enabled: false - -Style/YodaCondition: - Enabled: false - -Style/ZeroLengthPredicate: - Enabled: false - -Layout/ClosingParenthesisIndentation: - Enabled: false - -Layout/ExtraSpacing: - Enabled: false - -Layout/MultilineMethodCallBraceLayout: - Enabled: false - -Layout/MultilineMethodCallIndentation: - Enabled: false - -Layout/MultilineOperationIndentation: - Enabled: false - -Layout/SpaceAroundBlockParameters: - Enabled: false - -Layout/SpaceAroundOperators: - Enabled: false - -Layout/SpaceBeforeComma: - Enabled: false - -Style/BlockDelimiters: - Enabled: false - -Style/EmptyCaseCondition: - Enabled: false - -Style/MultilineIfModifier: - Enabled: false - -Style/RescueStandardError: - Enabled: false - -Style/StderrPuts: - Enabled: false - -Style/TernaryParentheses: - Enabled: false - -# This could likely be enabled, but it had a false positive on rspec-mocks -# (suggested change was not behaviour preserving) so I don't trust it. -Performance/HashEachMethods: - Enabled: false - -Naming/HeredocDelimiterNaming: - Enabled: false - -Layout/EmptyLineAfterMagicComment: - Enabled: false - -Layout/IndentArray: - Enabled: false - -Layout/IndentAssignment: - Enabled: false - -Layout/IndentHeredoc: - Enabled: false - -Layout/SpaceInsidePercentLiteralDelimiters: - Enabled: false - -Style/EmptyElse: - Enabled: false - -Style/IfInsideElse: - Enabled: false - -Style/RedundantReturn: - Enabled: false - -Style/StructInheritance: - Enabled: false - -Naming/VariableNumber: - Enabled: false - -Layout/SpaceInsideStringInterpolation: - Enabled: false - -Style/DateTime: - Enabled: false - -Style/ParenthesesAroundCondition: - Enabled: false - -Layout/EmptyLinesAroundBlockBody: - Enabled: false - -Lint/ImplicitStringConcatenation: - Enabled: false - -Lint/NestedMethodDefinition: - Enabled: false - -Style/RegexpLiteral: - Enabled: false - -Style/TrailingUnderscoreVariable: - Enabled: false - -Layout/EmptyLinesAroundAccessModifier: - Enabled: false diff --git a/.travis.yml b/.travis.yml index a1cc8fe9ce..40b827eea8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,57 +38,61 @@ dist: trusty matrix: include: # Rails dev / 6 builds >= 2.4.4 - - rvm: 2.6.3 + - rvm: 2.6.6 env: RAILS_VERSION=master - - rvm: 2.5.3 + - rvm: 2.5.8 env: RAILS_VERSION=master - - rvm: 2.4.4 + - rvm: 2.4.10 env: RAILS_VERSION=master # Rails 5.2 builds >= 2.2.2 - - rvm: 2.6.3 + - rvm: 2.6.6 env: RAILS_VERSION='~> 5.2.0' - - rvm: 2.5.3 + - rvm: 2.5.8 env: RAILS_VERSION='~> 5.2.0' - - rvm: 2.4.4 + - rvm: 2.4.10 env: RAILS_VERSION='~> 5.2.0' - - rvm: 2.3.7 + - rvm: 2.3.8 env: RAILS_VERSION='~> 5.2.0' - rvm: 2.2.10 - env: RAILS_VERSION='~> 5.2.0' + # An incompatibility with Ruby 2.2 in Rails 5.2.4.0 (still not fixed 5.2.4.3) + # prevents from testing against this combination. This bug is not in 5-2-stable: + # lib/action_dispatch/request/session.rb:96: syntax error, unexpected '.' + # id&.public_id + env: RAILS_VERSION='5-2-stable' # Rails 5.1 Builds >= 2.2.2 - - rvm: 2.6.3 + - rvm: 2.6.6 env: RAILS_VERSION='~> 5.1.0' - - rvm: 2.5.3 + - rvm: 2.5.8 env: RAILS_VERSION='~> 5.1.0' - - rvm: 2.4.4 + - rvm: 2.4.10 env: RAILS_VERSION='~> 5.1.0' - - rvm: 2.3.7 + - rvm: 2.3.8 env: RAILS_VERSION='~> 5.1.0' - rvm: 2.2.10 env: RAILS_VERSION='~> 5.1.0' # Rails 5.0 Builds >= 2.2.2 - - rvm: 2.6.3 + - rvm: 2.6.6 env: RAILS_VERSION='~> 5.0.0' - - rvm: 2.5.3 + - rvm: 2.5.8 env: RAILS_VERSION='~> 5.0.0' - - rvm: 2.4.4 + - rvm: 2.4.10 env: RAILS_VERSION='~> 5.0.0' - - rvm: 2.3.7 + - rvm: 2.3.8 env: RAILS_VERSION='~> 5.0.0' - rvm: 2.2.10 env: RAILS_VERSION='~> 5.0.0' # Rails 4.2 Builds >= 1.9.3 - - rvm: 2.4.4 + - rvm: 2.4.10 env: RAILS_VERSION='~> 4.2.0' - - rvm: 2.4.4 + - rvm: 2.4.10 env: RAILS_VERSION=4-2-stable - - rvm: 2.3.7 + - rvm: 2.3.8 env: RAILS_VERSION='~> 4.2.0' - - rvm: 2.3.7 + - rvm: 2.3.8 env: RAILS_VERSION=4-2-stable - rvm: 2.2.10 env: RAILS_VERSION='~> 4.2.0' @@ -108,9 +112,9 @@ matrix: env: RAILS_VERSION=4-2-stable # Rails 4.1 Builds >= 1.9.3, < 2.4 - - rvm: 2.3.7 + - rvm: 2.3.8 env: RAILS_VERSION='~> 4.1.0' - - rvm: 2.3.7 + - rvm: 2.3.8 env: RAILS_VERSION=4-1-stable - rvm: 2.2.10 env: RAILS_VERSION='~> 4.1.0' @@ -130,9 +134,9 @@ matrix: env: RAILS_VERSION=4-1-stable # Rails 4.0 Builds >= 1.8.11, < 2.4 - - rvm: 2.3.7 + - rvm: 2.3.8 env: RAILS_VERSION='~> 4.0.4' - - rvm: 2.3.7 + - rvm: 2.3.8 env: RAILS_VERSION=4-0-stable - rvm: 2.2.10 env: RAILS_VERSION='~> 4.0.4' @@ -152,9 +156,9 @@ matrix: env: RAILS_VERSION=4-0-stable # Rails 3.2 Builds < 2.4 - - rvm: 2.3.7 + - rvm: 2.3.8 env: RAILS_VERSION='~> 3.2.17' - - rvm: 2.3.7 + - rvm: 2.3.8 env: RAILS_VERSION=3-2-stable - rvm: 2.2.10 env: RAILS_VERSION='~> 3.2.17' @@ -202,12 +206,17 @@ matrix: env: RAILS_VERSION='~> 3.0.20' allow_failures: - - rvm: 2.6.3 + - rvm: 2.6.6 env: RAILS_VERSION=master - - rvm: 2.5.3 + - rvm: 2.5.8 env: RAILS_VERSION=master - - rvm: 2.4.4 + - rvm: 2.4.10 env: RAILS_VERSION=master + - rvm: 2.2.10 + # An actual incompatibility of 5.2.4.0-5.2.4.3 forces to use `5-2-stable`, + # but there's a minor difference in the generated tests that results in a + # minor failure. + env: RAILS_VERSION='5-2-stable' fast_finish: true branches: diff --git a/Gemfile b/Gemfile index 89036e90a9..98cf5e9dfc 100644 --- a/Gemfile +++ b/Gemfile @@ -11,9 +11,9 @@ gem 'yard', '~> 0.9.24', :require => false ### deps for rdoc.info group :documentation do - gem 'redcarpet' - gem 'github-markup' if RUBY_VERSION > '2.0.0' + gem 'redcarpet' + gem 'github-markup' gem 'relish' end end @@ -30,8 +30,10 @@ end if RUBY_VERSION < '1.9' gem 'ffi', '< 1.9.19' # ffi dropped Ruby 1.8 support in 1.9.19 -else - gem 'ffi', '~> 1.9.25' +elsif RUBY_VERSION < '2.0' + gem 'ffi', '< 1.11.0' # ffi dropped Ruby 2.0 support in 1.11.0 +elsif RUBY_VERSION < '2.3' + gem 'ffi', '< 1.13.0' end if RUBY_VERSION >= '2.0.0' @@ -80,8 +82,8 @@ if RUBY_VERSION <= '1.8.7' # cucumber and gherkin require rubyzip as a runtime dependency on 1.8.7 # Only < 1.0 supports 1.8.7 gem 'rubyzip', '< 1.0' -else - gem "rubyzip", '>= 1.2.2' +elsif RUBY_VERSION < '2.4' + gem 'rubyzip', '>= 1.2.2', '< 2.0.0' end if RUBY_VERSION >= '2.0.0' && RUBY_VERSION < '2.2.0' diff --git a/Gemfile-rails-dependencies b/Gemfile-rails-dependencies index 9d9bd20849..a952cda6d0 100644 --- a/Gemfile-rails-dependencies +++ b/Gemfile-rails-dependencies @@ -1,10 +1,5 @@ version_file = File.expand_path("../.rails-version", __FILE__) -# FIXME: rack 2.1.0 introduces a deprecation warning that rails is triggering, -# but in later versions this warning will be removed. Get rid of this hack once -# rack 2.1.0+ is out. -gem 'rack', '!= 2.1.0' - case version = ENV['RAILS_VERSION'] || (File.exist?(version_file) && File.read(version_file).chomp) || '' when /master/ gem "rails", :git => "https://github.com/rails/rails.git" @@ -26,13 +21,14 @@ when /stable$/ gem_list = %w[rails railties actionmailer actionpack activerecord activesupport] gem_list << 'activejob' if version > '4-1-stable' gem_list << 'actionview' if version > '4-0-stable' - if RUBY_VERSION >= "2.2" - gem_list << 'puma' if version > '5-0-stable' - end gem_list.each do |rails_gem| gem rails_gem, :git => "https://github.com/rails/rails.git", :branch => version end + + gem 'puma' if RUBY_VERSION >= '2.2' && version > '5-0-stable' + + gem "sprockets", '~> 3.0' if RUBY_VERSION < '2.5' && version >= '4-0-stable' when nil, false, "" if RUBY_VERSION < '1.9.3' # Rails 4+ requires 1.9.3+, so on earlier versions default to the last 3.x release. @@ -46,20 +42,49 @@ when nil, false, "" else gem "rails", version - if version >= '5-1-stable' && RUBY_VERSION >= "2.2" + major_minor_version = version.gsub(/[^\d\.]/,'').to_f + + if major_minor_version >= 5.1 && RUBY_VERSION >= "2.2" gem "puma" end - if RUBY_VERSION < "2.5" - gem "sprockets", "~> 3.0" - end + gem "sprockets", '~> 3.0' if RUBY_VERSION < '2.5' && major_minor_version >= 4.0 - if version.gsub(/[^\d\.]/,'').to_f >= 6.0 + if major_minor_version >= 6.0 gem "activerecord-jdbcsqlite3-adapter", "~> 60.0.rc1", :platforms => [:jruby] else gem 'activerecord-jdbcsqlite3-adapter', :platforms => [:jruby] end end -gem "i18n", '< 0.7.0' if RUBY_VERSION < '1.9.3' +gem "childprocess", '< 2.0.0' if RUBY_VERSION < '2.3' + +if RUBY_VERSION < '1.9.3' + gem "i18n", '< 0.7.0' +elsif RUBY_VERSION < '2.3.0' + gem "i18n", '< 1.5.2' +end + +gem "nio4r", '< 2.4.0' if RUBY_VERSION < '2.3' + +if RUBY_VERSION < '1.9.3' + gem "public_suffix", '< 1.4.0' +elsif RUBY_VERSION < '2.0' + gem "public_suffix", '< 2.0.0' +elsif RUBY_VERSION < '2.1' + gem "public_suffix", '< 3.0.0' +elsif RUBY_VERSION < '2.3' + gem "public_suffix", '< 4.0.0' +end + +# rack 2.1.0 introduces a deprecation warning that rails is triggering, +# but in later versions this warning is removed. +if RUBY_VERSION < '2.2' + gem "rack", '< 2.0.0', '!= 2.1.0' +elsif RUBY_VERSION < '2.3' + gem "rack", '< 2.2.0', '!= 2.1.0' +end + gem "test-unit" if RUBY_VERSION >= '2.2.0' && version =~ /3[.-]2[.-]/ + +gem "xpath", '< 3.2.0' if RUBY_VERSION < '2.3' diff --git a/Rakefile b/Rakefile index de4c5b3492..bd15a19681 100644 --- a/Rakefile +++ b/Rakefile @@ -60,7 +60,7 @@ namespace :generate do # Rails 4 cannot use a `rails` binstub generated by Bundler sh "rm -f #{bindir}/rails" - sh "bundle exec rails new ./tmp/example_app --no-rc --skip-javascript --skip-sprockets --skip-git --skip-test-unit --skip-listen --skip-bundle --template=example_app_generator/generate_app.rb" + sh "bundle exec rails new ./tmp/example_app --no-rc --skip-javascript --skip-bootsnap --skip-sprockets --skip-spring --skip-git --skip-test-unit --skip-listen --skip-bundle --template=example_app_generator/generate_app.rb" in_example_app do sh "./travis_retry_bundle_install.sh 2>&1" @@ -183,7 +183,7 @@ namespace :no_active_record do # Rails 4 cannot use a `rails` binstub generated by Bundler sh "rm -f #{bindir}/rails" - sh "bundle exec rails new #{example_app_dir} --no-rc --skip-active-record --skip-javascript --skip-bootsnap --skip-sprockets --skip-git --skip-test-unit --skip-listen --skip-bundle --template=example_app_generator/generate_app.rb" + sh "bundle exec rails new #{example_app_dir} --no-rc --skip-active-record --skip-javascript --skip-bootsnap --skip-sprockets --skip-spring --skip-git --skip-test-unit --skip-listen --skip-bundle --template=example_app_generator/generate_app.rb" in_example_app(:app_dir => example_app_dir) do sh "./travis_retry_bundle_install.sh 2>&1" diff --git a/features/support/env.rb b/features/support/env.rb index d4d96ebb81..ba56a9a4eb 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -2,19 +2,33 @@ require 'fileutils' module ArubaExt - def run_command(cmd, timeout = nil) - exec_cmd = cmd =~ /^rspec/ ? "bin/#{cmd}" : cmd - unset_bundler_env_vars - # Ensure the correct Gemfile and binstubs are found - in_current_directory do - with_unbundled_env do - super(exec_cmd, timeout) + if defined?(Aruba::VERSION) && Aruba::VERSION >= '0.14.12' + def run_command(cmd, timeout = nil) + exec_cmd = cmd =~ /^rspec/ ? "bin/#{cmd}" : cmd + unset_bundler_env_vars + # Ensure the correct Gemfile and binstubs are found + in_current_directory do + with_unbundled_env do + super(exec_cmd, timeout) + end + end + end + else + def run(cmd, timeout = nil) + exec_cmd = cmd =~ /^rspec/ ? "bin/#{cmd}" : cmd + super(exec_cmd, timeout) + end + # This method overrides Aruba 0.5.4 implementation so that we can reset Bundler to use the sample app Gemfile + def in_current_dir(&block) + Bundler.with_clean_env do + _mkdir(current_dir) + Dir.chdir(current_dir, &block) end end end def unset_bundler_env_vars - empty_env = with_environment { with_unbundled_env { ENV.to_h } } + empty_env = with_environment { with_unbundled_env { env_to_h } } aruba_env = aruba.environment.to_h (aruba_env.keys - empty_env.keys).each do |key| delete_environment_variable key @@ -31,14 +45,28 @@ def with_unbundled_env Bundler.with_clean_env { yield } end end -end -World(ArubaExt) + def env_to_h + if RUBY_VERSION > '2.0' + ENV.to_h + else + ENV.inject({}) { |h, (k, v)| h[k] = v; h } + end + end +end -Aruba.configure do |config| - config.exit_timeout = 30 +if defined?(Aruba::VERSION) && Aruba::VERSION >= '0.14.12' + Aruba.configure do |config| + config.exit_timeout = 30 + end +else + Before do + @aruba_timeout_seconds = 30 + end end +World(ArubaExt) + unless File.directory?('./tmp/example_app') system "rake generate:app generate:stuff" end diff --git a/lib/rspec/rails/configuration.rb b/lib/rspec/rails/configuration.rb index 10b8e90159..b61dfbcaf1 100644 --- a/lib/rspec/rails/configuration.rb +++ b/lib/rspec/rails/configuration.rb @@ -54,7 +54,9 @@ def self.add_test_type_configurations(config) end # @private - def self.initialize_configuration(config) # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity + # rubocop:disable Style/MethodLength + # rubocop:disable Style/CyclomaticComplexity + def self.initialize_configuration(config) config.backtrace_exclusion_patterns << /vendor\// config.backtrace_exclusion_patterns << %r{lib/rspec/rails} @@ -176,6 +178,7 @@ def filter_rails_from_backtrace! end end # rubocop:enable Style/MethodLength + # rubocop:enable Style/CyclomaticComplexity initialize_configuration RSpec.configuration end diff --git a/rspec-rails.gemspec b/rspec-rails.gemspec index d9ef49b90a..e57043bdbc 100644 --- a/rspec-rails.gemspec +++ b/rspec-rails.gemspec @@ -51,6 +51,11 @@ Gem::Specification.new do |s| end s.add_development_dependency 'cucumber', '~> 1.3.5' - s.add_development_dependency 'aruba', '~> 0.14.12' + if ENV['RAILS_VERSION'].gsub(/[^\d\.-]/, '').tr('-', '.') < '4.0' + # We use aruba `~> 0.5.4` as the last known working version and later versions (> 0.9) depend on thor ~> 0.19, which is incompatible with railties < 4.0. + s.add_development_dependency 'aruba', '~> 0.5.4' + else + s.add_development_dependency 'aruba', '~> 0.14.12' + end s.add_development_dependency 'ammeter', '~> 1.1.2' end diff --git a/script/downgrade_bundler_on_old_rails b/script/downgrade_bundler_on_old_rails index ae59f78626..98a9585d0d 100755 --- a/script/downgrade_bundler_on_old_rails +++ b/script/downgrade_bundler_on_old_rails @@ -13,7 +13,7 @@ if ruby -e "exit(ENV['RAILS_VERSION'].scan(/\d+\.\d+.\d+/)[0].to_f < 5)"; then # this only works on Ruby 2.3 which is luckily the version we need to fix if ruby -e "exit(RUBY_VERSION.to_f == 2.3)"; then - rvm @global do gem uninstall -aIx bundler + rvm @global do gem uninstall -aIx bundler || echo "Warning: error occured removing bundler from the global RVM gemset" fi gem install bundler -v '1.17.3' diff --git a/script/update_rubygems_and_install_bundler b/script/update_rubygems_and_install_bundler index a6b4a95925..d673293da6 100755 --- a/script/update_rubygems_and_install_bundler +++ b/script/update_rubygems_and_install_bundler @@ -11,11 +11,11 @@ if is_ruby_23_plus; then yes | gem install bundler else echo "Warning installing older versions of Rubygems / Bundler" - gem update --system '2.7.8' + gem update --system '2.7.10' gem install bundler -v '1.17.3' fi else echo "Warning installing older versions of Rubygems / Bundler" - gem update --system '2.7.8' + gem update --system '2.7.10' gem install bundler -v '1.17.3' fi diff --git a/spec/rspec/rails/example/view_example_group_spec.rb b/spec/rspec/rails/example/view_example_group_spec.rb index 567a56dd83..b2d1a820d5 100644 --- a/spec/rspec/rails/example/view_example_group_spec.rb +++ b/spec/rspec/rails/example/view_example_group_spec.rb @@ -218,17 +218,31 @@ def controller expect(view_spec.view).to eq(view) end - it 'is accessible to hooks' do + if RUBY_VERSION <= "2.3.0" && ENV["RAILS_VERSION"] !~ /stable/ && ::Rails.version.to_f == 5.2 + pending_only_on_ruby_22_rails_52 = """ + Rails 5.2.4.2 has a syntax error in ActionDispatch::Request::Session. + (A &. usage which does not work in 2.2.10) + It has been fixed but not released, this spec will not pass until that + has been released. + """ + else + pending_only_on_ruby_22_rails_52 = false + end + + # Regression test from rspec/rspec-rails#833 + it 'is accessible to configuration-level hooks', :pending => pending_only_on_ruby_22_rails_52 do with_isolated_config do run_count = 0 RSpec.configuration.before(:each, :type => :view) do - allow(view).to receive(:a_stubbed_helper) { :value } + # `view` is provided from the view example type, and serves to + # demonstrate this hook is run in the correct context. + allow(view).to receive(:render) { :value } run_count += 1 end group = RSpec::Core::ExampleGroup.describe 'a view', :type => :view do - specify { true } + specify { expect(view.render).to eq(:value) } end - group.run NullObject.new + group.run expect(run_count).to eq 1 end end