Back
browse-url (clj)
(source)function
(browse-url url)
Open url in a browser
Examples
nextjournal/clerk
(ns nextjournal.clerk.builder-test
(:require [babashka.fs :as fs]
[clojure.java.browse :as browse]
[clojure.string :as str]
[clojure.test :refer [deftest is testing]]
[matcher-combinators.test]
[nextjournal.clerk.builder :as builder]
[nextjournal.clerk.viewer :as viewer])
(:import (clojure.lang ExceptionInfo)
(java.io File)))
(deftest static-app
(let [url* (volatile! nil)
original-*ns* *ns*]
(with-redefs [clojure.java.browse/browse-url (fn [path]
(vreset! url* path))]
(testing "browser receives canonical url in this system arch"
(fs/with-temp-dir [temp {}]
(let [expected (-> (str/join (java.io.File/separator) [(.toString temp) "index.html"])
(str/replace (java.io.File/separator) "/"))]
(builder/build-static-app! {:browse? true
:paths ["notebooks/hello.clj"]
:out-path temp})
(is (= expected @url*)))))
r0man/oauth-clj
(ns oauth.google-test
(:require [no.en.core :refer [parse-url]]
[clojure.java.browse :refer [browse-url]]
[clojure.test :refer :all]
[oauth.google :refer :all]
[oauth.v2 :as v2]))
(deftest test-oauth-authorize
(with-redefs [browse-url (fn [target] (is (= (oauth-authorization-url google-client-id "http://example.com") target)))]
(oauth-authorize google-client-id "http://example.com")))
r0man/oauth-clj
(ns oauth.v1-test
(:require [clj-http.client :as http]
[clojure.java.browse :refer [browse-url]]
[clojure.test :refer :all]
[oauth.twitter-test :refer :all]
[oauth.v1 :refer :all]))
(deftest test-oauth-authorize
(let [expected "https://api.twitter.com/oauth/authorize?oauth_token=9BVHFCl8PCvGekptmdtL1169QkppJG6PgpUDQDWow"]
(with-redefs [browse-url (fn [url] (is (= expected url)))]
(oauth-authorize "https://api.twitter.com/oauth/authorize" "9BVHFCl8PCvGekptmdtL1169QkppJG6PgpUDQDWow"))))
r0man/oauth-clj
(ns oauth.v2-test
(:require [clj-http.client :as http]
[clojure.java.browse :refer [browse-url]]
[oauth.facebook :refer [*oauth-access-token-url* *oauth-authorization-url*]]
[oauth.facebook-test :refer [facebook-access-token facebook-access-token facebook-client-id facebook-code facebook-redirect-uri facebook-client-secret]]
[clojure.test :refer :all]
[oauth.v2 :refer :all]))
(deftest test-oauth-authorize
(with-redefs [browse-url #(is (= (oauth-authorization-url *oauth-authorization-url* facebook-client-id facebook-redirect-uri) %1))]
(oauth-authorize *oauth-authorization-url* facebook-client-id facebook-redirect-uri)))
r0man/oauth-clj
(ns oauth.instagram-test
(:require [no.en.core :refer [parse-url]]
[clojure.java.browse :refer (browse-url)]
[clojure.test :refer :all]
[oauth.instagram :refer :all]
[oauth.v2 :as v2]))
(deftest test-oauth-authorize
(with-redefs [browse-url (fn [target] (is (= (oauth-authorization-url client-id redirect-uri) target)))]
(oauth-authorize client-id redirect-uri)))