Title: Theory / Important / CS / Programming / Objective-C / test / OCMock
Tags: automatedNewLineAfterCommaSpace
On every note of this deck, unless a note says otherwise:
Language: Objective-C
Library: OCMock/OCMock.h

Instruction: OCMClassMock([ClassName class])
Page: https://ocmock.org/
Returns: A mock for ClassName, returning explicitly set values, or nil/default if not set
Name: A nice class mock

Instruction: OCMStub([mock params:Args...])
  .andReturn(value)
Page: https://ocmock.org/
Returns: Ensure that when [mock params:Args...] is called, it returns value
Variables: id mock // Some mock or partial mock

Instruction: OCMStub([mock methodName:[OCMArg any]]).andReturn(value)
Page: https://ocmock.org/
Effect: Ensure that when [mock methodName:] is called with any value, it returns value
Variables: id mock // Some mock or partial mock

Instruction: OCMVerify(
  atMost(n),
  [mock methodName:args...]
)
Page: https://ocmock.org/reference/
Effect: assert that [mock methodName:args...] is calleds at most n times.
Variables: id mock // Some mock or partial mock

Instruction: OCMPartialMock(myObject)
Page: https://ocmock.org/
Returns: A partial mock, that behaves as myObject except when explicitly different
Variables: id mock // Some mock or partial mock
Name: A partial mock

Instruction: OCMProtocolMock(@protocal(SomeProtocol))
Page: https://ocmock.org/
Returns: A mock for SomeProtocol, returning explicitly set values, or nil/default if not set
Variables: id myObject
Name: A nice protocol mock

Instruction: OCMStrictClassMock([ClassName class])
Page: https://ocmock.org/
Returns: A strict mock for ClassName, returning explicitly set values, throwing for other values
Name: A stict class mock

Instruction: OCMStrictProtocolMock(@protocal(SomeProtocol))
Page: https://ocmock.org/
Returns: A strict mock for SomeProtocol, returning explicitly set values, throwing otherwise
Variables: id myObject
Name: A strict protocol mock

Name: A strict mock
Definition: A mock that throw when return value is not explicitly set
Page: https://ocmock.org/reference
Context: OCMock

Name: A nice mock
Definition: A mock that return default value or nil when return value is not explicitly set
Page: https://ocmock.org/reference
Context: OCMock

Instruction: stubCase.andReturn(value)
Page: https://ocmock.org/reference
Effect: When the method indicated by stubCase is called, return value
Context: OCMock
Variables: id stubCase;

Instruction: stubCase.andCall(object, @selector(method))
Page: https://ocmock.org/reference
Effect: when stubCase is called, call [object method]
Context: OCMock
Variables: id stubCase;

Instruction: stubCase.andDo(block)
Page: https://ocmock.org/reference
Effect: When stubCase occur, execute block
Context: OCMock
Variables: id stubCase;

Instruction: OCMStub([mock someMethodWithReferenceArgument:[OCMArg setTo:anObject]]);
Page: https://ocmock.org/reference
Effect: todo (not clear)
Context: OCMock
Variables: id stubCase;

Instruction: stubCase.andThrow(exception)
Page: https://ocmock.org/reference
Effect: if stubCase is called, exception is thrown
Context: OCMock
Variables: id stubCase;

Instruction: stubCase.andPost(aNotification)
Page: https://ocmock.org/reference
Effect: if stubCase is called, post aNotification
Context: OCMock
Variables: id stubCase;

Instruction: OCMArg invokeBlock
Page: https://ocmock.org/reference
Effect: todo. not clear
Context: OCMock
Variables: id stubCase;

Instruction: stubCase.andForwardToRealObject()
Page: https://ocmock.org/reference
Effect: when stubCase is called, the same method is called on the real object's method/class function
Context: OCMock
Variables: id stubCase;

Instruction: stubCase.andDo(nil)
Page: https://ocmock.org/reference
Effect: if stubCase is called, nothing occurs
Context: OCMock
Variables: id stubCase;

