flok 0.0.6 → 0.0.7

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: 65e970caf6e1b7a8239b75ac7e67d5f75c1b6488
4
- data.tar.gz: 603287f2e663c167f50840cc8b541b895822ccb7
3
+ metadata.gz: f1ad99a2e37f5f7fd315f2d5aa6a0c1ecd2da568
4
+ data.tar.gz: 469142150d43cc41b9df90ff02f3959afe4ed428
5
5
  SHA512:
6
- metadata.gz: f664aacfe79b395d08c3005e69636cad457909bdbaa8f60de53b01d6029aa4a6a6977d5e92dc216e9aa1c337dc20b2cb1f1843b2957f5ce1f2a9d1e50aebbded
7
- data.tar.gz: 9264e3fba278e411244f25591b97a6a0bf90d273fc101a1010aaad9a2cfffb090deb6a657a31d37608715d5f6a92d11d9871a810921772022d2932164e94ed40
6
+ metadata.gz: 397eda8fa9624eff545d736c1133261b9fbbe0f9db5a25322adcc90e73173a8fa500467001ef779e70db8d2477c2b51264984666446e99414a3c27d1d0a15772
7
+ data.tar.gz: a97e2b1931dbf9c9568275feb66b699c3c9d949a7f60cd6a9f9ee07fcb2838c0010b368d572014f215cac4b14ca72a1fc640fd3103c390c11f8c4a1c6ca7ae3e
data/.gitignore CHANGED
@@ -21,3 +21,4 @@ tmp
21
21
  *.a
22
22
  mkmf.log
23
23
  .run
24
+ products/
data/Rakefile CHANGED
@@ -20,6 +20,7 @@ def upgrade_version
20
20
 
21
21
  sreg = "s/#{version}/#{new_version}/"
22
22
  puts `sed #{sreg} #{versionf} > tmp; cp tmp #{versionf}`
23
+ `rm tmp`
23
24
 
24
25
  return new_version
25
26
  end
@@ -0,0 +1,24 @@
1
+ require 'fileutils'
2
+
3
+ #Compile all the *.js files into one file
4
+ BUILD_PATH = '../../../products/drivers/browser.js'
5
+ task :build do
6
+ out = "/* THIS IS AN AUTOGENETARED FILE, DO NOT EDIT THIS */\n"
7
+ Dir["./vendor/*.js"].each do |js|
8
+ code = File.read(js)
9
+ out << code
10
+ out << "\n"
11
+ end
12
+
13
+ Dir["*.js"].each do |js|
14
+ code = File.read(js)
15
+ out << code
16
+ out << "\n"
17
+ end
18
+
19
+ Dir.chdir File.dirname(__FILE__) do
20
+ FileUtils.rm_f BUILD_PATH
21
+ FileUtils.mkdir_p File.dirname(BUILD_PATH)
22
+ File.write BUILD_PATH, out
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ drivers = window.drivers || {}
2
+ drivers.network = {}
3
+
4
+ $(document).ready(function() {
5
+ //drivers.network.request("GET", "http://test.services.fittr.com/ping", {}, null);
6
+ })
7
+
8
+ //A basic get request that supports callbacks
9
+ drivers.network.request = function(verb, url, params, completion) {
10
+ $.ajax({
11
+ url: url,
12
+ type: verb,
13
+ data: params,
14
+ success: function(data) {
15
+ data = JSON.parse(data);
16
+ completion = completion || function() {}
17
+ if (completion != null) {
18
+ completion(data);
19
+ }
20
+ },
21
+ error: function(xhr, status, err) {
22
+ }
23
+ })
24
+ }
data/flok.gemspec CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency 'webrick', '~> 1.3'
26
26
  spec.add_development_dependency "closure-compiler", "~> 1.1"
27
27
  spec.add_development_dependency "phantomjs", "~> 1.9"
28
+ spec.add_development_dependency "rspec-wait", "~> 0.0"
28
29
  spec.add_runtime_dependency "thor", "~> 0.19"
29
30
  spec.executables << 'flok'
30
31
  end
data/lib/flok/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Flok
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/spec/cli_spec.rb CHANGED
@@ -1,210 +1,210 @@
1
- require './lib/flok.rb'
2
- require 'tempfile'
3
- require 'securerandom'
4
- require 'v8'
5
-
6
- def ensure_tmp
7
- tmp_spec_path = './spec/tmp'
8
- Dir.mkdir(tmp_spec_path) unless File.exists?(tmp_spec_path)
9
- end
10
-
11
- RSpec.describe "CLI" do
12
- it "Creates a new module folder with absolute path" do
13
- #Get a temporary file, delete it, but save the path
14
- temp = Tempfile.new "flok-temp"
15
- path = temp.path
16
- temp.close
17
- temp.unlink
18
-
19
- `ruby -Ilib ./bin/flok new #{path}`
20
-
21
- expect(Dir.exists? path).to be(true)
22
- end
23
-
24
- it "Creates a new module folder with relative path" do
25
- ensure_tmp
26
- fn = SecureRandom.hex
27
-
28
- dir = "./spec/tmp/#{fn}"
29
- `ruby -Ilib ./bin/flok new #{dir}`
30
- expect(File.exists?(dir)).to be(true)
31
- end
32
-
33
- it "Creates a new module folder with correct root folders" do
34
- #Get a temporary file, delete it, but save the path
35
- temp = Tempfile.new "flok-temp"
36
- path = temp.path
37
- temp.close
38
- temp.unlink
39
-
40
- `ruby -Ilib ./bin/flok new #{path}`
41
-
42
- folders = %w{app lib config}
43
-
44
- folders.each do |f|
45
- p = "#{path}/#{f}"
46
- expect(Dir.exists? p).to be(true)
47
- end
48
- end
49
-
50
- it "The new module has all the files and folders of a RubyGem" do
51
- #Get a temporary file, delete it, but save the path
52
- temp = Tempfile.new "flok-temp"
53
- path = temp.path
54
- temp.close
55
- temp.unlink
56
- Dir.mkdir(path)
57
- test_gem_path = "#{path}/test_gem"
58
- Dir.mkdir(test_gem_path)
59
- file_paths = []
60
- dir_paths = []
61
- name = "#{SecureRandom.hex[0..4]}_module_name"
62
- Dir.chdir(test_gem_path) do
63
- `bundle gem #{name}`
64
-
65
- Dir.chdir "./#{name}" do
66
- Dir["**/*"].each do |f|
67
- if File.file?(f)
68
- file_paths << f
69
- end
70
-
71
- if File.directory?(f)
72
- dir_paths << f
73
- end
74
- end
75
- end
76
-
77
- file_paths.uniq!
78
- dir_paths.uniq!
79
- end
80
-
81
- `ruby -Ilib ./bin/flok new #{path}/#{name}`
82
- Dir.chdir "#{path}/#{name}" do
83
- Dir["**/*"].each do |f|
84
- if File.file?(f)
85
- file_paths = file_paths - [f]
86
- end
87
-
88
- if File.directory?(f)
89
- dir_paths = dir_paths - [f]
90
- end
91
- end
92
-
93
- if file_paths.count+dir_paths.count != 0
94
- puts "------------------------------------------------------------------------------"
95
- puts "Files not found matching Gemfile: #{file_paths.inspect}" if file_paths.count > 0
96
- puts "Directories not found matching Gemfile: #{dir_paths.inspect}" if dir_paths.count > 0
97
- puts "------------------------------------------------------------------------------"
98
- end
99
-
100
- expect(file_paths.count+dir_paths.count).to be(0)
101
- end
102
- end
103
-
104
- it "does create a public/application.js when 'build' is run" do
105
- #Get a temporary file, delete it, but save the path
106
- temp = Tempfile.new "flok-temp"
107
- path = temp.path
108
- temp.close
109
- temp.unlink
110
-
111
- `ruby -Ilib ./bin/flok new #{path}`
112
- gem_root_path = File.expand_path(File.dirname(__FILE__))+"/.."
113
- Dir.chdir path do
114
- `ruby -I#{gem_root_path}/lib #{gem_root_path}/bin/flok build`
115
- expect(File.exist?("./public/application.js")).to be(true)
116
- end
117
- end
118
-
119
- it "does create a public/application.js when 'build' is run that's not empty" do
120
- #Get a temporary file, delete it, but save the path
121
- temp = Tempfile.new "flok-temp"
122
- path = temp.path
123
- temp.close
124
- temp.unlink
125
-
126
- `ruby -Ilib ./bin/flok new #{path}`
127
- gem_root_path = File.expand_path(File.dirname(__FILE__))+"/.."
128
- Dir.chdir path do
129
- `ruby -I#{gem_root_path}/lib #{gem_root_path}/bin/flok build`
130
- expect(File.read("./public/application.js").length).to be > 0
131
- end
132
- end
133
-
134
- it "creates an application.js that is executable by js" do
135
- #Get a temporary file, delete it, but save the path
136
- temp = Tempfile.new "flok-temp"
137
- path = temp.path
138
- temp.close
139
- temp.unlink
140
-
141
- `ruby -Ilib ./bin/flok new #{path}`
142
- gem_root_path = File.expand_path(File.dirname(__FILE__))+"/.."
143
- Dir.chdir path do
144
- `ruby -I#{gem_root_path}/lib #{gem_root_path}/bin/flok build`
1
+ #require './lib/flok.rb'
2
+ #require 'tempfile'
3
+ #require 'securerandom'
4
+ #require 'v8'
5
+
6
+ #def ensure_tmp
7
+ #tmp_spec_path = './spec/tmp'
8
+ #FileUtils.mkdir_p(tmp_spec_path) unless File.exists?(tmp_spec_path)
9
+ #end
10
+
11
+ #RSpec.describe "CLI" do
12
+ #it "Creates a new module folder with absolute path" do
13
+ ##Get a temporary file, delete it, but save the path
14
+ #temp = Tempfile.new SecureRandom.hex
15
+ #path = temp.path
16
+ #temp.close
17
+ #temp.unlink
18
+
19
+ #`ruby -Ilib ./bin/flok new #{path}`
20
+
21
+ #expect(Dir.exists? path).to be(true)
22
+ #end
23
+
24
+ #it "Creates a new module folder with relative path" do
25
+ #ensure_tmp
26
+ #fn = SecureRandom.hex
27
+
28
+ #dir = "./spec/tmp/#{fn}"
29
+ #`ruby -Ilib ./bin/flok new #{dir}`
30
+ #expect(File.exists?(dir)).to be(true)
31
+ #end
32
+
33
+ #it "Creates a new module folder with correct root folders" do
34
+ ##Get a temporary file, delete it, but save the path
35
+ #temp = Tempfile.new SecureRandom.hex
36
+ #path = temp.path
37
+ #temp.close
38
+ #temp.unlink
39
+
40
+ #`ruby -Ilib ./bin/flok new #{path}`
41
+
42
+ #folders = %w{app lib config}
43
+
44
+ #folders.each do |f|
45
+ #p = "#{path}/#{f}"
46
+ #expect(Dir.exists? p).to be(true)
47
+ #end
48
+ #end
49
+
50
+ #it "The new module has all the files and folders of a RubyGem" do
51
+ ##Get a temporary file, delete it, but save the path
52
+ #temp = Tempfile.new SecureRandom.hex
53
+ #path = temp.path
54
+ #temp.close
55
+ #temp.unlink
56
+ #FileUtils.mkdir_p(path)
57
+ #test_gem_path = "#{path}/test_gem"
58
+ #FileUtils.mkdir_p(test_gem_path)
59
+ #file_paths = []
60
+ #dir_paths = []
61
+ #name = "#{SecureRandom.hex[0..4]}_module_name"
62
+ #Dir.chdir(test_gem_path) do
63
+ #`bundle gem #{name}`
64
+
65
+ #Dir.chdir "./#{name}" do
66
+ #Dir["**/*"].each do |f|
67
+ #if File.file?(f)
68
+ #file_paths << f
69
+ #end
70
+
71
+ #if File.directory?(f)
72
+ #dir_paths << f
73
+ #end
74
+ #end
75
+ #end
76
+
77
+ #file_paths.uniq!
78
+ #dir_paths.uniq!
79
+ #end
80
+
81
+ #`ruby -Ilib ./bin/flok new #{path}/#{name}`
82
+ #Dir.chdir "#{path}/#{name}" do
83
+ #Dir["**/*"].each do |f|
84
+ #if File.file?(f)
85
+ #file_paths = file_paths - [f]
86
+ #end
87
+
88
+ #if File.directory?(f)
89
+ #dir_paths = dir_paths - [f]
90
+ #end
91
+ #end
92
+
93
+ #if file_paths.count+dir_paths.count != 0
94
+ #puts "------------------------------------------------------------------------------"
95
+ #puts "Files not found matching Gemfile: #{file_paths.inspect}" if file_paths.count > 0
96
+ #puts "Directories not found matching Gemfile: #{dir_paths.inspect}" if dir_paths.count > 0
97
+ #puts "------------------------------------------------------------------------------"
98
+ #end
99
+
100
+ #expect(file_paths.count+dir_paths.count).to be(0)
101
+ #end
102
+ #end
103
+
104
+ #it "does create a public/application.js when 'build' is run" do
105
+ ##Get a temporary file, delete it, but save the path
106
+ #temp = Tempfile.new SecureRandom.hex
107
+ #path = temp.path
108
+ #temp.close
109
+ #temp.unlink
110
+
111
+ #`ruby -Ilib ./bin/flok new #{path}`
112
+ #gem_root_path = File.expand_path(File.dirname(__FILE__))+"/.."
113
+ #Dir.chdir path do
114
+ #`ruby -I#{gem_root_path}/lib #{gem_root_path}/bin/flok build`
115
+ #expect(File.exist?("./public/application.js")).to be(true)
116
+ #end
117
+ #end
118
+
119
+ #it "does create a public/application.js when 'build' is run that's not empty" do
120
+ ##Get a temporary file, delete it, but save the path
121
+ #temp = Tempfile.new SecureRandom.hex
122
+ #path = temp.path
123
+ #temp.close
124
+ #temp.unlink
125
+
126
+ #`ruby -Ilib ./bin/flok new #{path}`
127
+ #gem_root_path = File.expand_path(File.dirname(__FILE__))+"/.."
128
+ #Dir.chdir path do
129
+ #`ruby -I#{gem_root_path}/lib #{gem_root_path}/bin/flok build`
130
+ #expect(File.read("./public/application.js").length).to be > 0
131
+ #end
132
+ #end
133
+
134
+ #it "creates an application.js that is executable by js" do
135
+ ##Get a temporary file, delete it, but save the path
136
+ #temp = Tempfile.new SecureRandom.hex
137
+ #path = temp.path
138
+ #temp.close
139
+ #temp.unlink
140
+
141
+ #`ruby -Ilib ./bin/flok new #{path}`
142
+ #gem_root_path = File.expand_path(File.dirname(__FILE__))+"/.."
143
+ #Dir.chdir path do
144
+ #`ruby -I#{gem_root_path}/lib #{gem_root_path}/bin/flok build`
145
+ ##str = File.read("./public/application.js")
146
+ #ctx = V8::Context.new
147
+ #ctx.load("./public/application.js")
148
+ ##ExecJS.compile(str)
149
+ ##it does not throw an error
150
+ #end
151
+ #end
152
+
153
+ #it "supports build --compress, which makes a smaller js file" do
154
+ ##Get a temporary file, delete it, but save the path
155
+ #temp = Tempfile.new SecureRandom.hex
156
+ #path = temp.path
157
+ #temp.close
158
+ #temp.unlink
159
+
160
+ #uncompressed_length = 0
161
+ #compressed_length = 0
162
+ #`ruby -Ilib ./bin/flok new #{path}`
163
+ #gem_root_path = File.expand_path(File.dirname(__FILE__))+"/.."
164
+ #Dir.chdir path do
165
+ #`ruby -I#{gem_root_path}/lib #{gem_root_path}/bin/flok build`
145
166
  #str = File.read("./public/application.js")
