mocha icon indicating copy to clipboard operation
mocha copied to clipboard

Allow hiding satisfied expectations in test output

Open thomasmarshall opened this issue 4 years ago • 1 comments

It's often not important to see satisfied stubs in test output, and in some test suites the noise can be difficult to parse. This commit introduces an Expectation#quietly method which allows the suppression of test output for satisfied expectations on a case-by-case basis.

Example

setup do
  SomeGlobal.stubs(:foo).with(any_of(*SomeGlobal::THINGS)).quietly
  AnotherGlobal.stubs(:connection).quietly
end

test "foo" do
  Foo.stubs(:bar)
  Bar.expects(:baz)
end
Without #quietly With #quietly
Screenshot 2021-11-11 at 15 35 17 Screenshot 2021-11-11 at 17 46 29

Alternatives

One alternative might be to treat stubs and expectations differently, such that satisfied stubs are never reported. Or maybe satisfied expectations with a cardinality of 0 needn't be reported. Or maybe it's already possible to hook into Mockery somehow to override the reporting behaviour?

At the moment, we're monkey patching to achieve something similar but thought others might be interested in this change – no worries if not!

thomasmarshall avatar Nov 11 '21 17:11 thomasmarshall

@thomasmarshall Thanks for the PR. At first glance doing something about this sounds sensible. I wonder whether a configuration option might be more appropriate. I'm on leave at the moment, but I'll try to have a proper look at it when I'm back next week.

floehopper avatar Nov 12 '21 15:11 floehopper

@thomasmarshall I'm sorry I haven't got round to doing anything about this. I've opened #587 to capture the idea, because I still think it's a good one!

floehopper avatar Nov 11 '22 16:11 floehopper