Class: MockMethod

MockMethod


new MockMethod()

Source:

Methods


and_function(returnFunction)

Set execution function when should_receive called.

Parameters:
Name Type Description
returnFunction function

execute function

Source:
Example
mock("obj").should_receive("something").and_function(function(){
	return "1";
});
// obj.something(1); => "1"
// obj.something(1, 2); => "1"

and_return(returnVal)

set return value when should_receive called.

Parameters:
Name Type Description
returnVal Object

return value

Source:
Example
mock("obj").should_receive("something").and_return("1");
// obj.something(1); => "1"
// obj.something(1, 2); => "1"

and_throw(returnException)

Set exception error when should_receive called.

Parameters:
Name Type Description
returnException String

exception message

Source:
Example
mock("obj").should_receive("something").and_throw("error");
// obj.something(1); => new Error("error")
// obj.something(1, 2); => new Error("error")

with_param(params)

set parameters of should_receive.
If you use with_param that and_xxx method execute matching param.

Parameters:
Name Type Argument Description
params anything <repeatable>

list up parameters.

Source:
Returns:
Type
MockMethod
Example
mock("obj").should_receive("something").with_param(1,2).and_return("1");
// obj.something(1); => not return anything
// obj.something(1, 2); => "1"

// You can use `mock.anything`.
mock("obj").should_receive("something").with_param(1,mock.anything()).and_return("1");
// obj.something(1, 1); => "1"
// obj.something(1, 2); => "1"
// obj.something(1, 3); => "1"