Skip to content

Instantly share code, notes, and snippets.

@ritchiey
Created August 20, 2013 06:54
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 ritchiey/6277897 to your computer and use it in GitHub Desktop.
Save ritchiey/6277897 to your computer and use it in GitHub Desktop.
Good and bad solutions to a simple Jasmine spec
class Picture
setHeight: (height) ->
@width = 400
@height = 200
setWidth: (width) ->
@height = 50
@width = 100
describe "A picture", ->
beforeEach ->
@picture = new Picture(width: 200, height: 100)
describe "when its height is changed", ->
beforeEach -> @picture.setHeight 200
it "maintains its proportions", ->
expect(@picture.width).toEqual 400
expect(@picture.height).toEqual 200
describe "when its width is changed", ->
beforeEach -> @picture.setWidth 100
it "maintains its proportions", ->
expect(@picture.width).toEqual 100
expect(@picture.height).toEqual 50
class Picture
constructor: (options) ->
@width = options.width
@height = options.height
proportions: ->
@width / @height
setHeight: (height) ->
@width = height * @proportions()
@height = height
setWidth: (width) ->
@height = width / @proportions()
@width = width
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment