为什么茉莉花没有运行我的任何规格?

时间:2014-02-09 00:50:30

标签: javascript ruby-on-rails jasmine

我在gem 'jasmine', '~> 2.0.0'Gemfile)中添加了group :development, :test并运行了生成器rails g jasmine:install

我有一个简单的规范

# spec/javascripts/truth_spec.js 
describe("Truth", function() {
  it("herps the derps", function() {
    expect(true).toEqual(true);
  });
});

当我跑rake jasmine时,我的输出大概正常:

your server is running here: http://localhost:8888/
your tests are here:         /Users/jared/git/givegab/spec/javascripts
your source files are here:  /Users/jared/git/givegab

>> Thin web server (v1.5.1 codename Straight Razor)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:8888, CTRL+C to stop

我在浏览器中打开http://localhost:8888/,我得到一个空白的灰色屏幕。我的JS控制台是空的,没有错误,当我使用调试器跟踪执行时我可以单步执行 boot.jsjasmine.js。没有错误。

我可以在truth_spec.js中设置调试器断点,但它永远不会被命中。

这是我第一次使用茉莉花,所以请假设我遗漏了一些明显的东西

3 个答案:

答案 0 :(得分:3)

如果正确设置了jasmine,则在浏览器中打开http://localhost:8888/jasmine应运行所有规范。

您还可以使用以下命令运行特定规范:

http://localhost:8888/jasmine?spec=herps the derps

答案 1 :(得分:0)

如果您想使用交互式网络版,请确保您在config/initializers/中有一个名为jasminerice.rb的文件,其中包含以下内容:

# Use this file to set configuration options for Jasminerice, all of these are initialized to their respective defaults,
# but you can change them here.
if defined?(Jasminerice) == 'constant'
  Jasminerice.setup do |config|
    # Tell Jasminerice to automatically mount itself in your application. If set to false, you must manually mount the
    # engine in order to use Jasminerice.
    #config.mount = true

    # If automatically mounting Jasminerice, specify the location that it should be mounted at.  Defaults to /jasmine, so
    # you could access your tests at http://YOUR_SERVER_URL/jasmine
    #config.mount_at = '/jasmine'

    # Specify a path where your fixutures can be found. Defaults to 'spec/javascripts/fixtures'
    #config.fixture_path = 'spec/javascripts/fixtures'
  end
end

请务必在之后重新启动rails服务器。此初始化程序在运行时为jasmine Web视图设置路由,因此如果运行rake routes | grep jasmine,您应该看到以下内容:

jasminerice /jasmine Jasminerice::Engine GET /spec/:spec_id/fixtures/*filename(.:format) jasminerice/spec#fixtures spec_index GET /spec(.:format) jasminerice/spec#index GET /fixtures/*filename(.:format) jasminerice/spec#fixtures GET /(:suite)(.:format) jasminerice/spec#index

答案 2 :(得分:0)

我的同事找到了根本问题。令我们非常尴尬的是,我们覆盖了window.onload。我无法想到茉莉(或S.O.)能够找出这样一个愚蠢的错误。感谢您抽出宝贵时间帮助我们解决此问题。

宝石作者ragaskar helped us troubleshoot this,并给了我们一些很好的建议。