Skip to content

Instantly share code, notes, and snippets.

@gfontenot
Created August 2, 2013 20:42
Show Gist options
  • Save gfontenot/6143314 to your computer and use it in GitHub Desktop.
Save gfontenot/6143314 to your computer and use it in GitHub Desktop.
SpecBegin(TTUser)
describe(@"TTUser", ^{
__block TTUser *user;
__block NSDictionary *userDict;
before(^{
userDict = @{ @"name" : @"Hormell Ansley", @"email" : @"[email protected]", @"id" : @1 };
});
sharedExamplesFor(@"creating a user", ^(NSDictionary *dict){
beforeAll(^{
user = dict[@"user"];
});
it(@"creates a user object", ^{
expect(user).toNot.beNil;
});
it(@"sets the user's email", ^{
expect(user.email).to.equal(@"[email protected]");
});
it(@"sets the user's name", ^{
expect(user.name).to.equal(@"Horell Ansley"); // should fail, does not
});
});
describe(@"-initWithDictionary:", ^{
itShouldBehaveLike(@"creating a user", ^{
return @{ @"user" : [[TTUser alloc] initWithDictionary:userDict] };
});
});
describe(@"+userWithJSON:", ^{
itShouldBehaveLike(@"creating a user", ^{
return @{ @"user" : [TTUser userWithJSON:userDict] };
});
});
});
SpecEnd
@petejkim
Copy link

petejkim commented Aug 2, 2013

SpecBegin(TTUser)

describe(@"TTUser", ^{
  __block TTUser *user;
  __block NSDictionary *userDict;

  before(^{
    userDict = @{ @"name" : @"Hormell Ansley", @"email" : @"[email protected]", @"id" : @1 };
  });

  sharedExamplesFor(@"creating a user", ^(NSDictionary *dict){
    beforeEach(^{                                   // <------------------------ beforeEach instead of beforeAll
      user = dict[@"user"];
    });

    it(@"creates a user object", ^{
      expect(user).toNot.beNil();                    // <------------------------ need ()
    });

    it(@"sets the user's email", ^{
      expect(user.email).to.equal(@"[email protected]");
    });

    it(@"sets the user's name", ^{
      expect(user.name).to.equal(@"Horell Ansley"); // now fails as expected
    });
  });


  describe(@"-initWithDictionary:", ^{
    itShouldBehaveLike(@"creating a user", ^{
      return @{ @"user" : [[TTUser alloc] initWithDictionary:userDict] };
    });
  });

  describe(@"+userWithJSON:", ^{
    itShouldBehaveLike(@"creating a user", ^{
      return @{ @"user" : [TTUser userWithJSON:userDict] };
    });
  });
});

SpecEnd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment