Class: SpecGuard::RSpec::Transport::Result

Inherits:
Struct
  • Object
show all
Defined in:
lib/specguard/rspec/transport.rb

Overview

What the ingest endpoint said, in the one form the caller has to handle.

outcome is one of:

:success   a 2xx. `code` carries it (202 in the happy path).
:rejected  a non-2xx. `code` carries it; nothing was raised.
:failed    an exception was raised. `error` carries it.

Constant Summary collapse

ADVICE =

The status codes worth spelling out, because each implies a different thing for the reader to do. A 401 means "rotate or fix the key"; a 400 means "the payload this gem built was refused", which is a bug report and not a credentials problem. Printing a bare number would leave a CI operator to guess which of the two they are looking at.

{
  400 => "the endpoint rejected the payload",
  401 => "the API key was not accepted",
  403 => "this API key may not write to that repository",
  404 => "no ingest endpoint at that URL — check SPECGUARD_ENDPOINT",
  413 => "the payload was too large for the endpoint",
  429 => "rate limited by the endpoint"
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#codeObject

Returns the value of attribute code

Returns:

  • (Object)

    the current value of code



150
151
152
# File 'lib/specguard/rspec/transport.rb', line 150

def code
  @code
end

#errorObject

Returns the value of attribute error

Returns:

  • (Object)

    the current value of error



150
151
152
# File 'lib/specguard/rspec/transport.rb', line 150

def error
  @error
end

#outcomeObject

Returns the value of attribute outcome

Returns:

  • (Object)

    the current value of outcome



150
151
152
# File 'lib/specguard/rspec/transport.rb', line 150

def outcome
  @outcome
end

Instance Method Details

#reasonString?

A single clause naming what went wrong, for the one stderr line a run is allowed. nil on success, because there is nothing to say.

Returns:

  • (String, nil)


171
172
173
174
175
176
177
# File 'lib/specguard/rspec/transport.rb', line 171

def reason
  case outcome
  when :success then nil
  when :rejected then [+"HTTP #{code}", ADVICE[code]].compact.join("")
  else "#{error.class}: #{error.message}"
  end
end

#success?Boolean

Returns:

  • (Boolean)


165
# File 'lib/specguard/rspec/transport.rb', line 165

def success? = outcome == :success