Skip to content

Commit

Permalink
wip - support tags/context as kwargs too
Browse files Browse the repository at this point in the history
  • Loading branch information
solnic committed Oct 9, 2024
1 parent bab51b6 commit a5fa5f5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
14 changes: 7 additions & 7 deletions sentry-ruby/lib/sentry/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@
@tags = tags
end

def verify_exception(event, exception: nil, message: nil)
def verify_exception(event, exception: nil, message: nil, **)
return true unless exception && message

event.exception.values.any? do |sentry_exception|
sentry_exception.type == exception.name && sentry_exception.value == "#{message} (#{exception})"
end
end

def verify_context(event, **opts)
return true unless @context
def verify_context(event, context: @context, **)
return true unless context

event.contexts.any? { |key, value| value == @context[key] }
event.contexts.any? { |key, value| value == context[key] }
end

def verify_tags(event, **opts)
return true unless @tags
def verify_tags(event, tags: @tags, **)
return true unless tags

@tags.all? { |key, value| event.tags.include?(key) && event.tags[key] == value }
tags.all? { |key, value| event.tags.include?(key) && event.tags[key] == value }
end
end
16 changes: 16 additions & 0 deletions sentry-ruby/spec/sentry/rspec/matchers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,21 @@
.with_tags({ foo: "bar", baz: "qux" })
.with_context("rails.error" => { some: "stuff" })
end

it "matches error events with tags and context provided as arguments" do
Sentry.set_tags(foo: "bar", baz: "qux")
Sentry.set_context("rails.error", { some: "stuff" })

exception = StandardError.new("Gaah!")

Sentry.capture_exception(exception)

expect(sentry_events).to include_sentry_event(
exception: exception.class,
message: exception.message,
tags: { foo: "bar", baz: "qux" },
context: { "rails.error" => { some: "stuff" } }
)
end
end
end

0 comments on commit a5fa5f5

Please sign in to comment.