Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added running code at Janus exit, to allow post run clean-up.

  • Loading branch information...
commit b682526e1f73df7f3cd7b243f294f8dd04f607c1 1 parent 0ef1363
@gga authored
View
2  Gemfile
@@ -2,4 +2,4 @@ source :rubygems
gem "aruba"
gem "httparty"
-gem "harper"
+gem "harper", ">= 0.0.4"
View
6 Gemfile.lock
@@ -19,10 +19,11 @@ GEM
ffi (1.0.11)
gherkin (2.7.6)
json (>= 1.4.6)
- harper (0.0.3)
+ harper (0.0.4)
httparty
json (>= 1.4.6)
sinatra (>= 1.0.0)
+ trollop
httparty (0.8.1)
multi_json
multi_xml
@@ -46,11 +47,12 @@ GEM
tilt (~> 1.3, >= 1.3.3)
term-ansicolor (1.0.7)
tilt (1.3.3)
+ trollop (1.16.2)
PLATFORMS
ruby
DEPENDENCIES
aruba
- harper
+ harper (>= 0.0.4)
httparty
View
9 features/infra.feature
@@ -11,3 +11,12 @@ Feature: Infrastructure and support
"""
When I run janus
Then the output from janus should contain "hello from env"
+
+ Scenario: janus should allow code to be executed after all work has been done
+ Given a directory named "contracts/support"
+ And a file named "contracts/support/env.clj" with:
+ """
+ (at-exit #(println "exiting"))
+ """
+ When I run janus
+ Then the output from janus should contain "exiting"
View
1  features/support/env.rb
@@ -1,4 +1,5 @@
require 'aruba/cucumber'
+require 'harper/client'
class JanusWorld
View
54 features/support/harper_client.rb
@@ -1,54 +0,0 @@
-require 'open3'
-require 'httparty'
-require 'json'
-
-class HarperClient
- include HTTParty
-
- base_uri "localhost:4568"
-
- def initialize
- @started = false
- end
-
- def started?
- @started
- end
-
- def start
- read, write = IO.pipe
-
- fork do
- read.close
- Open3.popen2({}, "harper 4568", {:err => [:child, :out]}) do |i, o|
- found_start = false
- while !found_start && line = o.readline
- if line =~ /WEBrick::HTTPServer#start/
- write.puts "Harper started"
- found_start = true
- end
- end
- end
- end
-
- write.close
- read.readline
-
- @started = true
- end
-
- def stop
- self.class.put "/h/control", :body => {:command => "quit"}.to_json
- @started = false
- end
-
- def mock(mock)
- mock_body = case mock
- when String
- mock
- else
- mock.to_json
- end
- self.class.post "/h/mocks", :body => mock_body
- end
-end
View
12 src/janus/support.clj
@@ -1,7 +1,17 @@
(ns janus.support)
+(defn at-exit [code]
+ (.addShutdownHook (Runtime/getRuntime)
+ (proxy [Thread] []
+ (run []
+ (code)))))
+
(defn- load-support [support-file]
- (eval (read-string (slurp (.getPath support-file)))))
+ (let [support-ns (create-ns 'support-ns)]
+ (binding [*ns* support-ns]
+ (eval '(clojure.core/refer 'clojure.core))
+ (eval '(refer 'janus.support))
+ (eval (read-string (slurp (.getPath support-file)))))))
(defn environment []
(let [support-files (file-seq (clojure.java.io/file "." "contracts" "support"))]
Please sign in to comment.
Something went wrong with that request. Please try again.