Question

Je construis une application de Backbone.js sur Rails 3.1 back-end. J'utilise CoffeeScript pour écrire les classes de la colonne vertébrale, et Jasmine (via le jasmin sans tête-webkit) pour le test.

Compte tenu de ce qui suit (partiel) arbre:

.
├── app
│   ├── assets
│   │   ├── javascripts
│   │   │   └── views
│   │   │       ├── avia_view.js.coffee
├── spec
│   ├── javascripts
│   │   └── views
│   │       └── avia_view_spec.js.coffee

... j'attendre avia_view_spec.js.coffee à savoir sur Avia.AviaView, qui est défini dans avia_view.js.coffee.

Cependant, je reçois la sortie suivante de bundle exec jasmine-headless-webkit en cours d'exécution:

Running Jasmine specs...
F

Avia.AviaView render creates a new MatricesView . (/home/duncan/avia/spec/javascripts/views/avia_view_spec.js.coffee:10)
  ReferenceError: Can't find variable: Avia in /home/duncan/avia/spec/javascripts/views/avia_view_spec.js.coffee (line ~5)
  ReferenceError: Can't find variable: Avia in /home/duncan/avia/spec/javascripts/views/avia_view_spec.js.coffee (line ~10)

Mon jasmine.yml contient les éléments suivants:

src_files:
  - public/javascripts/prototype.js
  - public/javascripts/effects.js
  - public/javascripts/controls.js
  - public/javascripts/dragdrop.js
  - public/javascripts/application.js
  - public/javascripts/**/*.js

pense Je dois dire Jasmine pour charger le contenu de avia_view.js.coffee mais je ne suis pas tout à fait sûr de savoir comment. Ajout d'une référence explicite dans la section src_files dans jasmine.yml ne semble pas faire une différence ...

Quelqu'un pourrait-il s'il vous plaît me dire ce que je fais mal ici? Je soupçonne que c'est simple quelque chose ...

Était-ce utile?

La solution

Without having seen to much of your code, I'd suspect it beacuse of CoffeeScript's function wrapping (docs). You need to ensure that all the symbols you want to use are exported to somewhere you can get at them (here is a thorough discussion about that).

Edit: here's another longish and theoretical but good documentation on this topic.

Autres conseils

Try adding this to your avia_view.js.coffee

(exports ? this).Avia = Avia 

See this for a detailed explanation.

Alternatively try this;

window.Avia = Avia

We encountered the same problem; I highly recommend JasmineRice

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top