# CHANGES ## Muack 1.0.0 -- ? Improvements: * The internal conflicting method names are now a bit more informative and unique thus less likely to have conflicts. * Fixed a bug where mock and stub with the same method were defined. Previously, it would raise an undefined method error upon verifying while we're removing injected method. Now it could properly undefine injected methods. * Fixed issues mocking private methods. Now it would not only work without a problem, but also preserve the privilege if the original method is a private method. Note that for now, protected methods are treated as public methods though. * Fixed a bug where user customized Satisfy could crash if it's located on a top-level. i.e. class names without ::. Incompatible changes: * Removed proxy method. From now on, if you do not pass a block to a mock, then it would assume it's a proxy. You can think of instead of make an empty block as a default, the original method is the default. That means, previously, mock without a block would always return nil, but now it instead means a proxy. * Introduced peek_args method. Sometimes I really need to peek the arguments of a method, or trying to provide a different argument based on the original argument. So peek_args is the way to do it. * Introduced peek_return method. By duality, we also introduce something we can peek the return value. Using this along with a custom block doesn't really make sense, but this is actually the previous proxy block. Previously, if a mock is a proxy, then the block doesn't really mean the implementation, but a modification to the original return. That is, the current peek_return. Originally the block is quite inconsistent as the semantics of the block would change depending on it is a proxy or not. So to proxy the to_s method and then reverse the result, you write: ``` ruby str = 'str' Muack::API.mock(str).to_s.peek_return{ |s| s.reverse } p str.to_s # => 'rts' ``` * Removed plain value argument in `returns`. From now on, we should always use the block form. Instead, the argument was changed to be an optional option for specifying if the underlying block should be instance executed or not. By default, the block is lexical scoped. If passing `:instance_exec => true` to `returns`, `peek_args`, and `peek_return`, then the block is instead instance scoped, passing to the instance's `instance_exec`. This way, we would be able to touch the inside of mocked object. Without passing `:instance_exec => true`, `to_i` would be called on the top-level object instead. By passing this argument, `to_i` would be called in the string. ``` ruby str = '123' Muack::API.mock(str).int.returns(:instance_exec => true){to_i} p str.int # => 123 ``` ## Muack 0.7.3 -- 2013-10-01 * Added `Muack::API.including(element)` for detecting if the underlying element is included in the passed argument. ## Muack 0.7.2 -- 2013-08-23 * Show correct Expected error for special satisfiers. Previously, it would incorrectly showing Unexpected error. However it's considered expected, it's simply the number of times is wrong. ## Muack 0.7.1 -- 2013-07-13 * Added `respond_to` argument matcher corresponding to RR's duck_type. * Added `|` and `&` for argument matcher union and intersection. See README.md ## Muack 0.7.0 -- 2013-06-27 ### Incompatible changes * Now instead of using mock_proxy, we use `proxy` as a modifier. That says mock_proxy and stub_proxy no longer existed. like this: ``` ruby mock(object).to_s.proxy stub(object).to_s.proxy ``` We change this due to the introduction of spies. ### Enhancement * We have spies support now. Here's an example: ``` ruby subject = Object.new stub(subject).foo(1) subject.foo(1) spy(subject).foo(1) spy(subject).bar # This doesn't verify immediately. Muack.verify # This fails, saying `bar` was never called. ``` * It would now raise a `StubHasNoTimes` exception if you tried to set times on stubs, which has no meanings in Muack. Use `mock` or `spy` instead if you need to specify times. * Muack.reset and Muack.verify is now thread-safe. You can run test cases concurrently now. * AnyInstanceOf now has a more readable inspect. * Improved various error messages. e.g. CannotFindInjectionName. * You can now set ENV['MUACK_RECURSION_LEVEL'] to raise the limit to find a new method name when we're injecting a method. Normally this should not happen, and it could be a bug in Muack. But instead of putting a magic number 9 out there as before, this might be better. ## Muack 0.5.2 -- 2013-06-26 * Add `returns` modifier which you can pass the return values if passing a block to a certain method is not convenient (e.g. `[]`). Instead of sending `method_missing` to pass a block: ``` ruby stub(object).method_missing(:[], is_a(Fixnum)){ |a| a+1 } object[1] #=> 2 ``` You could now use `returns` to pass the block. ``` ruby stub(object)[is_a(Fixnum)].returns{ |a| a + 1 } object[1] #=> 2 ``` Or if you only want to return a simple value, you could also pass the value directly without passing a block: ``` ruby stub(object)[is_a(Fixnum)].returns(2) object[1] #=> 2 ``` ## Muack 0.5.1 -- 2013-06-25 * Fix issues with multiple call to any_instance_of with the same class. * any_instance_of now accepts a block as mock and others. * Fixed various bugs for dispatching methods with proxy and any_instance_of. ## Muack 0.5.0 -- 2013-06-24 * Birthday!