ruby-on-rails - Travis 因 webpacker 问题 (Rspec) rails 5.2 失败
问题描述
我刚刚开始在我的 rails 5.2 应用程序中使用 RSpec 进行测试。我正在将我的应用程序部署到我的远程 Github 存储库,然后在部署到 Heroku 之前由 Travis 对其进行测试。
我创建了一些非常简单的测试,这些测试都通过了,但我刚刚添加了一个新模型distilleries
,Travis 现在构建失败了。
Travis 似乎在抱怨无法在我的 Webpack 清单中找到文件。我的应用程序在本地完美运行。
当我rspec spec/models/distillery_spec.rb
在控制台中运行时,我得到 0 个错误。
我是在 Rails 中进行测试的新手,所以如果我在某处犯了新手错误,请保持温和。
特拉维斯日志
...
Failures:
1) Distilleries GET /distilleries works! (now write some real specs)
Failure/Error: <%= javascript_pack_tag 'application' %>
ActionView::Template::Error:
Webpacker can't find application.js in /home/travis/build/sfcooper/GD/public/packs-test/manifest.json. Possible causes:
1. You want to set webpacker.yml value of compile to true for your environment
unless you are using the `webpack -w` or the webpack-dev-server.
2. webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your webpack configuration is not creating a manifest.
Your manifest contains:
{
}
# ./app/views/layouts/application.html.erb:17:in `_app_views_layouts_application_html_erb___92036987216695529_24174260'
# ./spec/requests/distilleries_spec.rb:6:in `block (3 levels) in <top (required)>'
# ------------------
# --- Caused by: ---
# Webpacker::Manifest::MissingEntryError:
# Webpacker can't find application.js in /home/travis/build/sfcooper/GD/public/packs-test/manifest.json. Possible causes:
# 1. You want to set webpacker.yml value of compile to true for your environment
# unless you are using the `webpack -w` or the webpack-dev-server.
# 2. webpack has not yet re-run to reflect updates.
# 3. You have misconfigured Webpacker's config/webpacker.yml file.
# 4. Your webpack configuration is not creating a manifest.
# Your manifest contains:
# {
# }
# ./app/views/layouts/application.html.erb:17:in `_app_views_layouts_application_html_erb___92036987216695529_24174260'
Finished in 1.04 seconds (files took 2.32 seconds to load)
9 examples, 1 failure
Failed examples:
rspec ./spec/requests/distilleries_spec.rb:5 # Distilleries GET /distilleries works! (now write some real specs)
...
distillery_spec.rb
require 'rails_helper'
RSpec.describe Distillery, type: :model do
context 'validations' do
it { should validate_presence_of(:name) }
it { should validate_presence_of(:snippet) }
end
context 'associations' do
it { should have_many(:gins) }
end
end
工厂/酒厂.rb
FactoryGirl.define do
factory :distillery do
end
end
travis.yml
language: ruby
rvm:
- 2.4.0
before_script:
- bundle exec rake db:create --all
- bundle exec rake db:migrate
script:
- bundle exec rake ci:tests
services:
- postgresql
notifications:
email: false
deploy:
provider: heroku
api_key:
secure: ******
app:
master: thegd
on:
repo: sfcooper/GD
run:
- rails db:migrate
更新
我现在已经删除了整个distilleries_spec.rb
文件,但我仍然遇到同样的问题。我只是看不出 Travis 在哪里发现了清单文件的问题。
公共/包/manifest.json {
"application.css": "/packs/application-25e3a7ac7f3afb6db64c457a591257f8.css",
"application.css.map": "/packs/application-25e3a7ac7f3afb6db64c457a591257f8.css.map",
"application.js": "/packs/application-135f3e8e200516e9e3cd.js",
"application.js.map": "/packs/application-135f3e8e200516e9e3cd.js.map",
"botanicalselector.js": "/packs/botanicalselector-c06eacfbeb4820a881b6.js",
"botanicalselector.js.map": "/packs/botanicalselector-c06eacfbeb4820a881b6.js.map",
"countryselector.js": "/packs/countryselector-9f4de505e0d165ed7721.js",
"countryselector.js.map": "/packs/countryselector-9f4de505e0d165ed7721.js.map"
}
还要记住错误:
Webpacker 在 /home/travis/build/sfcooper/GD/public/packs-test/manifest.json 中找不到 application.js
我已确保此路径不在.gitignore
.
解决方案
解决了
多亏了这个 - https://github.com/rails/webpacker/issues/1494
我花了一点时间才注意到 Travis/public/packs-test/
不是在寻找 manifest.json 文件/public/packs
。
运行后:
RAILS_ENV=test bundle exec rails webpacker:compile
Travis 现在通过了构建。
推荐阅读
- ios - 从 SMS 中打开应用程序,例如地址打开 Plans 或 Doctolib
- android - 数据刷新后 StaggeredGridLayout 不会重新应用到 RecyclerView
- python - 在同一个子图中叠加两个子图(matplotlib)
- twilio - 如何通过 twilio CLI 将示例文本添加到自动驾驶仪任务?
- javascript - Scala.js 可以生成 TypeScript d.ts 类型绑定吗?
- ruby-on-rails - Google AutoML Ruby Gem 表:分配给子消息字段的无效字符串“”
- python - 变量何时存储值,何时存储引用?
- c# - 在 Unity3d 中使用 RESTful Web 服务,无法从“System.Collections.IEnumerable”转换为“字符串”......如何转换或解决?
- html - HTML 问题,奇怪的字符替换了 HREF 引号
- c# - 为什么 XPathNodeIterator 找不到所需的路径?