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

Implement assert_stripe_requested/3 #487

Merged

Conversation

maartenvanvliet
Copy link
Member

The assert_stripe_requested/3 function was not yet implemented.
To better test #480 (comment)
I implemented this function to test whether the request was actually called. This is done by sending a message to the current process and asserting whether it was received and has the right shape.

The a1147ee commit was the only one where I found a bug in the current code. All other fixes only concern the tests where the wrong thing was asserted because of a typo or another mistake.

In the case where two requests are made in a test, it is necessary to assert both requests. Otherwise the assert_stripe_requested/3 function might check the wrong request.

In a few cases the body, query_params or the request headers were also passed allong to assert_stripe_requested/3, these params are also asserted for being correct.

@coveralls
Copy link

coveralls commented May 4, 2019

Coverage Status

Coverage increased (+0.4%) to 85.56% when pulling 178f555 on maartenvanvliet:issues/add_request_assertions into 880e082 on code-corps:master.

assert expected_url == url

assert_stripe_request_body(expected_body, body)
assert_stripe_request_headers(expected_headers, headers)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

expected_body = Keyword.get(extra, :body)
expected_headers = Keyword.get(extra, :headers)

assert_received({method, url, headers, body, _})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean for these to be prefixed with expected_?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, they will pattern match to the received message. So url will contain the url the http client used. Right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh i figured these had to be variables in this function's scope. Not seeing 'method' in this scope for example.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They could've been pinned like assert_received({^expected_method, ^expected_url, headers, body, _}) as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah it is a macro that is expecting to pattern match the received message into those variables, correct? Now I understand.

@snewcomer snewcomer merged commit 7c54802 into beam-community:master May 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants