Module com.adobe.test.framework.Mocka

Functions

spy (class, method, fn) Spy utility method that creates a spy.
require (path)
beforeEach (fn)
xtest (description, ...)
test (description, fn, assertFail)
mock (class, model)
when (mockClass)
calls (method, times, ...)

Fields

default_mocks should be here because of using global mocka definitions

Local Functions

_makeFunction (name, classToMock)
getCurrentRunInfo () Retrieves current run information
_clone (t) Makes a shallow copy
_makeDoReturnFunction (class)
valToString (v) Converts a table to a string


Functions

spy (class, method, fn)
Spy utility method that creates a spy. Also returns the spy object when available

Parameters:

  • class - the path as passed to require
  • method - the method for stub
  • fn - the callback to execute - the actual stub
require (path)

Parameters:

  • path {string} - path to require Alters the real require to server either mock or real lua file - has same signature like lua require we force the reload of the package due to the beforeEach and the nature of mocking which gives us the possibility to make a function do something else for each test
beforeEach (fn)

Parameters:

  • fn {function} - the function to be ran beforeEach Test Saves the function in a variable in order to call it before each test for a suite
xtest (description, ...)

Parameters:

  • description {string}
  • ... {optional} This method is used to ignore a test and records that a test has been ignored for the final report
test (description, fn, assertFail)

Parameters:

  • description {string} - description of the test
  • fn {function} - actual function that describes the test (logic of the test)
  • assertFail {boolean} - specifing that I expect this test to fail - usually used for methods that throw errors This is the method used to specify to the framework that we want to run a test. Resets the mocks to the original state - no calls no return no latestCall, executes the beforeEach function if any than runs the test logic and counts if the test has failed or succeeded + duration.
mock (class, model)

Parameters:

  • class {string} name of the path to mock - this is the actual string that you give to require
  • model {array} - an array of strings specifying which are the methods that we want to mock This function creates a mock class with the functions you provide in the model. Each of the functions have an internal representation like so: doSomething is mapped to __doSomething. By default a function does not do anything it just records the calls and the latest call arguments. The internal representation contain info about the number of calls the real name of the function, latestCallArguments and has a doReturn function. The doReturn function is normally used if you want a mocked function to do something. Example: local classToMock = mock("class", {"doSomething"}) classToMock.__doSomething.doReturn = function() return 23 end
when (mockClass)

Parameters:

  • mockClass - the mock object Public function that decorates mock objects with the call that is needed
calls (method, times, ...)

Parameters:

  • method {function} - the actual internal representation class.__internalMethod
  • times {number} - the number of times a function was invoked
  • ... {array} [optional] - array of arguments. There is a numbering problem always start with the second argument, for example if we call a function with a, b, c than the arguments would be b, c, a (always the first argument becomes last. This method verifies that a method has been called a number of times with some arguments if present

Fields

default_mocks
should be here because of using global mocka definitions

Local Functions

_makeFunction (name, classToMock)

Parameters:

  • name {string} - name of the function that we want to make
  • classToMock {string} - name of the class we are making the function for Internal function - not to be used. This function creates a function with all the needed internals: calls, latestCallWith it also creates a real new function if specified. On call the function increments it's internals (calls) and saves the latestCallWithArguments. Also if present and a doReturn has been declared by a user than that function will be called with those parameters.
getCurrentRunInfo ()
Retrieves current run information

Returns:

    {currentSuiteNumber, currentSuiteInfo, currentTestNumber, currentTestInfo}
_clone (t)
Makes a shallow copy

Parameters:

  • t object - the object to clone
_makeDoReturnFunction (class)

Parameters:

  • class - full fledged class as you see it in the require Public function used only in before each - to spy on an object - (stub the replacement)
valToString (v)
Converts a table to a string

Parameters:

  • v table
generated by LDoc 1.4.6 Last updated 2018-07-04 06:57:58