module Expresenter::Common

Common collection of methods.

Constants

SPACE

White space.

Attributes

actual[R]

@return [#object_id] Returned value by the challenged subject.

definition[R]

@return [String] A readable string of the matcher and any expected values.

error[R]

@return [Exception, nil] Any possible raised exception.

expected[R]

@return [#object_id] The expected value.

got[R]

@return [#object_id] The result of the boolean comparison between the

actual value and the expected value through the matcher.
level[R]

@return [:MUST, :SHOULD, :MAY] The requirement level of the expectation.

Public Instance Methods

colored_char() click to toggle source

Express the result with one colored char.

@return [String] The colored char that identify the result.

# File lib/expresenter/common.rb, line 87
def colored_char
  color(char)
end
colored_string() click to toggle source

The colored string representation of the result.

@return [String] A string representing the result.

# File lib/expresenter/common.rb, line 94
def colored_string
  color(to_bold_s)
end
error?() click to toggle source

The state of error.

@return [Boolean] The test raised an error?

# File lib/expresenter/common.rb, line 45
def error?
  !error.nil?
end
inspect() click to toggle source

A string containing a human-readable representation of the result.

@return [String] The human-readable representation of the result.

# File lib/expresenter/common.rb, line 59
def inspect
  "#{self.class}(actual: #{actual.inspect}, " \
    "definition: #{definition.inspect}, "     \
    "error: #{error.inspect}, "               \
    "expected: #{expected.inspect}, "         \
    "got: #{got.inspect}, "                   \
    "negate: #{negate?.inspect}, "            \
    "level: #{level.inspect})"
end
negate?() click to toggle source

The value of the negate instance variable.

@return [Boolean] Evaluated to a negative assertion?

# File lib/expresenter/common.rb, line 38
def negate?
  @negate
end
passed?() click to toggle source

Did the test pass?

@return [Boolean] The spec passed or failed?

# File lib/expresenter/common.rb, line 31
def passed?
  !failed?
end
success?() click to toggle source

The state of success.

@return [Boolean] The test was a success?

# File lib/expresenter/common.rb, line 52
def success?
  got.equal?(true)
end
summary() click to toggle source

The summary of the result.

@return [String] A string representing the summary of the result.

# File lib/expresenter/common.rb, line 72
def summary
  if error?
    error.message
  elsif actual.is_a?(::Exception)
    actual.message
  elsif actual == expected
    ["expected", negation, "to", definition].compact.join(SPACE)
  else
    ["expected", actual.inspect, negation, "to", definition].compact.join(SPACE)
  end
end
titre() click to toggle source

Titre for the result.

@return [String] A string representing the titre.

# File lib/expresenter/common.rb, line 108
def titre
  if error?
    error.class.name
  else
    to_sym.to_s.capitalize
  end
end
to_s() click to toggle source

The representation of the result.

@return [String] A string representing the result.

# File lib/expresenter/common.rb, line 101
def to_s
  "#{titre}: #{summary}."
end

Protected Instance Methods

negation() click to toggle source

The negation, if any.

@return [String, nil] The negation, or an empty string.

# File lib/expresenter/common.rb, line 121
def negation
  "not" if negate?
end
to_bold_s() click to toggle source

The representation of the result with the title in bold.

@return [String] A string representing the result with the title in bold.

# File lib/expresenter/common.rb, line 128
def to_bold_s
  "\e[1m#{titre}\e[22m: #{summary}."
end