Skip to content

Fix false positives of rspec matchers #42

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/yabeda/rspec/increment_yabeda_counter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def increment_yabeda_counter(metric)
class IncrementYabedaCounter < BaseMatcher
def by(increment)
@expected_increment = increment
@expectations = { tags => increment } if tags
@expectations = { tags || {} => increment }
self
end

Expand Down
1 change: 1 addition & 0 deletions lib/yabeda/rspec/measure_yabeda_histogram.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def with(value)
return super if value.is_a?(Hash)

@expected_value = value
@expectations = { tags || {} => value }
self
end

Expand Down
1 change: 1 addition & 0 deletions lib/yabeda/rspec/observe_yabeda_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def with(value)
return super if value.is_a?(Hash)

@expected_value = value
@expectations = { tags || {} => value }
self
end

Expand Down
1 change: 1 addition & 0 deletions lib/yabeda/rspec/update_yabeda_gauge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def with(value)
return super if value.is_a?(Hash)

@expected_value = value
@expectations = { tags || {} => value }
self
end

Expand Down
2 changes: 1 addition & 1 deletion spec/yabeda/rspec/increment_yabeda_counter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
it "fails when given counter was incremented with any other value" do
expect do
expect do
Yabeda.other_counter.increment({})
Yabeda.test_counter.increment({})
end.to increment_yabeda_counter(Yabeda.test_counter).by(2)
end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
end
Expand Down
10 changes: 4 additions & 6 deletions spec/yabeda/rspec/measure_yabeda_histogram_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
it "fails when given histogram was updated with any other value" do
expect do
expect do
Yabeda.other_histogram.measure({}, 1)
Yabeda.test_histogram.measure({}, 1)
end.to measure_yabeda_histogram(Yabeda.test_histogram).with(2)
end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
end
Expand All @@ -68,17 +68,15 @@
it "fails when tags doesn't match" do
expect do
expect do
Yabeda.other_histogram.measure({ foo: :bar, baz: :qux }, 15)
Yabeda.test_histogram.measure({ foo: :bar, baz: :qux }, 15)
end.to measure_yabeda_histogram(Yabeda.test_histogram).with_tags(foo: :bar, baz: :boom)
end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
end

it "succeeds when subset of tags was specified and it matches" do
expect do
expect do
Yabeda.other_histogram.measure({ foo: :bar, baz: :qux }, 0.001)
end.to measure_yabeda_histogram(Yabeda.test_histogram).with_tags(foo: :bar)
end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
Yabeda.test_histogram.measure({ foo: :bar, baz: :qux }, 0.001)
end.to measure_yabeda_histogram(Yabeda.test_histogram).with_tags(foo: :bar)
end
end

Expand Down
10 changes: 4 additions & 6 deletions spec/yabeda/rspec/observe_yabeda_summary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
it "fails when given summary was updated with any other value" do
expect do
expect do
Yabeda.other_summary.observe({}, 1)
Yabeda.test_summary.observe({}, 1)
end.to observe_yabeda_summary(Yabeda.test_summary).with(2)
end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
end
Expand All @@ -68,17 +68,15 @@
it "fails when tags doesn't match" do
expect do
expect do
Yabeda.other_summary.observe({ foo: :bar, baz: :qux }, 15)
Yabeda.test_summary.observe({ foo: :bar, baz: :qux }, 15)
end.to observe_yabeda_summary(Yabeda.test_summary).with_tags(foo: :bar, baz: :boom)
end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
end

it "succeeds when subset of tags was specified and it matches" do
expect do
expect do
Yabeda.other_summary.observe({ foo: :bar, baz: :qux }, 0.001)
end.to observe_yabeda_summary(Yabeda.test_summary).with_tags(foo: :bar)
end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
Yabeda.test_summary.observe({ foo: :bar, baz: :qux }, 0.001)
end.to observe_yabeda_summary(Yabeda.test_summary).with_tags(foo: :bar)
end
end

Expand Down
10 changes: 4 additions & 6 deletions spec/yabeda/rspec/update_yabeda_gauge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
it "fails when given gauge was updated with any other value" do
expect do
expect do
Yabeda.other_gauge.set({}, 3)
Yabeda.test_gauge.set({}, 3)
end.to update_yabeda_gauge(Yabeda.test_gauge).with(2)
end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
end
Expand All @@ -68,17 +68,15 @@
it "fails when tags doesn't match" do
expect do
expect do
Yabeda.other_gauge.set({ foo: :bar, baz: :qux }, 0)
Yabeda.test_gauge.set({ foo: :bar, baz: :qux }, 0)
end.to update_yabeda_gauge(Yabeda.test_gauge).with_tags(foo: :bar, baz: :boom)
end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
end

it "succeeds when subset of tags was specified and it matches" do
expect do
expect do
Yabeda.other_gauge.set({ foo: :bar, baz: :qux }, 3)
end.to update_yabeda_gauge(Yabeda.test_gauge).with_tags(foo: :bar)
end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
Yabeda.test_gauge.set({ foo: :bar, baz: :qux }, 3)
end.to update_yabeda_gauge(Yabeda.test_gauge).with_tags(foo: :bar)
end
end

Expand Down