Skip to content

Commit

Permalink
Got rid of init
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattias Petter Johansson committed Feb 16, 2013
1 parent 349755e commit d6d525e
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 21 deletions.
27 changes: 15 additions & 12 deletions src/beautiful-lies.coffee
@@ -1,14 +1,12 @@
create_liar = (expectations) ->
host = {}
host.expect expectations
lies = {}
lies.plugins = require './plugins'

# Inject built-in plugins
create_liar.plugins = require './plugins'
expect = (expectations) ->

init = () ->
Object.prototype.expect = expect
if not expectations?
Object.prototype.expect = expect
return

expect = (expectations) ->
expectations = [ expectations ] if not Array.isArray expectations

for expectation in expectations
Expand All @@ -19,6 +17,12 @@ expect = (expectations) ->
this.__expectations.push e for e in expectations
this

lies.expect = expect

lies.init = () ->
expect()


preprocessExpectation = (expectation) ->
if not expectation.function_name?
throw new Error 'expectation must have property "function_name"'
Expand All @@ -28,9 +32,9 @@ preprocessExpectation = (expectation) ->

injectPlugins = (expectation) ->
for own key, value of expectation
if create_liar.plugins[key]
if lies.plugins[key]
delete expectation[key]
generated = create_liar.plugins[key](value)
generated = lies.plugins[key](value)
for own key, value of generated
expectation[key] = generated[key]

Expand Down Expand Up @@ -261,5 +265,4 @@ args_as_array = (arguments_obj) ->
return [] if not arguments_obj?
arg for arg in arguments_obj

module.exports.createLiar = create_liar
module.exports.init = init
module.exports = lies
2 changes: 1 addition & 1 deletion test/basic.coffee
Expand Up @@ -4,7 +4,7 @@ expect = chai.expect

lies = require '../src/beautiful-lies'

lies.init()
lies.expect()

describe 'expect (basic cases)', ->
liar = null
Expand Down
2 changes: 2 additions & 0 deletions test/call_validation.coffee
Expand Up @@ -4,6 +4,8 @@ expect = chai.expect

lies = require '../src/beautiful-lies'

lies.expect()

describe 'call validation', ->
sword = null
beforeEach ->
Expand Down
2 changes: 2 additions & 0 deletions test/callback_flow.coffee
Expand Up @@ -5,6 +5,8 @@ after = require('fluent-time').after

lies = require '../src/beautiful-lies'

lies.expect()

describe 'run_callback_flow', ->
liar = {}
beforeEach ->
Expand Down
2 changes: 1 addition & 1 deletion test/callback_ordered.coffee
Expand Up @@ -4,7 +4,7 @@ expect = chai.expect
after = require('fluent-time').after
lies = require '../src/beautiful-lies'

lies.init()
lies.expect()

# TODO: Add support for simultaneous calls of another (of) callback
# and the handler callback
Expand Down
5 changes: 4 additions & 1 deletion test/extender_syntax.coffee
Expand Up @@ -4,12 +4,15 @@ expect = chai.expect

lies = require '../src/beautiful-lies'

lies.expect()


# TODO change to addLie
describe 'Given that we call init()', ->
obj = null

beforeEach ->
lies.init()
lies.expect()
obj = {}

describe 'and call addLie on any object', ->
Expand Down
2 changes: 1 addition & 1 deletion test/misc.coffee
Expand Up @@ -4,7 +4,7 @@ expect = chai.expect

lies = require '../src/beautiful-lies'

lies.init()
lies.expect()

it 'Value should be implicit if on_value defined', (done) ->
liar = {}
Expand Down
2 changes: 1 addition & 1 deletion test/plugins.coffee
Expand Up @@ -5,7 +5,7 @@ expect = chai.expect

lies = require '../src/beautiful-lies'

lies.init()
lies.expect()

describe 'callback_result plugin', ->

Expand Down
8 changes: 4 additions & 4 deletions test/run.coffee
Expand Up @@ -3,8 +3,8 @@ should = chai.should()
expect = chai.expect
after = require('fluent-time').after
lies = require '../src/beautiful-lies'
lie = lies.lie
createLiar = lies.createLiar

lies.expect()

describe 'run function', ->

Expand All @@ -16,8 +16,8 @@ describe 'run function', ->
lastExecuted = null
runFunctionFunctionExecuted = false
callbackExecuted = false

bamseBear = createLiar
bamseBear = {}
bamseBear.expect
function_name: 'myFunction'
run_callback:
no_arguments: true
Expand Down

0 comments on commit d6d525e

Please sign in to comment.