boojs 0.0.19 → 0.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e11c8ef147bde4d7cd1d32bc6fe738777aee313
4
- data.tar.gz: 02912a09d53663c9208711136bba13ffb039c37d
3
+ metadata.gz: a6986660e9db31fd0c1344f0db02d96326090a5e
4
+ data.tar.gz: eaae81bfccf3a5bd904fd412dbfa4f92927c91a3
5
5
  SHA512:
6
- metadata.gz: 5f9d3e5416424f2469585cb328671fe46e63879cae3774f1dec207c85f8751358b5570d6f25ebbae8dea0a45ad5e3780cff7cd6f3de841bfffe38587bcdfbcc1
7
- data.tar.gz: 76153a49aa42fa73e8cb42b1d5abce7c6605ec56b5f6b016a5929541ab1ed64df709ed49ebbcfabbade2cab401d408a432de2e5409fb8efbe827eea343488e86
6
+ metadata.gz: 7ee8a3a28e6cec16dfc73e67fb1c6a0a7422993d5ae7c577e7acebddef4b20b52c442021fb015b455d32169b59946e4416ecf60c92b0c84088722a1093309e58
7
+ data.tar.gz: 56dfee67ae455e719aef13dd9cb43e110cf3c38dd3affc52876b7ce0ee426f060024ec7d60c935c3eb3d1fc458e59187ba7fbd1c9b8fbf01c68654c9f5125d75
data/boojs.gemspec CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "pry", "~> 0.1"
23
23
  spec.add_development_dependency "rake", "~> 10.3"
24
24
  spec.add_development_dependency "rspec", "~> 3.2"
25
+ spec.add_development_dependency 'webrick', '~> 1.3'
25
26
  spec.add_runtime_dependency "phantomjs", "~> 1.9"
26
27
  spec.add_runtime_dependency "greenletters", "~> 0.3"
27
28
  spec.executables << 'boojs'
data/lib/boojs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module BooJS
2
- VERSION = '0.0.19'
2
+ VERSION = '0.0.20'
3
3
  end
data/spec/helpers.rb ADDED
@@ -0,0 +1,103 @@
1
+ require 'securerandom'
2
+ require 'json'
3
+ require 'webrick'
4
+
5
+ #Duplex pipe
6
+ ###################################################################################################################
7
+ class IO
8
+ def self.duplex_pipe
9
+ return DuplexPipe.new
10
+ end
11
+ end
12
+
13
+ class DuplexPipe
14
+ def initialize
15
+ @r0, @w0 = IO.pipe
16
+ @r1, @w1 = IO.pipe
17
+ end
18
+
19
+ #Choose arbitrary side, just different ones for forked processes
20
+ def claim_low
21
+ @r = @r0
22
+ @w = @w1
23
+ end
24
+
25
+
26
+
27
+ def claim_high
28
+ @r = @r1
29
+ @w = @w0
30
+ end
31
+
32
+ def write msg
33
+ @w.write msg
34
+ end
35
+
36
+ def puts msg
37
+ @w.puts msg
38
+ end
39
+
40
+ def readline
41
+ @r.readline
42
+ end
43
+ end
44
+ ###################################################################################################################
45
+
46
+ #RESTful mock
47
+ ###################################################################################################################
48
+ module Webbing
49
+ def self.get path, port=nil, &block
50
+ Webbing.new "GET", path, port, &block
51
+ end
52
+
53
+ class Webbing
54
+ attr_accessor :pid
55
+ attr_accessor :port
56
+
57
+ def kill
58
+ Process.kill("KILL", @pid)
59
+ end
60
+
61
+ def initialize verb, path, port=nil, &block
62
+ @verb = verb
63
+ @path = path
64
+ @block = block
65
+ @port = port || rand(30000)+3000
66
+
67
+ @pipe = IO.duplex_pipe
68
+ @pid = fork do
69
+ @pipe.claim_high
70
+ @server = ::WEBrick::HTTPServer.new :Port => @port, :DocumentRoot => ".", :StartCallback => Proc.new {
71
+ @pipe.puts("ready")
72
+ }
73
+ @server.mount_proc '/' do |req, res|
74
+ @pipe.puts req.query.to_json
75
+ res.body = @pipe.readline
76
+ res.header["Access-Control-Allow-Origin"] = "*"
77
+ res.header["Content-Type"] = "json/text"
78
+ end
79
+ @server.mount_proc '/404' do |req, res|
80
+ res.header["Access-Control-Allow-Origin"] = "*"
81
+
82
+ raise WEBrick::HTTPStatus::NotFound
83
+ end
84
+ @server.start
85
+ end
86
+
87
+ @pipe.claim_low
88
+ @pipe.readline #Wait for 'ready'
89
+ Thread.new do
90
+ begin
91
+ loop do
92
+ params = JSON.parse(@pipe.readline)
93
+ res = @block.call(params)
94
+ @pipe.puts res.to_json
95
+ end
96
+ rescue => e
97
+ $stderr.puts "Exception: #{e.inspect}"
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
103
+ ###################################################################################################################
data/spec/sample_spec.rb CHANGED
@@ -1,20 +1,30 @@
1
+ require './spec/helpers'
2
+
1
3
  Dir.chdir File.join(File.dirname(__FILE__), '../')
2
4
  #Files that are reported as bugged end up here for testing.
3
5
  RSpec.describe "Live Culture" do
4
- it "Can run jquery_ajax.js and output success" do
5
- begin
6
- Timeout.timeout(8) do
7
- IO.popen "ruby -Ilib ./bin/boojs ./spec/samples/jquery_ajax.js", "r" do |p|
8
- begin
9
- @res = p.readline.strip
10
- ensure
11
- Process.kill 9, p.pid
6
+ it "Can run jquery_ajax.js and output success" do
7
+ begin
8
+ @web = Webbing.get("/", 4545) do |info|
9
+ {"hello" => "world"}
10
+ end
11
+
12
+ begin
13
+ Timeout.timeout(8) do
14
+ IO.popen "ruby -Ilib ./bin/boojs ./spec/samples/jquery_ajax.js", "r" do |p|
15
+ begin
16
+ @res = p.readline.strip
17
+ ensure
18
+ Process.kill 9, p.pid
19
+ end
12
20
  end
13
21
  end
22
+ rescue
14
23
  end
15
- rescue
16
- end
17
24
 
18
- expect(@res).to eq("success")
25
+ expect(@res).to eq("success")
26
+ ensure
27
+ Process.kill(:KILL, @web.pid)
28
+ end
19
29
  end
20
30
  end
@@ -24,4 +24,4 @@ if_net_request = function(verb, url, params) {
24
24
  return fd
25
25
  }
26
26
 
27
- if_net_request("GET", "http://localhost:32370", {})
27
+ if_net_request("GET", "http://localhost:4545", {})
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boojs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19
4
+ version: 0.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - seo
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webrick
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: phantomjs
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -115,6 +129,7 @@ files:
115
129
  - lib/boojs/version.rb
116
130
  - logo.png
117
131
  - spec/cli_spec.rb
132
+ - spec/helpers.rb
118
133
  - spec/sample_spec.rb
119
134
  - spec/samples/jquery_ajax.js
120
135
  - usage.gif
@@ -144,5 +159,6 @@ specification_version: 4
144
159
  summary: A boring javascript application framework
145
160
  test_files:
146
161
  - spec/cli_spec.rb
162
+ - spec/helpers.rb
147
163
  - spec/sample_spec.rb
148
164
  - spec/samples/jquery_ajax.js