Rails 配置上的 Konacha、Mocha、BackboneJS 和 Ruby
Konacha, Mocha, BackboneJS and Ruby on Rails configuration
我正在使用 Konacha 在我的 Ruby on 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_specific/itapp/collections/posts_spec.js。
也许它无法编译?检查 rake 输出是否有错误。
检查耙输出:
ActionView::Template::Error: 找不到我在 spec_helper.js
中需要的文件 'application'
所以出于某种原因,即使在我的 spec_helper 中,我正在尝试为测试环境加载 BackboneJS 应用程序,但它无法找到它。
任何 thoughts/ideas 我应该尝试得到这个 communicating/working?
--迈克·赖利
我想通了。问题是它没有在 app/assets/javascripts/ 下正确找到文件。我需要在 spec/javascripts/app_specific/itapp/models/post_spec.js 文件的顶部执行此操作:
//= require app_specific/itapp/models/post
一旦我这样做了,它就能够找到我正在测试的相关代码。我需要做更多的工作来清理 spec_helper.js 文件中的路径,但我不再受阻。
我正在使用 Konacha 在我的 Ruby on 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_specific/itapp/collections/posts_spec.js。 也许它无法编译?检查 rake 输出是否有错误。
检查耙输出:
ActionView::Template::Error: 找不到我在 spec_helper.js
中需要的文件 'application'所以出于某种原因,即使在我的 spec_helper 中,我正在尝试为测试环境加载 BackboneJS 应用程序,但它无法找到它。
任何 thoughts/ideas 我应该尝试得到这个 communicating/working?
--迈克·赖利
我想通了。问题是它没有在 app/assets/javascripts/ 下正确找到文件。我需要在 spec/javascripts/app_specific/itapp/models/post_spec.js 文件的顶部执行此操作:
//= require app_specific/itapp/models/post
一旦我这样做了,它就能够找到我正在测试的相关代码。我需要做更多的工作来清理 spec_helper.js 文件中的路径,但我不再受阻。