-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrails_test.rb
More file actions
68 lines (58 loc) · 1.89 KB
/
rails_test.rb
File metadata and controls
68 lines (58 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# frozen_string_literal: true
require 'test_helper'
require 'bundler'
require 'open3'
RAILS_VERSIONS = %w[
6.1.7.7
7.0.8.3
7.1.3.3
].freeze
RAILS_FLAGS = %w[
--api
--skip-action-cable
--skip-active-storage
--skip-bundle
--skip-git
--skip-javascript
--skip-keeps
--skip-system-test
--skip-test
].freeze
TMP_RAILS_ROOT = File.join(__dir__, '../tmp/test')
# Helper to ensure we raise if command is not successful
def run_command(*command)
stdout, stderr, status = Open3.capture3(*command)
if status.success? == false
errors = [
" Command Failed: #{command.join(' ')}",
stdout.split("\n").map { |line| " #{line}" }.join("\n"),
stderr.split("\n").map { |line| " #{line}" }.join("\n"),
]
raise errors.join("\n")
end
[stdout, stderr, status]
end
class RailsTest < Minitest::Test
def setup
FileUtils.mkdir_p(TMP_RAILS_ROOT) unless Dir.exist?(TMP_RAILS_ROOT)
end
RAILS_VERSIONS.each do |rails_version|
define_method "test_that_rails_#{rails_version.gsub('.', '_')}_works" do
Bundler.with_unbundled_env do
Dir.chdir(TMP_RAILS_ROOT) do
tmp_version_root = "rails_#{rails_version.gsub('.', '_')}"
FileUtils.remove_dir(tmp_version_root) if Dir.exist?(tmp_version_root)
run_command('gem', 'install', 'rails', '--version', rails_version, '--force')
run_command('rails', "_#{rails_version}_", 'new', *RAILS_FLAGS, tmp_version_root)
raise "Rails #{rails_version} app creation failed" unless Dir.exist?(tmp_version_root)
Dir.chdir(tmp_version_root) do
File.write('Gemfile', "gem 'diffcrypt', path: '../../..'", mode: 'a')
run_command('bundle', 'install')
stdout, _stderr, _status = run_command('bundle', 'exec', 'rails', 'r', 'puts Rails.version')
assert_equal rails_version, stdout.strip
end
end
end
end
end
end