File: runtime_spec.rb

package info (click to toggle)
jruby 9.3.9.0%2Bds-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 80,856 kB
  • sloc: ruby: 517,823; java: 260,094; xml: 31,930; ansic: 5,777; yacc: 4,973; sh: 1,163; makefile: 105; jsp: 48; tcl: 40; exp: 11
file content (56 lines) | stat: -rw-r--r-- 1,876 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

describe Java::OrgJruby::Ruby do

  before do
    @config = Java::OrgJruby::Ruby.get_global_runtime.instance_config
  end

  context "runtime with rspec" do

    before do
      @runtime = new_runtime(Java::OrgJruby::RubyInstanceConfig.new(@config))
      @runtime.evalScriptlet("require 'rubygems'")
      # setup rspec but disable autorun - we'll run ourselves :
      @runtime.evalScriptlet("require 'rspec/core'")
      @runtime.evalScriptlet("RSpec::Core::Runner.disable_autorun!")
      # helper OUT/ERR streams to use when running specs :
      @runtime.evalScriptlet("require 'stringio'")
      @runtime.evalScriptlet("ERR_IO = StringIO.new")
      @runtime.evalScriptlet("OUT_IO = StringIO.new")
    end

    after do
      @runtime.tear_down
    end

    it "should pass profile_data_spec" do
      check_passed_spec @runtime.evalScriptlet("RSpec::Core::Runner.run([ 'spec/profiler/profile_data_spec.rb' ], ERR_IO, OUT_IO)")
    end

    it "should pass profiler_basics_spec" do
      check_passed_spec @runtime.evalScriptlet("RSpec::Core::Runner.run([ 'spec/profiler/profiler_basics_spec.rb' ], ERR_IO, OUT_IO)")
    end

    it "should pass graph_profile_printer_spec" do
      check_passed_spec @runtime.evalScriptlet("RSpec::Core::Runner.run([ 'spec/profiler/graph_profile_printer_spec.rb' ], ERR_IO, OUT_IO)")
    end

    def check_passed_spec(exit_status)
      # print any errors if occured :
      @runtime.evalScriptlet("puts ERR_IO.string unless ERR_IO.string.empty?")
      expect( passed = (exit_status == 0) ).to be true
    ensure
      unless passed
        puts "spec not passed, output: \n"
        @runtime.evalScriptlet("puts OUT_IO.string")
      end
    end

  end

  def new_runtime(config = Java::OrgJruby::RubyInstanceConfig.new)
    config.processArguments(['-I.', '--profile.api'])
    Java::OrgJruby::Ruby.newInstance(config)
  end

end