ฉันใช้ Rack::Test เพื่อทดสอบแอปของฉันและต้องทดสอบการโพสต์ข้อมูลผ่าน อาแจ็กซ์
การทดสอบของฉันดูเหมือนว่า:
describe 'POST /user/' do
include Rack::Test::Methods
it 'must allow user registration with valid information' do
post '/user', {
username: 'test_reg',
password: 'test_pass',
email: '[email protected]'
}.to_json, {"CONTENT_TYPE" => 'application/json', "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest"}
last_response.must_be :ok?
last_response.body.must_match 'test_reg has been saved'
end
end
แต่ที่ฝั่งเซิร์ฟเวอร์จะไม่ได้รับข้อมูล POSTed
ฉันยังลองส่งแฮชของ params โดยไม่มี to_json
แต่นั่นก็ไม่ได้สร้างความแตกต่าง
มีความคิดอย่างไรในการทำเช่นนี้?