作者热门文章
- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
tl;博士——
是否可以仅在测试主体中包含 :js
测试时运行单个命令(例如 rake assets:precompile
)跑?
--
我正在开发一个 Rails 5、Ruby 2.3.1 应用程序,它有一个大型 rspec
测试套件。
我们最近在应用程序中安装了 webpacker
gem,这导致我们必须运行:
$ bundle exec rake assets:precompile
在运行测试之前。如果没有运行上述命令,测试将针对最近预编译的 Assets 运行。
这引起了一些麻烦,因为开发人员忘记了这一步,然后用头撞墙,直到有人记得在运行测试套件之前运行它。
理想情况下,我想简单地添加到 spec/spec_helper.rb
:
config.before(:suite) do
system('bundle exec rake assets:precompile')
end
但是,这将在每次运行测试套件或其中的任何子集之前运行预编译。这将大大减慢后端开发人员的开发时间,后端开发人员只是尝试运行通常需要 0.15 秒的单个请求规范。
此外,在使用 guard
进行开发时,我们通常会跳过运行 :js
测试,因为它们花费的时间太长。我们只是在部署或推送到远程分支之前运行 :js
规范作为健全性检查。
不幸的是,将 {:js => true}
选项添加到:
config.before(:suite, js:true)
也不起作用,因为 before(:suite)
的选项被忽略了。
最佳答案
使用 :js
标签过滤并对所有规范运行一次。
ENV[ 'ASSET_PRECOMPILE_DONE' ] = nil
config.before(:each, :js) do
if ! ENV[ 'ASSET_PRECOMPILE_DONE' ]
system 'bundle exec rake assets:precompile'
ENV[ 'ASSET_PRECOMPILE_DONE' ] = 'true'
end
end
关于ruby-on-rails - 运行抽佣 Assets :precompile before tests that include :js tag and skip otherwise,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46480226/
我是一名优秀的程序员,十分优秀!