Sim*_*per 3 rspec ruby-on-rails travis-ci webpack webpacker
我刚刚开始在我的 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)
...
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
工厂/酿酒厂.rb
FactoryGirl.define do
factory :distillery do
end
end
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
更新
我现在已经删除了整个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"
}
Run Code Online (Sandbox Code Playgroud)
还要记住错误:
Webpacker 在 /home/travis/build/sfcooper/GD/public/packs-test/manifest.json 中找不到 application.js
我已经确保这条路径不在.gitignore.
解决了
感谢这个 - https://github.com/rails/webpacker/issues/1494
我花了一点时间才注意到 Travis 正在寻找 manifest.json/public/packs-test/不仅仅是/public/packs.
运行后:
RAILS_ENV=test bundle exec rails webpacker:compile
Run Code Online (Sandbox Code Playgroud)
Travis 现在通过了构建。