From dd7fdf9a4b82d384d4977e9bff2226653814b34b Mon Sep 17 00:00:00 2001 From: Peter Solnica Date: Mon, 2 Sep 2024 09:11:19 +0000 Subject: [PATCH] Even better rspec skipper --- .../spec/sentry/rack/capture_exceptions_spec.rb | 4 ++-- sentry-ruby/spec/sentry/vernier/profiler_spec.rb | 6 +++--- sentry-ruby/spec/spec_helper.rb | 15 +++++++++++++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/sentry-ruby/spec/sentry/rack/capture_exceptions_spec.rb b/sentry-ruby/spec/sentry/rack/capture_exceptions_spec.rb index 266be8998..83095d842 100644 --- a/sentry-ruby/spec/sentry/rack/capture_exceptions_spec.rb +++ b/sentry-ruby/spec/sentry/rack/capture_exceptions_spec.rb @@ -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 @@ -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 diff --git a/sentry-ruby/spec/sentry/vernier/profiler_spec.rb b/sentry-ruby/spec/sentry/vernier/profiler_spec.rb index ae02e99dd..645ddcada 100644 --- a/sentry-ruby/spec/sentry/vernier/profiler_spec.rb +++ b/sentry-ruby/spec/sentry/vernier/profiler_spec.rb @@ -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 @@ -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/ } @@ -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] diff --git a/sentry-ruby/spec/spec_helper.rb b/sentry-ruby/spec/spec_helper.rb index 511ea6a56..3b72cd17d 100644 --- a/sentry-ruby/spec/spec_helper.rb +++ b/sentry-ruby/spec/spec_helper.rb @@ -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|