Sha256: 1be014c594879d5eee01e09f7b3217adbec2b7f37b1e5adbc577a5585fdf1637

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

require './test/test_helper'
require 'cli/monitored_request'

Struct.new('Response', :body)

class MonitoredRequestTest < MiniTest::Unit::TestCase
  def setup
    setup_api
    @monitored_request = Exercism::CLI::MonitoredRequest.new(@api)
  end

  def test_yield
    @monitored_request.request :success_action do |response, body|
      assert_equal 'Hi.', body["message"]
    end
  end

  def test_response_errors
    out, err = capture_subprocess_io do
      pid = fork { @monitored_request.request :failure_action }
      Process.wait pid
    end

    assert_match 'Error.', err
  end

  def test_handle_request_exceptions
    out, err = capture_subprocess_io do
      pid = fork { @monitored_request.request :exception_action }
      Process.wait pid
    end

    assert_match 'There was an issue with your request.', err
  end

  private

  def setup_api
    @api = Minitest::Mock.new

    def @api.failure_action
      Struct::Response.new('{"error":"Error."}')
    end

    def @api.success_action
      Struct::Response.new('{"message":"Hi."}')
    end

    def @api.exception_action
      raise Exception
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
exercism-0.0.28 test/cli/monitored_request_test.rb
exercism-0.0.27 test/cli/monitored_request_test.rb
exercism-0.0.26 test/cli/monitored_request_test.rb