Skip to content

Comments

Fix order in test assertions#21

Open
juxtin wants to merge 1 commit intoweavejester:masterfrom
juxtin:fix-test-assertions
Open

Fix order in test assertions#21
juxtin wants to merge 1 commit intoweavejester:masterfrom
juxtin:fix-test-assertions

Conversation

@juxtin
Copy link

@juxtin juxtin commented Jan 31, 2016

The convention for clojure.test is (is (= expected actual)), which is the reverse of what the template uses in handler_test.clj. This commit switches the arguments to = so that failures will be reported correctly.

The convention for clojure.test is `(is (= expected actual))`, which is
the reverse of what the template uses in handler_test.clj. This commit
switches the arguments to `=` so that failures will be reported correctly.
@weavejester
Copy link
Owner

The convention for clojure.test is (is (= expected actual))

Could you provide a source for that?

@juxtin
Copy link
Author

juxtin commented Jan 31, 2016

@weavejester sure thing, the clojure.test API reference has a bunch of examples. I also noticed this when I wrote a failing test and saw that "actual" and "expected" were backwards in the output.

@weavejester
Copy link
Owner

I don't see anything in the API reference. The example it gives would work either way around.

user> (is (= 5 (+ 2 2)))

FAIL in  (:1)
expected: (= 5 (+ 2 2))
  actual: (not (= 5 4))

@juxtin
Copy link
Author

juxtin commented Jan 31, 2016

Yeah, perhaps the docs aren't as explicit on this as I thought. But if you look at examples like this one:

(testing "Arithmetic"
  (testing "with positive integers"
    (is (= 4 (+ 2 2)))
    (is (= 7 (+ 3 4))))
  (testing "with negative integers"
    (is (= -4 (+ -2 -2)))
    (is (= -1 (+ 3 -4)))))

They consistently put the expression with the function call second, and the expected return value first.

@weavejester
Copy link
Owner

Sure, but that doesn't mean that the library favours one way over the other, just that the examples just happen to be written like that.

@juxtin
Copy link
Author

juxtin commented Jan 31, 2016

You're right, it turns out that humane-test-output was responsible for making the output look actually wrong when the reverse order is used. With that installed, I get:

user=> (is (= 5 (+ 2 2)))

expected: 5
  actual: 4
    diff: - 5
          + 4

That won't be an issue for many people, but I do think that following the convention is for the best. If it helps, this is also the way that Clojure's own tests are written (see example).

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.

2 participants