Konacha、Mocha、BackboneJS和Ruby on Rails配置

t0ybt7op  于 2022-11-24  发布在  Ruby
关注(0)|答案(1)|浏览(94)

我正在使用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');
  });
});

说明/javascripts/说明_帮助. 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;

我有一个配置/初始化/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输出:
操作视图::模板::错误:我在spec_helper.js中找不到我需要的文件“application”
因此,由于某种原因,即使在我的spec_helper中,我试图为测试环境加载BackboneJS应用程序,它也无法找到它。
我有什么想法/想法应该尝试让这个沟通/工作?
--迈克·莱利

ibps3vxo

ibps3vxo1#

我发现了这个问题,问题是它没有在app/assets/javascript/下正确地找到这个文件,我需要在spec/javascripts/app_specific/itapp/models/post_spec.js文件的顶部执行此操作:

//= require app_specific/itapp/models/post

一旦我这样做了,它就能够找到我正在测试的关联代码。我将需要多做一点工作来清理spec_helper.js文件中的路径,但我不再在这方面受阻。

相关问题