Clojure protocols are a great way to encapsulate operations with side
effects, but suffer from a lack of general test tooling. Shrubbery provides
a small set of basic building blocks for working with them.
New in this release:
– A throws function, which returns an object suitable for use with
On Tue, Oct 6, 2015 at 6:16 AM, Atamert Ölçgen wrote:
> It would be great if multiple return values for multiple calls were
> supported. First use case it something like an iteration, calling some
> protocol method repeatedly (possibly with different inputs). Another use
> case
This is awesome!
I might have more useful feedback (and PRs) in the future, because I can
see myself using this extensively.
It would be great if multiple return values for multiple calls were
supported. First use case it something like an iteration, calling some
protocol method repeatedly
Great to hear! Let me know if there are any questions I can answer.
Feedback gratefully accepted.
Cheers,
Brian
On Mon, Oct 5, 2015 at 11:56 AM, James Reeves wrote:
> Very nice. I was looking for something like this.
>
> - James
>
> On 5 October 2015 at 15:14, Brian
Clojure protocols are a great way to encapsulate operations with side
effects, but suffer from a lack of general test tooling. Shrubbery provides
a small set of basic building blocks for working with them:
* stub, which accepts a variable list of protocols and a optional hashmap
of simple value
Very nice. I was looking for something like this.
- James
On 5 October 2015 at 15:14, Brian Guthrie wrote:
> Clojure protocols are a great way to encapsulate operations with side
> effects, but suffer from a lack of general test tooling. Shrubbery provides
> a small set of
This looks neat Brian!
People who find this useful may also like a similar lib I wrote that provides
mocking tools at a single function level: https://github.com/glenjamin/q
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send
Clojure protocols are a great way to encapsulate operations with side
effects, but suffer from a lack of general test tooling. Shrubbery provides
a small set of basic building blocks for working with them:
* stub, which accepts a protocol and a hashmap of functions and returns an
implementation
On Wednesday, January 7, 2015 at 2:49:50 PM UTC-6, Sean Corfield wrote:
On Jan 7, 2015, at 10:21 AM, Allen Rohner aro...@gmail.com javascript:
wrote:
As a design rule, I prefer making I/O fns (things that hit the DB or a
REST API), 'dumb', and perform all logic/processing in fns that
On Jan 7, 2015, at 10:21 AM, Allen Rohner aroh...@gmail.com wrote:
As a design rule, I prefer making I/O fns (things that hit the DB or a REST
API), 'dumb', and perform all logic/processing in fns that just receive plain
data, and return plain data.
I’m curious: do you have wrapper functions
On Wednesday, December 31, 2014 8:48:27 AM UTC-6, Jonathon McKitrick wrote:
I use TDD and mocking/stubbing (conjure) to test each layer of my code.
The problem is when I change the function signature and the tests do not
break, because the mocks/stubs do not know when their argument lists
On Sat, Jan 3, 2015, at 02:46 AM, Brian Marick wrote:
I use TDD and mocking/stubbing (conjure) to test each layer of my code.
The problem is when I change the function signature and the tests do not
break, because the mocks/stubs do not know when their argument lists no
longer agree
I don't think there is an easy answer here, and note that this is a problem
generic to mocking (i.e. not clojure or midje specific).
The usual advice applies though:
- do you really need to mock? Unit testing is about the coarseness of
granularity which is defined more by cohesion
AM, Brian Marick wrote:
I use TDD and mocking/stubbing (conjure) to test each layer of my code.
The problem is when I change the function signature and the tests do
not
break, because the mocks/stubs do not know when their argument lists no
longer agree with the underlying function
as contract tests.
Here's a diagram of the problem:
login - check-pw
I've found that most code that uses mocking will test the login and the
check-pw bits, but completely neglect testing the arrow between them, and
when that happens, you get exactly the experience you described.
The other
a
test that pairs a login form with a check-pw and runs tests against this
system.
Some people call these tests integration tests or system tests. But I
think of them as contract tests.
Here's a diagram of the problem:
login - check-pw
I've found that most code that uses mocking will test
Thank you for all the responses! To be honest, I hoped that someone
would explain why this mocking style is a good thing, and I just
misunderstand something about the top-down development that the Midje
wiki suggests:
https://github.com/marick/Midje/wiki/The-idea-behind-top-down-development
Akos Gyimesi wrote:
Now, later that day I decide that I pass the whole user object to the
check-pw function. Maybe I want to use the user ID as a salt, or maybe I
just want to leave the possibility for checking password expiration,
etc. So I modify the test and the implementation of check-pw so
the mocking features for unfinished code
(they are indeed convenient in Midje), but remove them immediately after
the lower-level components are implemented.
I believe some people do that. I don't. The main reason is that doing so
will very often require spending time setting up data. My coding
...@exampler.com
javascript: wrote:
Timothy Baldridge wrote:
I don't recommend Midje at all. Many of the framework's mocking
facilities (such as providing) are abominations.
Hacker News notwithstanding, idiosyncratic interface is not a synonym
for abomination.
It may look cute
Agreed, Timothy - obviously the mental model gets more tangled when
state mocking comes into play, but the fact is, sometimes you don't have
the option (right away) of rewriting the code you're testing.
Midje has been great for the Cascalog community:
http://www.samritchie.io/testing-cascalog
more tangled when state
mocking comes into play, but the fact is, sometimes you don't have the
option (right away) of rewriting the code you're testing.
Midje has been great for the Cascalog community:
http://www.samritchie.io/testing-cascalog-with-midje/
http://www.samritchie.io/cascalog
running
clojure.test tests, making it easy to migrate when you get tired of
writing your own functions to compare expected to actual results in
different ways.
It's also reasonable to simply not use the mocking parts of Midje (or
other frameworks). Then you'll have clojure.test with a syntax you may
what's
going to happen, so let me go check every test that calls foo, or calls
something that calls foo to make sure it isn't overriding baz somehow.
Here I have to disagree. Technically, I think the description is wrong,
but the bit about mental model is more important. Midje's mocking
behavior
the factors I mentioned above (# of
years using Clojure, # of years using Midje, do they still use it, etc).
Timothy
On Fri, Jan 2, 2015 at 6:55 PM, Brian Marick mar...@exampler.com wrote:
Timothy Baldridge wrote:
I don't recommend Midje at all. Many of the framework's mocking
facilities
I use TDD and mocking/stubbing (conjure) to test each layer of my code.
The problem is when I change the function signature and the tests do not
break, because the mocks/stubs do not know when their argument lists no
longer agree with the underlying function they are mocking. Is there a
way
Timothy Baldridge wrote:
I don't recommend Midje at all. Many of the framework's mocking
facilities (such as providing) are abominations.
Hacker News notwithstanding, idiosyncratic interface is not a synonym
for abomination.
It may look cute,
but I've lost countless hours to bugs
I use TDD and mocking/stubbing (conjure) to test each layer of my code.
The problem is when I change the function signature and the tests do not
break, because the mocks/stubs do not know when their argument lists no
longer agree with the underlying function they are mocking. Is there a way
:48 AM, Jonathon McKitrick jmckitr...@gmail.com wrote:
I use TDD and mocking/stubbing (conjure) to test each layer of my code. The
problem is when I change the function signature and the tests do not break,
because the mocks/stubs do not know when their argument lists no longer agree
mocking facilities
(such as providing) are abominations. You shouldn't go around mucking with
functions and re-deffing them on the fly. It may look cute, but I've lost
countless hours to bugs and unexpected behavior related to Midje. IMO, stay
clear of that.
The pattern I do recommend is to break
On Dec 31, 2014, at 8:24 AM, Timothy Baldridge tbaldri...@gmail.com wrote:
This is one of the main reasons why I try to stay clear of heavy use of
invasive mocks. I can't tell you the amount of times I've looked at code and
realized that because of mocks nothing was really being tested at
The easiest way would be to wrap the class constructor in a function and
override that.
- James
On 15 December 2014 at 04:20, Eunmin Kim telepopso...@gmail.com wrote:
Hi! My question is, How can I exchange a java class for test like
`with-redefs`?
(defn run-a
[]
(... some logic
Hi! My question is, How can I exchange a java class for test like
`with-redefs`?
(defn run-a
[]
(... some logic
(.run (AClass. )))
(deftest some-test
(with-redefs [AClass MockAClass] ;; ???
(is (run-a)))
--
You received this message because you are subscribed to the Google
... and could
also fallback to using with-redefs.
if it integrates well with core.contracts, test.generative etc.
then its perfectly ok to use.
thank you have successful time
On Tuesday, November 27, 2012 9:22:29 AM UTC+1, Alex Baranosky wrote:
Conjure is a lightweight mocking library intended
, test.generative etc.
then its perfectly ok to use.
thank you have successful time
On Tuesday, November 27, 2012 9:22:29 AM UTC+1, Alex Baranosky wrote:
Conjure is a lightweight mocking library intended to be used on top of
clojure.test.
We've been using it at Runa for a long time
On Tuesday, November 27, 2012 3:22:29 AM UTC-5, Alex Baranosky wrote:
Conjure is a lightweight mocking library intended to be used on top of
clojure.test.
We've been using it at Runa for a long time, and it is compatible with all
versions of Clojure from 1.2 to 1.5-beta1.
https
Conjure is a lightweight mocking library intended to be used on top of
clojure.test.
We've been using it at Runa for a long time, and it is compatible with all
versions of Clojure from 1.2 to 1.5-beta1.
https://github.com/amitrathore/conjure
Alex
--
You received this message because you
On Thu, Sep 15, 2011 at 6:42 AM, Chris Perkins chrisperkin...@gmail.comwrote:
On Wednesday, September 14, 2011 11:19:13 AM UTC-4, Brian Hurt wrote:
Say I have two name spaces, A and B, with A depending on B. I want to
test namespace A, replacing module B with a mock B for testing purposes-
On Friday, September 16, 2011 3:12:49 PM UTC-4, Brian Hurt wrote:
How *should* I structure this code for testing? I was assuming the natural
way to do this is to make A, B, and C separate name spaces but maybe this is
wrong.
The best way to make these namespaces testable, in my opinion,
assurance it still works. So load it up into a
repl and play with it isn't a viable solution.
Or is clojure code just not testable/maintainable?
Brian
I don't have a detailed answer because I haven't done much mocking myself,
but I'm confident that it's possible. The reason for my
* the code- I need to be able to change
this code later, and have some assurance it still works. So load it up
into a repl and play with it isn't a viable solution.
Or is clojure code just not testable/maintainable?
Brian
I don't have a detailed answer because I haven't done much mocking
On Fri, Sep 16, 2011 at 4:01 PM, Stuart Sierra
the.stuart.sie...@gmail.comwrote:
On Friday, September 16, 2011 3:12:49 PM UTC-4, Brian Hurt wrote:
How *should* I structure this code for testing? I was assuming the
natural way to do this is to make A, B, and C separate name spaces but maybe
Brian Marick wrote Midje to support Clojure testing with a lot of mocking.
May be worth a try: https://github.com/marick/Midje
-S
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note
On Wednesday, September 14, 2011 11:19:13 AM UTC-4, Brian Hurt wrote:
Say I have two name spaces, A and B, with A depending on B. I want to test
namespace A, replacing module B with a mock B for testing purposes-
preferably without having to load B at all (B sucks in a bunch of stuff,
Say I have two name spaces, A and B, with A depending on B. I want to test
namespace A, replacing module B with a mock B for testing purposes-
preferably without having to load B at all (B sucks in a bunch of stuff,
like dependencies on databases and external web sites and etc. that I don't
want
You could call the mock file B_mock.clj
then
(require '[B-mock :as B])
Jonathan
On Wed, Sep 14, 2011 at 5:19 PM, Brian Hurt bhur...@gmail.com wrote:
Say I have two name spaces, A and B, with A depending on B. I want to test
namespace A, replacing module B with a mock B for testing purposes-
You can't easily prevent the loading of B unless it's in a separate
directory that isn't part of your classpath during testing.
You could define B-mock to load B and then redefine all the symbols.
-S
--
You received this message because you are subscribed to the Google
Groups Clojure group.
Hi, I'm currently working on my first real Clojure project, and I find
myself wanting a mocking tool. So I was wondering what you are using?
I tried googling, but I can't seem to find the Mockito of the clojure
world. Searching for a mocking tool in Clojure it looks like there is
a lot of small
Hi Erik,
Take a closer look at Midje, especially
https://github.com/marick/Midje/wiki/Metaconstants
I'm not an subject matter expert but to me it's close enough to
mocking/stubbing.
Cheers,
Ola
Erik Bakstad skrev 2011-06-28 08:56:
Hi, I'm currently working on my first real Clojure
not an subject matter expert but to me it's close enough to
mocking/stubbing.
Cheers,
Ola
Erik Bakstad skrev 2011-06-28 08:56:
Hi, I'm currently working on my first real Clojure project, and I find
myself wanting a mocking tool. So I was wondering what you are using?
I tried googling, but I can't seem
to
mocking/stubbing.
Cheers,
Ola
Erik Bakstad skrev 2011-06-28 08:56:
Hi, I'm currently working on my first real Clojure project, and I find
myself wanting a mocking tool. So I was wondering what you are using?
I tried googling, but I can't seem to find the Mockito of the clojure
On Jun 28, 2011, at 7:23 AM, László Török wrote:
...and a classic (not clojure specific)
http://codebetter.com/gregyoung/2008/02/13/mocks-are-a-code-smell/
One thing I'm trying to emphasize with Midje is that mocking in the context of
a functional language is (can be) about the logical
Hi,
maybe a different approach could be to use a richer datatype than a function,
which carries both: the command and the undo command.
(deftype Command [action undo])
Then you could do something like:
(defn do-patch!
[command args]
(dosync
(let [patch {:command command :args (vec
I think I misunderstand the issue, because this works for me:
(ns midje.util.git
(:use [midje.sweet]))
;; Code except for undo-patch is the same as before.
;; ...
;; I pulled remove-patch out of undo-patch because I was
;; getting a screwy read error I didn't want to figure out
;; at 5 in
I'd like to discuss this design approach. (It's unrelated to the
testing issue.) I avoided this design because the undo-fn is
determined at do-patch! time. The use case is for a persistent system
like Git where patches may be undone long after being done - e.g. long
after the patch is written
The issue is where do I specify that:
(undo-fn ...patch...) = (fn [] (reset! visible-evidence-of-a-side-
effect :happened!))
undo-fn is a multimethod in my design, which requires a corresponding
defmethod for each patch type. I need to create one for the scope of
the test, but defmethod by
On Dec 22, 2010, at 6:52 AM, Alyssa Kwan wrote:
The issue is where do I specify that:
(undo-fn ...patch...) = (fn [] (reset! visible-evidence-of-a-side-
effect :happened!))
The code you quoted is that specification. It doesn't matter that undo-fn is a
multimethod.
Here's what the notation
Thanks, Brian! I obviously didn't understand the nature of the
provided form. That's really cool notation! This is exactly what I
want.
What are the cons of using midje? Any reason I shouldn't migrate all
my unit testing to it?
Thanks!
Alyssa
On Dec 22, 9:46 am, Brian Marick
I love Midje and think migrating all the tests to it is a great idea.
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with
What are the cons of using midje? Any reason I shouldn't migrate all
my unit testing to it?
I'm biased, but I think Midje is ready for production use. There's a smooth
migration path because Midje uses the same reporting as clojure.test, so you
can mix styles in the same file and still use
Hi everyone,
Does anyone have any experience in mocking multimethods? I'm working
on a version control framework modeled after Git:
(def
^{:private true}
patches- (ref [])
(defn patches []
(seq @patches-))
(defn do-patch! [fn args]
(dosync
(apply fn args)
(let [patch {:fn fn
Hi Alyssa,
Using the midje library I was able to do your first test. I'm pretty tired
so I this might be it for the night.
(fact throws an error if can't resolve undo function
(undo-patch [2]) = (throws IllegalArgumentException No method in
multimethod 'undo-fn' for dispatch value: null))
Is
So I lied, I couldn't resist doing just one more:
(defn some-fn [] nil)
(fact calls the anonymous function that undo-fn returns
(undo-patch ...patch...) = @patches-
(provided
(undo-fn ...patch...) = some-fn
(some-fn) = nil))
The two provided statements are mboth mocking and stubbing
A better solution that looks like it works is this: load the mock module
second. Say I have a module I want to mock:
(ns tomock)
(defn foo [] 4)
and a module that requires it:
(ns totest
(:require tomock))
(defn bar [] (tomock/foo))
So if I create the file mock_tomock.clj which contains:
What I'd like to do is mock a full name-space for the purpose of testing
other functions that use or require the original name-space. Do people have
ideas or best practices for how I can do this?
The problem comes in that I very much prefer doing my uses/requires in the
name space declaration.
Brian,
I don't blame you -- I wouldn't want to put conditional requires in my
code either. Did you consider putting your mock code in a different
classpath?
Here is another idea. It's tempting to suggest that you write your
own version of ns that mucks with its arguments and then passes the
Id recommend using mockito instead:
http://mockito.org/
On Nov 12, 1:55 am, Howard Lewis Ship hls...@gmail.com wrote:
Try looking at this:
http://github.com/hlship/cascade/blob/master/src/main/clojure/cascade...
On Thu, Nov 5, 2009 at 5:00 AM, vanallan vanal...@gmail.com wrote:
Hi
Im
Try looking at this:
http://github.com/hlship/cascade/blob/master/src/main/clojure/cascade/mock.clj
On Thu, Nov 5, 2009 at 5:00 AM, vanallan vanal...@gmail.com wrote:
Hi
Im trying to convert a couple of Java methods in a Java project to
Clojure. The Java methods have test methods that mocks
On Mon, Sep 28, 2009 at 9:20 AM, Laurent PETIT laurent.pe...@gmail.comwrote:
2009/9/28 C. Florian Ebeling florian.ebel...@gmail.com
In Java I'd just have an interface
with two implementations, and bootstrap the tests with a different
implementation, in clojure I guess I'd do something
Sadly, even thou my application isn't all that smart I've already fallen
into that trap - as my test first launches a Jetty process running a
compojure app, and fires http calls at it - with the send-sms call being
behind compojure on another thread.
I'm thinking a different way of handling
From what I've seen of fixtures that just provides setup/teardown
functionality (unless I'm mistaken).
In my particular instance, I'm wanting to stub out a function defined
elsewhere. The function wraps an SMS sending service so I really won't want
to get text messages when running tests. In
a dynamic rebinding. This is what you can use:
(binding [existing-function (fn [a b] ...)]
;; your tests here
)
For mocking java interfaces and classes I'm quite happy with Mockito
[1], even though it's usage doesn't look always intuitive in clojure.
This is an example for mock-testing a hadoop
That doesn't to work for me here:
(defn disable-bulletin [f]
(info Mocking out Bulletin Connect SMS API)
(binding [com.jobsheet.util.bulletin/send-sms (fn [a b] (info
Sending mock SMS))]
(f)))
(use-fixtures :once disable-bulletin)
I even tried declaring the disable-bulletin
On Sep 27, 9:18 pm, John Harrop jharrop...@gmail.com wrote:
Isn't (binding [foo bar] ...) already such a mechanism? Or does the
fixtures feature let you specify such a binding for a whole group of tests
obviating the need to repeat the binding form in multiple test functions,
Yes. A fixture
in a separate thread), just using
dynamic binding in tests may not be enough, still the binding will not be
seen by default by other threads.
For mocking java interfaces and classes I'm quite happy with Mockito
[1], even though it's usage doesn't look always intuitive in clojure.
This is an example
This is exactly the sort of purpose I wrote c.c.mock for. It is
essentially a glorified binding, but it should fit the bill.
(expect [sms-func (times once (has-args [message recipient]))]
(code-under-test))
This can tie into clojure.test as well if you are using that.
On Sep 28, 3:50 am,
On Sun, Sep 27, 2009 at 12:55 AM, Mark Derricutt m...@talios.com wrote:
How are people handling mocking/stubbing in clojure?
For mocking clojure code, I would have a look at clojure.contrib.mock (1). I
haven't used it, but plan to check it out soon. Recently, while doing some
performance
wrote:
On Sun, Sep 27, 2009 at 12:55 AM, Mark Derricutt m...@talios.com wrote:
How are people handling mocking/stubbing in clojure?
For mocking clojure code, I would have a look at clojure.contrib.mock (1). I
haven't used it, but plan to check it out soon. Recently, while doing some
performance
On Sep 27, 12:55 am, Mark Derricutt m...@talios.com wrote:
How are people handling mocking/stubbing in clojure? Google finds me some
old posts about a called? function/macro as part of test-is which looks like
it'd do what I need but I can't seem to find any trace of it under
clojure/clojure
On Sun, Sep 27, 2009 at 8:06 PM, Stuart Sierra
the.stuart.sie...@gmail.comwrote:
On Sep 27, 12:55 am, Mark Derricutt m...@talios.com wrote:
How are people handling mocking/stubbing in clojure? Google finds me
some
old posts about a called? function/macro as part of test-is which looks
'lo all,
How are people handling mocking/stubbing in clojure? Google finds me some
old posts about a called? function/macro as part of test-is which looks like
it'd do what I need but I can't seem to find any trace of it under
clojure/clojure-contrib trunk.
Any pointers?
--
Pull me down under
...
When I started working on this library, I thought to myself, I can't
believe no one has put together an expectation/mocking library but I
couldn't find one so I went ahead and started my own. Of course, it
was not until I had an early working version that I discovered Allen
Rohner's
for writing this!
Stu
When I started working on this library, I thought to myself, I can't
believe no one has put together an expectation/mocking library but I
couldn't find one so I went ahead and started my own. Of course, it
was not until I had an early working version that I discovered
thought to myself, I can't
believe no one has put together an expectation/mocking library but I
couldn't find one so I went ahead and started my own. Of course, it
was not until I had an early working version that I discovered Allen
Rohner's expectation tools, but I figured that mine were
Of course, it was not until I had an early working version that I discovered
Allen
Rohner's expectation tools, but I figured that mine were sufficiently
different to merit further development (at least relative to the
latest code of his I could find).
Suggestions for further changes or
When I started working on this library, I thought to myself, I can't
believe no one has put together an expectation/mocking library but I
couldn't find one so I went ahead and started my own. Of course, it
was not until I had an early working version that I discovered Allen
Rohner's expectation
On Mar 13, 3:35 pm, Stephen C. Gilardi squee...@mac.com wrote:
On Mar 13, 2009, at 4:10 PM, Stuart Sierra wrote:
Hi Allen,
Sorry I haven't kept up with this. I think, though, that it's best to
have it as a standalone library in clojure-contrib, so that people can
use it with other
Hi folks - are there any frameworks out there for mocking?
Stubbing functions is pretty straightforward (and I see that fact comes with
a stubbing function built in), but I'd really like something that can do
mocking and mock expectations - something similar to stub, but with checking
, 7:39 am, Korny Sietsma ko...@sietsma.com wrote:
Hi folks - are there any frameworks out there for mocking?
Stubbing functions is pretty straightforward (and I see that fact comes with
a stubbing function built in), but I'd really like something that can do
mocking and mock expectations
Any other options out there?
I posted a patch for test-is a while ago that never made it in, and I
don't know why.
http://groups.google.com/group/clojure/browse_frm/thread/883d4833f869f764/47a45325c8f29599?lnk=gstq=test-is+expect+patch#47a45325c8f29599
The patch handles creating stub
Hi Allen,
Sorry I haven't kept up with this. I think, though, that it's best to
have it as a standalone library in clojure-contrib, so that people can
use it with other testing frameworks if they want to.
-Stuart
On Mar 13, 3:20 pm, Allen Rohner aroh...@gmail.com wrote:
Any other options out
On Mar 13, 2009, at 4:10 PM, Stuart Sierra wrote:
Hi Allen,
Sorry I haven't kept up with this. I think, though, that it's best to
have it as a standalone library in clojure-contrib, so that people can
use it with other testing frameworks if they want to.
-Stuart
Allen,
I see you have a
92 matches
Mail list logo