さて、私はメックを使用していて、迷っています。私の最初の言語 (約 7 か月間書いてきた) は Ruby です。私はRubyのモックを取得します。誰かが私を助けてくれることを願っています。また、Erlang を書き始めて 1 週間しか経っていません。
更新されたコード (ただし、モックはまだ機能していません)...
次のようなErlang console_ioプロンプター モジュールがあります。
-module(prompter).
-export([prompt/1, guess/0]).
prompt(Message) ->
console_io:gets(Message).
gets() ->
{_, [Input]} = io:fread("Enter: ", "~s"),
Input.
guess() ->
Guess_Input = gets(),
Guess_List = convert_guess_to_list(Guess_Input).
convert_guess_to_list(Guess_Input) ->
re:split(Guess_Input, "", [{return, list}, trim]).
私のテストは次のようになります。
-module(prompter_test).
-include_lib("eunit/include/eunit.hrl").
guess_1_test() ->
meck:new(prompter),
meck:expect(prompter, gets, fun() -> "aaaa" end),
?assertEqual(prompter:guess(), ["a","a","a","a"]),
?assert(meck:validate(prompter)),
meck:unload(prompter).
私が得ているエラーはこれです:
Eshell V5.9.3.1 (abort with ^G)
1> prompter_test: guess_1_test (module 'prompter_test')...*failed*
in function prompter:guess/0
called as guess()
in call from prompter_test:guess_1_test/0 (test/prompter_test.erl, line 10)
in call from prompter_test:guess_1_test/0
**error:undef
テストで gets 関数をモック (スタブ?) して、gets が "aaaa" を返すようにし、get_guess() でアサートすると、["a", "a", "a", "a" に等しい必要があります。 ]。
どうすればいいですか?