Skip to content

Commit

Permalink
make all the stuff work as a gem
Browse files Browse the repository at this point in the history
  • Loading branch information
nu7hatch committed Jul 20, 2012
1 parent cda17e9 commit 7cab655
Show file tree
Hide file tree
Showing 21 changed files with 3,494 additions and 100 deletions.
97 changes: 7 additions & 90 deletions README.md
Expand Up @@ -22,101 +22,18 @@ Or install it yourself as:

## Usage

Create a `spec/jasmine.rb` file and copy following content there (yeah, i'm
too lazy to write a generator for this, feel free to make one and send
me a pull request...):

require File.expand_path('../spec_helper', __FILE__)
require 'rspec/jasmine'

config_ru = File.expand_path('../../config.ru', __FILE__)
app, _ = Rack::Builder.parse_file(config_ru)
selected_suites = ENV['SUITES'].split(':') if !!ENV['SUITES']

Jasmine::SpecRunner.run(self,
:app => app,
:port => 3001,
:suites => selected_suites || %w{/tests.html}
)

Now download [latest version Jasmine](https://github.com/pivotal/jasmine/downloads)
unpack it and place `/lib` folder directly in your public directory. When you
are done, create a tests suite runner file - an html file which ties all this
stuff together, here's an example one (let's say `public/tests.html`):

<!DOCTYPE html>
<html>
<head>
<title>Jasmine Spec Runner</title>

<link rel="shortcut icon" type="image/png" href="/lib/jasmine-1.2.0/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="/lib/jasmine-1.2.0/jasmine.css">

<!-- Jasmine lib files -->
<script type="text/javascript" src="/lib/jasmine-1.2.0/jasmine.js"></script>
<script type="text/javascript" src="/lib/jasmine-1.2.0/jasmine-html.js"></script>

<!--
Your spec files - can be all the scripts separately, or some
nicely combined together with asset pipeline, etc.
-->
<script type="text/javascript" src="/assets/specs.js"></script>

<!-- Jasmine suite runner -->
<script type="text/javascript">
var jsApiReporter;
(function() {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;
jsApiReporter = new jasmine.JsApiReporter();
var htmlReporter = new jasmine.HtmlReporter();
jasmineEnv.addReporter(jsApiReporter);
jasmineEnv.addReporter(htmlReporter);
jasmineEnv.specFilter = function(spec) {
return htmlReporter.specFilter(spec);
};
var currentWindowOnload = window.onload;
window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
execJasmine();
};
function execJasmine() {
jasmineEnv.execute();
}
})();
</script>
</head>
<body>
</body>
</html>

Last thing to do, add following rake task to your `Rakefile`:

namespace :spec do
desc "Runs jasmine specs"
task :jasmine do
require File.expand_path('../spec/jasmine', __FILE__)
end
end

Yeap, we're done. Now you can run your Jasmine test suites with
rake command:
Check the example folder, it's the simples setup of `rspec-jasmine` together
with dummy Sinatra app. The most important files to check are `spec/jasmine.rb`,
`public/tests.html` and `Rakefile`. To run your tests use rake task:

$ rake spec:jasmine

You'll get nice output, formatted with your favorite RSpec formatter.

Probably I should write a generator for this stuff, but so far this is used only
in one project so I'm too lazy for it. If you have spare time you can do so
and send me a pull request.

## Contributing

1. Fork it
Expand Down
1 change: 1 addition & 0 deletions example/.rspec
@@ -0,0 +1 @@
--color
7 changes: 7 additions & 0 deletions example/Gemfile
@@ -0,0 +1,7 @@
source :rubygems

gem 'thin'
gem 'rake'
gem 'sinatra'
gem 'rspec', '>= 2.0'
gem 'rspec-jasmine', :path => '..'
18 changes: 18 additions & 0 deletions example/README.md
@@ -0,0 +1,18 @@
# Example app using RSpec::Jasmine

This is dummy sinatra application with some spec examples.

## Usage

Install dependencies with Bundler:

$ bundle install

Run test suite:

$ rake spec:jasmine

Enjoy!

NOTE: Yeap, one example is failing, it's fine - so you can see how
`rspec-jasmine` handles failed examples.
18 changes: 18 additions & 0 deletions example/Rakefile
@@ -0,0 +1,18 @@
require "rspec/core/rake_task"

desc 'Default: run specs.'
task :default => :spec

desc "Run specs"
RSpec::Core::RakeTask.new do |t|
end

namespace :spec do
desc "Runs jasmine specs"
task :jasmine do
require File.expand_path('../spec/jasmine', __FILE__)
end

desc "Run all test suites"
task :all => [:spec, :'spec:jasmine']
end
5 changes: 5 additions & 0 deletions example/config.ru
@@ -0,0 +1,5 @@
require 'sinatra'

set :public_folder, File.expand_path('../public', __FILE__)

run Sinatra::Application
20 changes: 20 additions & 0 deletions example/public/lib/jasmine-1.2.0/MIT.LICENSE
@@ -0,0 +1,20 @@
Copyright (c) 2008-2011 Pivotal Labs

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0 comments on commit 7cab655

Please sign in to comment.