我正在尝试设置我的 Rails Angular 项目以提供 JS 测试。我几乎尝试了在 Google 上找到的所有内容:
- Karma (以前称为睾丸)
- Jasmine + Jasmine-headless-WebKit
- Jasminerice
- 一些其他教程
但我都失败了。我正在寻找一种以最轻松的方式运行单元和端到端测试的方法(它可以在 Guard 或 Karma 中,我不在乎,但它必须在后台自动运行)。
有没有人有一些不错的文章和一个很好的例子来说明如何实现这一目标?在我的研究中,我发现了 this ,但恕我直言,这是一个如何不这样做的例子。
我的实际 Gemfile
:
source 'https://rubygems.org'
# Use Ruby 1.9.3 instead default Heroku's 1.9.2
# for development I suggest https://gist.github.com/1688857
ruby '1.9.3'
gem 'rails', '3.2.12'
# Use PostgreSQL, which is quite awesome, fast and easy
gem 'pg'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'bootstrap-sass', '~> 2.3.1'
# I heard that you like Compass
gem 'compass'
# Angular.js
gem 'angularjs-rails'
gem 'angularjs-rails-resource'
gem 'angular-ui-rails'
# Assets should be minified before production
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
# Serve static pages like a boss
gem 'high_voltage'
# Some user management will be nice
gem 'devise' # User management
# gem 'cancan' # And they privileges
# To use Jbuilder templates for JSON
gem 'jbuilder'
# Be fast and deadly as Puma
#gem 'puma'
# We need also some administration panel, don't we?
gem 'rails_admin'
# Some helpers
gem 'andand'
group :development do
# IRb is ugly. Use Pry for the God's sake
gem 'pry-rails'
# Deploy with Capistrano
# gem 'capistrano'
# or Vlad the Deployer
# gem 'vlad'
# Why bother yourself with rerunning tests? Use Guard
gem 'guard'
gem 'guard-rspec'
gem 'guard-spork'
gem 'guard-livereload'
gem 'guard-jasmine'
gem 'rb-fsevent', require: false
gem 'rb-inotify', require: false
# Who like ugly error pages? We don't.
gem 'better_errors'
gem 'binding_of_caller'
# Prettier documentation
gem 'yard'
end
group :development, :test do
# Use RSpec for testing
gem 'rspec-rails', '~> 2.12.0'
# Test JS using Jasmine
gem 'jasmine'
gem 'jasmine-headless-webkit'
# Some DB table generator
gem 'factory_girl_rails', '~> 4.1.0'
# And fake data generator
gem 'ffaker'
end
group :test do
# Some Gherkins will be also good (to vodka of course)
gem 'turnip', '~> 1.1.0'
# Aww, an of course some web browser will be also apprised
gem 'capybara', '~> 2.0.1'
# Clean DB after tests
gem 'database_cleaner'
# Some nice matchers
gem 'shoulda-matchers'
# Extend your mocks
gem 'bourne', '~> 1.2.1'
# Coverage reports will be nice
gem 'simplecov', require: false
end
附言: 如果我能以一种简单的方式创建覆盖率报告,那就太好了。
最佳答案
您可以使用 teaspoon它运行你最喜欢的测试套件(默认是 jasmine)并且他们有一个 wiki 来与 angular 集成。 Teaspoon 与 Assets 管道集成,因此您可以将所有有 Angular 的 gem 放入其中,并在 teaspoon 生成的 spec_helper.js 中需要它们。
另一件很酷的事情是:他们还有一个可用的保护插件。
关于ruby-on-rails - 如何设置 Rails Angular 项目来测试 JS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16159395/