diff --git a/.rubocop.yml b/.rubocop.yml index a65610a4e5..3df2c75ce0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -246,12 +246,6 @@ Style/ParallelAssignment: Style/ParenthesesAroundCondition: Enabled: false -Style/PerlBackrefs: - Exclude: - # We probably can refactor the backref out, but for now excluding it since - # we can't use named matches in 1.8.7 - - lib/generators/rspec/scaffold/scaffold_generator.rb - Style/PercentLiteralDelimiters: PreferredDelimiters: '%': () # double-quoted string @@ -264,12 +258,6 @@ Style/PercentLiteralDelimiters: '%W': '[]' # array of double-quoted strings '%x': () # a shell command as a string -# On 1.8 `proc` was `lambda`, so we used `Proc.new` to ensure we got real procs -# on all supported versions. -# http://batsov.com/articles/2014/02/04/the-elements-of-style-in-ruby-number-12-proc-vs-proc-dot-new/ -Style/Proc: - Enabled: false - Style/RegexpLiteral: Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 49612257d1..c339a6c9c9 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -21,3 +21,14 @@ Style/EachWithObject: # the new lambda syntax was not supported in ruby 1.8.7 Style/Lambda: Enabled: false + +# we couldn't use named matches in ruby 1.8.7 +Style/PerlBackrefs: + Exclude: + - lib/generators/rspec/scaffold/scaffold_generator.rb + +# On 1.8 `proc` was `lambda`, so we used `Proc.new` to ensure we got real procs +# on all supported versions. +# http://batsov.com/articles/2014/02/04/the-elements-of-style-in-ruby-number-12-proc-vs-proc-dot-new/ +Style/Proc: + Enabled: false diff --git a/.travis.yml b/.travis.yml index d97198aae6..cce3afa0b5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,11 +22,10 @@ bundler_args: "--binstubs --path ../bundle --retry=3 --jobs=3" before_install: - script/update_rubygems_and_install_bundler - - script/downgrade_bundler_on_old_rails - script/clone_all_rspec_repos before_script: - # Rails 4.x complains with a bundler rails binstub in PROJECT_ROOT/bin/ + # Rails 4+ complains with a bundler rails binstub in PROJECT_ROOT/bin/ - rm -f bin/rails - bundle exec rails --version diff --git a/Gemfile b/Gemfile index 8f9e096b19..24be8a44e4 100644 --- a/Gemfile +++ b/Gemfile @@ -51,7 +51,7 @@ gem 'mime-types', "~> 3" gem 'capybara', '~> 2.13', require: false if MAJOR < 6 - gem 'nokogiri', '1.8.5' + gem 'nokogiri', '1.9.1' else gem 'nokogiri', '>= 1.10.4' end diff --git a/Gemfile-custom.sample b/Gemfile-custom.sample index a5017674b5..81bbe0e475 100644 --- a/Gemfile-custom.sample +++ b/Gemfile-custom.sample @@ -8,12 +8,5 @@ group :development do platform :mri do gem 'rb-fsevent', '~> 0.9.0' gem 'ruby-prof', '~> 0.10.0' - - case RUBY_VERSION - when /^1.8/ - gem 'ruby-debug' - when /^1.9/ - gem 'debugger' - end end end diff --git a/Gemfile-rails-dependencies b/Gemfile-rails-dependencies index 0353dc70a2..6f507972ad 100644 --- a/Gemfile-rails-dependencies +++ b/Gemfile-rails-dependencies @@ -14,9 +14,7 @@ when /master/ gem 'puma', "3.12.1" gem 'activerecord-jdbcsqlite3-adapter', git: 'https://github.com/jruby/activerecord-jdbc-adapter', platforms: [:jruby] when /stable$/ - gem_list = %w[rails railties actionmailer actionpack activerecord activesupport] - gem_list << 'activejob' if version >= '4-2-stable' - gem_list << 'actionview' if version >= '4-2-stable' + gem_list = %w[rails railties actionmailer actionpack activerecord activesupport activejob actionview] gem 'puma', "3.12.1" if version > '5-0-stable' gem 'activerecord-jdbcsqlite3-adapter', git: 'https://github.com/jruby/activerecord-jdbc-adapter', platforms: [:jruby] @@ -29,9 +27,7 @@ when nil, false, "" else gem "rails", version - if version >= '5-1-stable' && RUBY_VERSION >= "2.3" - gem "puma" - end + gem "puma" if version >= '5-1-stable' if version.gsub(/[^\d\.]/,'').to_f >= 6.0 gem "activerecord-jdbcsqlite3-adapter", "~> 60.0.rc1", platforms: [:jruby] diff --git a/README.md b/README.md index 72d2c81920..a88a73fdd7 100644 --- a/README.md +++ b/README.md @@ -119,8 +119,7 @@ $ bundle exec rspec --help ``` **Optional:** If `bundle exec rspec` is too verbose for you, -you can generate a binstub at `bin/rspec` -and use that instead (Rails 4+ only): +you can generate a binstub at `bin/rspec` and use that instead: ```sh $ bundle binstubs rspec-core diff --git a/Rakefile b/Rakefile index d7d4f3c2d0..9a8fe089ff 100644 --- a/Rakefile +++ b/Rakefile @@ -12,7 +12,7 @@ require 'rspec/core/rake_task' require 'cucumber/rake/task' def rails_template_command - require "rails" + require "rails/version" if Rails.version.to_f >= 5.0 "app:template" else @@ -27,7 +27,7 @@ RSpec::Core::RakeTask.new(:spec) do |t| end Cucumber::Rake::Task.new(:cucumber) do |t| - version = ENV.fetch("RAILS_VERSION", "~> 4.2.0")[/\d[\.-]\d/] + version = ENV.fetch("RAILS_VERSION", "~> 5.2.0")[/\d[\.-]\d/] if version == "master" || version.nil? version = Float::INFINITY end @@ -37,19 +37,10 @@ Cucumber::Rake::Task.new(:cucumber) do |t| tags << "~@rails_pre_5.1" end - if version.to_f >= 5.0 - tags << "~@rails_pre_5" - end - if version.to_f == 5.0 tags << "~@system_test" end - if tags.empty? - tags << "~@rails_post_5" - tags << "~@system_test" - end - if version.to_f >= 6.0 tags << "~@rails_pre_6" end @@ -69,13 +60,13 @@ namespace :generate do unless File.directory?('./tmp/example_app') bindir = File.expand_path("bin") - # Rails 4 cannot use a `rails` binstub generated by Bundler + # 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-bootsnap -skip-sprockets --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" - # Rails 4 cannot use a `rails` binstub generated by Bundler + # Rails 4+ cannot use a `rails` binstub generated by Bundler sh "bundle binstubs bundler rspec-core rake --force" sh "bundle binstubs railties" unless File.exist?("bin/rails") @@ -192,13 +183,13 @@ namespace :no_active_record do unless File.directory?(example_app_dir) bindir = File.expand_path("bin") - # Rails 4 cannot use a `rails` binstub generated by Bundler + # 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" in_example_app(:app_dir => example_app_dir) do sh "./travis_retry_bundle_install.sh 2>&1" - # Rails 4 cannot use a `rails` binstub generated by Bundler + # Rails 4+ cannot use a `rails` binstub generated by Bundler sh "bundle binstubs bundler rspec-core rake --force" sh "bundle binstubs railties" unless File.exist?("bin/rails") diff --git a/appveyor.yml b/appveyor.yml index 68756416f9..2f8a6a7b34 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -33,9 +33,6 @@ test_script: environment: matrix: - - ruby_version: 200 - - ruby_version: 21 - - ruby_version: 22 - ruby_version: 23-x64 - ruby_version: 24-x64 - ruby_version: 25-x64 diff --git a/example_app_generator/generate_action_mailer_specs.rb b/example_app_generator/generate_action_mailer_specs.rb index 249114fc25..9df96d11e9 100644 --- a/example_app_generator/generate_action_mailer_specs.rb +++ b/example_app_generator/generate_action_mailer_specs.rb @@ -1,12 +1,6 @@ require 'active_support' require 'active_support/core_ext/module' -# We need to copy this method from Thor for older Rails versions -def comment_lines(path, flag, *args) - flag = flag.respond_to?(:source) ? flag.source : flag - gsub_file(path, /^(\s*)([^#|\n]*#{flag})/, '\1# \2', *args) -end - using_source_path(File.expand_path('..', __FILE__)) do # Comment out the default mailer stuff comment_lines 'config/environments/development.rb', /action_mailer/ diff --git a/example_app_generator/generate_app.rb b/example_app_generator/generate_app.rb index a407888601..30225b6018 100644 --- a/example_app_generator/generate_app.rb +++ b/example_app_generator/generate_app.rb @@ -25,9 +25,6 @@ gsub_file "Gemfile", /.*puma.*/, "" gsub_file "Gemfile", /.*gem..sqlite3.*/, "gem 'sqlite3', '~> 1.3.6'" gsub_file "Gemfile", /.*bootsnap.*/, "" - if RUBY_VERSION < '2.2.2' - gsub_file "Gemfile", /.*rdoc.*/, "gem 'rdoc', '< 6'" - end if Rails::VERSION::STRING >= '5.0.0' append_to_file('Gemfile', "gem 'rails-controller-testing'\n") @@ -42,7 +39,7 @@ if RUBY_VERSION < "2.4" gsub_file "Gemfile", /.*capybara.*/, "gem 'capybara', '~> 3.15.0'" end - if Rails::VERSION::STRING >= "5.2.0" && RUBY_VERSION < '2.3.0' + if Rails::VERSION::STRING >= "5.2.0" gsub_file "Gemfile", /.*chromedriver-helper.*/, "gem 'webdrivers', '< 4.0.0'" else gsub_file "Gemfile", /.*chromedriver-helper.*/, "gem 'webdrivers'" @@ -63,21 +60,7 @@ # Use our version of RSpec and Rails append_to_file 'Gemfile', <<-EOT.gsub(/^ +\|/, '') - |# Rack::Cache 1.3.0 requires Ruby >= 2.0.0 - |gem 'rack-cache', '< 1.3.0' if RUBY_VERSION < '2.0.0' - | - |if RUBY_VERSION >= '2.0.0' - | gem 'rake', '>= 10.0.0' - |elsif RUBY_VERSION >= '1.9.3' - | gem 'rake', '< 12.0.0' # rake 12 requires Ruby 2.0.0 or later - |else - | gem 'rake', '< 11.0.0' # rake 11 requires Ruby 1.9.3 or later - |end - | - |# Version 3 of mime-types 3 requires Ruby 2.0 - |if RUBY_VERSION < '2.0.0' - | gem 'mime-types', '< 3' - |end + |gem 'rake', '>= 10.0.0' | |gem 'rspec-rails', | :path => '#{rspec_rails_repo_path}', diff --git a/example_app_generator/no_active_record/app/models/in_memory/model.rb b/example_app_generator/no_active_record/app/models/in_memory/model.rb index 8e6cea7f8a..79ae3d83ed 100644 --- a/example_app_generator/no_active_record/app/models/in_memory/model.rb +++ b/example_app_generator/no_active_record/app/models/in_memory/model.rb @@ -1,6 +1,3 @@ -# Rails 4.0.x seems to be the only version that does not autoload `ActiveModel` -require 'active_model' - raise "ActiveRecord is defined but should not be!" if defined?(::ActiveRecord) module InMemory diff --git a/example_app_generator/spec/support/default_preview_path b/example_app_generator/spec/support/default_preview_path index 4371f0799a..5748e57b07 100755 --- a/example_app_generator/spec/support/default_preview_path +++ b/example_app_generator/spec/support/default_preview_path @@ -47,7 +47,7 @@ require_file_stub 'config/environment' do end end - I18n.enforce_available_locales = true if I18n.respond_to?(:enforce_available_locales) + I18n.enforce_available_locales = true end # Initialize the Rails application. diff --git a/example_app_generator/spec/verify_mailer_preview_path_spec.rb b/example_app_generator/spec/verify_mailer_preview_path_spec.rb index 0fa46e9f87..89349da951 100644 --- a/example_app_generator/spec/verify_mailer_preview_path_spec.rb +++ b/example_app_generator/spec/verify_mailer_preview_path_spec.rb @@ -16,12 +16,8 @@ def as_commandline(ops) end def capture_exec(*ops) - io = if RUBY_VERSION.to_f < 1.9 - IO.popen(as_commandline(ops)) - else - ops << { :err => [:child, :out] } - IO.popen(ops) - end + ops << { :err => [:child, :out] } + io = IO.popen(ops) # Necessary to ignore warnings from Rails code base out = io.readlines. reject { |line| line =~ /warning: circular argument reference/ }. @@ -39,7 +35,7 @@ def have_no_preview File.expand_path(File.join(__FILE__, '../support/default_preview_path')) } - if RSpec::Rails::FeatureCheck.has_action_mailer_show_preview? + if RSpec::Rails::FeatureCheck.has_action_mailer_preview? context 'in the development environment' do let(:custom_env) { { 'RAILS_ENV' => rails_env } } let(:rails_env) { 'development' } @@ -111,71 +107,6 @@ def have_no_preview ).to eq('test-host') end - it 'handles action mailer not being available' do - expect( - capture_exec( - custom_env.merge('NO_ACTION_MAILER' => 'true'), - exec_script - ) - ).to have_no_preview - end - end - elsif RSpec::Rails::FeatureCheck.has_action_mailer_preview? - context 'in the development environment', 'without `show_previews`' do - let(:custom_env) { { 'RAILS_ENV' => rails_env } } - let(:rails_env) { 'development' } - - it 'sets the preview path to the default rspec path' do - expect(capture_exec(custom_env, exec_script)).to eq( - "#{::Rails.root}/spec/mailers/previews" - ) - end - - it 'respects a custom `preview_path`' do - expect( - capture_exec( - custom_env.merge('CUSTOM_PREVIEW_PATH' => '/custom/path'), - exec_script - ) - ).to eq('/custom/path') - end - - it 'allows initializers to set options' do - expect( - capture_exec( - custom_env.merge('DEFAULT_URL' => 'test-host'), - exec_script - ) - ).to eq('test-host') - end - - it 'handles action mailer not being available' do - expect( - capture_exec( - custom_env.merge('NO_ACTION_MAILER' => 'true'), - exec_script - ) - ).to have_no_preview - end - end - - context 'in a non-development environment', 'without `show_previews`' do - let(:custom_env) { { 'RAILS_ENV' => rails_env } } - let(:rails_env) { 'test' } - - it 'does not set the preview path by default' do - expect(capture_exec(custom_env, exec_script)).to have_no_preview - end - - it 'respects a custom `preview_path`' do - expect( - capture_exec( - custom_env.merge('CUSTOM_PREVIEW_PATH' => '/custom/path'), - exec_script - ) - ).to eq('/custom/path') - end - it 'handles action mailer not being available' do expect( capture_exec( diff --git a/example_app_generator/travis_retry_bundle_install.sh b/example_app_generator/travis_retry_bundle_install.sh index cdcc0644e1..bcc4467919 100755 --- a/example_app_generator/travis_retry_bundle_install.sh +++ b/example_app_generator/travis_retry_bundle_install.sh @@ -4,7 +4,7 @@ set -e source FUNCTIONS_SCRIPT_FILE echo "Starting bundle install using shared bundle path" -if is_mri_192_plus; then +if is_mri; then travis_retry eval "RUBYOPT=$RUBYOPT:' --enable rubygems' bundle install --gemfile ./Gemfile --path REPLACE_BUNDLE_PATH --retry=3 --jobs=3" else travis_retry eval "bundle install --gemfile ./Gemfile --path REPLACE_BUNDLE_PATH --retry=3 --jobs=3" diff --git a/features/controller_specs/anonymous_controller.feature b/features/controller_specs/anonymous_controller.feature index 283d6a6342..7892b4dfac 100644 --- a/features/controller_specs/anonymous_controller.feature +++ b/features/controller_specs/anonymous_controller.feature @@ -175,32 +175,6 @@ Feature: anonymous controller When I run `rspec spec` Then the examples should all pass - @rails_pre_5 - Scenario: Infer base class from the described class - Given a file named "spec/controllers/base_class_can_be_inferred_spec.rb" with: - """ruby - require "rails_helper" - - class ApplicationController < ActionController::Base; end - - class FoosController < ApplicationController; end - - RSpec.describe FoosController, :type => :controller do - controller do - def index - render :text => "Hello World" - end - end - - it "creates anonymous controller derived from FoosController" do - expect(controller).to be_a_kind_of(FoosController) - end - end - """ - When I run `rspec spec` - Then the examples should all pass - - @rails_post_5 Scenario: Infer base class from the described class Given a file named "spec/controllers/base_class_can_be_inferred_spec.rb" with: """ruby @@ -225,41 +199,6 @@ Feature: anonymous controller When I run `rspec spec` Then the examples should all pass - @rails_pre_5 - Scenario: Use `name` and `controller_name` from the described class - Given a file named "spec/controllers/get_name_and_controller_name_from_described_class_spec.rb" with: - """ruby - require "rails_helper" - - class ApplicationController < ActionController::Base; end - class FoosController < ApplicationController; end - - RSpec.describe "Access controller names", :type => :controller do - controller FoosController do - def index - @name = self.class.name - @controller_name = controller_name - render :text => "Hello World" - end - end - - before do - get :index - end - - it "gets the class name as described" do - expect(assigns[:name]).to eq('FoosController') - end - - it "gets the controller_name as described" do - expect(assigns[:controller_name]).to eq('foos') - end - end - """ - When I run `rspec spec` - Then the examples should all pass - - @rails_post_5 Scenario: Use `name` and `controller_name` from the described class Given a file named "spec/controllers/get_name_and_controller_name_from_described_class_spec.rb" with: """ruby @@ -293,39 +232,6 @@ Feature: anonymous controller When I run `rspec spec` Then the examples should all pass - @rails_pre_5 - Scenario: Invoke `around_filter` and `around_action` in base class - Given a file named "spec/controllers/application_controller_around_filter_spec.rb" with: - """ruby - require "rails_helper" - - class ApplicationController < ActionController::Base - around_filter :an_around_filter - - def an_around_filter - @callback_invoked = true - yield - end - end - - RSpec.describe ApplicationController, :type => :controller do - controller do - def index - render :nothing => true - end - end - - it "invokes the callback" do - get :index - - expect(assigns[:callback_invoked]).to be_truthy - end - end - """ - When I run `rspec spec` - Then the examples should all pass - - @rails_post_5 Scenario: Invoke `around_filter` and `around_action` in base class Given a file named "spec/controllers/application_controller_around_filter_spec.rb" with: """ruby @@ -357,192 +263,6 @@ Feature: anonymous controller When I run `rspec spec` Then the examples should all pass - @rails_pre_5 - Scenario: Anonymous controllers only create resource routes - Given a file named "spec/controllers/application_controller_spec.rb" with: - """ruby - require "rails_helper" - - if defined?(ActionController::UrlGenerationError) - ExpectedRoutingError = ActionController::UrlGenerationError - else - ExpectedRoutingError = ActionController::RoutingError - end - - RSpec.describe ApplicationController, :type => :controller do - controller do - def index - render :text => "index called" - end - - def create - render :text => "create called" - end - - def new - render :text => "new called" - end - - def show - render :text => "show called" - end - - def edit - render :text => "edit called" - end - - def update - render :text => "update called" - end - - def destroy - render :text => "destroy called" - end - - def willerror - render :text => "will not render" - end - end - - describe "#index" do - it "responds to GET" do - get :index - expect(response.body).to eq "index called" - end - - it "also responds to POST" do - post :index - expect(response.body).to eq "index called" - end - - it "also responds to PUT" do - put :index - expect(response.body).to eq "index called" - end - - it "also responds to DELETE" do - delete :index - expect(response.body).to eq "index called" - end - end - - describe "#create" do - it "responds to POST" do - post :create - expect(response.body).to eq "create called" - end - - # And the rest... - %w{get post put delete}.each do |calltype| - it "responds to #{calltype}" do - send(calltype, :create) - expect(response.body).to eq "create called" - end - end - end - - describe "#new" do - it "responds to GET" do - get :new - expect(response.body).to eq "new called" - end - - # And the rest... - %w{get post put delete}.each do |calltype| - it "responds to #{calltype}" do - send(calltype, :new) - expect(response.body).to eq "new called" - end - end - end - - describe "#edit" do - it "responds to GET" do - get :edit, :id => "anyid" - expect(response.body).to eq "edit called" - end - - it "requires the :id parameter" do - expect { get :edit }.to raise_error(ExpectedRoutingError) - end - - # And the rest... - %w{get post put delete}.each do |calltype| - it "responds to #{calltype}" do - send(calltype, :edit, {:id => "anyid"}) - expect(response.body).to eq "edit called" - end - end - end - - describe "#show" do - it "responds to GET" do - get :show, :id => "anyid" - expect(response.body).to eq "show called" - end - - it "requires the :id parameter" do - expect { get :show }.to raise_error(ExpectedRoutingError) - end - - # And the rest... - %w{get post put delete}.each do |calltype| - it "responds to #{calltype}" do - send(calltype, :show, {:id => "anyid"}) - expect(response.body).to eq "show called" - end - end - end - - describe "#update" do - it "responds to PUT" do - put :update, :id => "anyid" - expect(response.body).to eq "update called" - end - - it "requires the :id parameter" do - expect { put :update }.to raise_error(ExpectedRoutingError) - end - - # And the rest... - %w{get post put delete}.each do |calltype| - it "responds to #{calltype}" do - send(calltype, :update, {:id => "anyid"}) - expect(response.body).to eq "update called" - end - end - end - - describe "#destroy" do - it "responds to DELETE" do - delete :destroy, :id => "anyid" - expect(response.body).to eq "destroy called" - end - - it "requires the :id parameter" do - expect { delete :destroy }.to raise_error(ExpectedRoutingError) - end - - # And the rest... - %w{get post put delete}.each do |calltype| - it "responds to #{calltype}" do - send(calltype, :destroy, {:id => "anyid"}) - expect(response.body).to eq "destroy called" - end - end - end - - describe "#willerror" do - it "cannot be called" do - expect { get :willerror }.to raise_error(ExpectedRoutingError) - end - end - end - """ - When I run `rspec spec` - Then the examples should all pass - - @rails_post_5 Scenario: Anonymous controllers only create resource routes Given a file named "spec/controllers/application_controller_spec.rb" with: """ruby @@ -727,31 +447,6 @@ Feature: anonymous controller When I run `rspec spec` Then the examples should all pass - @rails_pre_5 - Scenario: Draw custom routes for anonymous controllers - Given a file named "spec/controllers/application_controller_spec.rb" with: - """ruby - require "rails_helper" - - RSpec.describe ApplicationController, :type => :controller do - controller do - def custom - render :text => "custom called" - end - end - - specify "manually draw the route to request a custom action" do - routes.draw { get "custom" => "anonymous#custom" } - - get :custom - expect(response.body).to eq "custom called" - end - end - """ - When I run `rspec spec` - Then the examples should all pass - - @rails_post_5 Scenario: Draw custom routes for anonymous controllers Given a file named "spec/controllers/application_controller_spec.rb" with: """ruby @@ -775,33 +470,6 @@ Feature: anonymous controller When I run `rspec spec` Then the examples should all pass - @rails_pre_5 - Scenario: Draw custom routes for anonymous controllers which don't inherit from application controller - Given a file named "spec/controllers/other_controller_spec.rb" with: - """ruby - require "rails_helper" - class OtherController < ActionController::Base - end - - RSpec.describe OtherController, :type => :controller do - controller do - def custom - render :text => "custom called" - end - end - - specify "manually draw the route to request a custom action" do - routes.draw { get "custom" => "other#custom" } - - get :custom - expect(response.body).to eq "custom called" - end - end - """ - When I run `rspec spec` - Then the examples should all pass - - @rails_post_5 Scenario: Draw custom routes for anonymous controllers which don't inherit from application controller Given a file named "spec/controllers/other_controller_spec.rb" with: """ruby @@ -827,33 +495,6 @@ Feature: anonymous controller When I run `rspec spec` Then the examples should all pass - @rails_pre_5 - Scenario: Draw custom routes for defined controllers - Given a file named "spec/controllers/application_controller_spec.rb" with: - """ruby - require "rails_helper" - - class FoosController < ApplicationController; end - - RSpec.describe ApplicationController, :type => :controller do - controller FoosController do - def custom - render :text => "custom called" - end - end - - specify "manually draw the route to request a custom action" do - routes.draw { get "custom" => "foos#custom" } - - get :custom - expect(response.body).to eq "custom called" - end - end - """ - When I run `rspec spec` - Then the examples should all pass - - @rails_post_5 Scenario: Draw custom routes for defined controllers Given a file named "spec/controllers/application_controller_spec.rb" with: """ruby @@ -879,50 +520,6 @@ Feature: anonymous controller When I run `rspec spec` Then the examples should all pass - @rails_pre_5 - Scenario: Works with namespaced controllers - Given a file named "spec/controllers/namespaced_controller_spec.rb" with: - """ruby - require "rails_helper" - - class ApplicationController < ActionController::Base; end - - module Outer - module Inner - class FoosController < ApplicationController; end - end - end - - RSpec.describe Outer::Inner::FoosController, :type => :controller do - controller do - def index - @name = self.class.name - @controller_name = controller_name - render :text => "Hello World" - end - end - - it "creates anonymous controller derived from the namespace" do - expect(controller).to be_a_kind_of(Outer::Inner::FoosController) - end - - it "gets the class name as described" do - expect{ get :index }.to change{ - assigns[:name] - }.to eq('Outer::Inner::FoosController') - end - - it "gets the controller_name as described" do - expect{ get :index }.to change{ - assigns[:controller_name] - }.to eq('foos') - end - end - """ - When I run `rspec spec` - Then the examples should all pass - - @rails_post_5 Scenario: Works with namespaced controllers Given a file named "spec/controllers/namespaced_controller_spec.rb" with: """ruby diff --git a/features/controller_specs/controller_spec.feature b/features/controller_specs/controller_spec.feature index d4c8e41dfb..6ce5706beb 100644 --- a/features/controller_specs/controller_spec.feature +++ b/features/controller_specs/controller_spec.feature @@ -34,30 +34,7 @@ Feature: controller spec When I run `rspec spec` Then the example should pass - @rails_pre_5 - Scenario: setting a different content type for example json (request type) - Given a file named "spec/controllers/widgets_controller_spec.rb" with: - """ruby - require "rails_helper" - - RSpec.describe WidgetsController, :type => :controller do - describe "responds to" do - it "responds to html by default" do - post :create, { :widget => { :name => "Any Name" } } - expect(response.content_type).to eq "text/html" - end - - it "responds to custom formats when provided in the params" do - post :create, { :widget => { :name => "Any Name" }, :format => :json } - expect(response.content_type).to eq "application/json" - end - end - end - """ - When I run `rspec spec` - Then the example should pass - - @rails_post_5 @rails_pre_6 + @rails_pre_6 Scenario: setting a different content type for example json (request type) Given a file named "spec/controllers/widgets_controller_spec.rb" with: """ruby diff --git a/features/controller_specs/engine_routes.feature b/features/controller_specs/engine_routes.feature index 35845c6a0e..6493c6008f 100644 --- a/features/controller_specs/engine_routes.feature +++ b/features/controller_specs/engine_routes.feature @@ -3,7 +3,6 @@ Feature: engine routes for controllers Controller specs can specify the routeset that will be used for the example group. This is most useful when testing Rails engines. - @unsupported-on-rails-3-0 Scenario: specify engine route Given a file named "spec/controllers/widgets_controller_spec.rb" with: """ruby diff --git a/features/file_fixture.feature b/features/file_fixture.feature index c0231d984c..989d89c00f 100644 --- a/features/file_fixture.feature +++ b/features/file_fixture.feature @@ -18,7 +18,6 @@ Feature: file fixture ``` Scenario: Reading file content from fixtures directory - Given file fixtures are available And a file named "spec/fixtures/files/sample.txt" with: """ Hello diff --git a/features/mailer_specs/mailer_spec.feature b/features/mailer_specs/mailer_spec.feature index cd36e4ff5d..7036193018 100644 --- a/features/mailer_specs/mailer_spec.feature +++ b/features/mailer_specs/mailer_spec.feature @@ -1,6 +1,5 @@ Feature: mailer spec - @rails_post_5 Scenario: simple passing example Given a file named "spec/mailers/notifications_mailer_spec.rb" with: """ruby @@ -24,30 +23,3 @@ Feature: mailer spec """ When I run `rspec spec` Then the example should pass - - @rails_pre_5 - Scenario: using URL helpers without default options - Given a file named "config/initializers/mailer_defaults.rb" with: - """ruby - # no default options - """ - And a file named "spec/mailers/notifications_spec.rb" with: - """ruby - require 'rails_helper' - - RSpec.describe Notifications, :type => :mailer do - let(:mail) { Notifications.signup } - - it "renders the headers" do - expect(mail.subject).to eq("Signup") - expect(mail.to).to eq(["to@example.org"]) - expect(mail.from).to eq(["from@example.com"]) - end - - it 'renders the body' do - expect(mail.body.encoded).to match("Hi") - end - end - """ - When I run `rspec spec` - Then the examples should all pass diff --git a/features/mailer_specs/url_helpers.feature b/features/mailer_specs/url_helpers.feature index 8c1353022e..4e82101303 100644 --- a/features/mailer_specs/url_helpers.feature +++ b/features/mailer_specs/url_helpers.feature @@ -3,7 +3,6 @@ Feature: URL helpers in mailer examples Mailer specs are marked by `:type => :mailer` or if you have set `config.infer_spec_type_from_file_location!` by placing them in `spec/mailers`. - @rails_post_5 Scenario: using URL helpers with default options Given a file named "config/initializers/mailer_defaults.rb" with: """ruby @@ -22,7 +21,6 @@ Feature: URL helpers in mailer examples When I run `rspec spec` Then the examples should all pass - @rails_post_5 Scenario: using URL helpers without default options Given a file named "config/initializers/mailer_defaults.rb" with: """ruby @@ -41,42 +39,3 @@ Feature: URL helpers in mailer examples """ When I run `rspec spec` Then the examples should all pass - - @rails_pre_5 - Scenario: using URL helpers with default options - Given a file named "config/initializers/mailer_defaults.rb" with: - """ruby - Rails.configuration.action_mailer.default_url_options = { :host => 'example.com' } - """ - And a file named "spec/mailers/notifications_spec.rb" with: - """ruby - require 'rails_helper' - - RSpec.describe Notifications, :type => :mailer do - it 'should have access to URL helpers' do - expect { gadgets_url }.not_to raise_error - end - end - """ - When I run `rspec spec` - Then the examples should all pass - - @rails_pre_5 - Scenario: using URL helpers without default options - Given a file named "config/initializers/mailer_defaults.rb" with: - """ruby - # no default options - """ - And a file named "spec/mailers/notifications_spec.rb" with: - """ruby - require 'rails_helper' - - RSpec.describe Notifications, :type => :mailer do - it 'should have access to URL helpers' do - expect { gadgets_url :host => 'example.com' }.not_to raise_error - expect { gadgets_url }.to raise_error - end - end - """ - When I run `rspec spec` - Then the examples should all pass diff --git a/features/matchers/have_enqueued_mail_matcher.feature b/features/matchers/have_enqueued_mail_matcher.feature index c8fc5031b4..ab1ae50210 100644 --- a/features/matchers/have_enqueued_mail_matcher.feature +++ b/features/matchers/have_enqueued_mail_matcher.feature @@ -5,7 +5,6 @@ Feature: have_enqueued_mail matcher Background: Given active job is available - @rails_post_5 Scenario: Checking mailer class and method name Given a file named "spec/mailers/user_mailer_spec.rb" with: """ruby @@ -23,7 +22,6 @@ Feature: have_enqueued_mail matcher When I run `rspec spec/mailers/user_mailer_spec.rb` Then the examples should all pass - @rails_post_5 Scenario: Checking mailer enqueued time Given a file named "spec/mailers/user_mailer_spec.rb" with: """ruby @@ -40,39 +38,3 @@ Feature: have_enqueued_mail matcher """ When I run `rspec spec/mailers/user_mailer_spec.rb` Then the examples should all pass - - @rails_pre_5 - Scenario: Checking mailer class and method name - Given a file named "spec/mailers/user_mailer_spec.rb" with: - """ruby - require "rails_helper" - - RSpec.describe Notifications do - it "matches with enqueued mailer" do - ActiveJob::Base.queue_adapter = :test - expect { - Notifications.signup.deliver_later - }.to have_enqueued_mail(Notifications, :signup) - end - end - """ - When I run `rspec spec/mailers/user_mailer_spec.rb` - Then the examples should all pass - - @rails_pre_5 - Scenario: Checking mailer enqueued time - Given a file named "spec/mailers/user_mailer_spec.rb" with: - """ruby - require "rails_helper" - - RSpec.describe Notifications do - it "matches with enqueued mailer" do - ActiveJob::Base.queue_adapter = :test - expect { - Notifications.signup.deliver_later(:wait_until => Date.tomorrow.noon) - }.to have_enqueued_mail.at(Date.tomorrow.noon) - end - end - """ - When I run `rspec spec/mailers/user_mailer_spec.rb` - Then the examples should all pass diff --git a/features/matchers/have_http_status_matcher.feature b/features/matchers/have_http_status_matcher.feature index 38f6252924..27690ecda9 100644 --- a/features/matchers/have_http_status_matcher.feature +++ b/features/matchers/have_http_status_matcher.feature @@ -104,32 +104,6 @@ Feature: `have_http_status` matcher When I run `rspec spec/controllers/gadgets_spec.rb` Then the examples should all pass - @rails_pre_5 - Scenario: Using in a request spec - Given a file named "spec/requests/gadgets/widget_management_spec.rb" with: - """ruby - require "rails_helper" - - RSpec.describe "Widget management", :type => :request do - - it "creates a Widget and redirects to the Widget's page" do - get "/widgets/new" - expect(response).to have_http_status(:ok) - - post "/widgets", :widget => {:name => "My Widget"} - expect(response).to have_http_status(302) - - follow_redirect! - - expect(response).to have_http_status(:success) - end - - end - """ - When I run `rspec spec/requests` - Then the examples should all pass - - @rails_post_5 Scenario: Using in a request spec Given a file named "spec/requests/gadgets/widget_management_spec.rb" with: """ruby diff --git a/features/matchers/redirect_to_matcher.feature b/features/matchers/redirect_to_matcher.feature index e58c95aee0..a4b634202e 100644 --- a/features/matchers/redirect_to_matcher.feature +++ b/features/matchers/redirect_to_matcher.feature @@ -7,40 +7,6 @@ Feature: redirect_to matcher It is available in controller specs (spec/controllers) and request specs (spec/requests). - @rails_pre_5 - Scenario: redirect_to with four possible options - Given a file named "spec/controllers/widgets_controller_spec.rb" with: - """ruby - require "rails_helper" - - RSpec.describe WidgetsController do - - describe "#create" do - subject { post :create, :widget => { :name => "Foo" } } - - it "redirects to widget_url(@widget)" do - expect(subject).to redirect_to(widget_url(assigns(:widget))) - end - - it "redirects_to :action => :show" do - expect(subject).to redirect_to :action => :show, - :id => assigns(:widget).id - end - - it "redirects_to(@widget)" do - expect(subject).to redirect_to(assigns(:widget)) - end - - it "redirects_to /widgets/:id" do - expect(subject).to redirect_to("/widgets/#{assigns(:widget).id}") - end - end - end - """ - When I run `rspec spec/controllers/widgets_controller_spec.rb` - Then the examples should all pass - - @rails_post_5 Scenario: redirect_to with four possible options Given a file named "spec/controllers/widgets_controller_spec.rb" with: """ruby diff --git a/features/request_specs/request_spec.feature b/features/request_specs/request_spec.feature index 085a94fb4a..78aaae4fed 100644 --- a/features/request_specs/request_spec.feature +++ b/features/request_specs/request_spec.feature @@ -26,37 +26,6 @@ Feature: request spec request specs as of Capybara 2.0.0. The recommended way to use Capybara is with [feature specs](../feature-specs/feature-spec). - @rails_pre_5 - Scenario: specify managing a Widget with Rails integration methods - Given a file named "spec/requests/widget_management_spec.rb" with: - """ruby - require "rails_helper" - - RSpec.describe "Widget management", :type => :request do - - it "creates a Widget and redirects to the Widget's page" do - get "/widgets/new" - expect(response).to render_template(:new) - - post "/widgets", :widget => {:name => "My Widget"} - - expect(response).to redirect_to(assigns(:widget)) - follow_redirect! - - expect(response).to render_template(:show) - expect(response.body).to include("Widget was successfully created.") - end - - it "does not render a different template" do - get "/widgets/new" - expect(response).to_not render_template(:show) - end - end - """ - When I run `rspec spec/requests/widget_management_spec.rb` - Then the example should pass - - @rails_post_5 Scenario: specify managing a Widget with Rails integration methods Given a file named "spec/requests/widget_management_spec.rb" with: """ruby @@ -86,31 +55,7 @@ Feature: request spec When I run `rspec spec/requests/widget_management_spec.rb` Then the example should pass - @unsupported-on-rails-3-0 @rails_pre_5 - Scenario: requesting a JSON response - Given a file named "spec/requests/widget_management_spec.rb" with: - """ruby - require "rails_helper" - - RSpec.describe "Widget management", :type => :request do - - it "creates a Widget" do - headers = { - "ACCEPT" => "application/json", # This is what Rails 4 accepts - "HTTP_ACCEPT" => "application/json" # This is what Rails 3 accepts - } - post "/widgets", { :widget => {:name => "My Widget"} }, headers - - expect(response.content_type).to eq("application/json") - expect(response).to have_http_status(:created) - end - - end - """ - When I run `rspec spec/requests/widget_management_spec.rb` - Then the example should pass - - @rails_post_5 @rails_pre_6 + @rails_pre_6 Scenario: requesting a JSON response Given a file named "spec/requests/widget_management_spec.rb" with: """ruby @@ -150,26 +95,6 @@ Feature: request spec When I run `rspec spec/requests/widget_management_spec.rb` Then the example should pass - @rails_pre_5 - Scenario: providing JSON data - Given a file named "spec/requests/widget_management_spec.rb" with: - """ruby - require "rails_helper" - - RSpec.describe "Widget management", :type => :request do - - it "creates a Widget and redirects to the Widget's page" do - headers = { "CONTENT_TYPE" => "application/json" } - post "/widgets", '{ "widget": { "name":"My Widget" } }', headers - expect(response).to redirect_to(assigns(:widget)) - end - - end - """ - When I run `rspec spec/requests/widget_management_spec.rb` - Then the example should pass - - @rails_post_5 Scenario: providing JSON data Given a file named "spec/requests/widget_management_spec.rb" with: """ruby diff --git a/features/routing_specs/engine_routes.feature b/features/routing_specs/engine_routes.feature index 327809394d..dfa9764fbe 100644 --- a/features/routing_specs/engine_routes.feature +++ b/features/routing_specs/engine_routes.feature @@ -3,7 +3,6 @@ Feature: engine routes Routing specs can specify the routeset that will be used for the example group. This is most useful when testing Rails engines. - @unsupported-on-rails-3-0 Scenario: specify engine route Given a file named "spec/routing/engine_routes_spec.rb" with: """ruby diff --git a/features/step_definitions/additional_cli_steps.rb b/features/step_definitions/additional_cli_steps.rb index e4d7cd07ee..548e4196f6 100644 --- a/features/step_definitions/additional_cli_steps.rb +++ b/features/step_definitions/additional_cli_steps.rb @@ -27,12 +27,6 @@ end end -Given /file fixtures are available/ do - if !RSpec::Rails::FeatureCheck.has_file_fixture? - pending "file fixtures are not available" - end -end - Given /action cable testing is available/ do if !RSpec::Rails::FeatureCheck.has_action_cable_testing? pending "Action Cable testing is not available" diff --git a/features/support/capybara.rb b/features/support/capybara.rb index f9894f995d..6009be9f3e 100644 --- a/features/support/capybara.rb +++ b/features/support/capybara.rb @@ -1,10 +1,4 @@ Around "@capybara" do |scenario, block| - # We are caught in a weird situation here. rspec-rails supports 1.8.7 and - # above, but capybara beyond a certain version only supports 1.9.3 and above. - # On 1.8.7 and 1.9.2, we run most of the rspec-rails test suite but leave out - # parts that require capybara. - if RUBY_VERSION >= '1.9.3' - require 'capybara' - block.call - end + require 'capybara' + block.call end diff --git a/features/support/rails_versions.rb b/features/support/rails_versions.rb index c2fb48cf0f..e69de29bb2 100644 --- a/features/support/rails_versions.rb +++ b/features/support/rails_versions.rb @@ -1,4 +0,0 @@ -Around "@unsupported-on-rails-3-0" do |scenario, block| - require 'rails' - block.call unless ::Rails.version.to_s.start_with?("3.0") -end diff --git a/features/view_specs/view_spec.feature b/features/view_specs/view_spec.feature index 21a1af2c85..724bc4cae2 100644 --- a/features/view_specs/view_spec.feature +++ b/features/view_specs/view_spec.feature @@ -197,25 +197,6 @@ Feature: view spec When I run `rspec spec/views` Then the examples should all pass - @rails_pre_5 - Scenario: View specs can render text - Given a file named "spec/views/widgets/direct.html.erb_spec.rb" with: - """ruby - require "rails_helper" - - RSpec.describe "rendering text directly" do - it "displays the given text" do - - render :text => "This is directly rendered" - - expect(rendered).to match /directly rendered/ - end - end - """ - When I run `rspec spec/views` - Then the examples should all pass - - @rails_post_5 Scenario: View specs can render text Given a file named "spec/views/widgets/direct.html.erb_spec.rb" with: """ruby diff --git a/lib/generators/rspec/install/templates/spec/rails_helper.rb b/lib/generators/rspec/install/templates/spec/rails_helper.rb index 71e7104d57..aac43413eb 100644 --- a/lib/generators/rspec/install/templates/spec/rails_helper.rb +++ b/lib/generators/rspec/install/templates/spec/rails_helper.rb @@ -1,11 +1,7 @@ # This file is copied to spec/ when you run 'rails generate rspec:install' require 'spec_helper' ENV['RAILS_ENV'] ||= 'test' -<% if RUBY_VERSION >= '2.0.0' %> require File.expand_path('../config/environment', __dir__) -<% else %> -require File.expand_path('../../config/environment', __FILE__) -<% end %> # Prevent database truncation if the environment is production abort("The Rails environment is running in production mode!") if Rails.env.production? require 'rspec/rails' @@ -26,7 +22,7 @@ # # Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f } -<% if RSpec::Rails::FeatureCheck.can_maintain_test_schema? -%> +<% if RSpec::Rails::FeatureCheck.has_active_record_migration? -%> # Checks for pending migrations and applies them before tests are run. # If you are not using ActiveRecord, you can remove these lines. begin @@ -35,15 +31,6 @@ puts e.to_s.strip exit 1 end -<% elsif RSpec::Rails::FeatureCheck.can_check_pending_migrations? -%> -# Checks for pending migrations before tests are run. -# If you are not using ActiveRecord, you can remove these lines. -begin - ActiveRecord::Migration.check_pending! -rescue ActiveRecord::PendingMigrationError => e - puts e.to_s.strip - exit 1 -end <% end -%> RSpec.configure do |config| <% if RSpec::Rails::FeatureCheck.has_active_record? -%> diff --git a/lib/generators/rspec/scaffold/templates/api_controller_spec.rb b/lib/generators/rspec/scaffold/templates/api_controller_spec.rb index 1fc24e8402..47347f5ead 100644 --- a/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +++ b/lib/generators/rspec/scaffold/templates/api_controller_spec.rb @@ -46,11 +46,7 @@ describe "GET #index" do it "returns a success response" do <%= file_name %> = <%= class_name %>.create! valid_attributes -<% if RUBY_VERSION < '1.9.3' -%> - get :index, {}, valid_session -<% else -%> get :index, params: {}, session: valid_session -<% end -%> expect(response).to be_successful end end @@ -59,11 +55,7 @@ describe "GET #show" do it "returns a success response" do <%= file_name %> = <%= class_name %>.create! valid_attributes -<% if RUBY_VERSION < '1.9.3' -%> - get :show, {id: <%= file_name %>.to_param}, valid_session -<% else -%> get :show, params: {id: <%= file_name %>.to_param}, session: valid_session -<% end -%> expect(response).to be_successful end end @@ -72,20 +64,12 @@ context "with valid params" do it "creates a new <%= class_name %>" do expect { -<% if RUBY_VERSION < '1.9.3' -%> - post :create, {<%= ns_file_name %>: valid_attributes}, valid_session -<% else -%> post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session -<% end -%> }.to change(<%= class_name %>, :count).by(1) end it "renders a JSON response with the new <%= ns_file_name %>" do -<% if RUBY_VERSION < '1.9.3' -%> - post :create, {<%= ns_file_name %>: valid_attributes}, valid_session -<% else %> post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session -<% end -%> expect(response).to have_http_status(:created) expect(response.content_type).to eq('application/json') expect(response.location).to eq(<%= ns_file_name %>_url(<%= class_name %>.last)) @@ -94,11 +78,7 @@ context "with invalid params" do it "renders a JSON response with errors for the new <%= ns_file_name %>" do -<% if RUBY_VERSION < '1.9.3' -%> - post :create, {<%= ns_file_name %>: invalid_attributes}, valid_session -<% else %> post :create, params: {<%= ns_file_name %>: invalid_attributes}, session: valid_session -<% end -%> expect(response).to have_http_status(:unprocessable_entity) expect(response.content_type).to eq('application/json') end @@ -113,22 +93,14 @@ it "updates the requested <%= ns_file_name %>" do <%= file_name %> = <%= class_name %>.create! valid_attributes -<% if RUBY_VERSION < '1.9.3' -%> - put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, valid_session -<% else -%> put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, session: valid_session -<% end -%> <%= file_name %>.reload skip("Add assertions for updated state") end it "renders a JSON response with the <%= ns_file_name %>" do <%= file_name %> = <%= class_name %>.create! valid_attributes -<% if RUBY_VERSION < '1.9.3' -%> - put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, valid_session -<% else %> put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, session: valid_session -<% end -%> expect(response).to have_http_status(:ok) expect(response.content_type).to eq('application/json') end @@ -137,11 +109,7 @@ context "with invalid params" do it "renders a JSON response with errors for the <%= ns_file_name %>" do <%= file_name %> = <%= class_name %>.create! valid_attributes -<% if RUBY_VERSION < '1.9.3' -%> - put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, valid_session -<% else %> put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, session: valid_session -<% end -%> expect(response).to have_http_status(:unprocessable_entity) expect(response.content_type).to eq('application/json') end @@ -152,11 +120,7 @@ it "destroys the requested <%= ns_file_name %>" do <%= file_name %> = <%= class_name %>.create! valid_attributes expect { -<% if RUBY_VERSION < '1.9.3' -%> - delete :destroy, {id: <%= file_name %>.to_param}, valid_session -<% else -%> delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session -<% end -%> }.to change(<%= class_name %>, :count).by(-1) end end diff --git a/lib/rspec-rails.rb b/lib/rspec-rails.rb index 707e3b6d99..ced6174111 100644 --- a/lib/rspec-rails.rb +++ b/lib/rspec-rails.rb @@ -15,8 +15,7 @@ class Railtie < ::Rails::Railtie SourceAnnotationExtractor::Annotation.register_directories("spec") end end - # Rails-3.0.1 requires config.app_generators instead of 3.0.0's config.generators - generators = config.respond_to?(:app_generators) ? config.app_generators : config.generators + generators = config.app_generators generators.integration_tool :rspec generators.test_framework :rspec diff --git a/lib/rspec/rails/adapters.rb b/lib/rspec/rails/adapters.rb index 7b8b3356a4..ba8cc394e4 100644 --- a/lib/rspec/rails/adapters.rb +++ b/lib/rspec/rails/adapters.rb @@ -146,12 +146,11 @@ module ClassMethods # examples without exposing non-assertion methods in Test::Unit or # Minitest. def assertion_method_names - methods = ::RSpec::Rails::Assertions. + ::RSpec::Rails::Assertions. public_instance_methods. select do |m| m.to_s =~ /^(assert|flunk|refute)/ end - methods + test_unit_specific_methods end def define_assertion_delegators @@ -161,12 +160,6 @@ def define_assertion_delegators end end end - - # Starting on Rails 4, Minitest is the default testing framework so no - # need to add TestUnit specific methods. - def test_unit_specific_methods - [] - end end class AssertionDelegator diff --git a/lib/rspec/rails/example/feature_example_group.rb b/lib/rspec/rails/example/feature_example_group.rb index 9cee0120e0..ad46a666d1 100644 --- a/lib/rspec/rails/example/feature_example_group.rb +++ b/lib/rspec/rails/example/feature_example_group.rb @@ -15,9 +15,7 @@ module FeatureExampleGroup include app.routes.url_helpers if app.routes.respond_to?(:url_helpers) include app.routes.mounted_helpers if app.routes.respond_to?(:mounted_helpers) - if respond_to?(:default_url_options) - default_url_options[:host] ||= ::RSpec::Rails::FeatureExampleGroup::DEFAULT_HOST - end + default_url_options[:host] ||= ::RSpec::Rails::FeatureExampleGroup::DEFAULT_HOST end end diff --git a/lib/rspec/rails/example/view_example_group.rb b/lib/rspec/rails/example/view_example_group.rb index 93a2033f9d..418022edc1 100644 --- a/lib/rspec/rails/example/view_example_group.rb +++ b/lib/rspec/rails/example/view_example_group.rb @@ -43,10 +43,7 @@ module ExampleMethods included do include ::Rails.application.routes.url_helpers - - if ::Rails.application.routes.respond_to?(:mounted_helpers) - include ::Rails.application.routes.mounted_helpers - end + include ::Rails.application.routes.mounted_helpers end # @overload render @@ -188,10 +185,7 @@ def _include_controller_helpers before do _include_controller_helpers - if view.lookup_context.respond_to?(:prefixes) - # rails 3.1 - view.lookup_context.prefixes << _controller_path - end + view.lookup_context.prefixes << _controller_path controller.controller_path = _controller_path diff --git a/lib/rspec/rails/extensions/active_record/proxy.rb b/lib/rspec/rails/extensions/active_record/proxy.rb index 56152ff806..b60ecb6a73 100644 --- a/lib/rspec/rails/extensions/active_record/proxy.rb +++ b/lib/rspec/rails/extensions/active_record/proxy.rb @@ -2,15 +2,7 @@ # Delay this in order to give users a chance to configure `expect_with`... rspec.before(:suite) do if defined?(RSpec::Matchers) && RSpec::Matchers.configuration.syntax.include?(:should) && defined?(ActiveRecord::Associations) - # In Rails 3.0, it was AssociationProxy. - # In 3.1+, it's CollectionProxy. - const_name = [:CollectionProxy, :AssociationProxy].find do |const| - ActiveRecord::Associations.const_defined?(const) - end - - proxy_class = ActiveRecord::Associations.const_get(const_name) - - RSpec::Matchers.configuration.add_should_and_should_not_to proxy_class + RSpec::Matchers.configuration.add_should_and_should_not_to ActiveRecord::Associations::CollectionProxy end end end diff --git a/lib/rspec/rails/feature_check.rb b/lib/rspec/rails/feature_check.rb index 3f48a9cb76..2570d6659b 100644 --- a/lib/rspec/rails/feature_check.rb +++ b/lib/rspec/rails/feature_check.rb @@ -3,16 +3,6 @@ module Rails # @private module FeatureCheck module_function - def can_check_pending_migrations? - has_active_record_migration? && - ::ActiveRecord::Migration.respond_to?(:check_pending!) - end - - def can_maintain_test_schema? - has_active_record_migration? && - ::ActiveRecord::Migration.respond_to?(:maintain_test_schema!) - end - def has_active_job? defined?(::ActiveJob) end @@ -37,11 +27,6 @@ def has_action_cable_testing? defined?(::ActionCable) && ActionCable::VERSION::MAJOR >= 6 end - def has_action_mailer_show_preview? - has_action_mailer_preview? && - ::ActionMailer::Base.respond_to?(:show_previews=) - end - def has_action_mailer_parameterized? has_action_mailer? && defined?(::ActionMailer::Parameterized) end @@ -54,10 +39,6 @@ def has_action_mailbox? defined?(::ActionMailbox) end - def has_file_fixture? - ::Rails::VERSION::STRING > '5.0' - end - def type_metatag(type) "type: :#{type}" end diff --git a/lib/rspec/rails/fixture_support.rb b/lib/rspec/rails/fixture_support.rb index 1855588261..251bf50333 100644 --- a/lib/rspec/rails/fixture_support.rb +++ b/lib/rspec/rails/fixture_support.rb @@ -5,29 +5,18 @@ module FixtureSupport if defined?(ActiveRecord::TestFixtures) extend ActiveSupport::Concern include RSpec::Rails::SetupAndTeardownAdapter - include RSpec::Rails::MinitestLifecycleAdapter if ::ActiveRecord::VERSION::STRING > '4' + include RSpec::Rails::MinitestLifecycleAdapter include RSpec::Rails::MinitestAssertionAdapter include ActiveRecord::TestFixtures included do - # TODO: (DC 2011-06-25) this is necessary because fixture_file_upload - # accesses fixture_path directly on ActiveSupport::TestCase. This is - # fixed in rails by https://github.com/rails/rails/pull/1861, which - # should be part of the 3.1 release, at which point we can include - # these lines for rails < 3.1. - ActiveSupport::TestCase.class_exec do - include ActiveRecord::TestFixtures - self.fixture_path = RSpec.configuration.fixture_path - end - # /TODO - self.fixture_path = RSpec.configuration.fixture_path if ::Rails::VERSION::STRING > '5' self.use_transactional_tests = RSpec.configuration.use_transactional_fixtures else self.use_transactional_fixtures = RSpec.configuration.use_transactional_fixtures end - self.use_instantiated_fixtures = RSpec.configuration.use_instantiated_fixtures + self.use_instantiated_fixtures = RSpec.configuration.use_instantiated_fixtures def self.fixtures(*args) orig_methods = private_instance_methods diff --git a/lib/rspec/rails/matchers/base_matcher.rb b/lib/rspec/rails/matchers/base_matcher.rb index 7d9130a506..7f8682d2a5 100644 --- a/lib/rspec/rails/matchers/base_matcher.rb +++ b/lib/rspec/rails/matchers/base_matcher.rb @@ -119,15 +119,7 @@ def assert_ivars(*expected_ivars) raise "#{self.class.name} needs to supply#{ivar_list}" end - if RUBY_VERSION.to_f < 1.9 - # :nocov: - def present_ivars - instance_variables.map(&:to_sym) - end - # :nocov: - else - alias present_ivars instance_variables - end + alias present_ivars instance_variables # @private module HashFormatting diff --git a/lib/rspec/rails/tasks/rspec.rake b/lib/rspec/rails/tasks/rspec.rake index a58a518ffb..bc2fb54e12 100644 --- a/lib/rspec/rails/tasks/rspec.rake +++ b/lib/rspec/rails/tasks/rspec.rake @@ -35,16 +35,6 @@ namespace :spec do end end - # RCov task only enabled for Ruby 1.8 - if RUBY_VERSION < '1.9' - desc "Run all specs with rcov" - RSpec::Core::RakeTask.new(rcov: "spec:prepare") do |t| - t.rcov = true - t.pattern = "./spec/**/*_spec.rb" - t.rcov_opts = '--exclude /gems/,/Library/,/usr/,lib/tasks,.bundle,config,/lib/rspec/,/lib/rspec-,spec' - end - end - task :statsetup do require 'rails/code_statistics' types.each do |type, dir| diff --git a/rspec-rails.gemspec b/rspec-rails.gemspec index c8681cd5cd..5d94fe732d 100644 --- a/rspec-rails.gemspec +++ b/rspec-rails.gemspec @@ -11,7 +11,7 @@ Gem::Specification.new do |s| s.email = "rspec@googlegroups.com" s.homepage = "https://github.com/rspec/rspec-rails" s.summary = "RSpec for Rails" - s.description = "rspec-rails is a testing framework for Rails 4+." + s.description = "rspec-rails is a testing framework for Rails 5+." s.metadata = { 'bug_tracker_uri' => 'https://github.com/rspec/rspec-rails/issues', diff --git a/script/clone_all_rspec_repos b/script/clone_all_rspec_repos index 64f4ee8f5d..324031cfaa 100755 --- a/script/clone_all_rspec_repos +++ b/script/clone_all_rspec_repos @@ -13,10 +13,7 @@ if is_mri; then clone_repo "rspec-expectations" clone_repo "rspec-mocks" clone_repo "rspec-rails" - - if rspec_support_compatible; then - clone_repo "rspec-support" - fi + clone_repo "rspec-support" popd else diff --git a/script/custom_build_functions.sh b/script/custom_build_functions.sh index f8b0f06b48..256211d5e7 100644 --- a/script/custom_build_functions.sh +++ b/script/custom_build_functions.sh @@ -1,5 +1,5 @@ function run_cukes { - if is_mri_192_plus; then + if is_mri; then bin/rake acceptance --trace return $? elif is_jruby; then diff --git a/script/downgrade_bundler_on_old_rails b/script/downgrade_bundler_on_old_rails deleted file mode 100755 index bb838a77bd..0000000000 --- a/script/downgrade_bundler_on_old_rails +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -# This file was generated on 2019-01-03T20:34:23+00:00 from the rspec-dev repo. -# DO NOT modify it by hand as your changes will get lost the next time it is generated. - -set -e -source script/functions.sh - -if ruby -e "exit(ENV['RAILS_VERSION'].scan(/\d+\.\d+.\d+/)[0].to_f < 5)"; then - # On Rails versions less than 5, Bundler 2.0 is not supported - echo "Warning dowgrading to older version of Bundler" - echo "Current bundler versions installed: `gem list | grep '^bundler ('`" - - gem uninstall -aIx bundler || echo "Warning error occured removing bundler via gem" - - rvm @global do gem uninstall -aIx bundler || echo "Warning error occured removing bundler via rvm" - - echo "Bundler version list after uninstall: `gem list | grep '^bundler ('`" - - gem install bundler -v '1.17.3' -fi diff --git a/script/functions.sh b/script/functions.sh index e8c6a5af4e..e3db72de3e 100644 --- a/script/functions.sh +++ b/script/functions.sh @@ -13,7 +13,7 @@ MAINTENANCE_BRANCH=`cat maintenance-branch` # Don't allow rubygems to pollute what's loaded. Also, things boot faster # without the extra load time of rubygems. Only works on MRI Ruby 1.9+ -if is_mri_192_plus; then +if is_mri; then export RUBYOPT="--disable=gem" fi @@ -47,12 +47,7 @@ function run_cukes { echo "${PWD}/bin/cucumber" - if is_mri_192; then - # For some reason we get SystemStackError on 1.9.2 when using - # the bin/cucumber approach below. That approach is faster - # (as it avoids the bundler tax), so we use it on rubies where we can. - bundle exec cucumber --strict - elif is_jruby; then + if is_jruby; then # For some reason JRuby doesn't like our improved bundler setup RUBYOPT="-I${PWD}/../bundle -rbundler/setup" \ PATH="${PWD}/bin:$PATH" \ @@ -163,6 +158,8 @@ function check_documentation_coverage { end " + echo "bin/yard doc --no-cache" + # Some warnings only show up when generating docs, so do that as well. bin/yard doc --no-cache | ruby -e " while line = gets @@ -187,11 +184,6 @@ function run_all_spec_suites { fold "rspec-core specs" run_spec_suite_for "rspec-core" fold "rspec-expectations specs" run_spec_suite_for "rspec-expectations" fold "rspec-mocks specs" run_spec_suite_for "rspec-mocks" - if rspec_rails_compatible; then - fold "rspec-rails specs" run_spec_suite_for "rspec-rails" - fi - - if rspec_support_compatible; then - fold "rspec-support specs" run_spec_suite_for "rspec-support" - fi + fold "rspec-rails specs" run_spec_suite_for "rspec-rails" + fold "rspec-support specs" run_spec_suite_for "rspec-support" } diff --git a/script/update_rubygems_and_install_bundler b/script/update_rubygems_and_install_bundler index ba2ac25606..4a895d7842 100755 --- a/script/update_rubygems_and_install_bundler +++ b/script/update_rubygems_and_install_bundler @@ -5,11 +5,5 @@ set -e source script/functions.sh -if is_ruby_23_plus; then - yes | gem update --system - yes | gem install bundler -else - echo "Warning installing older versions of Rubygems / Bundler" - gem update --system '2.7.8' - gem install bundler -v '1.17.3' -fi +yes | gem update --system +yes | gem install bundler diff --git a/spec/generators/rspec/install/install_generator_spec.rb b/spec/generators/rspec/install/install_generator_spec.rb index 8d70234758..fd69026f69 100644 --- a/spec/generators/rspec/install/install_generator_spec.rb +++ b/spec/generators/rspec/install/install_generator_spec.rb @@ -7,10 +7,6 @@ def use_active_record_migration match(/ActiveRecord::Migration\./m) end - def check_pending_migrations - match(/ActiveRecord::Migration\.check_pending!/m) - end - def content_for(file_name) File.read(file(file_name)) end @@ -79,21 +75,9 @@ def filter_rails_from_backtrace expect(rails_helper).to filter_rails_from_backtrace end - if RSpec::Rails::FeatureCheck.can_maintain_test_schema? - specify "checking for maintaining the schema" do - run_generator - expect(rails_helper).to maintain_test_schema - end - elsif RSpec::Rails::FeatureCheck.can_check_pending_migrations? - specify "checking for pending migrations" do - run_generator - expect(rails_helper).to check_pending_migrations - end - else - specify "without a check for pending migrations" do - run_generator - expect(rails_helper).not_to use_active_record_migration - end + specify "checking for maintaining the schema" do + run_generator + expect(rails_helper).to maintain_test_schema end end @@ -121,7 +105,6 @@ def filter_rails_from_backtrace run_generator expect(rails_helper).not_to use_active_record_migration expect(rails_helper).not_to maintain_test_schema - expect(rails_helper).not_to check_pending_migrations end end diff --git a/spec/generators/rspec/mailer/mailer_generator_spec.rb b/spec/generators/rspec/mailer/mailer_generator_spec.rb index fda89a2ac9..6cfbf17e7e 100644 --- a/spec/generators/rspec/mailer/mailer_generator_spec.rb +++ b/spec/generators/rspec/mailer/mailer_generator_spec.rb @@ -13,12 +13,8 @@ end it { is_expected.to exist } it { is_expected.to contain(/require "rails_helper"/) } - if Rails.version.to_f >= 5.0 - # Rails 5 automatically appends Mailer to the provided constant so we do too - it { is_expected.to contain(/^RSpec.describe PostsMailer, #{type_metatag(:mailer)}/) } - else - it { is_expected.to contain(/^RSpec.describe Posts, #{type_metatag(:mailer)}/) } - end + # Rails 5+ automatically appends Mailer to the provided constant so we do too + it { is_expected.to contain(/^RSpec.describe PostsMailer, #{type_metatag(:mailer)}/) } it { is_expected.to contain(/describe "index" do/) } it { is_expected.to contain(/describe "show" do/) } end @@ -56,16 +52,8 @@ it { is_expected.to exist } it { is_expected.to contain(/class PostsPreview < ActionMailer::Preview/) } it { is_expected.to contain(/def index/) } - if Rails.version.to_f >= 5.0 - it { is_expected.to contain(/PostsMailer.index/) } - else - it { is_expected.to contain(/Posts.index/) } - end + it { is_expected.to contain(/PostsMailer.index/) } it { is_expected.to contain(/def show/) } - if Rails.version.to_f >= 5.0 - it { is_expected.to contain(/PostsMailer.show/) } - else - it { is_expected.to contain(/Posts.show/) } - end + it { is_expected.to contain(/PostsMailer.show/) } end end diff --git a/spec/generators/rspec/scaffold/scaffold_generator_spec.rb b/spec/generators/rspec/scaffold/scaffold_generator_spec.rb index 3fc754b26c..8dbfa8cee6 100644 --- a/spec/generators/rspec/scaffold/scaffold_generator_spec.rb +++ b/spec/generators/rspec/scaffold/scaffold_generator_spec.rb @@ -110,8 +110,7 @@ it { is_expected.to contain('assert_select "tr>td", text: 3.5.to_s, count: 2') } end - case - when Rails.version.to_f >= 5.1 + if Rails.version.to_f >= 5.1 describe 'with reference attribute' do before { run_generator %w(posts title:string author:references) } describe 'edit' do @@ -126,7 +125,7 @@ it { is_expected.to contain(/assert_select "input\[name=\?\]", "post\[title\]/) } end end - when Rails.version.to_f >= 4.0 + else describe 'with reference attribute' do before { run_generator %w(posts title:string author:references) } describe 'edit' do diff --git a/spec/rspec/rails/configuration_spec.rb b/spec/rspec/rails/configuration_spec.rb index 3b904cd97b..bc914d7589 100644 --- a/spec/rspec/rails/configuration_spec.rb +++ b/spec/rspec/rails/configuration_spec.rb @@ -253,9 +253,7 @@ def in_inferring_type_from_location_environment end end - if ::Rails::VERSION::STRING > '5' - it "has a default #file_fixture_path of 'spec/fixtures/files'" do - expect(config.file_fixture_path).to eq("spec/fixtures/files") - end + it "has a default #file_fixture_path of 'spec/fixtures/files'" do + expect(config.file_fixture_path).to eq("spec/fixtures/files") end end diff --git a/spec/rspec/rails/example/controller_example_group_spec.rb b/spec/rspec/rails/example/controller_example_group_spec.rb index 3e4d69f25d..6d982b51d3 100644 --- a/spec/rspec/rails/example/controller_example_group_spec.rb +++ b/spec/rspec/rails/example/controller_example_group_spec.rb @@ -84,20 +84,11 @@ def my_helper expect(example.foos_url).to eq('http://test.host/foos') end - if Rails.version.to_f >= 4.2 - it "calls NamedRouteCollection#route_defined? when it checks that given route is defined or not" do - expect(routes.named_routes).to receive(:route_defined?).and_return(true) - expect(routes.named_routes).not_to receive(:helpers) + it "calls NamedRouteCollection#route_defined? when it checks that given route is defined or not" do + expect(routes.named_routes).to receive(:route_defined?).and_return(true) + expect(routes.named_routes).not_to receive(:helpers) - example.foos_url - end - else - it "calls NamedRouteCollection#helpers#include? when it checks that given route is defined or not" do - expect(routes.named_routes).to \ - receive_message_chain(:helpers, :include?).with(:foos_url).and_return(true) - - example.foos_url - end + example.foos_url end end diff --git a/spec/rspec/rails/example/mailer_example_group_spec.rb b/spec/rspec/rails/example/mailer_example_group_spec.rb index 6145231049..82a6960087 100644 --- a/spec/rspec/rails/example/mailer_example_group_spec.rb +++ b/spec/rspec/rails/example/mailer_example_group_spec.rb @@ -9,12 +9,6 @@ module ::Rails; end allow(Rails).to receive_message_chain(:configuration, :action_mailer, :default_url_options).and_return({}) end - # On 1.9.2, we're getting travis failures from warnings being emitted by these specs - # only on 1.9.2 (and only on travis; can't repro locally). The warning is: - # /home/travis/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/net/smtp.rb:584: warning: previous definition of tlsconnect was here - # For now, we're just going to silence the warning. - around { |ex| with_isolated_stderr(&ex) } if RUBY_VERSION == '1.9.2' - it_behaves_like "an rspec-rails example group mixin", :mailer, './spec/mailers/', '.\\spec\\mailers\\' end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6d0b0001f8..cd0dc2dcb7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,7 +2,7 @@ module RSpecRails class Application < ::Rails::Application - self.config.secret_key_base = 'ASecretString' if config.respond_to? :secret_key_base + self.config.secret_key_base = 'ASecretString' if defined?(ActionCable) ActionCable.server.config.cable = { "adapter" => "test" } @@ -11,7 +11,7 @@ class Application < ::Rails::Application end end end -I18n.enforce_available_locales = true if I18n.respond_to?(:enforce_available_locales) +I18n.enforce_available_locales = true require 'rspec/support/spec' require 'rspec/rails'