????erlang??????????????????ù??????鯔???????elixir????????????????л?????rspec????????????
???????elixir/mix????????????????????????????????????????erlang??elixir???????????????????????????????????????????????????
??????????rebar????
??????erlang??????????????д???????
rebar create-app appid=rebar_mix_test
==> rebar_mix_test (create-app)
Writing src/rebar_mix_test.app.src
Writing src/rebar_mix_test_app.erl
Writing src/rebar_mix_test_sup.erl
???????????????otp??????????????????????????????????????api??????
????mix_worker.erl ????????????add??double??????
-module(mix_worker).
-behaviour(gen_server).
%% API
-export([start_link/0]).
-export([add/2]).
-export([double/1]).
-record(state?? {}).
-define(SERVER?? MODULE).
-export([init/1?? handle_call/3?? handle_cast/2?? handle_info/2??
terminate/2?? code_change/3]).
start_link() ->
gen_server:start_link({local?? SERVER}?? MODULE?? []?? []).
add(A?? B) ->
gen_server:call(MODULE?? {add?? A?? B}).
double(A) ->
gen_server:call(MODULE?? {double?? A}).
init([]) ->
{ok?? #state{}}.
handle_call({add?? X?? Y}?? _From?? State) ->
{reply?? X+Y?? State};
handle_call({double?? X}?? _From?? State) ->
{reply?? X*2?? State};
handle_call(_Request?? _From?? State) ->
Reply = ok??
{reply?? Reply?? State}.
handle_cast(_Msg?? State) ->
{noreply?? State}.
handle_info(_Info?? State) ->
{noreply?? State}.
terminate(_Reason?? _State) ->
ok.
code_change(_OldVsn?? State?? _Extra) ->
{ok?? State}.
?????????????????????
????init([]) ->
????{ok?? { {one_for_one?? 5?? 10}?? [CHILD(mix_worker?? worker)]} }.
????????????
rebar compile
==> rebar_mix_test (compile)
Compiled src/rebar_mix_test_sup.erl
Compiled src/mix_worker.erl
erl -pa deps/*/ebin ebin/
zsh: no matches found: deps/*/ebin
erl -pa ebin/
Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Eshell V7.3  (abort with ^G)
1> application:start(rebar_mix_test).
ok
2> observer:start().
ok
3> mix_worker:add(3??3).
6
4> mix_worker:double(232).
464
5>
???????mix_worker???????eunit????д????????????????????????д?????
????test/mix_worker_tests.erl
????-module(mix_worker_tests).
????-compile([export_all]).
????-include_lib("eunit/include/eunit.hrl").
????add_test() ->
????3 = mix_worker:add(1??2)??
????ok.
??????в????
rebar eunit
==> rebar_mix_test (eunit)
Compiled test/mix_worker_tests.erl
mix_worker_tests: add_test (module 'mix_worker_tests')...*failed*
in function gen_server:call/2 (gen_server.erl?? line 204)
in call from mix_worker_tests:add_test/0 (test/mix_worker_tests.erl?? line 7)
**exit:{noproc??{gen_server??call??[mix_worker??{add??1??2}]}}
output:<<"">>
=======================================================
Failed: 1.  Skipped: 0.  Passed: 0.
ERROR: One or more eunit tests failed.
ERROR: eunit failed while processing /Users/zhuoyikang/source/services/rebar_mix_test: rebar_abort
?????????mix_worker???????????????????
??????????????????????rebar_mix_test??
????add_test() ->
????ok = application:start(rebar_mix_test)??
????3 = mix_worker:add(1??2)??
????ok = application:stop(rebar_mix_test)??
????ok.