Giter VIP home page Giter VIP logo

Comments (8)

vladiim avatar vladiim commented on June 28, 2024

I had the same issue with #=require application in spec.js.coffee fixing it.

I am actually getting a ReferenceError on other resources also

When trying to go through Ryan Bate's RailsCast on Jasmine I get the following error:

ReferenceError: CreditCard is not defined
    at [object Object].<anonymous> (http://localhost:3000/assets/credit_card_spec.js?body=1:5:22)
    at [object Object].execute (http://localhost:3000/assets/jasmine.js?body=1:1024:15)
    at [object Object].next_ (http://localhost:3000/assets/jasmine.js?body=1:2025:31)
    at http://localhost:3000/assets/jasmine.js?body=1:2015:18

Although app/assets/javascipts/credit_card.js.coffee has the following:

CreditCard = cleanNumber: (number) ->
  number.replace /[- ]/g, ""

With #=require credit_card in either spec.js.coffee or credit_card_spec.js.coffee not having the same effect.

from jasminerice.

ryanb avatar ryanb commented on June 28, 2024

CoffeeScript automatically scopes its files. Try setting this.CreditCard so it is available globally.

from jasminerice.

vladiim avatar vladiim commented on June 28, 2024

Thanks Ryan! I had started doing stuff like window.CreditCard = class CreditCard to get around the issue which didn't feel right at all.

from jasminerice.

ryanb avatar ryanb commented on June 28, 2024

Try class @CreditCard. I don't know if that's a best practice, but seems to work for me.

from jasminerice.

vladiim avatar vladiim commented on June 28, 2024

Works a treat and much nicer syntax - thanks

from jasminerice.

vladiim avatar vladiim commented on June 28, 2024

As a point of interest for anyone reading I've been going through the prags Coffeescipt Book and you can also do:

class CreditCard
  # code goes here

root = exports ? window # exports for node.js global
root.CreditCard = CreditCard

from jasminerice.

bradphelan avatar bradphelan commented on June 28, 2024

The solution to the OP's problem is a missing

spec/javascripts/spec.js.coffee

#= require jquery
#= require credit_card
#= require_tree .

As Ryan Bates quite rightly points out in his screencast

from jasminerice.

ohcibi avatar ohcibi commented on June 28, 2024

Shouldnt jasmine do this by itself? I saw that jasmine needs jquery-1.3 to make the results on the results page foldable. I dont even need jquery in these particular steps so i think jasmine should load its jquery-1.3 with noConflict. Not sure if this is a jasmine or a jasmine-rails or a jasminerice issue.

from jasminerice.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.