0

Can't figure out whats going on here . . .

I've got a simple unit test thats designed to test a parser. Test case looks like this:

[parser didStartElement:@"mobileresponse" attributes:[NSDictionary dictionaryWithObject:@"http://www.espn.com/" forKey:@"rooturl"]];
[parser didStartElement:@"content" attributes:[NSDictionary dictionaryWithObject:@"/soccer" forKey:@"mobileFriendlyUrl"]];
NSString *mobileFriendlyURL = [parser valueForKey:@"mobile_friendly_url"];
STAssertEqualObjects(@"http://www.espn.com/soccer", mobileFriendlyURL, @"url path should be appended to root url");

now this is failing every time, but here is the output

'http://www.espn.com/soccer' should be equal to 'http://www.espn.com/soccer' url path should be appended to root url

Am I going crazy or are those the exact same?? Does anyone have any idea why this is throwing an error?

Sean Danzeiser
  • 9,141
  • 12
  • 52
  • 90

2 Answers2

0

just had to change the nsstring declaration to

[NSString stringWithFormat:@"%@",[parser valueForKey:@"mobile_friendly_url"]];
Sean Danzeiser
  • 9,141
  • 12
  • 52
  • 90
0

Well most probably the reason for this is that [parser valueForKey:@"mobile_friendly_url"] doesn't return an NSString.

Consider this example (the error is there to make a point):

NSString *mobileFriendlyURL = [NSURL URLWithString:@"http://www.espn.com/soccer"];
STAssertEqualObjects(@"http://www.espn.com/soccer", mobileFriendlyURL, @"");

This will fail with the same message as yours because you have compared 2 objects that are different (even if you assumed that mobileFriendlyURL was an NSString and declared its type as NSString). Finally the message just prints the description of the NSURL which is of course identical to your string and thus confusing you even more :)

A quick way to test this theory is to do something like this:

NSString *mobileFriendlyURL = [[NSURL URLWithString:@"http://www.espn.com/soccer"] description];
STAssertEqualObjects(@"http://www.espn.com/soccer", mobileFriendlyURL, @"");

Or even better do something similar to this in order to query the class:

NSLog(@"%@", [mobileFriendlyURL class]);

I hope that this makes sense...

Alladinian
  • 34,483
  • 6
  • 89
  • 91