Skip to content

Instantly share code, notes, and snippets.

View yangchenyun's full-sized avatar

Steven Yang yangchenyun

View GitHub Profile
@yangchenyun
yangchenyun / .osx
Created November 4, 2011 17:12 — forked from paulstefanort/.osx
Mac OS X Lion Modifications
# Originally from https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Enable the 2D Dock
defaults write com.apple.dock no-glass -bool true
# Disable menu bar transparency
defaults write -g AppleEnableMenuBarTransparency -bool false
# Expand save panel by default
defaults write -g NSNavPanelExpandedStateForSaveMode -bool true
@yangchenyun
yangchenyun / pygments.gist.css
Created November 10, 2011 11:43
Pygments syntax highlighter stylesheet
.gist-syntax { background: #ffffff; }
.gist-syntax .c { color: #999988; font-style: italic } /* Comment */
.gist-syntax .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.gist-syntax .k { color: #000000; font-weight: bold } /* Keyword */
.gist-syntax .o { color: #000000; font-weight: bold } /* Operator */
.gist-syntax .cm { color: #999988; font-style: italic } /* Comment.Multiline */
.gist-syntax .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
.gist-syntax .c1 { color: #999988; font-style: italic } /* Comment.Single */
.gist-syntax .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
.gist-syntax .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
@yangchenyun
yangchenyun / twilight_pygments.css
Created November 10, 2011 11:44 — forked from dansimpson/twilight_pygments.css
Pygments stylesheet based on Textmates's Twilight theme
pre.code { background: #181818; padding: 16px; color: #F8F8F8; font-family: Consolas, Monaco,"Lucida Console"; }
pre.code * { font-family: Consolas, Monaco,"Lucida Console"; }
pre.code .hll { background-color: #ffffcc }
pre.code .c { color: #5F5A60; font-style: italic } /* Comment */
pre.code .err { border:#B22518; } /* Error */
pre.code .k { color: #CDA869 } /* Keyword */
pre.code .cm { color: #5F5A60; font-style: italic } /* Comment.Multiline */
pre.code .cp { color: #5F5A60 } /* Comment.Preproc */
pre.code .c1 { color: #5F5A60; font-style: italic } /* Comment.Single */
pre.code .cs { color: #5F5A60; font-style: italic } /* Comment.Special */
GEM
remote: http://ruby.taobao.org/
specs:
activesupport (3.2.3)
i18n (~> 0.6)
multi_json (~> 1.0)
addressable (2.2.7)
chunky_png (1.2.5)
coffee-script (2.2.0)
coffee-script-source
@yangchenyun
yangchenyun / sample.coffee
Created July 29, 2012 14:15
sample calculator method
calculator = (method, numbers...) ->
switch method
when 'multiple' then @multiple(numbers)
when 'addition' then @addition(numbers)
when 'minus' then @minus(numbers)
when 'divide' then @divide(numbers)
else
throw new Error "method doesn't exist"
multiple = (numbers) ->
@yangchenyun
yangchenyun / spy-test.coffee
Created July 29, 2012 15:41
use spy to test calculator
describe "calculator", ->
it "should throw an error if no method is matched", ->
calculatorSpy = sinon.spy sample, 'calculator'
try
sample.calculator('non-exist-method', 1, 2)
catch e
sinon.assert.threw(calculatorSpy)
@yangchenyun
yangchenyun / spy-test.coffee
Created July 29, 2012 15:46
more detailed spy
it "should call the given method when parameter is valid", ->
multipleSpy = sinon.spy sample, 'multiple'
sample.calculator('multiple', 1, 2)
sinon.assert.calledOnce(multipleSpy)
sinon.assert.calledWithExactly(multipleSpy, [1, 2])
@yangchenyun
yangchenyun / spy-test.coffee
Created July 29, 2012 15:53
final calculator tests with stub
sample = require('../sample')
assert = require('assert')
sinon = require('sinon')
describe "calculator", ->
before ->
@calculator = sinon.spy sample, 'calculator'
@multiple = sinon.spy sample, 'multiple'
@addition = sinon.spy sample, 'addition'
@minus = sinon.spy sample, 'minus'
@yangchenyun
yangchenyun / spy-test.coffee
Created July 29, 2012 16:03
failed spy work
it "should call the given method when parameter is valid", ->
sample.calculator('minus', 1)
sinon.assert.calledOnce(@[method])
describe "calculator", ->
it "should call the given method when parameter is valid", ->
# stub the method instead of just 'spying' it
minusStub = sinon.stub sample, 'minus'
methods = ['multiple', 'addition', 'minus', 'divide']
sample.calculator('minus', 1)
sinon.assert.calledOnce(minusStub)
sinon.assert.calledWithExactly(minusStub, [1])