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!
Install CoffeeScript (one mildly roundabout approach follows):
-
Install homebrew
ruby -e "$(curl -fsSL https://gist.github.com/raw/323731/install_homebrew.rb)"
-
Install node.js
brew install node
-
Install npm
curl http://npmjs.org/install.sh | sh
-
Install CoffeeScript
npm install -g coffee-script
Run this project:
-
Install Bundler
gem install bundler
-
Clone this repo somewhere:
git clone git://github.com/searls/jasmine-coffee.git && cd jasmine-coffee
-
Tell Bundler to install Sinatra, CoffeeScript, and rack-coffee
bundle install
-
Run Sinatra to start serving up everything
bundle exec ruby sinatra.rb
-
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).
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.
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/pants.coffee
and a spec public/spec/pants-spec.coffee
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() {
alert("Pants!");
}).call(this);
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.