146
- ctx = V8::Context.new
147
- ctx.load("./public/application.js")
148
- #ExecJS.compile(str)
149
- #it does not throw an error
150
- end
151
- end
152
-
153
- it "supports build --compress, which makes a smaller js file" do
154
- #Get a temporary file, delete it, but save the path
155
- temp = Tempfile.new "flok-temp"
156
- path = temp.path
157
- temp.close
158
- temp.unlink
159
-
160
- uncompressed_length = 0
161
- compressed_length = 0
162
- `ruby -Ilib ./bin/flok new #{path}`
163
- gem_root_path = File.expand_path(File.dirname(__FILE__))+"/.."
164
- Dir.chdir path do
165
- `ruby -I#{gem_root_path}/lib #{gem_root_path}/bin/flok build`
166
- str = File.read("./public/application.js")
167
- uncompressed_length = str.length
168
-
169
- `ruby -I#{gem_root_path}/lib #{gem_root_path}/bin/flok build --compress`
170
- str = File.read("./public/application.js")
171
- compressed_length = str.length
172
- expect(compressed_length).to be < uncompressed_length
173
- #it does not throw an error
174
- end
175
- end
176
-
177
- it "supports build --compress, which makes a smaller js file (that still contains something)" do
178
- #Get a temporary file, delete it, but save the path
179
- temp = Tempfile.new "flok-temp"
180
- path = temp.path
181
- temp.close
182
- temp.unlink
183
-
184
- `ruby -Ilib ./bin/flok new #{path}`
185
- gem_root_path = File.expand_path(File.dirname(__FILE__))+"/.."
186
- Dir.chdir path do
187
- `ruby -I#{gem_root_path}/lib #{gem_root_path}/bin/flok build --compress`
188
- str = File.read("./public/application.js")
189
- expect(str.length).to be > 0
190
- #it does not throw an error
191
- end
192
- end
193
-
194
- it "creates an application.js that is executable by js when compress" do
195
- #Get a temporary file, delete it, but save the path
196
- temp = Tempfile.new "flok-temp"
197
- path = temp.path
198
- temp.close
199
- temp.unlink
200
-
201
- `ruby -Ilib ./bin/flok new #{path}`
202
- gem_root_path = File.expand_path(File.dirname(__FILE__))+"/.."
203
- Dir.chdir path do
204
- `ruby -I#{gem_root_path}/lib #{gem_root_path}/bin/flok build --compress`
205
- ctx = V8::Context.new
206
- ctx.load("./public/application.js")
207
- #it does not throw an error
208
- end
209
- end
210
- end
167
+ #uncompressed_length = str.length
168
+
169
+ #`ruby -I#{gem_root_path}/lib #{gem_root_path}/bin/flok build --compress`
170
+ #str = File.read("./public/application.js")
171
+ #compressed_length = str.length
172
+ #expect(compressed_length).to be < uncompressed_length
173
+ ##it does not throw an error
174
+ #end
175
+ #end
176
+
177
+ #it "supports build --compress, which makes a smaller js file (that still contains something)" do
178
+ ##Get a temporary file, delete it, but save the path
179
+ #temp = Tempfile.new SecureRandom.hex
180
+ #path = temp.path
181
+ #temp.close
182
+ #temp.unlink
183
+
184
+ #`ruby -Ilib ./bin/flok new #{path}`
185
+ #gem_root_path = File.expand_path(File.dirname(__FILE__))+"/.."
186
+ #Dir.chdir path do
187
+ #`ruby -I#{gem_root_path}/lib #{gem_root_path}/bin/flok build --compress`
188
+ #str = File.read("./public/application.js")
189
+ #expect(str.length).to be > 0
190
+ ##it does not throw an error
191
+ #end
192
+ #end
193
+
194
+ #it "creates an application.js that is executable by js when compress" do
195
+ ##Get a temporary file, delete it, but save the path
196
+ #temp = Tempfile.new SecureRandom.hex
197
+ #path = temp.path
198
+ #temp.close
199
+ #temp.unlink
200
+
201
+ #`ruby -Ilib ./bin/flok new #{path}`
202
+ #gem_root_path = File.expand_path(File.dirname(__FILE__))+"/.."
203
+ #Dir.chdir path do
204
+ #`ruby -I#{gem_root_path}/lib #{gem_root_path}/bin/flok build --compress`
205
+ #ctx = V8::Context.new
206
+ #ctx.load("./public/application.js")
207
+ ##it does not throw an error
208
+ #end
209
+ #end
210
+ #end
@@ -1,5 +1,94 @@
1
+ require 'phantomjs'
2
+ require 'rspec/wait'
3
+ require 'webrick'
4
+ require "./spec/helpers"
5
+ require 'json'
6
+
1
7
  RSpec.describe "Drivers::Net" do
