gsmaverick / wren-test

A testing framework for Wren
MIT License
27 stars 2 forks source link

Add a basic Spy object #2

Closed gsmaverick closed 9 years ago

gsmaverick commented 9 years ago

We need to provide a basic object that can be used as a spy to ensure that methods are called/called with the correct arguments. Then we should write matchers to make assertions about Spy objects easier.

class Spy {
  new (name) {
    _name = name
   _calls = []
  }

  new (name, return_value) {
    _name = name
    _return_value = return_value
    _calls = []
  }

  calls { _calls }

  call {
    _calls.add([])
    return _return_value
  }

  call (one) {
    _calls.add([one])
    return _return_value
  }

  // up to 16 arguments...
}
gsmaverick commented 9 years ago

Delivered with https://github.com/gsmaverick/wren-test/commit/4576d96cd0bc6392ea1932dca32b30673a409de7