testdouble / jasmine-rails

A Jasmine runner for rails projects that's got you covered in both the terminal and the browser
http://rubygems.org/gems/jasmine-rails
MIT License
377 stars 154 forks source link

Unable to run Jasmine tests with fixtures #123

Closed almagest closed 7 years ago

almagest commented 10 years ago

Hi,

I'm attempting to use jasmine-rails to process coffeescript (both code & tests), but I keep seeing "ReferenceError: Can't find variable: Regions in [...]/tmp/jasmine/assets/jasmine-specs.js (line 10723)". I check the compiled jasmine-specs.js file and I see Regions defined before line 10723. Can you offer any suggestions on how to get these tests running? Also, let me know if you need to see anything else. Thanks.

Relevant gems in use:

Includes:

Failing test (settings_spec.js.coffee):

describe 'Settings', ->
  beforeEach ->
    loadFixtures('settings.html')
    Regions.setup()
    Modal.setup()
    return

  it 'should disable all locations dropdowns except APAC on page load', ->
    expect($("#locations_apac")).toBeHidden()
    expect($("#locations_emea")).toBeVisible()
nathany commented 10 years ago

You need jasmine-jquery https://github.com/velesin/jasmine-jquery#html-fixtures

gem 'jasmine-jquery-rails'
nathany commented 10 years ago

I haven't gotten much further due to NETWORK_ERR: XMLHttpRequest Exception mentioned in the README: https://github.com/searls/jasmine-rails#ajax--xhrs.

I don't know how to specify --allow-file-access-from-files or --web-security=no when running rake spec:javascript.

It would be nice to get our tests passing again (coming from Teaspoon) before transitioning to something like https://github.com/searls/jasmine-fixture.

nathany commented 10 years ago

The following gets fixtures working the web UI: https://github.com/travisjeffery/jasmine-jquery-rails/issues/4#issuecomment-29684484

nathany commented 10 years ago

rake spec:javascript

If https://github.com/searls/jasmine-rails/blob/master/lib/jasmine_rails/runner.rb#L21 passes the argument "--web-security=no" to phantomjs, the XMLHttpRequest Exception is solved... but then onto another issue:

Error: Fixture could not be loaded: spec/javascripts/fixtures/name.html (status: error, message: undefined)

I also experimented with https://github.com/searls/jasmine-fixture but had some initial trouble getting it to load from helpers. (or at least, affix wasn't defined)

nathany commented 10 years ago

As pointed out on Stack Overflow, the problem here is that fixtures are being loaded relative to tmp/jasmine (where the runner is) rather than relative to the Rails.root.

http://stackoverflow.com/questions/21763470/jasmine-jquery-loadfixtures-with-jasmine-2-0-wont-work

nathany commented 10 years ago

It turns out that --web-security=no was unnecessary.

I added this to spec_helper.js.coffee:

# rake spec:javascript loads specs relative to the tmp/jasmine/runner.html, need to override:
jasmine.getFixtures().fixturesPath="../../spec/javascripts/fixtures"
guilhermepontes commented 9 years ago

Thank you @nathany! Helped me a lot! :heart: :grin:

nathany commented 9 years ago

You’re welcome. ;-)

greshny commented 9 years ago

@nathany thank you very much!!!! :+1:

joker-777 commented 9 years ago

Please have a look to my PR https://github.com/travisjeffery/jasmine-jquery-rails/pull/12. It will add jasmine-jquery fixture support for Rails without special configs necessary and it even supports HAML!

ccallebs commented 8 years ago

It seems like I can only choose to run the specs on the command line or via http://localhost:3000/specs using the solution above.

jasmine.getFixtures().fixturesPath = "../../spec/javascripts/fixtures";

It would be nice to conditionally load the fixtures based on whether it was via the browser or the command line. I'll look into that.

enkanba commented 8 years ago

Hi, @ccallebs, were you able to figure out how to make it run for both command line and via browser? I am running into the same problem.

ccallebs commented 8 years ago

@enkanba I never was -- we just settled on the command line. Sorry :(

searls commented 7 years ago

(Maybe) fixed by #216