<NME> api_response_spec.rb
<BEF> ADDFILE
<MSG> Deprecate ResponseError and turn ApiResponse into a Result object

<DFF> @@ -0,0 +1,30 @@
+# frozen_string_literal: true
+require 'minitest_helper'
+
+describe TelegramBot::ApiResponse do
+  ApiResponse = TelegramBot::ApiResponse
+  ExampleResponse = Struct.new(:body, :status)
+
+  def test_error_handling
+    body = { "result" => "oops" }
+    example_response = ExampleResponse.new(JSON.dump(body), 404)
+    response = ApiResponse.new(example_response)
+
+    refute response.ok?
+    assert_kind_of ApiResponse::ResponseError, response.error
+    assert_raises(ApiResponse::ResponseError) do
+      response.value!
+    end
+    assert_equal body, response.error.data
+  end
+
+  def test_success_case
+    body = { "result" => "hello" }
+    example_response = ExampleResponse.new(JSON.dump(body), 200)
+    response = ApiResponse.new(example_response)
+
+    assert response.ok?
+    assert_nil response.error
+    assert_equal "hello", response.value!
+  end
+end

{'addition_count': 30, 'commit_subject': 'Deprecate ResponseError and turn ApiResponse into a Result object', 'deletion_count': 0, 'file_extension': '.rb', 'lang': 'rb', 'license': 'mit', 'repo_name': 'eljojo/telegram_bot'}