• Stars
    star
    478
  • Rank 91,950 (Top 2 %)
  • Language
    Ruby
  • Created over 13 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Pain free coffeescript testing under Rails 3.1

Jasminerice

Utilizing Jasmine and taking full advantage of the Rails 3.1 asset pipeline Jasminerice removes any excuse YOU have for not testing your out of control sprawl of CoffeeScript files.

This project rocks and uses the MIT-LICENSE.

Development Notice

Brad Phelan is no longer actively developing this project but is accepting reasonable pull requests, so continue on with contributing.

This project is looking for a home :)

2013/1/17:

Brad (bradphelan) posted a notice saying that he wasn't actively maintaining the project and that it was looking for a home.

2013/1/27:

I (jejacks0n) offered to contribute to the project, and Brad granted me collaboration privileges. I added some specs and integration tests that will make contributing a little easier.

We'll be managing pull requests and issues together, and if someone would like to take over and move it to a different home you should contact Brad directly.

Headless Testing

See guard-jasmine for details.

Installation

This gem has been tested and run with Rails 3.1 and 3.2. It should also run on Rails 4.

Just include it in your Gemfile:

group :development, :test do
  gem "jasminerice", :git => 'https://github.com/bradphelan/jasminerice.git'
end

The engine is automatically mounted into your application in the development and test environments. If you'd like to change that behavior, you can change which groups the gem is included in via the gemfile.

Optionally, you can run the installer.

rails g jasminerice:install

This will add the required spec.js.coffee, an example spec, and fixture to help get you started. It will also add a intializer config/initializers/jasminerice.rb which can be used for easy setup of Jasminerice's options.

Usage

CoffeeScripts

Create a file spec/javascripts/spec.js.coffee (or run the install generator), and add the following content.

#= require_tree ./

In the case where you need access to all your application javascripts then you can use something like the following, which will pull in all the files from your application and all specs from the javascripts directory.

#= require_tree ./
#= require_tree ../../app/assets/javascripts

The Rails 3.1 asset pipeline using Sprockets and Tilt ensure conversion to javascript.

You can also use the #= require directive in your specs to pull in dependencies manually. Here's an example spec/javascripts/example_spec.js.coffee:

#= require foo
#= require bar

describe "Foo", ->
  it "it is not bar", ->
    v = new Foo()
    expect(v.bar()).toEqual(false)

describe "Bar", ->
  it "it is not foo", ->
    v = new Bar()
    expect(v.foo()).toEqual(false)

Stylesheets

For including stylesheets in your specs, Jasminerice uses spec/javascripts/spec.css. You can use Sprockets directives to include css files here.

/*= require application
 */

Fixtures

Jasminerice makes files located in the spec/javascripts/fixtures directory available as fixture. For example, if you put a file named example_fixture.html.haml in that path it will be available at the /jasmine/fixtures/example_fixture URL.

spec/javascripts/fixtures/example_fixture.html.haml

%h2 Test Fixture
%p Using fixtures

Since Jasminerice automatically makes a patched version of jasmine-jquery available in your specs, you can load the example fixture in your spec with the following.

loadFixtures('example_fixture')

You can also load JSON fixtures, e.g. spec/javascripts/fixtures/json/bar.json

getJSONFixture('bar')

Helper Methods

You can declare Jasminerice::SpecHelper (perhaps put inside lib/) to make helpers available to jasminerice fixtures.

So in your lib directory, create the helper, e.g. lib/jasminerice/spec_helper.rb

module Jasminerice
  module SpecHelper
    def print_a_test
      "foo"
    end
  end
end

Then you can use it in your fixtures.

spec/javascripts/fixtures/example_fixture.html.haml

%h1 Here is my helper
= print_a_test

Running Specs

Start your server...

rails s

Browse to...

http://localhost:3000/jasmine

Watch your specs run.

Asset debugging

You can override your current environment's config.assets.debug configuration per request by adding ?debug=false or ?debug=true to the jasmine path, eg.

http://localhost:3000/jasmine?debug=false

This will concatenate all your css and javascript into single file which can improve your suite's loading speed significantly.

Compatibility with Require.js

If you use Require.js in your project and need to load your modules in your jasmine specs, there is an option to prevent jasminerice from automatically executing the test runner before the modules are defined. This enables you to start the execution manually whenever you want in your spec/javascripts/spec.js.coffee file:

#= require your/specs/and/other/stuff
# at the end of this file add:

jasmine.rice.autoExecute = false

define 'jasmine.waitsfor.requirejs', ->
require ['jasmine.waitsfor.requirejs'], jasmine.getEnv().execute

The shown example defines a dummy module in require.js that is required immediately on the next line. This is a simple hack to wait until require.js has initialized all modules and start the jasmine runner after that.

Of course you can use jasmine.rice.autoExecute = false also for all other cases where you need to control when your specs should be executed!

Author

More Repositories

1

rocket_tag

modern high performance tagging library for Rails 3.1 +
Ruby
149
star
2

immer.loves.svelte

TypeScript
55
star
3

SketchSolve.NET

SketchSolve ported to ( Wrapped ) for .NET
C#
9
star
4

FUNCUI.Samples

FUNCUI.Samples
F#
8
star
5

svelt3

Svelte wrapper for threejs designed to be easily extendible with minimal code
Svelte
7
star
6

ohmyderdiedas

German Language Trainer
JavaScript
7
star
7

Active-Illusion

Create read only models backed by queries not by tables
Ruby
6
star
8

wkhtmltopdf-osx

Gem for using wkhtmltopdf on osx.
Ruby
3
star
9

vimgonesurfing

Usefull vim scripts from Brad Phelan
Vim Script
2
star
10

DMValidatorFramework

Objective-C
2
star
11

openkitchen

rails backend for gobbq
Ruby
2
star
12

ImmutableObjectGraphLens

Add functional and composable lenses to the immutable object graph
C#
1
star
13

rest_kat

Ruby
1
star
14

emu-eggs

Based on snippetsEmu each snippet is factored out into a separate file
Vim Script
1
star
15

ofcourse

U3A Course manager
Ruby
1
star
16

vimrc

my vimrc file
Vim Script
1
star
17

wkhtmltopdf-rails

Meta gem depending on wkhtmltopdf-osx and wkhtmltopdf-heroku
1
star
18

loopdi

Live looper ( maybe oneday )
C#
1
star
19

Shambolics

Symbolic calculus for fsharp
F#
1
star
20

proxymock

TODO: one-line summary of your gem
Ruby
1
star
21

kinderhaus

css & php & html for kinderhaus.at
1
star
22

FSharpWPFReactiveTest

F#
1
star
23

bradgonecooking

Usefull Chef Cookbooks
Ruby
1
star
24

slackjax

Provides a slack client to enter math via wpf-math renderer
C#
1
star
25

forminator

JavaScript
1
star
26

thisfile

TODO: one-line summary of your gem
Ruby
1
star
27

acts_as_challenged

An achievements/challenge engine for your rails application
Ruby
1
star
28

svelte-x3dom-demo

A demo of using x3domn with svelte
JavaScript
1
star
29

sfml-test

C++
1
star