{"issue":{"created_at":"2011-10-19T07:57:55Z","state":"open","updated_at":"2011-11-23T04:53:02Z","user":{"gravatar_id":"a65b45853169d71e03426f1be946ddcc","id":303632,"url":"https://api.github.com/users/jevgeni","login":"jevgeni","avatar_url":"https://secure.gravatar.com/avatar/a65b45853169d71e03426f1be946ddcc?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"comments":7,"body":" I am trying to mock java calls using meta constants like this:\r\n\r\n```clojure\r\n(ns midje.test.core\r\n (:use [midje.sweet]))\r\n\r\n(defn write [socket message]\r\n (.write (.getOutputStream socket) (.getBytes message)))\r\n\r\n(fact\r\n (write ...sock.. \"hello\") => nil\r\n (provided\r\n   (.getOutputStream ..sock..) => System/out))\r\n```\r\n\r\nI expect that (.getOutputStream ..sock..) will be replaced with System/\r\nout in the write function call. However, I get \"java.lang.Exception:\r\nUnable to resolve var: .getOutputStream in this context (core.clj:\r\n10)\"\r\n\r\n\r\n\r\nConsidering you know which functions are to be mocked:\r\n\r\n```clojure\r\n(fact ...\r\n (provided\r\n  (.toUpperCase ..meta..) => \"LO\"))\r\n```\r\nit should be possible to perform something like this during macro evaluation:\r\n\r\n```clojure\r\n(gen-interface\r\n :name midje.Stub\r\n :methods [[toUpperCase [] String]])\r\n\r\n(def stub\r\n (proxy [midje.Stub] []\r\n  (toUpperCase [] \"LO\")))\r\n```\r\n(assuming that interface name is generated and there is some mechanism\r\nto clean \\*compile-path\\*)\r\n\r\nThen associate ..meta.. with this stub and use it like this:\r\n\r\n```clojure\r\nuser=> (.toUpperCase stub)\r\n\"LO\"\r\n```","assignee":{"gravatar_id":"7d2cc799db6f5916a1ca4df1259d7d32","id":45647,"url":"https://api.github.com/users/AlexBaranosky","login":"AlexBaranosky","avatar_url":"https://secure.gravatar.com/avatar/7d2cc799db6f5916a1ca4df1259d7d32?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"id":1991462,"pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"labels":[{"name":"wishlist","color":"DDDDDD","url":"https://api.github.com/repos/marick/Midje/labels/wishlist"}],"number":55,"title":"Mocking java method calls","closed_at":null,"html_url":"https://github.com/marick/Midje/issues/55","milestone":null,"url":"https://api.github.com/repos/marick/Midje/issues/55"},"action":"created","comment":{"created_at":"2011-11-23T04:53:02Z","updated_at":"2011-11-23T04:53:02Z","user":{"gravatar_id":"7d2cc799db6f5916a1ca4df1259d7d32","id":45647,"url":"https://api.github.com/users/AlexBaranosky","login":"AlexBaranosky","avatar_url":"https://secure.gravatar.com/avatar/7d2cc799db6f5916a1ca4df1259d7d32?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"body":"A couple of proposed syntaxes for creating mocks/stubs (not spies)\r\n\r\n```clojure\r\n(provided (mocking bar IBar (.size [this] 10)))\r\n```\r\n```clojure\r\n(fact (x) => 1 (provided (.foo IFoo f) => 2 (.bar IBar b) => 3 (.baz IBaz bz ) => 4))\r\n```","id":2845015,"url":"https://api.github.com/repos/marick/Midje/issues/comments/2845015"}}