Sha256: f783bcdba22cb78c2359b204565ea08b3204a98431f4e9cd70810e91a2f8f101

Contents?: true

Size: 1.89 KB

Versions: 6

Compression:

Stored size: 1.89 KB

Contents

require 'fileutils'
require 'erb'

module Shenandoah
  class Runner
    def initialize(locator, options = {})
      @locator = locator
      @quiet = options[:quiet]
    end

    # Runs the specified specs.  Returns an array of the specs that passed.
    def run_console(specs)
      FileUtils.cd @locator.spec_path do
        runner_cmd = rhino_command(shen_path_to('lib/shenandoah/javascript/console/runner.js'))
        args = [
          shen_path_to,
          @locator.main_path,
          @locator.spec_path
        ]

        return specs.select { |spec|
          system("#{runner_cmd} '#{args.join("' '")}' '#{spec.sub(%r{^#{@locator.spec_path}/}, '')}' #{@quiet ? '> /dev/null' : ''}")
        }
      end
    end

    def run_shell
      create_shell_html
      create_shell_js

      rlwrap = `which rlwrap`.chomp.sub(/^no.*/, '') # some versions of which report errors on stdout
      cmd = "#{rlwrap} #{rhino_command('-f', shell_js_path, '-f', '-')}"
      $stderr.puts "Starting shell with #{cmd}"
      system(cmd)
    end

    private

    def shen_path_to(file=nil)
      File.expand_path(File.dirname(__FILE__) + "/../../#{file}")
    end
    alias :shenandoah_root :shen_path_to

    def rhino_command(*args)
      "java -jar '#{shen_path_to 'lib/shenandoah/javascript/console/js.jar'}' -w -debug '#{args.join("' '")}'"
    end

    def shell_html_path
      "#{@locator.tmp_path}/shell.html"
    end

    def shell_js_path
      "#{@locator.tmp_path}/shell.js"
    end

    def create_shell_html
      FileUtils.mkdir_p File.dirname(shell_html_path)
      File.open(shell_html_path, 'w') do |f|
        f.write "<html><body></body></html>"
      end
    end

    def create_shell_js
      js = ERB.new(File.read(shen_path_to('lib/shenandoah/javascript/console/shell.js.erb'))).result(binding)
      FileUtils.mkdir_p File.dirname(shell_js_path)
      File.open(shell_js_path, 'w') { |f| f.write js }
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
rsutphin-shenandoah-0.1.1 lib/shenandoah/runner.rb
rsutphin-shenandoah-0.1.2 lib/shenandoah/runner.rb
shenandoah-0.2.0 lib/shenandoah/runner.rb
shenandoah-0.1.3 lib/shenandoah/runner.rb
shenandoah-0.1.1 lib/shenandoah/runner.rb
shenandoah-0.1.2 lib/shenandoah/runner.rb