-
Notifications
You must be signed in to change notification settings - Fork 1
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
Same type for asserting occurrences of same value #25
Conversation
When you have an unknown value that needs to repeat in the expected assertion you don't have a lot of good options. You can let the result, and pull out as many values as you want to check but this quickly gets cumbersome, where the structure of actual needs to be declared twice, once to pull out the values to check and again in expected. In this case, we want to assert, that `<id1>` and `<id2> are the same across the actual value. We can do this with `=?/same` ``` (let [actual [{:id <id1> :ref [:field <id1>]} {:id <id2> :ref [:field <id1>]}] id1 (get-in actual [0 :id]) id2 (get-in actual [1 :id])] (is (=? [{:id id1 :ref [:field id1]} {:id id2 :ref [:field id2] actual))) (let [actual [{:id <id1> :ref [:field <id1>]} {:id <id2> :ref [:field <id1>]}]] (is (=? [{:id (=?/same :id1) :ref [:field (=?/same :id1)]} {:id (=?/same :id2) :ref [:field (=?/same :id2)]}] actual))) ```
this looks awesome! Only thought, what about throwing the label into motivating: approximately-equal-test=> (is (=? {:parent {:foo [(=?/same :a) (=?/same :a) (=?/same :b)]
:bar (=?/same :a)
:qux {:a {:b [[(=?/same :b)]]}}}}
{:parent {:foo [1 1 2]
:bar 1
:qux {:a {:b [[3]]}}}}))
FAIL in () (NO_SOURCE_FILE:46)
expected: {:parent {:foo [(same :a) (same :a) (same :b)], :bar (same :a), :qux {:a {:b [[(same :b)]]}}}}
actual: {:parent {:foo [1 1 2], :bar 1, :qux {:a {:b [[3]]}}}}
nil Here the |
@dpsutton
|
I'm not seeing any output when running the test: (deftest foo
(testing "foo"
(is (=? {:foo [(=?/same :a) (=?/same :a) (=?/same :b)]
:qux (=?/same :b)}
{:foo [1 1 2]
:qux 3})))) mb.hawk.assert-exprs.approximately-equal-test=> (binding [clojure.test/*test-out* *out*] (clojure.test/run-test foo))
Testing mb.hawk.assert-exprs.approximately-equal-test
FAIL in (foo) (approximately_equal_test.clj:193)
foo
expected: {:foo [(same :a) (same :a) (same :b)], :qux (same :b)}
actual: {:foo [1 1 2], :qux 3}
Ran 1 tests containing 1 assertions.
1 failures, 0 errors.
{:test 1, :pass 0, :fail 1, :error 0, :type :summary} |
update: need to install the humane-test-output for somereason. approximately-equal-test=> (require '[pjstadig.humane-test-output :as humane-test-output])
nil
approximately-equal-test=> (humane-test-output/activate!)
#object[clojure.lang.MultiFn 0x45a970a0 "clojure.lang.MultiFn@45a970a0"]
approximately-equal-test=> (clojure.test/run-test foo)
Testing mb.hawk.assert-exprs.approximately-equal-test
FAIL in (foo) (approximately_equal_test.clj:193)
foo
expected: {:foo [(same :a) (same :a) (same :b)], :qux (same :b)}
actual: {:foo [1 1 2], :qux 3}
diff: - {:qux (not= #_ (same :b) 2 3)}
Ran 1 tests containing 1 assertions.
1 failures, 0 errors.
{:test 1, :pass 0, :fail 1, :error 0, :type :summary} |
When you have an unknown value that needs to repeat in the expected assertion you don't have a lot of good options. You can let the result, and pull out as many values as you want to check but this quickly gets cumbersome, where the structure of actual needs to be declared twice, once to pull out the values to check and again in expected.
In this case, we want to assert, that
<id1>
and<id2>
are the same across the actual value. We can do this with=?/same