Skip to content

Commit

Permalink
Closes #31.
Browse files Browse the repository at this point in the history
  • Loading branch information
vittoriom committed Jan 7, 2014
1 parent eb7853b commit 63bfc25
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion VMDInstrumenter.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'VMDInstrumenter'
s.version = '0.8.1'
s.version = '0.9'
s.summary = 'A simple Objective-C singleton to instrument, trace, and suppress selectors at runtime.'
s.author = {
'Vittorio Monaco' => 'vittorio.monaco1@gmail.com'
Expand Down
3 changes: 3 additions & 0 deletions VMInstrumenter/VMDInstrumenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ - (void) traceSelector:(SEL)selectorToTrace forInstancesOfClass:(Class)classToIn

- (void) protectSelector:(SEL)selectorToProtect onClass:(Class)classToInspect fromBeingCalledFromSourcesOtherThanStacktraceFramesPassingTest:(VMDFrameTestBlock)testBlock
{
if(!classToInspect)
return;

NSString *protectedSelectorName = [VMDHelper generatePlausibleSelectorNameForSelectorToProtect:selectorToProtect ofClass:classToInspect];
if([self.protectedSelectors containsObject:protectedSelectorName])
@throw [NSException exceptionWithName:NSInternalInconsistencyException
Expand Down
23 changes: 23 additions & 0 deletions VMInstrumenter_Tests/VMInstrumenter_Tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,30 @@ - (void) testOnBlock2
});*/

context(@"from being called from sources other than classes passing a specific test block", ^{
it(@"should do nothing if the class is nil", ^{
[[theBlock(^{
[_instrumenter protectSelector:@selector(dontCallMe)
onClass:nil fromBeingCalledFromSourcesOtherThanClassesPassingTest:^BOOL(__unsafe_unretained Class callingClass) {
return YES;
}];
}) shouldNot] raise];
});

it(@"should protect the selector if the class is valid", ^{
[_instrumenter protectSelector:@selector(testOnClass2)
onClass:[ProtectHelper class] fromBeingCalledFromSourcesOtherThanClassesPassingTest:^BOOL(__unsafe_unretained Class callingClass) {
return [NSStringFromClass(callingClass) hasPrefix:@"Tests"];
}];
ProtectHelper *helper = [ProtectHelper new];
[[theBlock(^{
[helper testOnClass2];
}) shouldNot] raise];

ProtectHelperChecker *checker = [ProtectHelperChecker new];
[[theBlock(^{
[checker callSelector:@selector(testOnClass2) onObject:helper];
}) should] raise];
});
});
});

Expand Down

0 comments on commit 63bfc25

Please sign in to comment.