Skip to content

Commit

Permalink
Remove code related to Rails < 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pirj committed Dec 20, 2019
1 parent 930c141 commit d52a135
Show file tree
Hide file tree
Showing 54 changed files with 71 additions and 1,103 deletions.
12 changes: 0 additions & 12 deletions .rubocop.yml
Expand Up @@ -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
Expand All @@ -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

Expand Down
11 changes: 11 additions & 0 deletions .rubocop_todo.yml
Expand Up @@ -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
3 changes: 1 addition & 2 deletions .travis.yml
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions Gemfile-custom.sample
Expand Up @@ -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
8 changes: 2 additions & 6 deletions Gemfile-rails-dependencies
Expand Up @@ -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]

Expand All @@ -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]
Expand Down
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -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
Expand Down
21 changes: 6 additions & 15 deletions Rakefile
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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")

Expand Down Expand Up @@ -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")

Expand Down
3 changes: 0 additions & 3 deletions appveyor.yml
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions 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/
Expand Down
21 changes: 2 additions & 19 deletions example_app_generator/generate_app.rb
Expand Up @@ -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")
Expand All @@ -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'"
Expand All @@ -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}',
Expand Down
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion example_app_generator/spec/support/default_preview_path
Expand Up @@ -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.
Expand Down
75 changes: 3 additions & 72 deletions example_app_generator/spec/verify_mailer_preview_path_spec.rb
Expand Up @@ -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/ }.
Expand All @@ -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' }
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion example_app_generator/travis_retry_bundle_install.sh
Expand Up @@ -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"
Expand Down

0 comments on commit d52a135

Please sign in to comment.