0

我正在使用 Konacha 在我的 Ruby on Rails 应用程序中测试 BackboneJS 应用程序。我已经阅读了网络上的每个教程,它显示了设置和开始工作是多么容易。不幸的是,我没有达到这样的成功水平。这是我所拥有的:

应用程序/资产/javascripts/app_specific/itapp/models/post.js

Itapp.Models.Post = Backbone.Model.extend({
  isFirstPost: function() {
    return (this.get('id') === Itapp.bootstrap.posts[0].get('id'));
  },
});

规范/javascripts/app_specific/itapp/models/post_spec.js

//= require spec_helper

var expect = chai.expect;

describe("Posts", function() {
  it("should have a first post", function() {
    //just trying anything to get some kind of valid error/issue
    //I could put anything here and it wouldn't matter, just FYI
    expect(typeof this.isFirstPost).to.equal('function');
  });
});

规范/javascripts/spec_helper.js 文件:

// Require the appropriate asset-pipeline files:
//= require application

//Any other testing specific code here...
//Custom matchers, etc....

Konacha.mochaOptions.ignoreLeaks = true

beforeEach(function() {
  return window.page = $("#konacha");
});

// set the Mocha test interface
// see http://mochajs.org/#interfaces
mocha.ui('bdd');

//
// ignore the following globals during leak detection
mocha.globals(['YUI']);

//
// or, ignore all leaks
mocha.ignoreLeaks();

//
// set slow test timeout in ms
mocha.timeout(5);

//
// Show stack trace on failing assertion.
chai.config.includeStack = true;

我确实有一个 config/initializers/konacha.rb 文件:

Konacha.configure do |config|
  config.spec_dir     = "spec/javascripts"
  config.spec_matcher = /_spec\.|_test\./
  config.stylesheets  = %w(application)
  config.driver = :selenium
end if defined?(Konacha)

我得到的错误:

错误:无法加载 app_specific/itapp/collections/posts_spec.js。也许它无法编译?检查 rake 输出是否有错误。

检查 rake 输出:

ActionView::Template::Error: 在我的 spec_helper.js 中找不到我需要的文件“应用程序”

因此,出于某种原因,即使在我的 spec_helper 中我试图为测试环境加载 BackboneJS 应用程序,它也无法找到它。

我应该尝试让这种沟通/工作的任何想法/想法?

——迈克·莱利

4

1 回答 1

0

我想通了。问题是它没有正确找到 app/assets/javascripts/ 下的文件。我需要在 spec/javascripts/app_specific/itapp/models/post_spec.js 文件的顶部执行此操作:

//= require app_specific/itapp/models/post

一旦我这样做了,它就能够找到我正在测试的相关代码。我需要做更多的工作来清理 spec_helper.js 文件中的路径,但我不再受此限制。

于 2015-02-16T22:16:49.673 回答