Skip to content

Commit 85fe645

Browse files
authored
Merge pull request #2784 from rspec/fix-rails-8-with-2781-and-2783
Fix rails 8 build with 2781 and 2783
2 parents 418daeb + e2bc292 commit 85fe645

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

Gemfile-rails-dependencies

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ def add_net_gems_dependency
1111
end
1212
end
1313

14-
# sqlite3 is an optional, unspecified, dependency and Rails 6.0 only supports `~> 1.4`
15-
if RUBY_VERSION.to_f < 3
16-
# sqlite3 1.7.x doesn't work on all platforms for Ruby 2.x
17-
gem 'sqlite3', '~> 1.4', '< 1.7', platforms: [:ruby]
18-
else
19-
gem 'sqlite3', '~> 1.4', platforms: [:ruby]
14+
def add_sqlite3_gem_dependency
15+
# sqlite3 is an optional, unspecified, dependency and Rails 6.0 only supports `~> 1.4`
16+
if RUBY_VERSION.to_f < 3
17+
# sqlite3 1.7.x doesn't work on all platforms for Ruby 2.x
18+
gem 'sqlite3', '~> 1.4', '< 1.7', platforms: [:ruby]
19+
else
20+
gem 'sqlite3', '~> 1.4', platforms: [:ruby]
21+
end
2022
end
2123

2224
if RUBY_VERSION.to_f < 2.7
@@ -30,17 +32,22 @@ when /main/
3032
gem "rails", :git => "https://github.com/rails/rails.git"
3133
gem 'activerecord-jdbcsqlite3-adapter', git: 'https://github.com/jruby/activerecord-jdbc-adapter', platforms: [:jruby]
3234
gem 'selenium-webdriver', require: false
35+
36+
# Rails 8 requires 2.0.0
37+
gem 'sqlite3', '~> 2.0', platforms: [:ruby]
3338
when /stable$/
3439
gem_list = %w[rails railties actionmailer actionpack activerecord activesupport activejob actionview]
3540
gem 'activerecord-jdbcsqlite3-adapter', git: 'https://github.com/jruby/activerecord-jdbc-adapter', platforms: [:jruby]
3641

3742
gem_list.each do |rails_gem|
3843
gem rails_gem, :git => "https://github.com/rails/rails.git", :branch => version
3944
end
45+
add_sqlite3_gem_dependency
4046
when nil, false, ""
4147
gem "rails", "~> 7.0.0"
4248
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
4349
gem 'selenium-webdriver', require: false
50+
add_sqlite3_gem_dependency
4451
else
4552
version_number = version.split(' ').last
4653
add_net_gems_dependency if version_number < '7.0'
@@ -55,4 +62,5 @@ else
5562
else
5663
gem 'selenium-webdriver', require: false
5764
end
65+
add_sqlite3_gem_dependency
5866
end

example_app_generator/generate_app.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929

3030
gsub_file "Gemfile", /.*rails-controller-testing.*/, "gem 'rails-controller-testing', git: 'https://github.com/rails/rails-controller-testing'"
3131

32-
# sqlite3 is an optional, unspecified, dependency and Rails 6.0 only supports `~> 1.4`, and Ruby 2.7 only supports < 1.7
32+
# sqlite3 is an optional, unspecified, dependency of which Rails 6.0 only supports `~> 1.4`, Ruby 2.7 only supports < 1.7 and Rails 8.0 only supports `~> 2.0`
3333
if RUBY_VERSION.to_f < 3
3434
gsub_file "Gemfile", /.*gem..sqlite3.*/, "gem 'sqlite3', '~> 1.4', '< 1.7'"
35+
elsif Rails::VERSION::STRING > '8'
36+
gsub_file "Gemfile", /.*gem..sqlite3.*/, "gem 'sqlite3', '~> 2.0'"
3537
else
3638
gsub_file "Gemfile", /.*gem..sqlite3.*/, "gem 'sqlite3', '~> 1.4'"
3739
end

lib/rspec-rails.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,24 @@ class Railtie < ::Rails::Railtie
99
# As of Rails 5.1.0 you can register directories to work with `rake notes`
1010
require 'rails/source_annotation_extractor'
1111
::Rails::SourceAnnotationExtractor::Annotation.register_directories("spec")
12+
13+
# As of Rails 8.0.0 you can register directories to work with `rails stats`
14+
if ::Rails::VERSION::STRING >= "8.0.0"
15+
require 'rails/code_statistics'
16+
17+
dirs = Dir['./spec/**/*_spec.rb']
18+
.map { |f| f.sub(/^\.\/(spec\/\w+)\/.*/, '\\1') }
19+
.uniq
20+
.select { |f| File.directory?(f) }
21+
22+
Hash[dirs.map { |d| [d.split('/').last, d] }].each do |type, dir|
23+
name = type.singularize.capitalize
24+
25+
::Rails::CodeStatistics.register_directory "#{name} specs", dir
26+
::Rails::CodeStatistics::TEST_TYPES << "#{name} specs"
27+
end
28+
end
29+
1230
generators = config.app_generators
1331
generators.integration_tool :rspec
1432
generators.test_framework :rspec

lib/rspec/rails/tasks/rspec.rake

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

66
task default: :spec
77

8-
task stats: "spec:statsetup"
8+
if ::Rails::VERSION::STRING < "8.0.0"
9+
task stats: "spec:statsetup"
10+
end
911

1012
desc "Run all specs in spec directory (excluding plugin specs)"
1113
RSpec::Core::RakeTask.new(spec: "spec:prepare")

0 commit comments

Comments
 (0)