-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testing mode with RSpec matchers #25
Conversation
Great job! Testing yabeda is now a little bit tricky and not standardized:
Having rspec matchers simplifies testing. WDYT if we remove internal yabeda values in the same release? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Awesome!
module Yabeda | ||
# Fake monitoring system adapter that collects latest metric values for later inspection | ||
class TestAdapter < BaseAdapter | ||
include Singleton |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we plan to add Mintiest support in the future, it's probably worth considering some kind of per-thread storage (for multithread tests).
expect { block }.to increment_yabeda_counter(Yabeda.counter).by(1)
4e44256
to
138a471
Compare
Goal: provide tools to make testing that Yabeda metrics are being changed as expected to be convenient and allow users not to rely on Yabeda internals that are going to change
Usage with RSpec
Add the following to your
rails_helper.rb
(orspec_helper.rb
):Now you can use
increment_yabeda_counter
,update_yabeda_gauge
, andmeasure_yabeda_histogram
matchers:You can scope metrics by used tags with
with_tags
:Note that tags you specified doesn't need to be exact, but can be a subset of tags used on metric update. In this example updates with following sets of tags
{ method: "command", command: "subscribe", status: "SUCCESS" }
and{ method: "command", command: "subscribe", status: "FAILURE" }
will make test example to pass.And check for values with
by
for counters,to
for gauges, andwith
for gauges and histograms (and you can use other matchers here):