EzDevInfo.com

speclj

pronounced "speckle": a TDD/BDD framework for Clojure.

Is there a single command to run tests from both clojure.test and Speclj?

I have an already working application that has some tests written with clojure.test

I want to create some new tests to raise code coverage, but this time using Speclj since tests look nicer.

However, now in order to make sure all tests are passing, I need to run lein test to run tests from clojure.test and lein spec to run tests from speclj.

Is there a single command to run all the tests no matter the library I chose?


Source: (StackOverflow)

How to make a test pending

I am trying to make tests pending in clojure sepclj.

The doc suggest to add pending to the characteristics. How is it supposed to be added ?

The following approaches do not produce the expected behavior:

(it :pending "should ...")
(it "should ..." :pending)
(pending (it "should ..."))

Thanks


Source: (StackOverflow)

Advertisements

Reusing a stub/redef across a speclj context

I'm writing tests for a Clojure app using Speclj. I'm accustomed in BDD to do things like this:

context "some context"
  stub my-function :return true
  it "has behavior one"
    should true my-function
  it "has behavior two"
    should_not false my-function

But in Speclj I can't seem to find an example of how to share the stub across the characteristics, so I'm currently stuck writing code like this:

(describe "this"
  (context "that"
    (it "accepts nil"
      (with-redefs [called-fn (constantly nil)]
          (should= nil (my-fn nil)))))
    (it "accepts 1"
      (with-redefs [called-fn (constantly nil)]
          (should= 100 (my-fn 1))))))

(I realize this is a somewhat contrived example and arguably those assertions could all go under one characteristic, but let's suppose for now that I have good reason to write the code like this.)

I want, however, to just have to stub called-fn once, but moving this up out of the its raises errors because the real called-fn gets called instead of my redef.

Is there a way to reuse redefs (or use Speclj stubs) in Speclj so I'm not stuck pushing them all down inside the characteristics?


Source: (StackOverflow)

How to start the Speclj tutorial?

Inspired by this coding kata I'd like to try the Clojure language.

After installing lein on my Ubuntu box, I wanted to use speclj for testing, so I went to the official tutorial page, where I was told to simply execute lein new speclj change-counter to create my new project.

However, it seems to me that Leiningen thinks that my project name is "speclj" instead of "change-counter", so instead of having src/change-counter/core.clj I have src/speclj/core.clj.

What am I missing here? (~/.lein is empty.)


Source: (StackOverflow)

Clojure Speclj with-redefs and a stub from a different thread

I'm testing a function to make sure that it calls a function that's in another namespace. I'd like to stub the function out (using speclj stub), so I can record the invocations.

(defn fn-under-test []
  (p/helper-fn))

(describe "test"
  (with-stubs)
  (around [it]
    (with-redefs [p/helper-fn (stub :helper)]
      (it)))
  (it "should call the helper-fn"
    (fn-under-test)
    (should-have-invoked :helper {:times 1})))

I get an exception:

java.lang.Exception: Stub recoding not bound.  Please add (with-stubs) to the decribe/context.

If helper-fn is defined in the current namespace, everything works as expected. How can I stub a function in another namespace using speclj?

EDIT: The exception occurs when the stubbed function is called from a different thread. I created a pull request that fixes the issue.


Source: (StackOverflow)