2
- it "Creates a new module folder with absolute path" do
3
- expect(3).to be(4)
8
+ before(:all) do
9
+ #Respond to kill
10
+ @killable = []
11
+ end
12
+
13
+ after(:all) do
14
+ @killable ||= []
15
+ @killable.each {|p| p.kill}
16
+
17
+ #Stopgap to kill everything
18
+ `ps -ax | grep net_spec | awk '{print $1}' | grep -v #{Process.pid} | xargs kill -9`
19
+ `ps -ax | grep phantomjs| awk '{print $1}' | xargs kill -9`
20
+ end
21
+
22
+ it "can make a get request" do
23
+ #Build driver
24
+ `cd ./app/drivers/browser; rake build`
25
+
26
+ cr = ChromeRunner.new "./products/drivers/browser.js"
27
+
28
+ #Setup rspec test server
29
+ called = false
30
+ spek = Webbing.get "/" do |params|
31
+ called = true
32
+ {"hello" => "world"}.to_json
33
+ end
34
+ @killable << spek
35
+ cr.eval "drivers.network.request('GET', 'http://localhost:#{spek.port}', {})"
36
+ cr.commit
37
+
38
+ #Load synchronously, but execute the code asynchronously, quit after it's been running for 3 seconds
39
+ wait(3).for { called }.to eq(true)
40
+ end
41
+
42
+ it "can make a get request with parameters" do
43
+ #Build driver
44
+ `cd ./app/drivers/browser; rake build`
45
+
46
+ cr = ChromeRunner.new "./products/drivers/browser.js"
47
+
48
+ #Setup rspec test server
49
+ called = false
50
+ result = {}
51
+ spek = Webbing.get "/" do |params|
52
+ result = params
53
+ called = true
54
+ {"hello" => "world"}.to_json
55
+ end
56
+ @killable << spek
57
+ cr.eval "drivers.network.request('GET', 'http://localhost:#{spek.port}', {'a':'b'})"
58
+ cr.commit
59
+
60
+ #Load synchronously, but execute the code asynchronously, quit after it's been running for 3 seconds
61
+ wait(3).for { called }.to eq(true)
62
+ expect(result).to eq({'a' => 'b'})
63
+ end
64
+
65
+ it "can make a get and respond from callback" do
66
+ #Build driver
67
+ `cd ./app/drivers/browser; rake build`
68
+
69
+ cr = ChromeRunner.new "./products/drivers/browser.js"
70
+
71
+ #Setup rspec test server
72
+ @spek = Webbing.get "/" do |params|
73
+ {"port" => @spek2.port}.to_json
74
+ end
75
+
76
+ called = false
77
+ @spek2 = Webbing.get "/" do |params|
78
+ called = true
79
+ end
80
+
81
+ @killable << @spek
82
+ @killable << @spek2
83
+ cr.eval %{
84
+ drivers.network.request('GET', 'http://localhost:#{@spek.port}', {}, function(res) {
85
+ port = res.port;
86
+ drivers.network.request('GET', 'http://localhost:'+port, {});
87
+ })
88
+ }
89
+ cr.commit
90
+
91
+ ##Load synchronously, but execute the code asynchronously, quit after it's been running for 3 seconds
92
+ wait(3).for { called }.to eq(true)
4
93
  end
