我正在使用Konacha测试Rails应用程序中的BackboneJS应用程序。我读过网络上的每一个教程,它显示了设置和工作是多么容易。不幸的是,我并没有取得这样的成功。以下是我所拥有的:
app/assets/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'));
},
});spec/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');
});
});spec/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_专用/itapp/collections/post_spec.js。也许它没能编译?检查rake输出的错误。
检查rake输出:
ActionView::Template::Error:未能找到我在spec_helper.js中需要的文件“应用程序”
因此,由于某种原因,即使在我的spec_helper中,我试图为测试环境加载BackboneJS应用程序,但它无法找到它。
有什么想法/想法,我应该尝试让这个沟通/工作吗?
-迈克·赖利
发布于 2015-02-16 22:16:49
我想出来了。问题是它找不到app/assets/javascripts/下的文件。我需要在spec/javascripts/app_specific/itapp/models/post_spec.js文件的顶部这样做:
//= require app_specific/itapp/models/post一旦我这样做,它就能够找到我正在测试的相关代码。我需要做更多的工作来清理spec_helper.js文件中的路径,但是我不再被阻止了。
https://stackoverflow.com/questions/28547597
复制相似问题