request.env['CONTENT_TYPE'] = "application/json"
request.env['RAW_POST_DATA'] = [jsonデータ]
とりあえず以下ヘルパーを作成しときました。
module JsonRequest
module TestHelpers
def json_post(action, json, *argument)
request.env['CONTENT_TYPE'] = "application/json"
request.env['RAW_POST_DATA'] = json
post action, *argument
end
end
end
RSpec.configure do |config|
config.include JsonRequest::TestHelpers, :type => :controller
end