Skip to content

Commit

Permalink
feat(ruby): check if truffleruby
Browse files Browse the repository at this point in the history
  • Loading branch information
marian13 committed Mar 20, 2023
1 parent b5c9918 commit 341ced1
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/convenient_service/support/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ def version
def jruby?
::RUBY_PLATFORM.to_s.match?(/java/)
end

##
# Returns `true` when TruffleRuby, `false` otherwise.
#
# @return [Boolean]
#
# @internal
# NOTE: Taken from irb testing. May NOT be stable.
#
# TODO: Find a confirmation of stability.
#
def truffleruby?
::RUBY_ENGINE.to_s.match?(/truffleruby/)
end
end
end
end
Expand Down
46 changes: 46 additions & 0 deletions spec/lib/convenient_service/support/ruby_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,52 @@
end
end
end

describe ".truffleruby?" do
context "when `::RUBY_ENGINE` is NOT valid" do
context "when `::RUBY_ENGINE` is `nil`" do
before do
stub_const("RUBY_ENGINE", nil)
end

it "returns `false`" do
expect(described_class.truffleruby?).to eq(false)
end
end

context "when `::RUBY_ENGINE` is empty string" do
before do
stub_const("RUBY_ENGINE", "")
end

it "returns `false`" do
expect(described_class.truffleruby?).to eq(false)
end
end
end

context "when `::RUBY_ENGINE` is valid" do
context "when `::RUBY_ENGINE` does NOT match `/truffleruby/`" do
before do
stub_const("RUBY_ENGINE", "jruby")
end

it "returns `false`" do
expect(described_class.truffleruby?).to eq(false)
end
end

context "when `::RUBY_ENGINE` matches `/truffleruby/`" do
before do
stub_const("RUBY_ENGINE", "truffleruby")
end

it "returns `true`" do
expect(described_class.truffleruby?).to eq(true)
end
end
end
end
end
end
# rubocop:enable RSpec/NestedGroups

0 comments on commit 341ced1

Please sign in to comment.