slagyr / speclj

pronounced "speckle": a TDD/BDD framework for Clojure.
MIT License
458 stars 58 forks source link

NullPointerException using `should-invoke` when test ought to pass #165

Closed dknesek closed 3 years ago

dknesek commented 3 years ago

core_spec.clj

(ns unit-conversion-grading.core-spec
  (:require [speclj.core :refer :all]
            [unit-conversion-grading.core :refer :all]))

(describe "project setup"
  (it "should print 'Hello World!'"
    ((should-invoke println {:with ["Hello, world!"] :return [nil]}
                    (run [])))))

core.clj

(ns unit-conversion-grading.core)

(defn run [args]
  (println "Hello, world!"))

result

----- Sat Jan 02 11:36:10 CST 2021 -------------------------------------------------------------------
took 0.08222 to determine file statuses.
reloading files:
  /Users/doug/projects/unit-conversion-grading/spec/unit_conversion_grading/core_spec.clj

project setup
- should print 'Hello World!' (FAILED)

Failures:

  1) project setup should print 'Hello World!'

     java.lang.NullPointerException
        at unit_conversion_grading.core_spec$eval1463$fn__1464$fn__1469.invoke(core_spec.clj:7)
        ... 36 stack levels elided ...

When I force the test to fail with a different expected string, e.g., "foo", I get the expected test response

project setup
- should print 'Hello World!' (FAILED)

Failures:

  1) project setup should print 'Hello World!'
     Expected: invocation of println with ["foo"]
          got: (["Hello, world!"])
     /Users/doug/projects/unit-conversion-grading/spec/unit_conversion_grading/core_spec.clj:7

Here's my Java setup

java 11.0.1 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)

Here's project.clj

(defproject unit-conversion-grading "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :main unit-conversion-grading.core
  :dependencies [[org.clojure/clojure "1.8.0"]]
  :profiles {:dev {:dependencies [[speclj "3.3.2"]]}}
  :plugins [[speclj "3.3.2"]]
  :test-paths ["spec"])

Here's unit-conversion-grading.iml

<?xml version="1.0" encoding="UTF-8"?>
<module cursive.leiningen.project.LeiningenProjectsManager.displayName="unit-conversion-grading:0.1.0-SNAPSHOT" cursive.leiningen.project.LeiningenProjectsManager.isLeinModule="true" type="JAVA_MODULE" version="4">
  <component name="NewModuleRootManager">
    <output url="file://$MODULE_DIR$/target/classes" />
    <output-test url="file://$MODULE_DIR$/target/classes" />
    <exclude-output />
    <content url="file://$MODULE_DIR$">
      <sourceFolder url="file://$MODULE_DIR$/dev-resources" isTestSource="false" />
      <sourceFolder url="file://$MODULE_DIR$/resources" isTestSource="false" />
      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
      <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
      <excludeFolder url="file://$MODULE_DIR$/target" />
    </content>
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="library" name="Leiningen: clojure-complete:0.2.5" level="project" />
    <orderEntry type="library" name="Leiningen: fresh:1.1.2" level="project" />
    <orderEntry type="library" name="Leiningen: mmargs:1.2.0" level="project" />
    <orderEntry type="library" name="Leiningen: nrepl:0.6.0" level="project" />
    <orderEntry type="library" name="Leiningen: org.clojure/clojure:1.8.0" level="project" />
    <orderEntry type="library" name="Leiningen: speclj:3.3.2" level="project" />
    <orderEntry type="library" name="Leiningen: trptcolin/versioneer:0.1.1" level="project" />
  </component>
</module>
dknesek commented 3 years ago

I'm a dumbass. Extra pair of parens.