代码之家  ›  专栏  ›  技术社区  ›  Simon Cooper

Travis因Webpacker问题(RSPEC)Rails 5.2而失败

  •  0
  • Simon Cooper  · 技术社区  · 6 年前

    我刚开始在我的Rails 5.2应用程序中使用rspec进行测试。我正在将我的应用程序部署到我的远程Github存储库,然后由Travis在部署到Heroku之前对其进行测试。

    我创建了一些非常简单的测试,这些测试通过了OK,但我刚添加了一个新模型 distilleries 而特拉维斯现在正在建造失败。

    特拉维斯似乎在抱怨我的网络包里找不到文件。我的应用程序在本地工作得很好。

    当我奔跑 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)
    
    ...
    

    酿酒厂-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
    

    特拉维斯

    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在哪里发现清单文件有问题。

    public/packs/manifest.json(公共/packs/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在中找不到application.js /home/travis/build/sfcooper/gd/public/packs test/manifest.json

    我保证这条路不在 .gitignore .

    1 回复  |  直到 6 年前
        1
  •  1
  •   Simon Cooper    6 年前

    解决了它

    多亏了这个- https://github.com/rails/webpacker/issues/1494

    我花了一点时间才注意到Travis在找manifest.json /public/packs-test/ 不只是 /public/packs .

    运行后:

    RAILS_ENV=test bundle exec rails webpacker:compile
    

    Travis现在通过了构建。

    推荐文章