Instruction: stubCase.andFulfill(expectation)
Page: https://ocmock.org/reference
Effect: When the method is invoked an expectation in the XCTest framework is fulfilled.
Context: OCMock
Variables: id stubCase;

Instruction: stubCase.andLog(
  format,
  ...
)
Page: https://ocmock.org/reference
Effect: When the method is invoked the message constructed from format and the arguments is logged via NSLog.
Context: OCMock
Variables: id stubCase;
Extra: It is likely that you want to use this in a chain,
  maybe followed by andReturn(
) or andForwardToRealObject(
).

Instruction: stubCase.andBreak()
Page: https://ocmock.org/reference
Effect: When the method is invoked the debugger is opened as if a breakpoint was hit.
Context: OCMock
Variables: id stubCase;
Extra: The stack will end somewhere in the implementation of OCMock but if you look further up, past the __forwarding__ frames, you should be able to see where your code invoked the method.

Page: https://ocmock.org/reference
Syntactic sugar: OCMVerify([mock methodCall])
Implementation: OCMVerify(atLeast(1), [mock methodCall])
Language: Objective-C
Variables: id stubCase;
Context: OCMock
Library: OCMock/OCMock.h

Page: https://ocmock.org/reference
Syntactic sugar: never()
Implementation: atMost(0)
Language: Objective-C
Variables: id stubCase;
Context: OCMock
Library: OCMock/OCMock.h

Instruction: [OCMarg
  any
]
Page: https://ocmock.org/reference
Context: OCMock
Returns: A constraint accepting everything

Instruction: [OCMarg
  anyPointer
]
Page: https://ocmock.org/reference
Context: OCMock
Returns: A constraint accepting every pointers

Instruction: [OCMarg
  anySelector
]
Page: https://ocmock.org/reference
Context: OCMock
Returns: A constraint accepting every selectors

Instruction: stub.ignoringNonObjectArgs()
Page: https://ocmock.org/reference
Effect: todo: understand
Context: OCMock

Instruction: [OCMarg
  isNil
]
Page: https://ocmock.org/reference
Context: OCMock
Returns: Constraint accepting only nil

Instruction: [OCMarg
  isNotNil
]
Page: https://ocmock.org/reference
Context: OCMock
Returns: Constraint accepting everything but nil

Instruction: [OCMock
  isNotEqual:value
]
Page: https://ocmock.org/reference
Context: OCMock
Returns: Constraint accepting everything but value

Instruction: [OCMock
  isKindOfClass:[SomeClass class]
]
Page: https://ocmock.org/reference
Context: OCMock
Returns: Constraint accepting any value of SomeClass

Instruction: [OCMock
  checkWithSelecton:aSelector
  onObject:anObject
]
Page: https://ocmock.org/reference
Context: OCMock
Returns: Constraint accepting any value v such that [anObject aSelector:v] returns YES

Instruction: [OCMock
  checkWithBlock:block
]
Page: https://ocmock.org/reference
Context: OCMock
Returns: Constraint accepting any value v such that block(v) returns YES

Name: A constraint
Definition: A rule to accept or reject some argument to a method
Page: https://ocmock.org/reference
Context: OCMock

Question: What are the possible OCMock constraints
Answer: a specific value
Page: https://ocmock.org/reference
Context: OCMock
Answer2: OCMarg's constraint
Answer3: Hamcrest's matchers
Name: A constraint

Instruction: OCMVerify(
  times(n)
  [mock methodName:args...]
)
Page: https://ocmock.org/reference/
Effect: assert that [mock methodName:args...] is calleds n times
Variables: id mock // Some mock or partial mock

Instruction: OCMVerify(
  atLeast(n)
  [mock methodName:args...]
)
Page: https://ocmock.org/reference/
Effect: assert that [mock methodName:args...] is calleds at least n times.
Variables: id mock // Some mock or partial mock