Code Monkey home page Code Monkey logo

gen_server_mock's Introduction

gen_server_mock.erl - gen_server mocking

Summary

gen_server mocking. This project is functioning but still young.

Example

     {ok, Mock} = gen_server_mock:new(),

     gen_server_mock:expect_call(Mock, fun(one,  _From, _State)            -> ok end),
     gen_server_mock:expect_call(Mock, fun(two,  _From,  State)            -> {ok, State} end),
     gen_server_mock:expect_call(Mock, fun(three, _From,  State)           -> {ok, good, State} end),
     gen_server_mock:expect_call(Mock, fun({echo, Response}, _From, State) -> {ok, Response, State} end),
     gen_server_mock:expect_cast(Mock, fun(fish, State) -> {ok, State} end),
     gen_server_mock:expect_info(Mock, fun(cat,  State) -> {ok, State} end),
     
     ok = gen_server:call(Mock, one),
     ok = gen_server:call(Mock, two),
     good = gen_server:call(Mock, three),
     tree = gen_server:call(Mock, {echo, tree}),
     ok   = gen_server:cast(Mock, fish),
     Mock ! cat,
     
     gen_server_mock:assert_expectations(Mock),
     {ok}.

More Examples

See test/src/eunit_gen_server_mock.erl

Usage

Currently three expectations are supported: expect_call, expect_cast, expect_info.

The fun argument takes the same arguments as the respective handle_ gen_server call. However, unlike the handle_ calls, the response should be one of ok, {ok, NewState}, {ok, Response, NewState}. Anything else will be considered a failure.

For example:

  • expect_call(Mock, fun(Request, From, State) -> ok end)
  • expect_cast(Mock, fun(Msg, State) -> {ok, State} end)
  • expect_info(Mock, fun(Info, State) -> {error, State} end) (will raise an error, return {ok, State} for success)

Status

Alpha. API may change depending on feedback. Hosted on Github - patches readily accepted.

Dependencies

  • skelerl, if you want to run tests
  • tested with eunit, should work with other libraries in theory

Bugs / Problems

I suspect that one could write a more general process mocking library relatively easily.

References

Authors

  • Nate Murray <nmurray [AT] attinteractive.com> github

gen_server_mock's People

Contributors

jashmenn avatar auser avatar yannickg avatar

Watchers

 avatar James Cloos avatar

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.