Skip to content

Commit d067a38

Browse files
committed
chore: Add smoke tests using real-world apps
1 parent ce60c11 commit d067a38

File tree

4 files changed

+128
-1
lines changed

4 files changed

+128
-1
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
/doc/
66
/pkg/
77
/spec/reports/
8-
/tmp/
8+
/tmp/*
9+
!/tmp/.keep
910

1011
# rspec failure tracking
1112
.rspec_status

.rubocop.yml

+4
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ Layout/LeadingCommentSpace:
3030

3131
Style/AccessorGrouping:
3232
Enabled: false
33+
34+
RSpec/DescribeClass:
35+
Exclude:
36+
- "spec/smoke_spec.rb"

spec/smoke_spec.rb

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe "Smoke Tests" do
4+
def system!(*args)
5+
system(*args, exception: true)
6+
end
7+
8+
def tmp_repo(repo:, ref:, &)
9+
Dir.mktmpdir(nil, "tmp") do |dir|
10+
Dir.chdir(dir) do
11+
system! "git clone --branch #{ref} --depth 1 https://github.com/#{repo} ."
12+
Bundler.with_unbundled_env(&)
13+
end
14+
end
15+
end
16+
17+
def add_rbs_trace_to_gemfile
18+
gem_path = File.expand_path("..", __dir__)
19+
File.open("Gemfile", "a") do |f|
20+
f.puts("gem 'rbs-trace', path: '#{gem_path}'")
21+
end
22+
end
23+
24+
describe "Redmine", skip: ENV["SMOKE_TEST_REDMINE"].nil? do
25+
subject(:run_tests) do
26+
tmp_repo(repo: "redmine/redmine", ref: version) do
27+
add_rbs_trace_to_gemfile
28+
29+
File.write("config/database.yml", <<~YAML)
30+
default: &default
31+
adapter: sqlite3
32+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
33+
timeout: 5000
34+
35+
development:
36+
<<: *default
37+
database: db/development.sqlite3
38+
39+
test:
40+
<<: *default
41+
database: db/test.sqlite3
42+
YAML
43+
File.open("test/test_helper.rb", "a") do |f|
44+
f.write(<<~RUBY)
45+
tracing = RBS::Trace::MethodTracing.new(log_level: :debug, raises: true)
46+
tracing.enable
47+
48+
Minitest.after_run do
49+
tracing.disable
50+
tracing.insert_rbs
51+
tracing.save_rbs("sig/trace/")
52+
end
53+
RUBY
54+
end
55+
56+
system! "bundle install"
57+
system! "bin/rails db:migrate"
58+
system! "bin/rails test --fail-fast --seed 0"
59+
end
60+
end
61+
62+
let(:version) { "6.0.2" }
63+
64+
before do
65+
# refs: https://github.com/redmine/redmine/blob/6.0.2/Gemfile#L3
66+
if RUBY_VERSION.start_with?("3.4")
67+
puts "Redmine v#{version} does not support Ruby v3.4."
68+
raise
69+
end
70+
end
71+
72+
it "runs tests with rbs-trace enabled" do
73+
expect { run_tests }.not_to raise_error
74+
end
75+
end
76+
77+
describe "Mastodon", skip: ENV["SMOKE_TEST_MASTODON"].nil? do
78+
subject(:run_tests) do
79+
tmp_repo(repo: "mastodon/mastodon", ref: version) do
80+
add_rbs_trace_to_gemfile
81+
82+
File.open("spec/rails_helper.rb", "a") do |f|
83+
f.write(<<~RUBY)
84+
RSpec.configure do |config|
85+
tracing = RBS::Trace::MethodTracing.new(log_level: :debug, raises: true)
86+
87+
config.before(:suite) { tracing.enable }
88+
config.after(:suite) do
89+
tracing.disable
90+
tracing.insert_rbs
91+
tracing.save_rbs("sig/trace/")
92+
end
93+
end
94+
RUBY
95+
end
96+
97+
env = {
98+
"DISABLE_SIMPLECOV" => "true",
99+
"RAILS_ENV" => "test"
100+
}
101+
system! env, "bin/setup"
102+
system! env, "bin/flatware fan bin/rails db:test:prepare"
103+
system! env, "bin/rails assets:precompile"
104+
system! env, "bin/flatware rspec -r ./spec/flatware_helper.rb --fail-fast --seed 0"
105+
end
106+
end
107+
108+
let(:version) { "v4.3.2" }
109+
110+
before do
111+
# refs: https://github.com/mastodon/mastodon/blob/v4.3.2/.ruby-version
112+
if RUBY_VERSION != "3.3.5"
113+
puts "Mastodon #{version} support Ruby v3.3.5 only."
114+
raise
115+
end
116+
end
117+
118+
it "runs tests with rbs-trace enabled" do
119+
expect { run_tests }.not_to raise_error
120+
end
121+
end
122+
end

tmp/.keep

Whitespace-only changes.

0 commit comments

Comments
 (0)