multiple mock
MeterSoft opened this issue · comments
i trying mock some function in my module. I have many functions but need mock only some. I thy this
with_mock(Api.PageParser, [
load_html: fn(url) -> PageParserMock.load_html(url) end,
load_user: fn(user_id, api_key) -> PageParserMock.load_user(user_id, api_key) end,
load_listings: fn(user_id, api_key) -> PageParserMock.load_listings(user_id, api_key) end
])
but when i run test it return
** (UndefinedFunctionError) function Api.PageParser.validate/1 is undefined or private. Did you mean one of:
* validate/1
when i try
with_mocks([
{Api.PageParser, [], [load_html: fn(url) -> PageParserMock.load_html(url) end]},
{Api.PageParser, [], [load_user: fn(user_id, api_key) -> PageParserMock.load_user(user_id, api_key) end]},
{Api.PageParser, [], [load_listings: fn(user_id, api_key) -> PageParserMock.load_listings(user_id, api_key) end]},
]) do
i got
** (UndefinedFunctionError) function Api.PageParser.validate/1 is undefined (module Api.PageParser is not available)
Why i have this behauver?
I think you need to add the passthrough option. There is an example in the
readme
…On Thu, Jun 21, 2018, 1:06 PM Semenets Bohdan ***@***.***> wrote:
i trying mock some function in my module. I have many functions but need
mock only some. I thy this
with_mock(AirbnbApi.PageParser, [
load_html: fn(url) -> PageParserMock.load_html(url) end,
load_user: fn(user_id, api_key) -> PageParserMock.load_user(user_id, api_key) end,
load_listings: fn(user_id, api_key) -> PageParserMock.load_listings(user_id, api_key) end
])
but when i run test it return
** (UndefinedFunctionError) function AirbnbApi.PageParser.validate/1 is undefined or private. Did you mean one of:
* validate/1
when i try
with_mocks([
{AirbnbApi.PageParser, [], [load_html: fn(url) -> PageParserMock.load_html(url) end]},
{AirbnbApi.PageParser, [], [load_user: fn(user_id, api_key) -> PageParserMock.load_user(user_id, api_key) end]},
{AirbnbApi.PageParser, [], [load_listings: fn(user_id, api_key) -> PageParserMock.load_listings(user_id, api_key) end]},
]) do
i got
** (UndefinedFunctionError) function AirbnbApi.PageParser.validate/1 is undefined (module AirbnbApi.PageParser is not available)
Why i have this behauver?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#84>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAWpXtjM3mKQKtBT0rVGS9xyYNmch3AIks5t-4w3gaJpZM4Ux79P>
.
passthrough option did not help me.
with_mock(Api.PageParser, [:passthrough], [
load_html: fn(url) -> PageParserMock.load_html(url) end,
load_user: fn(user_id, api_key) -> PageParserMock.load_user(user_id, api_key) end,
load_listings: fn(user_id, api_key) -> PageParserMock.load_listings(user_id, api_key) end
])
when i added :passthrough it start called another functions in load_html function.
load_html contain Http request and i need just stub load_html and return my response
@jjh42 Api.PageParser.validate(url) called outside this module. It called in controller
@MeterSoft Is there still an issue?
@Olshansk hi, yes i have the same issue on other place and project