Reputation: 17528
I added gem 'jasmine', '~> 2.0.0'
in my Gemfile
(group :development, :test
) and ran the generator rails g jasmine:install
.
I have one simple spec:
# spec/javascripts/truth_spec.js
describe("Truth", function() {
it("herps the derps", function() {
expect(true).toEqual(true);
});
});
When I run rake jasmine
I get presumably normal output:
your server is running here: http://localhost:8888/
your tests are here: /Users/jared/git/givegab/spec/javascripts
your source files are here: /Users/jared/git/givegab
>> Thin web server (v1.5.1 codename Straight Razor)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:8888, CTRL+C to stop
I open http://localhost:8888/
in my browser and I get a blank grey screen. My JS console is empty, no errors, and when I trace execution using a debugger I can step through boot.js
and jasmine.js
. No errors are raised.
I can set a debugger breakpoint in truth_spec.js
and it never gets hit.
This is my first time using jasmine, so please assume I am missing something obvious.
Upvotes: 5
Views: 8375
Reputation: 17528
My colleague has found the root problem. To our great embarrassment, we were overwriting window.onload
. I can't think of any way jasmine (or S.O.) could have identified such a foolish mistake. Thanks for taking the time to help us troubleshoot this.
The gem author ragaskar helped us troubleshoot this, and gave us some good tips.
Upvotes: 0
Reputation: 8231
Make sure you have a file in config/initializers/
called jasminerice.rb
, with the following contents in it, if you want to use the interactive web version:
# Use this file to set configuration options for Jasminerice, all of these are initialized to their respective defaults,
# but you can change them here.
if defined?(Jasminerice) == 'constant'
Jasminerice.setup do |config|
# Tell Jasminerice to automatically mount itself in your application. If set to false, you must manually mount the
# engine in order to use Jasminerice.
#config.mount = true
# If automatically mounting Jasminerice, specify the location that it should be mounted at. Defaults to /jasmine, so
# you could access your tests at http://YOUR_SERVER_URL/jasmine
#config.mount_at = '/jasmine'
# Specify a path where your fixutures can be found. Defaults to 'spec/javascripts/fixtures'
#config.fixture_path = 'spec/javascripts/fixtures'
end
end
Be sure to restart your rails server afterward. This initializer sets up the routes at runtime for the jasmine web view, so if you run rake routes | grep jasmine
, you should see the following:
jasminerice /jasmine Jasminerice::Engine
GET /spec/:spec_id/fixtures/*filename(.:format) jasminerice/spec#fixtures
spec_index GET /spec(.:format) jasminerice/spec#index
GET /fixtures/*filename(.:format) jasminerice/spec#fixtures
GET /(:suite)(.:format) jasminerice/spec#index
Upvotes: 0
Reputation: 1067
If jasmine is setup correctly, then opening http://localhost:8888/jasmine
in your browser should run all of your specs.
You can also run specific specs with:
http://localhost:8888/jasmine?spec=herps the derps
Upvotes: 3