Rightpoint / RZBluetooth

Core Bluetooth helper library
Other
136 stars 47 forks source link

Mocking cannot be enabled and disabled on demand #82

Closed mplorentz closed 6 years ago

mplorentz commented 6 years ago

Issue

Enabling and disabling RZBluetooth mocking is not working as I expect.

Steps to reproduce:

  1. Enable mocking (RZBEnableMock(true))
  2. Disable mocking (RZBEnableMock(false))
  3. Enable mocking (RZBEnableMock(true))
  4. Instantiate a CBPeripheralManager

Expected: CBPeripheralManager.mock is not nil. Actual: CBPeripheralManager.mock is nil.

Example

I've attached and example project. It is a mixed Objective-C/Swift framework project since that is how my current project is set up. You can demonstrate the issue by running the tests. RZBDisableMockExample.zip

cpatterson-lilly commented 6 years ago

Hmmm. This might be related to using method_exchangeImplementations for swizzling the alloc methods.

See these articles: https://blog.newrelic.com/2014/04/16/right-way-to-swizzle/ http://petersteinberger.com/blog/2014/a-story-about-swizzling-the-right-way-and-touch-forwarding/

KingOfBrian commented 6 years ago

I'm going to close this as a dupe of #80