1

问题描述:

我为 ROR 设置了 jasmine,当我编写 jasmine 测试用例(即“helloworld.js”)来测试 app/assets/javascripts 中存在的 javascript 代码(即“hello.js”)时。当我执行它时,它给出了 ReferenceError: helloWorld is not defined。当我将“hello.js”文件放入 spec/javascript/helper/ 中时,测试用例得到执行而没有任何错误。

ROR项目说明:

我为 ROR(ruby on rails)项目设置了 jasmine 以下是项目的版本信息: Rails -v 3.2 jasmine 1.2.1 require.js 2.0.6

ROR项目目录结构:

blog/ app/ assets/ javascripts/ hello.js application.coffee spec/ javascripts/ helpers/ support/ jasmine.yml helloworld.js spec_helper.rb
/config requirejs.yml Gemfile

**Gemfile:**

    group :development, :test do
  gem 'rspec-rails'
  gem "capybara"
  gem "launchy"
  gem 'jasmine'
end

你好.js:

function helloWorld() {
    return "Hello world!";
}

helloworld.js

    describe("Hello world", function() {
    it("says hello", function() {
        expect(helloWorld()).toEqual("Hello world!");
    });
});

需要js.yml:

deps:[jquery,主干,下划线] 导出:Backbone.Paginator 路径:spin:spin-1.2.5 jquery.spin:jquery.spin-0.0.1 jed:jed-0.5.0beta 文本:text-2.0.1 玉:翡翠0.27.0翡翠运行时:翡翠运行时0.27.0降价:markdown-0.4.0主干分页器:主干分页器-0.1.54.8fcc333d18 fs:compat/fs路径:compat/path po:plugins/po j: plugins/j stubModules: - text - po - j excludeShallow: - utils/po2json # find vendor/assets/javascripts/jade-0.27.0 -name '*.js' | grep -v 运行时 | sed -E's/. 5 jquery.spin:jquery.spin-0.0.1 jed:jed-0.5.0beta 文本:text-2.0.1 玉:jade-0.27.0 jam.runtime:jade.runtime-0.27.0 markdown:markdown-0.4。 0 骨干网.paginator:骨干网.paginator-0.1.54.8fcc333d18 fs:compat/fs 路径:compat/path po:plugins/po j:plugins/j stubModules:-text -po -j excludeShallow:-utils/po2json #查找供应商/assets/javascripts/jade-0.27.0 -name '*.js' | grep -v 运行时 | sed -E's/. 5 jquery.spin:jquery.spin-0.0.1 jed:jed-0.5.0beta 文本:text-2.0.1 玉:jade-0.27.0 jam.runtime:jade.runtime-0.27.0 markdown:markdown-0.4。 0 骨干网.paginator:骨干网.paginator-0.1.54.8fcc333d18 fs:compat/fs 路径:compat/path po:plugins/po j:plugins/j stubModules:-text -po -j excludeShallow:-utils/po2json #查找供应商/assets/javascripts/jade-0.27.0 -name '*.js' | grep -v 运行时 | sed -E's/. 8fcc333d18 fs: compat/fs path: compat/path po: plugins/po j: plugins/j stubModules: - text - po - j excludeShallow: - utils/po2json # find vendor/assets/javascripts/jade-0.27.0 -name '*.js' | grep -v 运行时 | sed -E's/. 8fcc333d18 fs: compat/fs path: compat/path po: plugins/po j: plugins/j stubModules: - text - po - j excludeShallow: - utils/po2json # find vendor/assets/javascripts/jade-0.27.0 -name '*.js' | grep -v 运行时 | sed -E's/.玉[^/]+/(.).js$/ -jade/\1/' -jade/编译器 -jade/doctypes -jade/filters -jade/inline-tags -jade/jade -jade/lexer -jade/nodes/attrs -jade/nodes/block -comment -jade/nodes/block -jade/nodes/case -jade/nodes/code -jade/nodes/comment -jade/nodes/doctype -jade/nodes/each -jade/nodes/filter -jade/nodes/index -jade/nodes/literal -jade/nodes/mixin -jade/nodes/node -jade/nodes/tag -jade/nodes/text -jade/parser -jade/自关闭 -jade/utils include: # 强制包含这个用于运行已编译的 Jade 模板 - 玉/运行时模块: - 名称:应用程序 - 名称:locale/application_es 语言环境:es - 名称:locale/application_en 语言环境:en wrap:true 地图:markdown:util:compat/noop 玉:sass:compat/noop 手写笔:compat/noop 折扣:compat/noop markdown- js:compat/noop 标记:compat/noop less:compat/noop utils/jade.trans:jade/jade:jade/runtimecompat/noop 标记:compat/noop less:compat/noop utils/jade.trans:jade/jade:jade/runtimecompat/noop 标记:compat/noop less:compat/noop utils/jade.trans:jade/jade:jade/runtime

茉莉花.yml

> 
# src_files
#
# Return an array of filepaths relative to src_dir to include before jasmine specs.
# Default: []
#
# EXAMPLE:
#
# src_files:
#   - lib/source1.js
#   - lib/source2.js
#   - dist/**/*.js
#
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
  - app/assets/javascripts/*.js

# stylesheets
#
# Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
# Default: []
#
# EXAMPLE:
#
# stylesheets:
#   - css/style.css
#   - stylesheets/*.css
#
stylesheets:
  - stylesheets/**/*.css

# helpers
#
# Return an array of filepaths relative to spec_dir to include before jasmine specs.
# Default: ["helpers/**/*.js"]
#
# EXAMPLE:
#
# helpers:
#   - helpers/**/*.js
#
helpers:
  - helpers/**/*.js

# spec_files
#
# Return an array of filepaths relative to spec_dir to include.
# Default: ["**/*[sS]pec.js"]
#
# EXAMPLE:
#
# spec_files:
#   - **/*[sS]pec.js
#
spec_files:
  - '**/*[sS]pec.js'

# src_dir
#
# Source directory path. Your src_files must be returned relative to this path. Will use root if left blank.
# Default: project root
#
# EXAMPLE:
#
# src_dir: public
#
src_dir: 

# spec_dir
#
# Spec directory path. Your spec_files must be returned relative to this path.
# Default: spec/javascripts
#
# EXAMPLE:
#
# spec_dir: spec/javascripts
#
spec_dir: spec/javascripts

我使用以下命令在 ROR 上设置和运行 jasmine

$rails g jasmine:install
$rake jasmine
your tests are here:

[2012-08-22 21:35:44] 信息 WEBrick 1.3.1 [2012-08-22 21:35:44] 信息 ruby​​ 1.9.2 (2012-04-20) [i686-linux] [2012-08 -22 21:35:44] WARN TCPServer 错误:地址已在使用中-bind(2) [2012-08-22 21:35:44] INFO WEBrick::HTTPServer#start: pid=3210 port=8888

4

1 回答 1

0

尝试在 jasmine.yml 文件的 src_dir 中提供 app/assets/javascript。

于 2013-02-01T09:48:02.050 回答