jasmine-rails-light 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ Copyright 2011 Justin Searls & Mark Van Holstyn
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,134 @@
1
+ # jasmine-rails gem
2
+
3
+ This project is intended to make it a little easier to integrate [Jasmine](https://github.com/pivotal/jasmine/wiki) into your workflow, particularly if you're working in Rails 3.1 or later. (If you're on earlier versions of Rails, I'd suggest directly using the combination of Pivotal's [jasmine gem](https://github.com/pivotal/jasmine-gem) and [jasmine-headless-webkit](http://johnbintz.github.com/jasmine-headless-webkit/).)
4
+
5
+ By bundling this gem and configuring your project, you can expect to:
6
+
7
+ * Be able to run Jasmine specs from the command line (*and fast*) with John Bintz's excellent [jasmine-headless-webkit](http://johnbintz.github.com/jasmine-headless-webkit/)
8
+ * Be able to run Jasmine specs in a browser (wherever you choose to mount the jasmine-rails engine)
9
+ * Write specs or source in [CoffeeScript](http://jashkenas.github.com/coffee-script/), leveraging the [asset pipeline](http://railscasts.com/episodes/279-understanding-the-asset-pipeline) to pre-process it
10
+
11
+ ## Prerequisites
12
+
13
+ Install qt for its headless webkit widget. The easiest way (on a Mac) that I've found is to use [homebrew](https://github.com/mxcl/homebrew):
14
+
15
+ brew install qt
16
+
17
+ For help installing the qt libs on other platforms, the I'd recommend [perusing capybara-webkit driver's documentation](https://github.com/thoughtbot/capybara-webkit), becuse it has the same dependency.
18
+
19
+ ## Adding the gem
20
+
21
+ Add jasmine-rails to your Gemfile, like so
22
+
23
+ group :test, :development do
24
+ gem 'jasmine-rails'
25
+ end
26
+
27
+ Next, run `bundle install`.
28
+
29
+ Now, we'll use the jasmine gem to initialize a jasmine.yml configuration file:
30
+
31
+ bundle exec jasmine init
32
+
33
+ And remove some files the jasmine gem creates that you won't need:
34
+
35
+ rm public/javascripts/Player.js public/javascripts/Song.js spec/javascripts/PlayerSpec.js spec/javascripts/helpers/SpecHelper.js lib/tasks/jasmine.rake
36
+
37
+ Next, edit the generated `spec/javascripts/support/jasmine.yml` file to ensure that it will find all your JavaScript sources and specs. The default file is written for Rails <3.1 so it doesn't know about the asset directories. As an example, mine looks like this:
38
+
39
+ src_files:
40
+ - "vendor/**/*.{js,coffee}"
41
+ - "lib/**/*.{js,coffee}"
42
+ - "app/**/*.{js,coffee}"
43
+
44
+ stylesheets:
45
+ - "vendor/**/*.css"
46
+ - "lib/**/*.css"
47
+ - "app/**/*.css"
48
+
49
+ helpers:
50
+ - "helpers/**/*.{js,coffee}"
51
+
52
+ spec_files:
53
+ - "**/*[Ss]pec.{js,coffee}"
54
+
55
+ src_dir:
56
+
57
+ spec_dir: spec/javascripts
58
+
59
+ ## Running from the command line
60
+
61
+ If you were to run:
62
+
63
+ bundle exec jasmine-headless-webkit --color
64
+
65
+ You'd hopefully see something like:
66
+
67
+ Running Jasmine specs...
68
+
69
+ PASS: 0 tests, 0 failures, 0.001 secs.
70
+
71
+ I encourage you to explore John Bintz's excellent [jasmine-headless-webkit's documentation](http://johnbintz.github.com/jasmine-headless-webkit/) for more ideas, like creating a Rake task or running it on a display-less CI server.
72
+
73
+ If you experience an error at this point, the most likely cause is JavaScript being loaded out of order, or otherwise conflicting with other existing JavaScript in your project. See "Debugging" below.
74
+
75
+ ## Running from your browser
76
+
77
+ Just mount jasmine-rails by adding something like this to your routes.rb:
78
+
79
+ ``` ruby
80
+ mount JasmineRails::Engine => "/specs" unless Rails.env.production?
81
+ ```
82
+
83
+ Now when you run `bundle exec rails s`, and navigate to [http://localhost:3000/specs](http://localhost:3000/specs), you should see a Jasmine spec runner in your browser.
84
+
85
+ ## Debugging
86
+
87
+ ### In your browser
88
+
89
+ In my workflow, I like to work with specs in the command line until I hit a snag and could benefit from debugging in [Web Inspector](http://www.webkit.org/blog/1091/more-web-inspector-updates/) or [Firebug](http://getfirebug.com/) to figure out what's going on.
90
+
91
+ When debugging, I append the query param "**debug_assets=true**" like so: [http://localhost:3000/specs?debug_assets=true](http://localhost:3000/specs?debug_assets=true).
92
+
93
+ This is telling the asset pipeline to include each of your scripts in *individual* `<script>` tags. Seeing each script loaded separately makes debugging much easier for me.
94
+
95
+ ### From the command line
96
+
97
+ Even though they both read from the same config file, it's certainly possible that your specs will pass in the browser and fail from the command line. In this case, you can try to debug or analyze what's going on by using the "--keep" flag from jasmine-headless-webkit.
98
+
99
+ By running:
100
+
101
+ bundle exec jasmine-headless-webkit --keep
102
+
103
+ If the tests fail, jasmine-headless-webkit will leave its generated spec runner HTML file persisted in your rails root folder. It'll be named something like "specrunner.48160.html".
104
+
105
+ ## Guard
106
+
107
+ [Guard](https://github.com/guard/guard) is a great tool for triggering spec runs when files change. To use it, you can bundle these gems:
108
+
109
+ group :test, :development do
110
+ ...
111
+ gem 'guard-rails-assets'
112
+ gem 'guard-jasmine-headless-webkit'
113
+ ...
114
+ end
115
+
116
+ In my Guardfile, this configuration is working well for me:
117
+
118
+ guard 'rails-assets' do
119
+ watch(%r{^.*/assets/.+$})
120
+ watch('config/application.rb')
121
+ end
122
+
123
+ spec_location = "spec/javascripts/%s_spec"
124
+
125
+ guard 'jasmine-headless-webkit' do
126
+ watch(%r{^app/views/.*\.jst$})
127
+ watch(%r{^public/javascripts/(.*)\.js$}) { |m| newest_js_file(spec_location % m[1]) }
128
+ watch(%r{^.*/assets/javascripts/(.*)\.(js|coffee)$}) { |m| newest_js_file(spec_location % m[1]) }
129
+ watch(%r{^spec/javascripts/(.*)_spec\..*}) { |m| newest_js_file(spec_location % m[1]) }
130
+ end
131
+
132
+ Finally, to run guard, just:
133
+
134
+ bundle exec guard
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'JasmineRails'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+ Bundler::GemHelper.install_tasks
28
+
29
+ require 'rake/testtask'
30
+
31
+ Rake::TestTask.new(:test) do |t|
32
+ t.libs << 'lib'
33
+ t.libs << 'test'
34
+ t.pattern = 'test/**/*_test.rb'
35
+ t.verbose = false
36
+ end
37
+
38
+
39
+ task :default => :test
@@ -0,0 +1,7 @@
1
+ // This is a manifest file that'll be compiled into including all the files listed below.
2
+ // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
+ // be included in the compiled file accessible from http://example.com/assets/application.js
4
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
+ // the compiled file.
6
+ //
7
+ //= require_jasmine js
@@ -0,0 +1,7 @@
1
+ /*
2
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
3
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
4
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
5
+ *
6
+ *= require_jasmine css
7
+ */
@@ -0,0 +1,4 @@
1
+ module JasmineRails
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module JasmineRails
2
+ class SpecRunnerController < ApplicationController
3
+ end
4
+ end
@@ -0,0 +1,46 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
2
+ <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
3
+ <head>
4
+ <meta content="text/html;charset=UTF-8" http-equiv="Content-Type"/>
5
+ <title>Jasmine suite</title>
6
+
7
+ <%= stylesheet_link_tag "jasmine_rails/application" %>
8
+ <%= javascript_include_tag "jasmine_rails/application" %>
9
+
10
+ <!-- executing jasmine's runner -->
11
+ <script type="text/javascript">
12
+ var jsApiReporter;
13
+ (function() {
14
+ var jasmineEnv = jasmine.getEnv();
15
+
16
+ jsApiReporter = new jasmine.JsApiReporter();
17
+ var trivialReporter = new jasmine.TrivialReporter();
18
+
19
+ jasmineEnv.addReporter(jsApiReporter);
20
+ jasmineEnv.addReporter(trivialReporter);
21
+
22
+ jasmineEnv.specFilter = function(spec) {
23
+ return trivialReporter.specFilter(spec);
24
+ };
25
+
26
+ var currentWindowOnload = window.onload;
27
+
28
+ window.onload = function() {
29
+ if (currentWindowOnload) {
30
+ currentWindowOnload();
31
+ }
32
+ execJasmine();
33
+ };
34
+
35
+ function execJasmine() {
36
+ jasmineEnv.execute();
37
+ }
38
+
39
+ })();
40
+ </script>
41
+ </head>
42
+ <body>
43
+ <div id="jasmine_content"></div>
44
+ <%= yield %>
45
+ <body>
46
+ </html>
@@ -0,0 +1,11 @@
1
+ require 'processes_jasmine_directives'
2
+ require 'jasmine'
3
+ require 'jasmine-core'
4
+
5
+ assets = Rails.application.assets
6
+
7
+ assets.register_preprocessor 'application/javascript', ProcessesJasmineDirectives
8
+ assets.register_preprocessor 'text/css', ProcessesJasmineDirectives
9
+
10
+ assets.append_path Jasmine::Config.new.spec_dir
11
+ assets.append_path Jasmine::Core.path
@@ -0,0 +1,6 @@
1
+ require 'jasmine-core'
2
+ require 'jasmine'
3
+
4
+ JasmineRails::Engine.routes.draw do
5
+ root :to => "spec_runner#index"
6
+ end
@@ -0,0 +1,4 @@
1
+ require "jasmine_rails/engine"
2
+
3
+ module JasmineRails
4
+ end
@@ -0,0 +1,5 @@
1
+ module JasmineRails
2
+ class Engine < Rails::Engine
3
+ isolate_namespace JasmineRails
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module JasmineRails
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,38 @@
1
+ require 'jasmine-core'
2
+ require 'sprockets/directive_processor'
3
+
4
+ class ProcessesJasmineDirectives < Sprockets::DirectiveProcessor
5
+ ASSET_TYPES = ["css","js"]
6
+
7
+ def process_require_jasmine_directive(asset_type)
8
+ return unless ASSET_TYPES.include?(asset_type)
9
+
10
+ send("require_jasmine_#{asset_type}")
11
+ send("require_user_#{asset_type}")
12
+ end
13
+
14
+ ASSET_TYPES.each do |asset_type|
15
+ define_method "require_jasmine_#{asset_type}" do
16
+ Jasmine::Core.send("#{asset_type}_files").each do |f|
17
+ context.require_asset "/#{Jasmine::Core.path}/#{f}"
18
+ end
19
+ end
20
+
21
+ define_method "require_user_#{asset_type}" do
22
+ config = Jasmine::Config.new
23
+ config.send("#{asset_type}_files").each do |f|
24
+ context.require_asset full_path_for(f,config)
25
+ end
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def full_path_for(partial_path,config)
32
+ if partial_path.include?(config.spec_path)
33
+ partial_path.gsub(/#{config.spec_path}/,config.spec_dir)
34
+ else
35
+ "#{Rails.root}#{partial_path}"
36
+ end
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jasmine-rails-light
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Justin Searls
14
+ - Mark Van Holstyn
15
+ - Cory Flanigan
16
+ autorequire:
17
+ bindir: bin
18
+ cert_chain: []
19
+
20
+ date: 2011-12-01 00:00:00 Z
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: rails
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 3
33
+ - 1
34
+ - 0
35
+ version: 3.1.0
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: jasmine
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 3
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: rspec
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ type: :development
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ name: gimme
68
+ prerelease: false
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ type: :development
79
+ version_requirements: *id004
80
+ description: Provides a Jasmine Spec Runner that plays nicely with Rails 3.1 assets without jasmine-headless-webkit
81
+ email:
82
+ - searls@gmail.com
83
+ - mvanholstyn@gmail.com
84
+ - seeflanigan@gmail.com
85
+ executables: []
86
+
87
+ extensions: []
88
+
89
+ extra_rdoc_files: []
90
+
91
+ files:
92
+ - app/assets/javascripts/jasmine_rails/application.js
93
+ - app/assets/stylesheets/jasmine_rails/application.css
94
+ - app/controllers/jasmine_rails/application_controller.rb
95
+ - app/controllers/jasmine_rails/spec_runner_controller.rb
96
+ - app/views/jasmine_rails/spec_runner/index.html.erb
97
+ - app/views/layouts/jasmine_rails/spec_runner.html.erb
98
+ - config/initializers/sprockets.rb
99
+ - config/routes.rb
100
+ - lib/jasmine-rails.rb
101
+ - lib/jasmine_rails/engine.rb
102
+ - lib/jasmine_rails/version.rb
103
+ - lib/processes_jasmine_directives.rb
104
+ - MIT-LICENSE
105
+ - Rakefile
106
+ - README.md
107
+ homepage: https://github.com/ThoughtWorksStudios/jasmine-rails
108
+ licenses: []
109
+
110
+ post_install_message:
111
+ rdoc_options: []
112
+
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ hash: 3
121
+ segments:
122
+ - 0
123
+ version: "0"
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ hash: 3
130
+ segments:
131
+ - 0
132
+ version: "0"
133
+ requirements: []
134
+
135
+ rubyforge_project:
136
+ rubygems_version: 1.8.9
137
+ signing_key:
138
+ specification_version: 3
139
+ summary: Makes Jasmine easier on Rails 3.1
140
+ test_files: []
141
+