Comments (4)
It's not a bug. You have a basic misunderstanding of what the code is doing. OCMClassMock does not return a class level mock, it's returning an "mock" instance of the class. Please follow through with posting to stack overflow so that others can easily find the answer if they have similar questions.
from ocmock.
UPDATE:
when I try a simplified version to test whether the mock is working:
- (void)testMock {
id policyMock = OCMClassMock([PrivacyPolicy class]);
OCMExpect([policyMock hasPermissionFor:OCMOCK_ANY scene:OCMOCK_ANY]).andReturn(YES);
PrivacyConfig *config = [PrivacyConfig currentConfig];
PrivacyPolicy *policy = [config getPolicyWithPermission:TestPermissionKey];
BOOL val = [policy hasPermissionFor:KSPKTestPermissionKey scene:@"test"];
XCTAssertTrue(val);
OCMVerify([policyMock hasPermissionFor:OCMOCK_ANY scene:OCMOCK_ANY]); // fail
}
When I tried to explicitly call hasPermissionFor:scene:
it seems no matter with or without .andForwardToRealObject().andReturn(YES)
the XCTAssertTrue and OCMVerify never pass, indicating the mock is not working at all.
I'm not sure if this is a limitation, or bug? because it seems PrivacyPolicy is a very simple class and nothing special.
from ocmock.
This looks like a problem with using OCMock. What is the object returned by getPolicyWithPermission:
? Assuming that this is not the mock object, how would the mock notice that a method is called on that object?
Please do not ask follow-up questions here. Questions relating to the use of OCMock should be asked on StackOverflow. Thank you.
from ocmock.
@erikdoe I do hesitated where to ask before opening this thread, but eventually I thought I have read the doc and thinking it's worthy of confirming whether it's a bug or not.
Because in the doc
id mock = OCMClassMock([SomeClass class]);
OCMStub([mock someMethod]).andReturn(myValue);
/* run code under test */
OCMVerify([mock someMethod]);
it seems I can hook a instance method on a Class level mock?
getPolicyWithPermission
returns a PrivacyPolicy instance, which I assume
id policyMock = OCMClassMock([PrivacyPolicy class]);
OCMExpect([policyMock hasPermissionFor:OCMOCK_ANY scene:OCMOCK_ANY]).andReturn(YES);
should work for this returned object? Could you confirm this is not a bug?
e.g. how could I mock a instance method for all instance for a specific class? Thanks.
from ocmock.
Related Issues (20)
- Using OCMArg setTo generates an error Implicit conversion HOT 1
- Please drop "v" prefix for tagged versions for a better experience with Swift Package Manager HOT 2
- Swift Package Manager support is incomplete HOT 6
- ocmock tests have problems with Xcode 13.0b2 on iOS15 HOT 3
- Documentation link is dead / goes to porn HOT 1
- Unable to access class methods +(void) while I am write down test case for my own framework -(void) instance methods are working fine using OCMock HOT 2
- OCMock not loading for macOS test target
- When I OCMProtocolMock a protocol(This protocol has a method),How can I invoke the real implementation of the method HOT 4
- Mac Catalyst Support HOT 1
- Incompatible function pointer types
- A question about the andDo function
- Developer Account agnostic build scripts HOT 1
- Do not require xcpretty HOT 1
- ReadOnly Mock HOT 1
- OCMPartialMock initialized with NSConstantArray is crashing on Xcode 14.0b3 HOT 3
- `va_arg()` causes `EXC_BAD_ACCESS` in mocked objects HOT 5
- OCMVerify with CMTime argument fails on m1 mac. HOT 2
- Error in partial mock documentation HOT 1
- Release 3.9.2 not on Cocoapods HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ocmock.