我正在开发一个Rails 4项目,我正在尝试编写Jasmine测试,但它看起来并不像Jasmine检测到我的任何文件。
我的spec / javascripts文件夹如下所示:
./
├── e2e
│ └── products_scenarios.js
├── foo_spec.js
└── support
└── jasmine.yml
和jasmine.yml内部:
# # path to parent directory of src_files
# # relative path from Rails.root
# # defaults to app/assets/javascripts
# src_dir: "app/assets/javascripts"
#
# # path to parent directory of css_files
# # relative path from Rails.root
# # defaults to app/assets/stylesheets
# css_dir: "app/assets/stylesheets"
#
# # list of file expressions to include as source files
# # relative path from src_dir
# src_files:
# - "application.{js.coffee,js,coffee}"
#
# # list of file expressions to include as css files
# # relative path from css_dir
# css_files:
#
# # path to parent directory of spec_files
# # relative path from Rails.root
# # defaults to spec/javascripts
spec_dir: spec/javascripts
#
# # list of file expressions to include as helpers into spec runner
# # relative path from spec_dir
# helpers:
# - "helpers/**/*.{js.coffee,js,coffee}"
# list of file expressions to include as specs into spec runner
# relative path from spec_dir
spec_files:
- "**/*[Ss]pec.{js.coffee,js,coffee}"
# path to directory of temporary files
# (spec runner and asset cache)
# defaults to tmp/jasmine
# tmp_dir: "tmp/jasmine"
和foo_spec.js内部:
describe('Foo', function() {
it("does something", function() {
expect(1+1).toBe(2);
});
});
describe('ProductsCtrl', function() {
beforeEach(module('ilook'));
it('sets title to zzzzz', inject(function($controller) {
var scope = {},
ctrl = $controller('ProductsCtrl', { $scope: scope });
expect(scope.title).toBe("My zzzz");
}));
});
但是,当我运行测试时:
Nets-Mac-Pro:mysite emai$ be rake spec:javascript
Running `"/Users/emai/.phantomjs/1.9.7/darwin/bin/phantomjs" "/Users/emai/.rvm/gems/ruby-2.0.0-p247@mysite/gems/jasmine-rails-0.9.1/lib/jasmine_rails/../assets/javascripts/jasmine-runner.js" "/Users/emai/Documents/mysite/tmp/jasmine/runner.html?spec="`
Running: /Users/emai/Documents/mysite/tmp/jasmine/runner.html?spec=
Starting...
Finished
-----------------
0 specs, 0 failures in 0.002s.
它说我没有规格。这是怎么回事?我保存了所有文件。
答案 0 :(得分:0)
添加此文件
# src_files
#
# Return an array of filepaths relative to src_dir to include before jasmine specs.
# Default: []
#
# EXAMPLE:
#
# src_files:
# - lib/source1.js
# - lib/source2.js
# - dist/**/*.js
#
src_files:
- assets/application.js
- assets/jasmine-jquery.js
# stylesheets
#
# Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
# Default: []
#
# EXAMPLE:
#
# stylesheets:
# - css/style.css
# - stylesheets/*.css
#
stylesheets:
- stylesheets/**/*.css
# helpers
#
# Return an array of filepaths relative to spec_dir to include before jasmine specs.
# Default: ["helpers/**/*.js"]
#
# EXAMPLE:
#
# helpers:
# - helpers/**/*.js
#
helpers:
- helpers/**/*.js
# spec_files
#
# Return an array of filepaths relative to spec_dir to include.
# Default: ["**/*[sS]pec.js"]
#
# EXAMPLE:
#
# spec_files:
# - **/*[sS]pec.js
#
spec_files:
- '**/*[sS]pec.js'
# src_dir
#
# Source directory path. Your src_files must be returned relative to this path. Will use root if left blank.
# Default: project root
#
# EXAMPLE:
#
# src_dir: public
#
src_dir:
# spec_dir
#
# Spec directory path. Your spec_files must be returned relative to this path.
# Default: spec/javascripts
#
# EXAMPLE:
#
# spec_dir: spec/javascripts
#
spec_dir: spec/javascripts
还尝试运行以下命令来运行jasmine
rake jasmine
它会给你端口号。因此,在该端口上运行服务器numvber