Konacha を使用して、Ruby on Rails アプリケーションで BackboneJS アプリケーションをテストしています。私は Web 上のすべてのチュートリアルを読みましたが、セットアップと作業がいかに簡単かを示しています。残念ながら、私はこのレベルの成功を収めていません。これが私が持っているものです:
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 を読み込めませんでした。おそらくコンパイルに失敗しましたか?レーキ出力でエラーをチェックします。
レーキ出力の確認:
ActionView::Template::Error: spec_helper.js で必要なファイル 'application' が見つかりませんでした
そのため、spec_helper でテスト環境用に BackboneJS アプリケーションをロードしようとしても、何らかの理由でそれを見つけることができません。
このコミュニケーション/機能を実現するために私が試みるべき考え/アイデアはありますか?
――マイク・ライリー