LoginSignup
1
1

More than 5 years have passed since last update.

apiでのリクエスト失敗をテストする

Posted at

あるapiに書いてある、以下のコードをテストしたい

code.rb
fail ActionController::BadRequest unless params[:application_token].in?(Settings.access_grants)

方法1: status codeで400が返ってくることをテスト

api_spec.rb
context 'when the application token is wrong' do
  let(:application_token) { 'wrong_token' }
  it { expect(response).to have_http_status(400) }
end

方法2: errorのkeyがあることをテスト

work in progress

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1