Skip to content

Commit 0b61a4b

Browse files
authored
Add back Ruby 2.2 support for Rails 5 (#2332)
* Add extra debugging tool for specs expected to pass * Add back Ruby 2.2 support for Rails 5
1 parent b628615 commit 0b61a4b

File tree

8 files changed

+74
-11
lines changed

8 files changed

+74
-11
lines changed

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ matrix:
7878
env: RAILS_VERSION='~> 5.2.0'
7979
- rvm: 2.3.8
8080
env: RAILS_VERSION='~> 5.2.0'
81+
- rvm: 2.2.10
82+
env: RAILS_VERSION='~> 5.2.0'
83+
allow_failure: true
84+
- rvm: 2.2.10
85+
env: RAILS_VERSION='5-2-stable'
8186

8287
# Rails 5.1 Builds >= 2.2.2
8388
- rvm: 2.6.6
@@ -88,6 +93,8 @@ matrix:
8893
env: RAILS_VERSION='~> 5.1.0'
8994
- rvm: 2.3.8
9095
env: RAILS_VERSION='~> 5.1.0'
96+
- rvm: 2.2.10
97+
env: RAILS_VERSION='~> 5.1.0'
9198

9299
# Rails 5.0 Builds >= 2.2.2
93100
- rvm: 2.6.6
@@ -98,5 +105,7 @@ matrix:
98105
env: RAILS_VERSION='~> 5.0.0'
99106
- rvm: 2.3.8
100107
env: RAILS_VERSION='~> 5.0.0'
108+
- rvm: 2.2.10
109+
env: RAILS_VERSION='~> 5.0.0'
101110

102111
fast_finish: true

Gemfile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ case RAILS_VERSION
2222
when /master/
2323
MAJOR = 6
2424
MINOR = 0
25+
when /5-2-stable/
26+
MAJOR = 5
27+
MINOR = 2
2528
when /stable/
2629
MAJOR = 6
2730
MINOR = 0
@@ -46,7 +49,11 @@ gem 'rake', '~> 12'
4649

4750
gem 'mime-types', "~> 3"
4851

49-
gem 'capybara', '>= 2.13', '< 4.0', require: false
52+
if RUBY_VERSION.to_f == 2.2
53+
gem 'capybara', '~> 3.1.0'
54+
else
55+
gem 'capybara', '>= 2.13', '< 4.0', require: false
56+
end
5057

5158
if MAJOR < 6
5259
gem 'nokogiri', '1.9.1'
@@ -56,7 +63,9 @@ end
5663

5764
gem "rubyzip", '~> 1.2'
5865

59-
gem 'rubocop', '~> 0.80.1'
66+
if RUBY_VERSION.to_f >= 2.3
67+
gem 'rubocop', '~> 0.80.1'
68+
end
6069

6170
custom_gemfile = File.expand_path('Gemfile-custom', __dir__)
6271
eval_gemfile custom_gemfile if File.exist?(custom_gemfile)

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ RSpec::Core::RakeTask.new(:spec) do |t|
2727
end
2828

2929
Cucumber::Rake::Task.new(:cucumber) do |t|
30-
version = ENV.fetch("RAILS_VERSION", "~> 6.0.0")[/\d[\.-]\d/]
30+
version = ENV.fetch("RAILS_VERSION", "~> 6.0.0")[/\d[\.-]\d/].tr('-', '.')
3131
if version == "master" || version.nil?
3232
version = Float::INFINITY
3333
end

example_app_generator/generate_app.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
end
3737

3838
if Rails::VERSION::STRING >= "5.1.0"
39-
if RUBY_VERSION < "2.4"
39+
if RUBY_VERSION < "2.3"
40+
gsub_file "Gemfile", /.*capybara.*/, "gem 'capybara', '~> 3.1.0'"
41+
elsif RUBY_VERSION < "2.4"
4042
gsub_file "Gemfile", /.*capybara.*/, "gem 'capybara', '~> 3.15.0'"
4143
end
4244
if Rails::VERSION::STRING >= "5.2.0"

lib/rspec/rails/example/mailer_example_group.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ module MailerExampleGroup
2121

2222
included do
2323
include ::Rails.application.routes.url_helpers
24-
options = ::Rails.configuration.action_mailer.default_url_options
25-
options&.each { |key, value| default_url_options[key] = value }
24+
options = ::Rails.configuration.action_mailer.default_url_options || {}
25+
options.each { |key, value| default_url_options[key] = value }
2626
end
2727

2828
# Class-level DSL for mailer specs.

script/update_rubygems_and_install_bundler

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,11 @@
55
set -e
66
source script/functions.sh
77

8-
gem update --no-document --system
9-
gem install --no-document bundler
8+
if is_ruby_23_plus; then
9+
gem update --no-document --system
10+
gem install --no-document bundler
11+
else
12+
echo "Warning installing older versions of Rubygems / Bundler"
13+
gem update --system '2.7.8'
14+
gem install bundler -v '1.17.3'
15+
fi

spec/rspec/rails/example/view_example_group_spec.rb

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'support/group_failure_formatter'
2+
13
module RSpec::Rails
24
RSpec.describe ViewExampleGroup do
35
it_behaves_like "an rspec-rails example group mixin", :view,
@@ -234,17 +236,29 @@ def _view; end # Stub method
234236
expect(view_spec.view).to eq(view)
235237
end
236238

237-
it 'is accessible to hooks' do
239+
if RUBY_VERSION <= "2.3.0" && ENV["RAILS_VERSION"] !~ /stable/ && ::Rails.version.to_f == 5.2
240+
pending_only_on_ruby_22_rails_52 = """
241+
Rails 5.2.4.2 has a syntax error in ActionDispatch::Request::Session.
242+
(A &. usage which does not work in 2.2.10)
243+
It has been fixed but not released, this spec will not pass until that
244+
has been released.
245+
"""
246+
else
247+
pending_only_on_ruby_22_rails_52 = false
248+
end
249+
250+
it 'is accessible to hooks', pending: pending_only_on_ruby_22_rails_52 do
238251
with_isolated_config do
239252
run_count = 0
240253
RSpec.configuration.before(:each, type: :view) do
241254
allow(view).to receive(:render) { :value }
242255
run_count += 1
243256
end
244257
group = RSpec::Core::ExampleGroup.describe 'a view', type: :view do
245-
specify { true }
258+
specify { expect(true).to eq true }
246259
end
247-
group.run
260+
group.run(failure_reporter)
261+
expect(failure_reporter.exceptions).to eq []
248262
expect(run_count).to eq 1
249263
end
250264
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module RSpec::Rails::TestSupport
2+
class FailureReporter
3+
def initialize
4+
@exceptions = []
5+
end
6+
attr_reader :exceptions
7+
8+
def example_failed(example)
9+
@exceptions << example.exception
10+
end
11+
12+
def method_missing(name, *_args, &_block)
13+
end
14+
end
15+
16+
def failure_reporter
17+
@failure_reporter ||= FailureReporter.new
18+
end
19+
end
20+
21+
RSpec.configure do |config|
22+
config.include RSpec::Rails::TestSupport
23+
end

0 commit comments

Comments
 (0)