Ruby 3.0.3 Rails 7.0.0.alpha2 elasticsearch 7.17.1 searchkick 5.0.3
我的測驗都通過了,local但沒有通過 GitHub 操作,我不知道為什么......你知道如何顯示錯誤 500 的詳細資訊嗎?這是水豚測驗
這是我添加的配置
結果
Run echo $ELASTIC_SEARCH_URL
http://localhost:49154
health
green
create index
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 99 100 66 100 33 985 492 --:--:-- --:--:-- --:--:-- 1477
{"acknowledged":true,"shards_acknowledged":true,"index":"iot_log"}read_only_allow_delete
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 67 100 21 100 46 3000 6571 --:--:-- --:--:-- --:--:-- 9571
{"acknowledged":true}watermarks
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 654 100 418 100 236 12294 6941 --:--:-- --:--:-- --:--:-- 19818
{
"acknowledged" : true,
"persistent" : { },
"transient" : {
"cluster" : {
"routing" : {
"allocation" : {
"disk" : {
"watermark" : {
"low" : "50gb",
"flood_stage" : "10gb",
"high" : "20gb"
}
}
}
},
"info" : {
"update" : {
"interval" : "1m"
}
}
}
}
}
Run bundle exec rails test
bundle exec rails test
bundle exec rails test:controllers
# bundle exec rails test test/controllers/companies_controller_test.rb:105
bundle exec rails test:system
shell: /usr/bin/bash -e {0}
env:
RAILS_ENV: test
NODE_ENV: test
ES_HOME: /home/runner/elasticsearch/7.17.1
DB_PASSWORD: postgres
DB_PORT: 5432
REDIS_PORT: 49153
ELASTIC_SEARCH_URL: http://localhost:49154
Running 33 tests in a single process (parallelization threshold is 50)
Run options: --seed 9006
# Running:
F
Failure:
TasksControllerTest#test_should_destroy_task_&_related_permission(s)_where_user_!=_assignee [/home/runner/work/hubflo/hubflo/test/controllers/tasks_controller_test.rb:134]:
Expected response to be a <3XX: redirect>, but was a <500: Internal Server Error>
rails test test/controllers/tasks_controller_test.rb:128
編輯答案
所以我使用了答案rescue_from中的選項
錯誤是
#<Searchkick::ImportError: {"type"=>"index_not_found_exception", "reason"=>"no such index [companies_test]", "resource.type"=>"index_expression", "resource.id"=>"companies_test", "index_uuid"=>"_na_", "index"=>"companies_test"} on item with id '650928[31](https://github.com/Hubflo-sas/hubflo/runs/5795678731?check_suite_focus=true#step:16:31)2'>
F
Failure:
CompaniesControllerTest#test_should_destroy_company [/home/runner/work/hubflo/hubflo/test/controllers/companies_controller_test.rb:110]:
Expected response to be a <3XX: redirect>, but was a <500: Internal Server Error>
rails test test/controllers/companies_controller_test.rb:104
我必須在運行測驗之前運行這個命令bundle exec rake searchkick:reindex:all
uj5u.com熱心網友回復:
<500: Internal Server Error>表示您的控制器中引發了一些例外,但未正確救援。如果您無法在開發環境中重現該問題,您可以:
- 在控制器的操作中添加 a
begin..rescue,然后在救援中添加:p $ERROR_INFO.message($ERROR_INFO是一個特殊變數,其中包含最后一次救援的例外,這是一種更易讀的使用方式$!
def my_controller_action
# ... (business logic)
rescue
p $ERROR_INFO.message
end
您還可以rescue_from在 ApplicationController 中添加一個全域變數
class ApplicationController
rescue_from Exception, with: :my_exception_handler
private
def my_exception_handler
# exception handling logic ( logging to Sentry for example etc.)
end
end
這是rails檔案中更詳細的示例
- 或者,使用 rails minitest,您可以運行
rails test --backtrace(來源此處),其中有更多有趣的選項,您可能希望在 CI 中使用,甚至在本地開發時使用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/456273.html