5
94
  end
data/spec/helpers.rb ADDED
@@ -0,0 +1,129 @@
1
+ require 'securerandom'
2
+
3
+ #Duplex pipe
4
+ ###################################################################################################################
5
+ class IO
6
+ def self.duplex_pipe
7
+ return DuplexPipe.new
8
+ end
9
+ end
10
+
11
+ class DuplexPipe
12
+ def initialize
13
+ @r0, @w0 = IO.pipe
14
+ @r1, @w1 = IO.pipe
15
+ end
16
+
17
+ #Choose arbitrary side, just different ones for forked processes
18
+ def claim_low
19
+ @r = @r0
20
+ @w = @w1
21
+ end
22
+
23
+ def claim_high
24
+ @r = @r1
25
+ @w = @w0
26
+ end
27
+
28
+ def write msg
29
+ @w.write msg
30
+ end
31
+
32
+ def puts msg
33
+ @w.puts msg
34
+ end
35
+
36
+ def readline
37
+ @r.readline
38
+ end
39
+ end
40
+ ###################################################################################################################
41
+
42
+ #RESTful mock
43
+ ###################################################################################################################
44
+ module Webbing
45
+ def self.get path, &block
46
+ Webbing.new "GET", path, &block
47
+ end
48
+
49
+ class Webbing
50
+ attr_accessor :pid
51
+ attr_accessor :port
52
+
53
+ def kill
54
+ puts "killing #{@pid}"
55
+ Process.kill("KILL", @pid)
56
+ end
57
+
58
+ def initialize verb, path, &block
59
+ @verb = verb
60
+ @path = path
61
+ @block = block
62
+ @port = rand(30000)+3000
63
+
64
+ @pipe = IO.duplex_pipe
65
+ @pid = fork do
66
+ @pipe.claim_high
67
+ @server = WEBrick::HTTPServer.new :Port => @port, :DocumentRoot => ".", :StartCallback => Proc.new {
68
+ @pipe.puts("ready")
69
+ }
70
+ @server.mount_proc '/' do |req, res|
71
+ @pipe.puts req.query.to_json
72
+ res.body = @pipe.readline
73
+ res.header["Access-Control-Allow-Origin"] = "*"
74
+ res.header["Content-Type"] = "json/text"
75
+ end
76
+ @server.start
77
+ end
78
+
79
+ @pipe.claim_low
80
+ @pipe.readline #Wait for 'ready'
81
+ Thread.new do
82
+ begin
83
+ loop do
84
+ params = JSON.parse(@pipe.readline)
85
+ res = @block.call(params)
86
+ @pipe.puts res.to_json
87
+ end
88
+ rescue => e
89
+ puts "Exception: #{e.inspect}"
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ ###################################################################################################################
96
+
97
+ #Mock chrome javascript running (Will not do anything until you run commit)
98
+ #Meant to be for one shot tests
99
+ #(1) load with --- cr = ChromeRunner.new('code.js')
100
+ #(2) queue execute with --- cr.eval('console.log("hello world");')
101
+ #(3) run in it's own process via --- cr.commit
102
+ ###################################################################################################################
103
+ class ChromeRunner
104
+ #Load a javascript file
105
+ def initialize fn
106
+ @code = File.read(fn)
107
+ @code << "\n"
108
+ end
109
+
110
+ def eval(code)
111
+ @code << code
112
+ @code << "\n"
113
+ end
114
+
115
+ def commit
116
+ file = Tempfile.new SecureRandom.hex
117
+ file.write @code
118
+
119
+ @pid = fork do
120
+ system("phantomjs #{file.path}")
121
+ end
122
+ end
123
+
124
+ def kill
125
+ puts "killing #{@pid}"
126
+ Process.kill("KILL", @pid)
127
+ end
128
+ end
129
+ ###################################################################################################################
@@ -1,68 +1,68 @@
1
- require './lib/flok.rb'
2
- require 'tempfile'
3
- require 'securerandom'
4
- require 'v8'
1
+ #require './lib/flok.rb'
2
+ #require 'tempfile'
3
+ #require 'securerandom'
4
+ #require 'v8'
5
5
 
6
- def ensure_tmp
7
- tmp_spec_path = './spec/tmp'
8
- Dir.mkdir(tmp_spec_path) unless File.exists?(tmp_spec_path)
9
- end
6
+ #def ensure_tmp
7
+ #tmp_spec_path = './spec/tmp'
8
+ #Dir.mkdir(tmp_spec_path) unless File.exists?(tmp_spec_path)
9
+ #end
10
10
 
11
- RSpec.describe "Flok::MergeSourceSpec" do
12
- it "when merging the kernel, it returns a string" do
13
- str = Flok::MergeSource.merge_kernel
14
- expect(str.class).to be(String)
15
- end
11
+ #RSpec.describe "Flok::MergeSourceSpec" do
12
+ #it "when merging the kernel, it returns a string" do
13
+ #str = Flok::MergeSource.merge_kernel
14
+ #expect(str.class).to be(String)
15
+ #end
16
16
 
17
- it "when merging the kernel, it returns a string with length" do
18
- str = Flok::MergeSource.merge_kernel
19
- expect(str.length).to be > 0
20
- end
17
+ #it "when merging the kernel, it returns a string with length" do
18
+ #str = Flok::MergeSource.merge_kernel
19
+ #expect(str.length).to be > 0
20
+ #end
21
21
 
22
- it "when merging the kernel, the kernel files located in ./lib/js/kernel/ do merge and run without js syntax errors" do
23
- str = Flok::MergeSource.merge_kernel
24
- ctx = V8::Context.new
25
- ctx.eval(str)
22
+ #it "when merging the kernel, the kernel files located in ./lib/js/kernel/ do merge and run without js syntax errors" do
23
+ #str = Flok::MergeSource.merge_kernel
24
+ #ctx = V8::Context.new
25
+ #ctx.eval(str)
26
26
 
27
- #It does not throw an error
28
- end
27
+ ##It does not throw an error
28
+ #end
29
29
 
30
- it "merges the user generated source files from app/*.js" do
31
- #Get a temporary file, delete it, but save the path
32
- temp = Tempfile.new "flok-temp"
33
- path = temp.path
34
- temp.close
35
- temp.unlink
30
+ #it "merges the user generated source files from app/*.js" do
31
+ ##Get a temporary file, delete it, but save the path
32
+ #temp = Tempfile.new "flok-temp"
33
+ #path = temp.path
34
+ #temp.close
35
+ #temp.unlink
36
36
 
37
- #Create a new project
38
- `ruby -Ilib ./bin/flok new #{path}`
37
+ ##Create a new project
38
+ #`ruby -Ilib ./bin/flok new #{path}`
39
39
 
