2014-12-22 10 views
0

나는이 같은 수준의 조롱과 다양한 예제를 통해 검토 한 결과 :키위의 클래스 메소드를 감시하는 방법은 무엇입니까?

https://groups.google.com/forum/#!topic/kiwi-bdd/hrR2Om3Hv3I

https://gist.github.com/sgleadow/4029858

Mocking expectations in Kiwi (iOS) for a delegate

클래스 Test는 클래스 메소드 fetch 있습니다.

내가 얻으려고하는 것은 테스트하고 싶은 클래스의 작업 중에 클래스의 메서드가 호출되는지 확인하는 것입니다.

내가 무엇 :

it(@"test", ^{ 
     id mock = [KWMock mockForClass:[Test class]]; 
     [[mock should] receive:@selector(fetch)]; 
     Repository *rep = [[Repository sharedInstance] rep]; //method `rep` invokes [Test fetch] at some point 
    }); 

그리고 테스트는 다음과 같은 오류와 함께 실패합니다

[FAILED], expected subject to receive -fetch exactly 1 time, but received it 0 times 

내가 잘못 뭐하는 거지? 스파이 메커니즘은 클래스 메소드에서 어떻게 작동해야합니까?

답변

1
[[Test should] receive:@selector(fetch)]; 

어떻게 메소드 클래스를 검사해야할까요? 인스턴스 클래스가 아니기 때문에 조롱 된 클래스 객체가 필요하지 않습니다. 글을 쓸 때 자동 완성 기능이 나타나지 않을 수도 있으므로 강제로해야합니다.