Skip to content
An Interface Compatibility Suite for Ruby Embeddings of Javascript.
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Shared specs for a Ruby interface to JavaScript.

Useful for different JavaScript interpreters wanting to present a unified interface to Ruby.

Currently used by :


You'll need RSpec to use the specs RedJS provides.

add this your spec_helper.rb :

require 'redjs'
module RedJS
  Context = MyECMA::Context # e.g. V8::Context
  Error   = MyECMA::JSError # e.g. Rhino::JSError

add spec/redjs_spec.rb similar to this :

require File.expand_path('../spec_helper', File.dirname(__FILE__))

require 'redjs/load_specs'

describe MyJS::Context do

  it_behaves_like 'RedJS::Context'


Filter particular specs

In case you need to conform with specs defined in a higher version number but can't pass specs from a previous version, you might (temporarily) exclude 'em :

# Gemfile :
gem 'redjs', :branch => "0.6", 
    :git => 'git://'

# spec_helper.rb :
RSpec.configure do |config|
  config.filter_run_excluding :compat => /(0.4.4)|(0.5.0)/

API Requirements


  • should be instantiable using new without arguments or with a hash of options
  • desired options passed to :
    • :with emulates JavaScript's with statement (provides a shorthand for writing recurring accesses to the passed objects)
  • if a block is provided should yield the context instance
  • contexts provide an eval method for evaluating JavaScript code
  • context instances implement [] for exposing Ruby instances to JavaScript do |context|
  context["math"] =
  context.eval(", 22)") #=> 42


  • common error class for propagating errors that occur in JS into the Ruby side
Something went wrong with that request. Please try again.