Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

105 Commits

Repository files navigation

RedJS

https://github.com/cowboyd/redjs

Shared specs for a Ruby interface to JavaScript.

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

Currently used by :

Usage

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

add this your spec_helper.rb :

require'redjs'moduleRedJSContext=MyECMA::Context# e.g. V8::ContextError=MyECMA::JSError# e.g. Rhino::JSErrorend

add spec/redjs_spec.rb similar to this :

requireFile.expand_path('../spec_helper',File.dirname(__FILE__))require'redjs/load_specs'describeMyJS::Contextdoit_behaves_like'RedJS::Context'end

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://github.com/cowboyd/redjs.git'# spec_helper.rb :RSpec.configuredo |config|
config.filter_run_excluding:compat=>/(0.4.4)|(0.5.0)/end

API Requirements

RedJS::Context

  • should be instantiable using new without arguments or with a hash of options
  • desired options passed to Context.new :
    • :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
MyJS::Context.newdo |context|
context["math"]=MyMath.newcontext.eval("math.plus(20, 22)")#=> 42end

RedJS::Error

  • common error class for propagating errors that occur in JS into the Ruby side

About

An Interface Compatibility Suite for Ruby Embeddings of Javascript.

Resources

Stars

7 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages