【发布时间】:2013-08-16 13:39:25
【问题描述】:
我在控制器的代码中使用HTTP status code symbols,例如:
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 ==)
这是HTTP status code symbols in Rack的最新列表。
【问题讨论】:
标签: ruby-on-rails rspec http-status-codes human-readable