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

Allow for keyword function mocking #393

Merged
merged 2 commits into from Jul 4, 2017

Conversation

philomates
Copy link
Collaborator

@philomates philomates commented Jun 20, 2017

Spent some more time looking at how provided handles mocks with nested expressions and realized that it isn't handling keyword functions (i.e (:a-num {:a-num 1})), as brought up in #389.

Currently when an expression is used as an argument in a provided statement, Midje does not evaluate that expression, but rather only mocks function calls with those that exact expression as an argument. For example:

(def my-inc inc)
(fact "Able to mock exact nested function invocations"
  (f (my-inc 1)) => 2
  (provided
    (f (my-inc 1)) => 2))

works, but if we do some partial evaluation in our test statement, the test fails:

(fact "Unable to handle partial evaluation of mocked functions"
  (f 2) => 2
  (provided
    (f (my-inc 1)) => 2))

This is a trade-off in test framework expressiveness that makes sense.

When we apply this to keyword functions, Midje fails here due to the fact that the fnref classification function doesn't handle keywords.
This prevents us from doing things like

(unfinished f)
(fact "Able to mock exact keyword accessor function invocations"
  (f (:fst {:fst 2})) => 2
  (provided
    (f (:fst {:fst 2})) => 2))

Addresses #362 and #281

@marick
Copy link
Owner

marick commented Jun 21, 2017

I originally had some notion of separating out data access (via keywords) from function calls. That was probably a bad idea; certainly it didn't get used.

https://github.com/marick/Midje/wiki/Data-Prerequisites

I don't have an opinion about how to handle keywords-as-functions.

@rafaeldff rafaeldff merged commit ce7dbc2 into marick:master Jul 4, 2017
@philomates philomates deleted the pm/keyword-mocking branch July 4, 2017 17:03
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

Successfully merging this pull request may close these issues.

None yet

3 participants