-
Notifications
You must be signed in to change notification settings - Fork 140
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
ConformTo matcher added #134
Conversation
Playing a little devils' advocate here, is checking the existence of a protocol any more useful than testing the method directly? (AKA test what is does and not how it does it). Although if you could present a use case, that's isn't solved by directly testing the method(s) a protocol supports, that works for me.— On Sat, Nov 2, 2013 at 5:14 AM, Alexey Denisov notifications@github.com
|
@jeffh, not sure that I've understood you correctly, but here is at least the one case when this matcher will be useful: Also I've used both matchers ( It's not a necessary feature, but just a shorthand. |
@AlexDenisov, sorry for the late reply. I guess I'm arguing that testing protocol conformity goes against the philosophy of TDD in more cases than not. Something along the lines of TDD, where did it all go wrong or Growing Object-Oriented Software, Guided by Tests. These resources basically explain that tests should avoid testing every line of code directly, but the intended behavior. Simply put, don't test the algorithm, but test the result. So this line in your project: https://github.com/railsware/BloodMagic/blob/master/BloodMagic/Specs/Specs/Modules/Lazy/LazySpec.mm#L151 describe(@"property with protocol", ^{
__block BMTestProtocolModel *instance;
beforeEach(^{
initializer = [BMInitializer lazyInitializer];
initializer.protocols = @[@protocol(BMLazyTestProtocol)];
initializer.initializer = ^id(id sender) {
instance = [[BMTestProtocolModel new] autorelease];
return instance;
};
[initializer registerInitializer];
});
it(@"initializes with based on the protocol", ^{
subject.propertyWithProtocol should be_same_instance_as(instance);
});
}); Testing that BMTestProtocolModel supports the protocol isn't behavior that the subject under test (BMLazyModel) doesn't provide. I couldn't find any other examples in that testing protocol conformity in the project your listed there. I'm just worried that adding a conforms_to matcher doesn't gain anything to testability at the cost of encouraging new testers start testing the incorrect way (using conformsToProtocol: instead of testing what those protocol methods actually do). If I didn't make it clear or you still disagree please let me know. Granted, if @idoru or @akitchen, find this valuable we can merge it in. |
@jeffh, thanks for the good explanation, your words have sense. Regarding this concrete case, just want to clarify: actually I care only about that Anyway, thank you for feedback, I've learned a lot, again 😄 |
I think there's value in the matcher. It's a bit different from BeInstanceOf, arguably, but not much. At run time vs compile time things are not guaranteed to be what's declared. I can think of two use cases off the top of my head: testing a provider, and testing the construction of a class at run time. This matcher (like BeInstanceOf) simply moves the check into Cedar's DSL Of course, Jeff's points about testing behavior are good advice, and worth considering instead of this check in most cases.
|
Fair enough. @AlexDenisov, you could just fix a couple of coding-styles related stuff and I'll merge it in. |
@end | ||
|
||
@interface Conformer : NSObject | ||
<IConformer> |
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.
Please make protocol declaration the same line as the class declaration.
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.
Ok, will do it.
before merge please: . use Nil for the class |
@akitchen, what should I do with constructors/destructor? |
Let's focus on ConformTo for this pull request; please try to honor the code style using BeInstanceOf.h as an example https://github.com/pivotal/cedar/blob/master/Source/Headers/Matchers/Base/BeInstanceOf.h Thank you :) (oops, edited to indicate ConformTo) |
You mean |
@akitchen, done. |
Thanks for the contribution @AlexDenisov, sorry for all the troubles I've caused. |
@jeffh, it's okay 👍 |
Similar matcher to #132.