Sha256: 3d58fc04598cad009b55d1cf09822a5aa9655ad61dfd86e224e8aff2dcfe6351

Contents?: true

Size: 1.51 KB

Versions: 5

Compression:

Stored size: 1.51 KB

Contents

require "rubygems"
require "test/unit"

%w(../lib ../ext/spidermonkey).each do |path|
  $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), path)))
end

# If the test isn't running from Rake, make sure the extension's current.
Rake rescue Dir.chdir(File.dirname(__FILE__) + "/..") { %x(rake extensions) }

require "johnson"

module Johnson
  class TestCase < Test::Unit::TestCase
    class TestLogger
      def debug(string)
        puts string
      end
    end

    undef :default_test if method_defined? :default_test

    def setup
      @runtime = Johnson::Runtime.new
      #@runtime.delegate.gc_zeal = 2
      #@runtime.delegate.debugger = Johnson::SpiderMonkey::Debugger.new(TestLogger.new)
    end
    
    def assert_js(expression, options={})
      runtime = options[:runtime] || @runtime
      assert(runtime.evaluate(expression), "Expected JS expression [#{expression}] to be true.")
    end
    
    def assert_js_equal(expected, expression, options={})
      runtime = options.delete(:runtime) || @runtime
      options.each { |k, v| runtime[k.to_s] = v }
      assert_equal(expected, runtime.evaluate(expression))
    end
  end

  class NodeTestCase < Test::Unit::TestCase
    include Johnson::Nodes
  
    undef :default_test if method_defined? :default_test
    
    def setup
      @parser = Johnson::Parser
    end
  
    def assert_sexp(expected, actual)
      assert_equal(expected, actual.to_sexp)
    end

    def assert_ecma(expected, actual)
      assert_equal(expected, actual.to_ecma)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
jbarnette-johnson-1.0.0.200811251942 test/helper.rb
jbarnette-johnson-1.0.0.20081126120511 test/helper.rb
jbarnette-johnson-1.0.0.20090127202936 test/helper.rb
jbarnette-johnson-1.0.0.20090225110820 test/helper.rb
jbarnette-johnson-1.0.0.20090326122910 test/helper.rb