"client" is a qualified name. So either use "client#", but you don't want that since the macro should be anaphoric. The other option, which you're close to, is using "~'client", which essentially makes "client" 'unqualified'.
Jonathan On Fri, May 27, 2011 at 7:46 PM, nil <[email protected]> wrote: > I was looking at > http://saucelabs.com/blog/index.php/2009/12/running-your-selenium-tests-in-parallel-clojure/ > and in the comments, :Scott suggested that a macro could reduce some > of the boilerplate that you see here: > > (def test-google > { > :name "google" > :test (fn [client] > (doto client > (.open "http://www.google.com") > (.type "q" "Sauce Labs") > (.click "btnG") > (.waitForPageToLoad "5000")) > (.isTextPresent client "Selenium"))}) > > (def test-yahoo > { > :name "yahoo" > :test (fn [client] > (doto client > (.open "http://yahoo.com") > (.type "p" "Sauce Labs") > (.click "search-submit") > (.waitForPageToLoad "5000")) > (.isTextPresent client "Selenium"))}) > > You can see the boilerplate of defining the map, typing the names of > the two keys, calling the thing "test-<name>" ... So I tried writing a > macro for this. But when I use my first attempt, it says Can't use > qualified name as parameter. Here's my first attempt: > > (defmacro deftest [name & body] > (let [test-n (symbol (str "test-" name)) > n (str name)] > `(def ~test-n > {:name ~n > :test (fn [client] > ~@body)}))) > > The macro expansion of the following looks good, but actually running > it yields the complaint mentioned above: > > (deftest google > (doto client > (.open "http://www.google.com") > (.type "q" "Sauce Labs") > (.click "btnG") > (.waitForPageToLoad "5000")) > (.isTextPresent client "Selenium")) > > My second attempt works ...... > > (defmacro deftest [name client & body] > (let [test-n (symbol (str "test-" name)) > n (str name)] > `(def ~test-n > {:name ~n > :test (fn [~client] > ~@body)}))) > > ... but now the user has to mention the client twice: > > (deftest google client > (doto client > (.open "http://www.google.com") > (.type "q" "Sauce Labs") > (.click "btnG") > (.waitForPageToLoad "5000")) > (.isTextPresent client "Selenium")) > > How do I get around this? > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to [email protected] > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en
