1

I'm using Kiwi to test some classes and I need to stub a class method just to return a fake file path. I know that i can solve exposing some path property or create a subclass just for test, but i prefere to keep only one class and stub some methods.

this is the test:

it(@"return the full list of POS", ^(){
    NSString *sample_data_path = [[NSBundle bundleForClass:[self class]] pathForResource:@"sample_pos" ofType:@"plist"];
    Class p = [PointOfSale class];
    [p stub:@selector(sampleDataPath) andReturn:sample_data_path];
    NSArray *allPos = [p findAll];
    [[theValue([allPos count]) should] equal:theValue(100)];
});

I'm confused because this test pass and fail alternatively, one success and one failure. There is not any "before_each"or other running test...

someone has the same issue?

IgnazioC
  • 4,554
  • 4
  • 33
  • 46

1 Answers1

0

I found the cause of this issue. The method sampleDataPath in the original and in the stub class return a file path that is supposed to be in different bundle (mainbundle and test bundle). But even the "production" file was copied in the test bundle, so we had two file with the same name on the same bundle, because of this the result of the test was unpredictable ;)

So....if you have an issue like this,double check your file names!

IgnazioC
  • 4,554
  • 4
  • 33
  • 46