Sha256: 35cabdf2740bbfc4d4b4c638c442d24a72da6ba4363b7694840fcfd166ab96f5

Contents?: true

Size: 1.76 KB

Versions: 2

Compression:

Stored size: 1.76 KB

Contents

Dir.chdir File.join File.dirname(__FILE__), '../../'
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, config
    compiler = Flok::ServicesCompiler
    js_src(fn)
    js_res = compiler.compile(js_src(fn), js_src(config))
    ctx = V8::Context.new
    ctx.eval js_res

    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 "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 a copy of all the functions" do
     #ctx, _  = compile "service0", "config0"

    ##on_wakeup
    #res = ctx.eval("test_on_wakeup")
    #expect(res).not_to eq(nil)

    ##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

  #If SEND works, then all kernel macros should work
  it "Can compile with a SEND macro" do
     ctx, src  = compile "service3", "config0"

     expect(src).not_to include("SEND")
     expect(src).to include("_q.push")
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flok-0.0.40 spec/etc/services_compiler_spec.rb
flok-0.0.39 spec/etc/services_compiler_spec.rb