我正在模拟来自外部服务的请求,该服务不具有真实性令牌。如果缺少skip_before_action :verify_authenticity_token
,我希望测试失败。
如何从Rspec请求规范执行此操作?
目前我正在使用post
,如下所示,但很高兴接受。
post endpoint, my_json_string, {'CONTENT_TYPE' => "application/json"}
答案 0 :(得分:34)
CSRF保护disabled in test environment。尝试启用它:
before do
ActionController::Base.allow_forgery_protection = true
end
after do
ActionController::Base.allow_forgery_protection = false
end