升级 sprockets-rails gem 中断测试
Upgrading sprockets-rails gem breaks tests
从2.3.3版本升级到sprockets-rails
3.0版本后,下面的集成测试失败。它曾经通过但现在给出错误:Expected exactly 2 elements matching "img[src*='profile.gif']", found 0..
.
测试:
get user_path(@user1)
puts @response.body
assert_select "img[src*='profile.gif']", count: 2
puts @response.body
确认图像存在两次,因为正文包含两次:
src="/assets/account/profile-3454be0beae***256dab6d.gif"
。尽管如此,测试还是失败了。
有人明白吗?我该如何解决?
更改似乎与 rails 4
有关,如 Asset Pipeline documentation 中所述:
Rails 4 no longer sets default config values for Sprockets in test.rb,
so test.rb now requires Sprockets configuration. The old defaults in
the test environment are: config.assets.compile = true,
config.assets.compress = false, config.assets.debug = false and
config.assets.digest = false.
因此,如果在测试环境中不需要摘要,则应在 config/environments/test.rb
文件中明确配置:
config.assets.digest = false
从2.3.3版本升级到sprockets-rails
3.0版本后,下面的集成测试失败。它曾经通过但现在给出错误:Expected exactly 2 elements matching "img[src*='profile.gif']", found 0..
.
测试:
get user_path(@user1)
puts @response.body
assert_select "img[src*='profile.gif']", count: 2
puts @response.body
确认图像存在两次,因为正文包含两次:
src="/assets/account/profile-3454be0beae***256dab6d.gif"
。尽管如此,测试还是失败了。
有人明白吗?我该如何解决?
更改似乎与 rails 4
有关,如 Asset Pipeline documentation 中所述:
Rails 4 no longer sets default config values for Sprockets in test.rb, so test.rb now requires Sprockets configuration. The old defaults in the test environment are: config.assets.compile = true, config.assets.compress = false, config.assets.debug = false and config.assets.digest = false.
因此,如果在测试环境中不需要摘要,则应在 config/environments/test.rb
文件中明确配置:
config.assets.digest = false