Tag: 人类可读

如何在RSpec中使用HTTP状态码符号?

我在控制器的代码中使用HTTP状态代码符号 ,例如: render json: { auth_token: user.authentication_token, user: user }, status: :created 要么 render json: { errors: [“Missing parameter.”] }, success: false, status: :unprocessable_entity 在我的请求规范的代码我也想使用符号: post user_session_path, email: @user.email, password: @user.password expect(last_response.status).to eq(201) … expect(last_response.status).to eq(422) 但是,我使用符号而不是整数的每个测试都会失败: Failure/Error: expect(last_response.status).to eq(:created) expected: :created got: 201 (compared using ==) 以下是Rack中最新的HTTP状态代码符号列表。