Created
August 20, 2013 06:54
-
-
Save ritchiey/6277897 to your computer and use it in GitHub Desktop.
Good and bad solutions to a simple Jasmine spec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Picture | |
setHeight: (height) -> | |
@width = 400 | |
@height = 200 | |
setWidth: (width) -> | |
@height = 50 | |
@width = 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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