Skip to content

Commit 2f570d3

Browse files
authored
Add JRuby Support (#43)
It is recommended to use version `9.2.10.0` or later.
1 parent 0a1c9d7 commit 2f570d3

File tree

13 files changed

+116
-12
lines changed

13 files changed

+116
-12
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: jruby-ruby-project
2+
3+
on:
4+
push:
5+
branches: [ 'main' ]
6+
pull_request:
7+
8+
concurrency:
9+
group: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}-jruby-ruby
10+
cancel-in-progress: true
11+
12+
jobs:
13+
main:
14+
name: ruby-${{ matrix.ruby }} rspec-${{ matrix.rspec }} simplecov-${{ matrix.simplecov }}
15+
runs-on: ubuntu-latest
16+
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
ruby: [ 'jruby-9.2.10.0', 'jruby-9.2.19.0', 'jruby-9.3.0.0' ]
21+
rspec: [ '3.6.0', '3.7.0', '3.8.0', '3.9.0', '3.10.0' ]
22+
simplecov: [ '0.12.0', '0.13.0', '0.14.0', '0.15.0', '0.16.0', '0.17.0', '0.18.0', '0.19.0', '0.20.0', '0.21.0' ]
23+
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v2
27+
28+
- name: Setup Ruby
29+
uses: ruby/setup-ruby@v1
30+
with:
31+
ruby-version: ${{ matrix.ruby }}
32+
33+
- name: Install Dependencies
34+
run: bundle install --jobs 3 --retry 3
35+
36+
- name: Run Features for Ruby Project
37+
env:
38+
RSPEC_VERSION: "~> ${{ matrix.rspec }}"
39+
SIMPLECOV_VERSION: "~> ${{ matrix.simplecov }}"
40+
run: JRUBY_OPTS="--debug -X+O" bundle exec cucumber --retry 3 --no-strict-flaky --tags @ruby-app

.github/workflows/rails-5-project.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ jobs:
4040
RSPEC_RAILS_VERSION: "~> ${{ matrix.rspec-rails }}"
4141
SIMPLECOV_VERSION: "~> 0.${{ matrix.simplecov }}.0"
4242
BRANCH_COVERAGE: "${{ matrix.simplecov >= 18 && 'true' || 'false' }}"
43-
run: bundle exec cucumber --tags @rails-app
43+
run: bundle exec cucumber --retry 3 --no-strict-flaky --tags @rails-app

.github/workflows/rails-6-project.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ jobs:
4040
RSPEC_RAILS_VERSION: "~> ${{ matrix.rspec-rails }}"
4141
SIMPLECOV_VERSION: "~> 0.${{ matrix.simplecov }}.0"
4242
BRANCH_COVERAGE: "${{ matrix.simplecov >= 18 && 'true' || 'false' }}"
43-
run: bundle exec cucumber --tags @rails-app
43+
run: bundle exec cucumber --retry 3 --no-strict-flaky --tags @rails-app

.github/workflows/ruby-project-part-1.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ jobs:
3737
env:
3838
RSPEC_VERSION: "~> ${{ matrix.rspec }}"
3939
SIMPLECOV_VERSION: "~> ${{ matrix.simplecov }}"
40-
run: bundle exec cucumber --tags @ruby-app
40+
run: bundle exec cucumber --retry 3 --no-strict-flaky --tags @ruby-app

.github/workflows/ruby-project-part-2.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ jobs:
3838
RSPEC_VERSION: "~> ${{ matrix.rspec }}"
3939
SIMPLECOV_VERSION: "~> ${{ matrix.simplecov }}"
4040
BRANCH_COVERAGE: true
41-
run: bundle exec cucumber --tags @ruby-app
41+
run: bundle exec cucumber --retry 3 --no-strict-flaky --tags @ruby-app

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ installed.
3434

3535
* [Demo](#demo)
3636
* [Getting Started](#getting-started)
37+
* [Working with JRuby](#working-with-jruby)
3738
* [Configuring CI Caching](#configuring-ci-caching)
3839
* [Advanced Configuration](#advanced-configuration)
3940
* [Filters](#filters)
@@ -135,6 +136,16 @@ any of the application code.**
135136
3. After running your tests, open `rspec_tracer_report/index.html` in the browser
136137
of your choice.
137138

139+
### Working with JRuby
140+
141+
It is recommend to use **JRuby 9.2.10.0+**. Also, configure it with **`JRUBY_OPTS="--debug -X+O"`**
142+
or have the `.jrubyrc` file:
143+
144+
```ruby
145+
debug.fullTrace=true
146+
objectspace.enabled=true
147+
```
148+
138149
## Configuring CI Caching
139150

140151
To enable RSpec Tracer to share cache between different builds on CI, update the

features/support/env.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@
2424
if ENV.fetch('SKIP_COVERAGE_VALIDATION', 'false') == 'true'
2525
setup_file = File.join(File.expand_path('../..', __dir__), 'support', 'coverage_setup')
2626

27-
set_environment_variable('RUBYOPT', "-r#{setup_file} #{ENV['RUBYOPT']}")
27+
case RUBY_ENGINE
28+
when 'ruby'
29+
set_environment_variable('RUBYOPT', "-r#{setup_file} #{ENV['RUBYOPT']}")
30+
when 'jruby'
31+
set_environment_variable('JRUBY_OPTS', "--debug -X+O -r#{setup_file} #{ENV['JRUBY_OPTS']}")
32+
end
2833
end
2934
end
3035

lib/rspec_tracer.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ def start(&block)
3434
RSpecTracer.running = false
3535
RSpecTracer.pid = Process.pid
3636

37+
return if RUBY_ENGINE == 'jruby' && !valid_jruby_opts?
38+
3739
puts 'Started RSpec tracer'
3840

3941
configure(&block) if block
@@ -127,6 +129,20 @@ def simplecov?
127129

128130
private
129131

132+
def valid_jruby_opts?
133+
return true if Java::OrgJruby::RubyInstanceConfig.FULL_TRACE_ENABLED &&
134+
JRuby.runtime.object_space_enabled?
135+
136+
puts <<-WARN.strip.gsub(/\s+/, ' ')
137+
RSpec Tracer is not running as it requires debug and object space enabled. Use
138+
command line options "--debug" and "-X+O" or set the "debug.fullTrace=true" and
139+
"objectspace.enabled=true" options in your .jrubyrc file. You can also use
140+
JRUBY_OPTS="--debug -X+O".
141+
WARN
142+
143+
false
144+
end
145+
130146
def initial_setup
131147
unless setup_rspec
132148
puts 'Could not find a running RSpec process'

lib/rspec_tracer/coverage_reporter.rb

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,17 @@ def peek_coverage
167167
end
168168

169169
def line_stub(file_path)
170+
case RUBY_ENGINE
171+
when 'ruby'
172+
ruby_line_stub(file_path)
173+
when 'jruby'
174+
jruby_line_stub(file_path)
175+
end
176+
end
177+
178+
def ruby_line_stub(file_path)
170179
lines = File.foreach(file_path).map { nil }
171-
iseqs = [RubyVM::InstructionSequence.compile_file(file_path)]
180+
iseqs = [::RubyVM::InstructionSequence.compile_file(file_path)]
172181

173182
until iseqs.empty?
174183
iseq = iseqs.pop
@@ -179,5 +188,28 @@ def line_stub(file_path)
179188

180189
lines
181190
end
191+
192+
# rubocop:disable Metrics/AbcSize
193+
def jruby_line_stub(file_path)
194+
lines = File.foreach(file_path).map { nil }
195+
root_node = ::JRuby.parse(File.read(file_path))
196+
197+
visitor = org.jruby.ast.visitor.NodeVisitor.impl do |_name, node|
198+
if node.newline?
199+
if node.respond_to?(:position)
200+
lines[node.position.line] = 0
201+
else
202+
lines[node.line] = 0
203+
end
204+
end
205+
206+
node.child_nodes.each { |child| child&.accept(visitor) }
207+
end
208+
209+
root_node.accept(visitor)
210+
211+
lines
212+
end
213+
# rubocop:enable Metrics/AbcSize
182214
end
183215
end

tasks/features/coverage/rspec_tracer.rake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace :features do
1212
SIMPLECOV_COMMAND_NAME="features:coverage:rspec_tracer"
1313
RSPEC_VERSION="~> 3.10"
1414
SIMPLECOV_VERSION="~> 0.21"
15-
bundle exec cucumber --tags "@ruby-app and @no-simplecov"
15+
bundle exec cucumber --retry 3 --no-strict-flaky --tags "@ruby-app and @no-simplecov"
1616
COMMAND
1717

1818
exit(1) unless system(command)

0 commit comments

Comments
 (0)