-
-
Notifications
You must be signed in to change notification settings - Fork 156
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
Verifying Expectation halfway through the test #56
Comments
Hi Jakub. Interesting idea. However, I can't really see why it would be useful. Why wouldn't you just split the test into two tests with a different expectation in each? Do you have a concrete example where this idea would be useful? Thanks for your interest in Mocha. Cheers, JM. |
Hi, sometimes when I call two methods that call another one, I have to set the
when I guess splitting the test is a good way to go, but I was just curious if there's a possibility in mocha right now for that. |
So if I understand you correctly, you're saying that given a class and test like this :- class MyClass
def initialize(collaborator)
@collaborator = collaborator
end
def method_one
1.times { @collaborator.foo }
end
def method_two
2.times { @collaborator.foo }
end
def method_three
method_one
method_two
end
end
require "test/unit"
require "mocha"
class MyClassTest < Test::Unit::TestCase
def test_method_three
collaborator = mock("collaborator")
my_object = MyClass.new(collaborator)
collaborator.expects(:foo).times(3)
my_object.method_three
end
end I can change def method_one
2.times { @collaborator.foo }
end
def method_two
1.times { @collaborator.foo }
end And the test will still pass. Is that what you mean? I think the way it currently works makes sense to me. The test only cares how many times If you care about how many times You might also want to look at the Mocha::StateMachine examples e.g. Mocha::Expectation#when, Mocha::Expectation#then. This might allow you to do something like what you are talking about. So far I haven't been convinced to make any changes to Mocha. If you are happy with the above explanation, can you close this issue? Otherwise you need to try harder to convince me that Mocha is missing some important functionality! |
You did understand me correctly and both solutions that you've provided are great. I wasn't aware of the StateMachine implementation, I'll have to take a closer look at it. Thanks for your time and a lengthy response |
Is there a way to check single Expectation before the end of a test?
Rspec-Mocks has following syntax
and it got me thinking if it's possible to verify expectation and then replace it with another one (for example to test two functions in one test case).
The text was updated successfully, but these errors were encountered: