jasmine-rails 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -13,12 +13,12 @@ By bundling this gem and configuring your project, you can expect to:
13
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
14
 
15
15
  brew install qt
16
-
16
+
17
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
18
 
19
- ## Adding the gem
19
+ ## Adding & configuring the gem
20
20
 
21
- Add jasmine-rails to your Gemfile, like so
21
+ First, add jasmine-rails to your Gemfile, like so
22
22
 
23
23
  group :test, :development do
24
24
  gem 'jasmine-rails'
@@ -26,42 +26,55 @@ Add jasmine-rails to your Gemfile, like so
26
26
 
27
27
  Next, run `bundle install`.
28
28
 
29
- Now, we'll use the jasmine gem to initialize a jasmine.yml configuration file:
29
+ In order to run any specs, you'll need a Jasmine configuration in `spec/javascripts/support/jasmine.yml`. [Here's an example](https://github.com/searls/jasmine-rails/tree/master/spec/dummy/spec/javascripts/support) from this repo's [dummy project](https://github.com/searls/jasmine-rails/tree/master/spec/dummy).
30
+
31
+ ``` yaml
32
+ src_files:
33
+ - "application.{js,coffee}"
34
+
35
+ stylesheets:
30
36
 
31
- bundle exec jasmine init
37
+ helpers:
38
+ - "helpers/**/*.{js,coffee}"
32
39
 
33
- And remove some files the jasmine gem creates that you won't need:
40
+ spec_files:
41
+ - "**/*[Ss]pec.{js,coffee}"
34
42
 
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:
43
+ src_dir: "app/assets/javascripts"
38
44
 
39
- src_files:
40
- - "vendor/**/*.{js,coffee}"
41
- - "lib/**/*.{js,coffee}"
42
- - "app/**/*.{js,coffee}"
45
+ spec_dir: spec/javascripts
43
46
 
44
- stylesheets:
45
- - "vendor/**/*.css"
46
- - "lib/**/*.css"
47
- - "app/**/*.css"
47
+ asset_paths:
48
+ - "vendor/assets/javascripts"
49
+ ```
50
+
51
+ ### Writing asset manifests
48
52
 
49
- helpers:
50
- - "helpers/**/*.{js,coffee}"
53
+ I prefer to have just one asset manifest per project, as the `jasmine.yml` file above suggests. One way to accomplish that is to require your `vendor` (and, if necessary, `lib`) manifests within your application manifest. For an example, check out the repo's [dummy project](https://github.com/searls/jasmine-rails/tree/master/spec/dummy).
51
54
 
52
- spec_files:
53
- - "**/*[Ss]pec.{js,coffee}"
55
+ Here's `app/assets/javascripts/application.js`
54
56
 
55
- src_dir: app/assets/javascripts
57
+ ``` javascript
58
+ //= require vendor
59
+ //= require_tree .
60
+ ```
56
61
 
57
- spec_dir: spec/javascripts
62
+ And here's `vendor/assets/javascripts/vendor.js` (as referenced on the first line of `application.js` above)
63
+
64
+ ``` javascript
65
+ //= require jquery
66
+ //= require jquery_ujs
67
+ //= require_tree .
68
+ ```
69
+
70
+ Assets in gems come along for the ride, as well. Additionally, you can follow a similar scheme to import any JavaScript libs you might reference from a `lib/assets/javascripts/lib.js` manifest file.
58
71
 
59
72
  ## Running from the command line
60
73
 
61
74
  If you were to run:
62
75
 
63
76
  bundle exec jasmine-headless-webkit --color
64
-
77
+
65
78
  You'd hopefully see something like:
66
79
 
67
80
  Running Jasmine specs...
@@ -88,26 +101,24 @@ Now when you run `bundle exec rails s`, and navigate to [http://localhost:3000/s
88
101
 
89
102
  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
103
 
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).
104
+ [When debugging, if you've disabled the asset pipeline's debug mode in dev/test, you may need to append the query param `?debug_assets=true` like so: [http://localhost:3000/specs?debug_assets=true](http://localhost:3000/specs?debug_assets=true). The asset pipeline will include individual `script` tags for each of your scripts when in debug mode, which migh tmake debugging easier.]
92
105
 
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
106
  ### From the command line
96
107
 
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.
108
+ 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
109
 
99
110
  By running:
100
111
 
101
112
  bundle exec jasmine-headless-webkit --keep
102
113
 
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".
114
+ 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 "jhw.48160.html".
104
115
 
105
116
  ## Guard
106
117
 
107
118
  [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
119
 
109
120
  group :development do
110
- ...
121
+ ...
111
122
  gem 'guard-jasmine-headless-webkit'
112
123
  ...
113
124
  end
@@ -4,8 +4,8 @@
4
4
  <meta content="text/html;charset=UTF-8" http-equiv="Content-Type"/>
5
5
  <title>Jasmine Specs</title>
6
6
 
7
- <%= stylesheet_link_tag "jasmine_rails/application" %>
8
- <%= javascript_include_tag "jasmine_rails/application" %>
7
+ <%= stylesheet_link_tag *JasmineRails::JhwAdapter.new.css_files %>
8
+ <%= javascript_include_tag *JasmineRails::JhwAdapter.new.js_files %>
9
9
 
10
10
  <!-- executing jasmine's runner -->
11
11
  <script type="text/javascript">
@@ -1,11 +1,7 @@
1
- require 'processes_jasmine_directives'
2
1
  require 'jasmine'
3
2
  require 'jasmine-core'
4
3
 
5
4
  assets = Rails.application.assets
6
5
 
7
- assets.register_preprocessor 'application/javascript', ProcessesJasmineDirectives
8
- assets.register_preprocessor 'text/css', ProcessesJasmineDirectives
9
-
10
6
  assets.append_path Jasmine::Config.new.spec_dir
11
7
  assets.append_path Jasmine::Core.path
@@ -1,3 +1,3 @@
1
1
  module JasmineRails
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jasmine-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-07-31 00:00:00.000000000 Z
14
+ date: 2012-09-19 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -103,8 +103,6 @@ executables: []
103
103
  extensions: []
104
104
  extra_rdoc_files: []
105
105
  files:
106
- - app/assets/javascripts/jasmine_rails/application.js
107
- - app/assets/stylesheets/jasmine_rails/application.css
108
106
  - app/controllers/jasmine_rails/application_controller.rb
109
107
  - app/controllers/jasmine_rails/spec_runner_controller.rb
110
108
  - app/views/jasmine_rails/spec_runner/index.html.erb
@@ -115,7 +113,6 @@ files:
115
113
  - lib/jasmine_rails/engine.rb
116
114
  - lib/jasmine_rails/jhw_adapter.rb
117
115
  - lib/jasmine_rails/version.rb
118
- - lib/processes_jasmine_directives.rb
119
116
  - lib/tasks/jasmine-rails_tasks.rake
120
117
  - MIT-LICENSE
121
118
  - Rakefile
@@ -1 +0,0 @@
1
- //= require_jasmine js
@@ -1,3 +0,0 @@
1
- /*
2
- *= require_jasmine css
3
- */
@@ -1,24 +0,0 @@
1
- require 'jasmine-core'
2
- require 'sprockets/directive_processor'
3
-
4
- class ProcessesJasmineDirectives < Sprockets::DirectiveProcessor
5
- def process_require_jasmine_directive(asset_type)
6
- reset_circular_dependencies
7
- context.depend_on(Rails.root)
8
- JasmineRails::JhwAdapter.new.send("#{asset_type}_files").each do |full_path|
9
- context.depend_on(full_path)
10
- context.require_asset(full_path)
11
- end
12
- end
13
-
14
- private
15
-
16
- def reset_circular_dependencies
17
- #This is an internal thread-local variable Sprockets uses.
18
- # Unfortunately, it's the only way I've found to avoid
19
- # (seemingly) spurious `CircularDependencyError`s from being
20
- # raised whenever a file changes.
21
- Thread.current[:sprockets_circular_calls] = nil
22
- end
23
-
24
- end