Coder Social home page Coder Social logo

hoax's Introduction

GitHub tag Build Status Hex.pm

hoax

Yet another mocking library for Erlang.

Build

hoax requires rebar to build. To build hoax, go to the hoax directory and simply type:

rebar compile

To make sure hoax works on your platform, run the tests:

rebar eunit

Note that hoax's unit tests require Eunit >= 2.2.1 (OTP R14B04).

hoax's People

Contributors

mattvonvielen avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

hoax's Issues

Deprecate HOAX_FIXTURE macro

After "dogfooding" hoax for as long as I have, I've found lots of little problems with the HOAX_FIXTURE macro, the most important being its extreme departure from OTP convention in that it declares a top-level function and therefore must be invoked at module level.

Hoax should deprecate the use of this macro, and instead provide fixture creation functions. Usage would be similar to the following:

foo_module_fixture_test_() ->
    hoax:fixture(?MODULE).

Also, the following utility function seems like a good idea to facilitate mixing hoax tests with non-hoax tests without requiring a fixture:

foo_module_bar_function_something_test() ->
    hoax:test(fun() ->
        % test body - setup/expectations, assertions, etc
    end).

Add error message for "module already mocked"

Accidentally creating two mocks of the same module gives an unhelpful error experience.

Error:

XXX_test: YYY...*failed*
in function hoax_expect:assert_exported/2 (src/hoax_expect.erl, line 24)
in call from hoax:mock/2 (src/hoax.erl, line 23)
in call from XXX_test:YYY/0 (test/XXX_test.erl, line 23)
**error:{no_such_function_to_mock,{request,0}}

Example test:

test_with_two_mocks_of_same_module() ->
    mock(module1, [
            ?expect(function1,
                ?withArgs([arg1, arg2, arg3, arg4]),
                ?andReturn(function1_result))
        ]),
    mock(module1, [
            ?expect(function2,
                ?withArgs([arg5, arg6]),
                ?andReturn(function2_result))
        ]).

Missing vim formatting directives

As a contributor, I don't know how to correctly format source code as there are directives.

Possibly suggestion:
%% -- erlang-indent-level: 4;indent-tabs-mode: nil; fill-column: 92 --
%% ex: ts=4 sw=4 et tw=92

Happy to apply to all source and open a PR if you reply with a preferred format.

Unexpected Argument error feedback

It would be very helpful if the mocks (when raising an unexpected argument error) could also display what they are expecting for a particular function call.

Especially when dealing with complex records being passed, it can often be somewhat difficult to figure out what the mismatch is or what's causing it, requiring extra debugging to figure out what's out of alignment. Diffs would also be nice bonus feature.

Clarify API for mocks to raise exceptions

Currently the API is ?andThrow() or {throw, _} but the implementation uses erlang:error/1.

Change {throw, _} to use erlang:throw/1 and provide support for {error, _} and {exit, _} using erlang:error/1 and erlang:exit/1 respectively.

Handle zero-arity expectations correctly

Zero-arity expectations create two clauses, resulting in a warning to stderr.

output:<<":0: Warning: this clause cannot match because a previous clause at line 0 always matches
">>

More detailed error for "no such function to mock"

In this situation, there is already a module (somewhere) named 'test'. The error we get is this:

foo_test: bar_test_case...*failed*                                                                                                                                                                             
in function hoax_expect:assert_exported/2 (src/hoax_expect.erl, line 12)
in call from hoax:mock/2 (src/hoax.erl, line 24)
in call from foo_test:bar_test_case/0 (test/foo_test.erl, line 135)
**error:{no_such_function_to_mock,{test_api,1}}

A better error might be:

**error:{no_such_function_to_mock,"test:test_api/1", "/source/path/from/metadata/for/test.erl_or_beam"}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.