Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple mock #84

Open
MeterSoft opened this issue Jun 21, 2018 · 5 comments
Open

multiple mock #84

MeterSoft opened this issue Jun 21, 2018 · 5 comments

Comments

@MeterSoft
Copy link

MeterSoft commented Jun 21, 2018

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?

@jjh42
Copy link
Owner

jjh42 commented Jun 21, 2018 via email

@MeterSoft
Copy link
Author

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

@MeterSoft
Copy link
Author

@jjh42 Api.PageParser.validate(url) called outside this module. It called in controller

@Olshansk
Copy link
Collaborator

@MeterSoft Is there still an issue?

@MeterSoft
Copy link
Author

@Olshansk hi, yes i have the same issue on other place and project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants