Answer by Automatico for How to check calls to a method called from...
The new syntax for doing this is as follows:allow_any_instance_of(ExampleClass).to receive(:example_method).and_return("Example")expect_any_instance_of(ExampleClass).to...
View ArticleAnswer by xaxxon for How to check calls to a method called from constructor...
Another answer is to use rspec spies. The issue here is that you have to create a mock for the methods you want to make requirements on after the fact. Turns out it's not hard, but you still have to...
View ArticleAnswer by xaxxon for How to check calls to a method called from constructor...
Here's the best I came up with, but I don't like it:Create a new method in Class that runs a block on the allocated, but not yet initialize'd object. I put this in the before block in my spec file, but...
View ArticleAnswer by Leo Correa for How to check calls to a method called from...
Expectations are meant to be placed before the code that will be expected to meet them. MyClass.any_instance.should_receive(:do_something).exactly(1).timeMyClass.newThat should work.
View ArticleHow to check calls to a method called from constructor in rspec?
If I have a class where the constructor calls another function, how do I check that it was called and the right number of times?class MyClass def initialize(count) count.times{self.do_something} end...
View Article
More Pages to Explore .....