Last active
February 11, 2018 04:57
-
-
Save apeckham/754cee2d4cbb04f0c18deabff120a7aa to your computer and use it in GitHub Desktop.
JRuby / Clojure interop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lein new app x | |
#cd x | |
#:aot :all in project.clj | |
#lein compile | |
#env CLASSPATH=$(lein classpath) jirb -rjava -w -d | |
java_import "clojure.java.api.Clojure" | |
Java::ClojureJavaApi::Clojure.var("clojure.core", "+").invoke(2,3,4) | |
c = Java::ClojureJavaApi::Clojure | |
r = c.var("clojure.core", "require") | |
r.invoke(c.read("x.core")) | |
c.var("x.core", "-main").invoke() | |
Hello, World! | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns jruby-example.core-test | |
(:require [clojure.test :refer :all] | |
[zweikopf.core :as z])) | |
(z/init-ruby-context) | |
(z/ruby-require "rspec") | |
(z/ruby-require "bundler") | |
(z/call-ruby (z/ruby-eval "Bundler") :require) | |
(deftest z-test | |
(is (= 3 (z/ruby-eval "1 + 2")))) | |
(deftest rspec-test | |
(let [stderr (z/ruby-eval "STDERR") | |
stdout (z/ruby-eval "STDOUT")] | |
(is (zero? (-> "RSpec::Core::Runner" z/ruby-eval (z/call-ruby :run (z/rubyize ["spec"]) stderr stdout)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment