spec/etc/services_compiler_spec.rb in flok-0.0.36 vs spec/etc/services_compiler_spec.rb in flok-0.0.38

- old
+ new

@@ -2,40 +2,59 @@ require './lib/flok' require './spec/env/etc' RSpec.describe "lib/services_compiler" do #Return a v8 instance of a compiled js file - def compile fn + def compile fn, config compiler = Flok::ServicesCompiler js_src(fn) - js_res = compiler.compile(js_src(fn)) + js_res = compiler.compile(js_src(fn), js_src(config)) ctx = V8::Context.new ctx.eval js_res - ctx + + return ctx, js_res end #Get the source for a file in ./service_compiler/*.rb def js_src fn Dir.chdir File.join(File.dirname(__FILE__), "service_compiler") do return File.read(fn+'.rb') end end - it "Can call compile method and get on_init" do - ctx = compile "service0" - - #The service defines a variable in on_init, this should be always accessible - res = ctx.eval("test_service_var") - expect(res).to eq(true) + it "Does fail to compile a controller with a non-existant type" do + expect { compile "service_bad_type" }.to raise_exception end - it "Can call compile method and get on_request" do - ctx = compile "service0" + it "Can call compile method and get a copy of all the functions" do + ctx, _ = compile "service0", "config0" - #Should be able to call on_request generated request function - ctx.eval('service_test_req({}, 0, "test")') + #on_wakeup + res = ctx.eval("test_on_wakeup") + expect(res).not_to eq(nil) - #That should have set a variable - res = JSON.parse(ctx.eval("JSON.stringify(test_service_request)")) - expect(res).to eq([{}, 0, "test"]) + #on_sleep + res = ctx.eval("test_on_sleep") + expect(res).not_to eq(nil) + + #on_connect + res = ctx.eval("test_on_connect"); + expect(res).not_to eq(nil) + + #on_disconnect + res = ctx.eval("test_on_disconnect") + expect(res).not_to eq(nil) + + #on_event + res = ctx.eval("test_on_hello"); + expect(res).not_to eq(nil) + + #on_handle_timer_events + res = ctx.eval("test_handle_timer_events"); + expect(res).not_to eq(nil) + end + + it "Can call compile method with options" do + ctx, js = compile "service1", "config2" + expect(js).to include("23rntoheuh3nthoeunthn23th"); end end