jjh42 / mock

Mocking library for Elixir language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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?

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