Ruby on Rails - RSpec api json 恢复 html 而不是 json

问题描述 投票:0回答:0

这是我用于 rspec 测试时间表创建的代码:

    it 'Create timesheet' do
        timesheet = {
            start_date: Date.new(2023,1,1), 
            end_date: Date.new(2023,1,31)
        }
        sign_in_as_a_valid_user
        post "/timesheets.json", headers: headers, params: timesheet, as: :json
        expect(response).to have_http_status(:created)
        json_response = JSON.parse(response.body)
        byebug
        expect(json_response['start_date']).to eq(2023,1,1)
        expect(json_response['end_date']).to eq(2023,1,31)
    end

当我在控制台中运行测试时,它返回以下错误:

1) Api Create timesheet
     Failure/Error: <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload', defer: true %>
     
     ActionView::Template::Error:
       Webpacker can't find application.js in /home/yir/Documents/workspace/projet1/alpha/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:
       {
       }

谁能告诉我如何解决这个问题?

ruby-on-rails ruby-on-rails-4 rspec rspec-rails
© www.soinside.com 2019 - 2024. All rights reserved.