Closed markcodexq closed 2 years ago
@markcodexq теперь необходимо добавить тесты для для данного concern, можно посмотреть пример создания фейкого контроллера в файле Todoser/spec/controllers/concerns/api_responders_spec.rb, пример теста для проверки flash
expect(flash[:success]).to match(/Some text/)
expect(flash[:alert]).to match(/Some error text/)
require 'rails_helper'
describe Resulteable, type :controller do
controller(ApplicationController) do
include ApiRespoders
def render_object
ok(token: "Bearer token")
end
end
before do
routes.draw do
get :render_object, to: "anonymous#render_object"
end
end
it 'success flash resultable' do
get :render_object
expect(flash[:success]).to match(/Some text/)
end
end
Примерно такое?
require 'rails_helper' describe Resulteable, type :controller do controller(ApplicationController) do include ApiRespoders def render_object ok(token: "Bearer token") end end before do routes.draw do get :render_object, to: "anonymous#render_object" end end it 'success flash resultable' do get :render_object expect(flash[:success]).to match(/Some text/) end end
Примерно такое?
У тебя должно быть два метода у контроллера, так же у тебя не вызывается сам методо который тестируешь, должно быть что-то вроде
def success
result = Result.new(true, "success object", nil)
flash_service_result(result)
end
require 'rails_helper'
describe Resulteable, type: :controller do
controller(ApplicationController) do
include Resulteable
def success
result = Result.new(true, "success object", nil)
flash_service_result(result)
end
end
end
it 'success flash resultable' do
get :success
expect(flash[:success]).to match(/Some Text/)
end
end
не понимаю как вызвать в тесте метод success?
@markcodexq ты в тесте по факту создаешь новый контроллер
controller(ApplicationController) do
Добавляешь в него нужные тебе action
def success ...
def error ...
Затем ты добавляешь нужные тебе роуты для http запроса
before do
routes.draw do
get :success, to: "anonymous#success"
# и путь для error
end
end
Затем внутри блока it делаешь запрос
get :success
и в итоге идет вызов нужного тебе метода контроллера, после вызова этого метода нужно проверить flash
Да я так сделал и пишет
require 'rails_helper'
describe Resulteable, type: :controller do
controller(ApplicationController) do
include Resulteable
def success
result = Result.new(true, "success object", nil)
flash_service_result(result)
end
end
before do
routes.draw do
get :success, to: "anonymous#success"
end
end
it 'success flash resultable' do
get :success
expect(flash[:success]).to match(/Some Text/)
end
end
Всё запушил, внёс изменения, тесты прошли успешно
@markcodexq в целом все ок, есть замечанию по стилям, прошу исправить
Исправил
Теперь исправил с rubocop
@markcodexq Погоди, правильнее будет просто вмержить эту ветку в задачу, иначе будет сильное дробление(что в целом не плохо когда есть какой нибудь Продук, но в нашем случае слишком маленькая команда)