3
votes

I recently upgraded to Rails 4.1

Im using the gem 'jasmine-rails', which is working fine by itself.

I am also trying to use gem 'jasmine-jquery-rails' to load fixtures, but am unable to load it (jasmine simply doesnt recognise the jasmine-jquery functions). I added "jasmine-jquery.js" to my jasmine yml file.

I also tried adding the file directly into my app/javascripts/assets folder, and changing the jasmine.yml file to

src_dir: "app/assets/javascripts"
src_files:
  - "application.{js.coffee,js,coffee}"
  - "jasmine-jquery.js"

but it still will not load jasmine-jquery.

Any thoughts?

3

3 Answers

1
votes

All you need is the following.

In the jasmine.yml file it suffices to have:

spec_files:
  - "**/*[Ss]pec.{js.coffee,js,coffee}"

Then in the spec file you need to include the files needed for testing (those files are in the asset pipeline, so you just need to include it. that's what the jasmine-rails gems are for).

Maybe this example might help:

//= require jquery
//= require jasmine-jquery
describe("Jasmine jQuery Test", function() {
  it("works out of the box", function() {
    expect($('<input type="checkbox" checked="checked"/>')).toBeChecked();
  });
});

Note that you require the files used for testing. In this case jquery and jasmine-jquery.

jquery is required because jasmine-jquery uses its functionality (as mentioned in the docs on GitHub) and jasmine-jquery is required because we use a matcher "toBeChecked()".

Think of it this way, all your Rails asset files are in the asset pipeline, so in your test files you just need to include what you need for testing.

Happy coding

0
votes

Try adding:

#= require jquery
#= require support/jasmine-jquery-1.7.0

to your spec/javascripts/spec_helper.coffee file.

HTH, Jarra

0
votes

@Elyasin gave a working solution except that you have to require jasmine-jquery in each of your js spec files. Add //= require jasmine-jquery to app/assets/javascripts/application.js. Then you don't have to require it ever again anywhere else. It works good for me.