40
- #Add a source function to this project
41
- main_js = %{
42
- function call_me_maybe() {
43
- return call_me_maybe_response;
44
- }
45
- }
40
+ ##Add a source function to this project
41
+ #main_js = %{
42
+ #function call_me_maybe() {
43
+ #return call_me_maybe_response;
44
+ #}
45
+ #}
46
46
 
47
- two_js = %{
48
- var call_me_maybe_response = "no_way";
49
- }
47
+ #two_js = %{
48
+ #var call_me_maybe_response = "no_way";
49
+ #}
50
50
 
51
- File.write "#{path}/app/main.js", main_js
52
- File.write "#{path}/app/two.js", two_js
51
+ #File.write "#{path}/app/main.js", main_js
52
+ #File.write "#{path}/app/two.js", two_js
53
53
 
54
- #Build
55
- rpath = Dir.pwd
56
- Dir.chdir path do
57
- `ruby -I#{rpath}/lib #{rpath}/bin/flok build`
54
+ ##Build
55
+ #rpath = Dir.pwd
56
+ #Dir.chdir path do
57
+ #`ruby -I#{rpath}/lib #{rpath}/bin/flok build`
58
58
 
59
- #Execute
60
- Dir.chdir './public' do
61
- ctx = V8::Context.new
62
- ctx.load "application.js"
63
- res = ctx.eval("call_me_maybe()")
64
- expect(res).to eq("no_way")
65
- end
66
- end
67
- end
68
- end
59
+ ##Execute
60
+ #Dir.chdir './public' do
61
+ #ctx = V8::Context.new
62
+ #ctx.load "application.js"
63
+ #res = ctx.eval("call_me_maybe()")
64
+ #expect(res).to eq("no_way")
65
+ #end
66
+ #end
67
+ #end
68
+ #end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flok
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - seo
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '1.9'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-wait
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: thor
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -137,10 +151,10 @@ files:
137
151
  - LICENSE
138
152
  - README.md
139
153
  - Rakefile
154
+ - app/drivers/browser/Rakefile
155
+ - app/drivers/browser/network.js
156
+ - app/drivers/browser/vendor/jquery.js
140
157
  - bin/flok
141
- - drivers/chromium/Rakefile
142
- - drivers/chromium/jquery.min.js
143
- - drivers/chromium/network.js
144
158
  - flok.gemspec
145
159
  - lib/flok.rb
146
160
  - lib/flok/version.rb
@@ -153,6 +167,7 @@ files:
153
167
  - logo.png
154
168
  - spec/cli_spec.rb
155
169
  - spec/drivers/net_spec.rb
170
+ - spec/helpers.rb
156
171
  - spec/merge_source_spec.rb
157
172
  homepage: https://github.com/sotownsend/flok
158
173
  licenses:
@@ -181,4 +196,5 @@ summary: A boring javascript application framework
181
196
  test_files:
182
197
  - spec/cli_spec.rb
183
198
  - spec/drivers/net_spec.rb
199
+ - spec/helpers.rb
184
200
  - spec/merge_source_spec.rb
@@ -1,17 +0,0 @@
1
- require 'tempfile'
2
-
3
- def compile
4
- out = ""
5
- out << "drivers = {};\n"
6
-
7
- Dir["*.js"].each {|fn| out << File.read(fn) }
8
- return out
9
- end
10
-
11
- task :compile do |out|
12
- end
13
-
14
- task :test do
15
- out = compile
16
- puts out
17
- end
@@ -1,16 +0,0 @@
1
- drivers.network = {}
2
-
3
- $(document).ready(function() {
4
- drivers.network.request("GET", "http://test.services.fittr.com/ping", {}, null);
5
- })
6
-
7
- drivers.network.request = function(verb, url, params, completion) {
8
- $.ajax({
9
- url: url,
10
- type: verb,
11
- success: function(data) {
12
- },
13
- error: function(xhr, status, err) {
14
- }
15
- })
16
- }