Skip to content

Instantly share code, notes, and snippets.

@Dakuan
Created April 9, 2013 22:09
Show Gist options
  • Save Dakuan/5349866 to your computer and use it in GitHub Desktop.
Save Dakuan/5349866 to your computer and use it in GitHub Desktop.
Javascript jasmine spec
describe("Tip Model", function() {
it("should exist", function() {
return expect(Mychicken.Models.Tip).toBeDefined();
});
describe("Attributes", function() {
return it('should have attributes', function() {
var tip;
tip = new Mychicken.Models.Tip();
expect(tip.attributes.content).toBeDefined();
return expect(tip.attributes.html).toBeDefined();
});
});
describe("#parseUrls", function() {
beforeEach(function() {
this.tip = new Mychicken.Models.Tip();
return spyOn(this.tip, '_render');
});
it('should call render if there are any long urls', function() {
this.tip.attributes.content = 'the quick brown http://www.google.com';
this.tip.parseUrls();
return expect(this.tip._render).toHaveBeenCalled();
});
return it('should not call render if there are no long urls', function() {
this.tip.attributes.content = "this quick brown";
this.tip.parseUrls();
return expect(this.tip._render.calls.length).toEqual(0);
});
});
describe('#_toHtml', function() {
beforeEach(function() {
return this.tip = new Mychicken.Models.Tip();
});
it('should contain a link if a hash tag is present', function() {
return expect(this.tip._toHtml('#word')).toContain('<a');
});
return it('should not contain a link if a hash tag is not present', function() {
return expect(this.tip._toHtml('word')).toNotContain('<a');
});
});
describe("#_detectUrl", function() {
beforeEach(function() {
return this.tip = new Mychicken.Models.Tip();
});
it('should return false when a url is not present', function() {
return expect(this.tip._detectUrl('the')).toBe(false);
});
return it('should return true when a url is present', function() {
return expect(this.tip._detectUrl('http://www.mostlyharmlessdesign.co.uk')).toBe(true);
});
});
describe('#_detectHash', function() {
beforeEach(function() {
return this.Tip = new Mychicken.Models.Tip();
});
it('should return false if the word does not begin with the # symbol', function() {
return expect(this.Tip._detectHash('word')).toBe(false);
});
return it('should return true if the word begins with the # symbol', function() {
return expect(this.Tip._detectHash('#hashtag')).toBe(true);
});
});
return describe('#setContent', function() {
beforeEach(function() {
this.Tip = new Mychicken.Models.Tip();
return this.Tip.setContent('blah');
});
it('should set the content attribute', function() {
return expect(this.Tip.attributes.content).toNotBe(null);
});
return it('should set the html attribute', function() {
return expect(this.Tip.attributes.html).toNotBe(null);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment