Skip to content

Commit

Permalink
Even better rspec skipper
Browse files Browse the repository at this point in the history
  • Loading branch information
solnic committed Sep 2, 2024
1 parent 3a9367b commit 4d2785b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
4 changes: 2 additions & 2 deletions sentry-ruby/spec/sentry/rack/capture_exceptions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ def will_be_sampled_by_sdk
end
end

describe "profiling with StackProf", when: :stack_prof_installed? do
describe "profiling with StackProf", when: [:stack_prof_installed?, :rack_available?] do
context "when profiling is enabled" do
let(:app) do
->(_) do
Expand Down Expand Up @@ -760,7 +760,7 @@ def will_be_sampled_by_sdk
end
end

describe "profiling with vernier", when: :vernier_installed? do
describe "profiling with vernier", when: [:vernier_installed?, :rack_available?] do
context "when profiling is enabled" do
let(:app) do
->(_) do
Expand Down
6 changes: 3 additions & 3 deletions sentry-ruby/spec/sentry/vernier/profiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "sentry/vernier/profiler"

RSpec.describe Sentry::Vernier::Profiler, when: [:ruby_version?, :>=, "3.2.1"] do
RSpec.describe Sentry::Vernier::Profiler, when: { ruby_version?: [:>=, "3.2.1"] } do
subject(:profiler) { described_class.new(Sentry.configuration) }

before do
Expand Down Expand Up @@ -251,7 +251,7 @@
expect(thread2[:name]).to eq("thread-bar-1")
end

it 'has correct frames', when: [:ruby_version?, :>=, "3.3"] do
it 'has correct frames', when: { ruby_version?: [:>=, "3.3"] } do
frames = profiler.to_hash[:profile][:frames]

foo_frame = frames.find { |f| f[:function] =~ /foo/ }
Expand All @@ -264,7 +264,7 @@
expect(foo_frame[:abs_path]).to include('sentry-ruby/sentry-ruby/spec/support/profiler.rb')
end

it 'has correct stacks', when: [:ruby_version?, :>=, "3.3"] do
it 'has correct stacks', when: { ruby_version?: [:>=, "3.3"] } do
profile = profiler.to_hash[:profile]
frames = profile[:frames]
stacks = profile[:stacks]
Expand Down
15 changes: 13 additions & 2 deletions sentry-ruby/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,20 @@
end

config.before(:each, when: true) do |example|
meth, *args = example.metadata[:when]
guards =
case value = example.metadata[:when]
when Symbol then [value]
when Array then value
when Hash then value.map { |k, v| [k, v].flatten }
else
raise ArgumentError, "Invalid `when` metadata: #{value.inspect}"
end

skip_examples = guards.any? do |meth, *args|
!TestHelpers.public_send(meth, *args)
end

skip("Skipping because `#{meth}(#{args.join(", ")})` returned false") unless TestHelpers.public_send(meth, *args)
skip("Skipping because one or more guards `#{guards.inspect}` returned false") if skip_examples
end

RSpec::Matchers.define :have_recorded_lost_event do |reason, data_category, num: 1|
Expand Down

0 comments on commit 4d2785b

Please sign in to comment.