Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7916421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:48:09+00:00 2026-06-03T14:48:09+00:00

Background I’m new to Clojure so please forgive any glaring errors. I am trying

  • 0

Background

I’m new to Clojure so please forgive any glaring errors. I am trying to test some Clojure data access code that uses the redis-clojure library. Whilst my integration tests will, of course, test the full stack I do not want my unit tests to be reliant upon connecting to a redis server instance. Mocking the actual Redis commands with Midje appears to be relatively straight-forward however, the connection macro is more difficult to deal with.

Suggestions needed

What can’t seem to do or find via the Midje documentation is way of mocking the redis connection or redefining the macro. The relevant top level connection macro from core.clj is:

(defmacro with-server
  "Evaluates body in the context of a connection to Redis server
  specified by server-spec.

  server-spec is a map with any of the following keys:
    :host     (\"127.0.0.1\")
    :port     (6379)
    :db       (0)
    :timeout  (5000)
    :password (nil)"
  ([server-spec & body]
     `(with-connection connection# *pool* ~server-spec
        (binding [redis.vars/*channel* (make-direct-channel connection#)]
          ~@body))))

(original code in context here)

I don’t appear to be able to redefine the macro in my test code and wrapping the macro in a function doesn’t get me any further forwards as I still need the body to be executed to produce my result. What I’d ideally like to do is execute the body passed into the connection macro and discard the rest of the macro. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:48:11+00:00Added an answer on June 3, 2026 at 2:48 pm

    I suggest asking your question on the Midje mailing list (and then, of course, posting the final answer here). Without knowing what you’re trying to test, it’s hard to give advice. Perhaps (following Freeman and Pryce’s Growing Object-Oriented Software (which does apply to Clojure – indeed, supporting that style was the reason I wrote Midje)), you want to separate your problem into two parts. First, you want to build a set of functions that isolate Redis. You test that those functions work correctly with slow and cumbersome direct tests that work with the real database.

    Those functions would hide the connection and the need for a wrapping macro.

    Then you can test that your code calls the isolation functions correctly, using Midje prerequisites.

    Avdi Grimm’s Objects on Rails is another book that does a decent job of talking about isolating the database.

    Note: I don’t know anything about Redis, but several other Clojure->database libraries dispense with the intellectually appealing wrapping-macros (with-server). Instead, they go the stateful route and have a global variable that holds the connection, much like (say) Ruby database libraries ActiveRecord (implicitly) and Sequel (explicitly) do. Despite being less pure, it seems to make life (including testing) simpler. In Midje, that connection could be represented by a metaconstant.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: I'm new to CakePHP. I have a small test site (mostly composted of
Background: I am trying to add data to a SQL DB with C#. I
Background: As a short project over winter break, I'm trying to implement a programming
Background: I want to check-out the source code from Cliche , which is stored
Background I'm trying to implement a simple web server part as a web interface
Background: I am comming from the Java world and I am fairly new to
Background I am writing code in VS 2010, .NET 4, C#. Also, in case
Background info I am trying to upgrade a custom CMS to support the HTML5
Background : With a Python Script, I scraping data (html) from a Website and
[background below] I've got my data modelled out in SQLObject in Python on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.