Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
76 lines (39 sloc) 3.5 KB

Jasmine + CoffeeScript + Sinatra (w/rack-coffee) -> Fast feedback!

So, you want to use Jasmine for TDD/BDD and you want to use CoffeeScript for sparing your keyboard's poor '{' and '}' keys from any more abuse? Well, then here's a skeleton project for you!

Get up and running

Install CoffeeScript (one mildly roundabout approach follows):

  1. Install homebrew

     ruby -e "$(curl -fsSL"
  2. Install node.js

     brew install node
  3. Install npm

     curl | sh
  4. Install CoffeeScript

     npm install -g coffee-script

Run this project:

  1. Install Bundler

     gem install bundler 
  2. Clone this repo somewhere:

     git clone git:// && cd jasmine-coffee
  3. Tell Bundler to install Sinatra, CoffeeScript, and rack-coffee

     bundle install
  4. Run Sinatra to start serving up everything

     bundle exec ruby sinatra.rb
  5. Visit the spec runner in your browser:

     open http://localhost:4567/SpecRunner.html

Now you're cooking with gas (and perhaps trying to avoid thinking about how putting Jasmine in Coffee would actually taste).

This project's example code

To help get you started, this project includes an example class called "ReducesUrls" with a #reduce method that will take a URL string and break it up into its components (e.g. host, port, query string, and a parameter object of what was on the query string). To see how it works, check out the spec.

Adding your own CoffeeScript

In short: add CoffeeScripts to public/src and public/spec with a ".coffee" extension. They'll be accessible from the web with a ".js" extension, which is how you'll want to reference them from your SpecRunner.html file.

For example, let's say you want to write a script about pants. You would simply create a source public/src/ and a spec public/spec/ and fill them up with CoffeeScript. Or a silly alert:

alert "Pants!"

To see that they get loaded as JavaScript in the browser, the SpecRunner should include:

<script type="text/javascript" src="src/pants.js"></script>
<script type="text/javascript" src="spec/pants-spec.js"></script>

Upon loading the SpecRunner in a browser, you should see your alert and, upon inspection, be able to take a look at the generated CoffeeScript. Which, at the time of this writing, would look a little like:

(function() {

Go forth!

Now all you have to do is go write code. If you'd like an intro on getting started with Jasmine (in JavaScript), I've posted a presentation and another example standalone project on github.