Skip to content

Instantly share code, notes, and snippets.

@Dakuan
Created April 9, 2013 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dakuan/5349851 to your computer and use it in GitHub Desktop.
Save Dakuan/5349851 to your computer and use it in GitHub Desktop.
Coffeescript jasmine spec
describe "Tip Model", ->
it "should exist", ->
expect(Mychicken.Models.Tip).toBeDefined()
describe "Attributes", ->
it 'should have attributes', ->
tip = new Mychicken.Models.Tip()
expect(tip.attributes.content).toBeDefined()
expect(tip.attributes.html).toBeDefined()
describe "#parseUrls", ->
beforeEach ->
this.tip = new Mychicken.Models.Tip()
spyOn(this.tip, '_render')
it 'should call render if there are any long urls', ->
this.tip.attributes.content = 'the quick brown http://www.google.com'
this.tip.parseUrls()
expect(this.tip._render).toHaveBeenCalled()
it 'should not call render if there are no long urls', ->
this.tip.attributes.content = "this quick brown"
this.tip.parseUrls()
expect(this.tip._render.calls.length).toEqual(0)
describe '#_toHtml', ->
beforeEach ->
this.tip = new Mychicken.Models.Tip()
it 'should contain a link if a hash tag is present', ->
expect(this.tip._toHtml('#word')).toContain('<a')
it 'should not contain a link if a hash tag is not present', ->
expect(this.tip._toHtml('word')).toNotContain('<a')
describe "#_detectUrl", ->
beforeEach ->
this.tip = new Mychicken.Models.Tip()
it 'should return false when a url is not present', ->
expect(this.tip._detectUrl('the')).toBe false
it 'should return true when a url is present', ->
expect(this.tip._detectUrl('http://www.mostlyharmlessdesign.co.uk')).toBe true
describe '#_detectHash', ->
beforeEach ->
this.Tip = new Mychicken.Models.Tip()
it 'should return false if the word does not begin with the # symbol', ->
expect(this.Tip._detectHash('word')).toBe false
it 'should return true if the word begins with the # symbol', ->
expect(this.Tip._detectHash('#hashtag')).toBe true
describe '#setContent', ->
beforeEach ->
this.Tip = new Mychicken.Models.Tip()
this.Tip.setContent('blah')
it 'should set the content attribute', ->
expect(this.Tip.attributes.content).toNotBe null
it 'should set the html attribute', ->
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