您可能想尝试evergreen
(https://github.com/jnicklas/evergreen)。它允许您使用jasmine
无头浏览器或 JS 引擎内部的浏览器编写测试用例并运行测试。
您可以在自述文件部分https://github.com/jnicklas/evergreen#readme找到此 gem 的用法
不幸的是,evergreen 还不能很好地与新的 rails 3.1 功能配合使用(在做出这个答案时)。所以我尝试创建一些猴子补丁来让它发挥良好。
# config/evergreen.rb
unless defined?(CONFIG_EVERGREEN_LOADED)
CONFIG_EVERGREEN_LOADED = true
require ::File.expand_path('../environment', __FILE__)
unless "".respond_to?(:each) # this monkey patch make the old capybara play well with ruby 1.9.2
String.class_eval do
def each &block
self.lines &block
end
end
end
module Evergreen
class << self
def application_with_additions(suite)
app = application_without_additions(suite)
app.map "/assets" do
assets = Rails.application.config.assets
if assets.enabled
require 'sprockets'
sprockets = Sprockets::Environment.new(suite.root)
sprockets.static_root = File.join(suite.root, 'public', assets.prefix)
sprockets.paths.concat assets.paths
sprockets.js_compressor = nil
run sprockets
end
end
app
end
alias_method :application_without_additions, :application
alias_method :application, :application_with_additions
end
end