clucumber 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -13,7 +13,7 @@ First, install the clucumber gem via rubygems:
13
13
 
14
14
  gem install clucumber
15
15
 
16
- On the lisp side, clucumber depends on cl-interpol, cl-ppcre, trivial-backtrace, usocket and st-json. All of these are available in clbuild, and I recommend you use this to manage your lisp libraries.
16
+ On the lisp side, clucumber depends on cl-interpol, cl-ppcre, trivial-backtrace, usocket and st-json. All of these are available in [quicklisp](http://quicklisp.org), and I recommend you use this to manage your lisp libraries.
17
17
 
18
18
  Getting started
19
19
  ---------------
@@ -30,19 +30,20 @@ Files in support and step_definitions/ are loaded (not file-compiled)
30
30
  in alphabetical order, with support/ files being loaded before step
31
31
  definitions.
32
32
 
33
+ Put a .wire file into your step_definitions dir; I like to name it `features/step_definitions/clucumber.wire`. See [examples/clucumber.wire](//github.com/antifuchs/clucumber/tree/master/examples/clucumber.wire) for one that works for me.
34
+
33
35
  In your `features/support/env.rb`, you use something like this:
34
36
 
35
37
  require 'clucumber'
36
38
  begin
37
- ClucumberSubprocess.launch(File.expand_path("../", File.dirname(__FILE__)),
38
- :port => 42428).listen <<-LISP
39
+ ClucumberSubprocess.launch(File.expand_path("../", File.dirname(__FILE__))).listen <<-LISP
39
40
  ;; Put code here that loads your application.
40
41
  LISP
41
42
  rescue PTY::ChildExited
42
43
  STDERR.puts(@main_clucumber && @main_clucumber.output)
43
44
  end
44
45
 
45
- This will launch a lisp with clucumber loaded (pass :lisp parameter to `ClucumberSubprocess.new` to specify which lisp, it defaults to sbcl), and start listening on port 42428.
46
+ This will launch a lisp with clucumber loaded (pass :lisp parameter to `ClucumberSubprocess.new` to specify which lisp, it defaults to sbcl), and (if you used the [examples/clucumber.wire](//github.com/antifuchs/clucumber/tree/master/examples/clucumber.wire) file) start listening on port 42428.
46
47
 
47
48
  Then, on the command line, you run cucumber:
48
49
 
data/lib/clucumber.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'pty'
2
+ require 'erb'
2
3
  require 'fileutils'
3
4
 
4
5
  class ClucumberSubprocess
@@ -18,19 +19,19 @@ class ClucumberSubprocess
18
19
  def initialize(dir, options={})
19
20
  @dir = dir
20
21
  @lisp = options[:lisp] || ENV['LISP'] || 'sbcl --disable-debugger'
21
- @port = options[:port] || raise("Need a port to run clucumber on.")
22
+ @port = options[:port]
22
23
  @output = ""
23
24
  end
24
25
 
25
26
  def run
26
- set_port_from_wire_file and return if wire_file_exists?
27
+ set_port
27
28
 
28
29
  Dir.chdir(@dir) do
29
30
  @out, @in, @pid = PTY.spawn(@lisp)
30
31
  end
31
32
  @reader = Thread.start {
32
33
  record_output
33
- }
34
+ }
34
35
  cluke_dir = File.expand_path("clucumber/", File.dirname(__FILE__))
35
36
  Dir[cluke_dir + '/**/*.fasl'].each do |fasl|
36
37
  FileUtils.rm(fasl)
@@ -46,21 +47,24 @@ class ClucumberSubprocess
46
47
  (asdf:oos 'asdf:load-op :clucumber)
47
48
  (clucumber-external:start #p"./" "localhost" #{@port})
48
49
  LISP
50
+ sleep 1
49
51
  end
50
52
 
51
53
  def listen(additional_forms="")
52
- start_clucumber_server(additional_forms) unless wire_file_exists?
53
-
54
- until socket = TCPSocket.new("localhost", @port) rescue nil
54
+ start_clucumber_server(additional_forms) unless connectable?
55
+ until connectable?
55
56
  raise LaunchFailed, "Couldn't start clucumber:\n#{@output}" unless alive?
56
- sleep 0.01
57
+ sleep 0.5
57
58
  end
58
- socket.close
59
+ sleep 1
60
+ end
59
61
 
60
- unless wire_file_exists?
61
- File.open(wire_file, "w") do |out|
62
- YAML.dump({'host' => "localhost", 'port' => @port}, out)
63
- end
62
+ def connectable?
63
+ if socket = TCPSocket.new("127.0.0.1", @port) rescue nil
64
+ socket.close
65
+ true
66
+ else
67
+ false
64
68
  end
65
69
  end
66
70
 
@@ -77,7 +81,6 @@ class ClucumberSubprocess
77
81
 
78
82
  def kill
79
83
  if @pid
80
- FileUtils.rm_f wire_file
81
84
  @reader.terminate!
82
85
  Process.kill("TERM", @pid)
83
86
  Process.waitpid(@pid)
@@ -110,7 +113,12 @@ class ClucumberSubprocess
110
113
  File.exist?(wire_file)
111
114
  end
112
115
 
113
- def set_port_from_wire_file
114
- @port = YAML.parse_file(wire_file)['port']
116
+ def set_port
117
+ unless @port
118
+ @port = YAML.load(ERB.new(File.read(wire_file)).result)['port'] ||
119
+ ENV['CLUCUMBER_PORT'] ||
120
+ raise("Need a port to run clucumber on.")
121
+ @port = @port.to_i
122
+ end
115
123
  end
116
124
  end
@@ -29,4 +29,4 @@
29
29
  :type "asd")
30
30
  vendor-dir)))
31
31
 
32
- (load (merge-pathnames #p"clucumber.asd" *load-truename*))
32
+ (push (make-pathname :name nil :type nil :version nil :defaults *load-truename*) asdf:*central-registry*)
@@ -34,15 +34,27 @@
34
34
  (defvar *stream*)
35
35
 
36
36
  (defun serve-cucumber-requests (socket &aux (*stream* (socket-stream socket)))
37
- (handler-case
38
- (loop
39
- (let* ((line (read-line *stream*))
40
- (message (read-json line nil))
41
- (reply (call-wire-protocol-method message)))
42
- (st-json:write-json reply *stream*)
43
- (terpri *stream*)
44
- (finish-output *stream*)))
45
- (end-of-file nil nil)))
37
+ (handler-case
38
+ (loop
39
+ (let* ((line (handler-case (read-line *stream*)
40
+ (error ()
41
+ (close *stream*)
42
+ (return :socket-error))))
43
+ (message (read-json line nil))
44
+ (reply (call-wire-protocol-method message)))
45
+ (format *trace-output* "Read json message ~s -> ~s~%" line message)
46
+ (handler-case (progn (st-json:write-json reply *stream*)
47
+ (terpri *stream*)
48
+ (finish-output *stream*))
49
+ (error ()
50
+ (close *stream*)
51
+ (return :socket-error)))))
52
+ (error ()
53
+ (close *stream*)
54
+ (format t "OHAI ich bin ein scheissprogramm~%")
55
+ (force-output *standard-output*)
56
+ (sleep 10)
57
+ (return-from serve-cucumber-requests :socket-error))))
46
58
 
47
59
 
48
60
  ;;; Step definitions
@@ -89,8 +101,9 @@
89
101
  (let ((server (usocket:socket-listen host port :reuse-address t)))
90
102
  (unwind-protect
91
103
  (loop
104
+ (with-open-file (*trace-output* #p"/tmp/trace.out" :direction :output :if-exists :append :if-does-not-exist :create)
92
105
  (let ((socket (usocket:socket-accept server :element-type 'character)))
93
- (serve-cucumber-requests socket))
106
+ (serve-cucumber-requests socket)))
94
107
  (when quit (return)))
95
108
  (usocket:socket-close server))))
96
109
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clucumber
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 2
10
- version: 0.3.2
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andreas Fuchs
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-01 00:00:00 +02:00
18
+ date: 2011-06-15 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -199,15 +199,13 @@ files:
199
199
  - lib/clucumber/vendor/usocket/vendor/split-sequence.lisp
200
200
  - LICENSE
201
201
  - README.md
202
- - test/helper.rb
203
- - test/test_clucumber.rb
204
202
  has_rdoc: true
205
203
  homepage: http://github.com/antifuchs/clucumber
206
204
  licenses: []
207
205
 
208
206
  post_install_message:
209
- rdoc_options:
210
- - --charset=UTF-8
207
+ rdoc_options: []
208
+
211
209
  require_paths:
212
210
  - lib
213
211
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -235,6 +233,5 @@ rubygems_version: 1.3.7
235
233
  signing_key:
236
234
  specification_version: 3
237
235
  summary: Test drive your Common Lisp application from Cucumber
238
- test_files:
239
- - test/helper.rb
240
- - test/test_clucumber.rb
236
+ test_files: []
237
+
data/test/helper.rb DELETED
@@ -1,10 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
-
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- $LOAD_PATH.unshift(File.dirname(__FILE__))
7
- require 'clucumber'
8
-
9
- class Test::Unit::TestCase
10
- end
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestClucumber < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end