Class: RSpec::RfcHelper::Spec

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/rfc_helper/spec.rb

Overview

Represents one spec

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(section:, text:, id: nil) ⇒ Spec

Initializes a new Spec

text should have one verb surrounded by brackets, representing what this Spec expects:

bad: It [[MUST]] work with a missing user but [[MAY]] log a warning

Use two Specs instead:

It [[MUST]] work with a missing user but MAY log a warning
It MUST work with a missing user but [[MAY]] log a warning

When nothing is highlighted, spec will appear as a “note”.

Parameters:

  • section (String)

    Section number

  • text (String)

    Paragraph from the RFC.

  • id (Symbol, NilClass) (defaults to: nil)

    Unique identifier



26
27
28
29
30
31
32
33
34
35
# File 'lib/rspec/rfc_helper/spec.rb', line 26

def initialize(section:, text:, id: nil)
  raise "Missing text ({section: #{section}, text: #{text}, id: #{id})" unless text.is_a?(String) && !text.empty?
  raise "Missing section ({section: #{section}, text: #{text}, id: #{id})" unless section.is_a?(String) && !section.empty?

  @id       = id
  @section  = section.to_s
  @text     = text
  @examples = []
  set_verb
end

Instance Attribute Details

#examplesObject (readonly)

Returns the value of attribute examples.



8
9
10
# File 'lib/rspec/rfc_helper/spec.rb', line 8

def examples
  @examples
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/rspec/rfc_helper/spec.rb', line 8

def id
  @id
end

#sectionObject (readonly)

Returns the value of attribute section.



8
9
10
# File 'lib/rspec/rfc_helper/spec.rb', line 8

def section
  @section
end

#textObject (readonly)

Returns the value of attribute text.



8
9
10
# File 'lib/rspec/rfc_helper/spec.rb', line 8

def text
  @text
end

#verbObject (readonly)

Returns the value of attribute verb.



8
9
10
# File 'lib/rspec/rfc_helper/spec.rb', line 8

def verb
  @verb
end

Instance Method Details

#add_example(example) ⇒ Object

Adds an RSpec example

Parameters:

  • example (RSpec::Core::Example)

    RSpec example



64
65
66
# File 'lib/rspec/rfc_helper/spec.rb', line 64

def add_example(example)
  @examples << example
end

#status:unknown|:pass|:has_pending|:failing

Determines status from RSpec examples

Statuses:

unknown: No test currently covers this spec
failing: At least one example failed
has_pending: Some examples are pending, other passed
pass: All examples passed

Returns:

  • (:unknown|:pass|:has_pending|:failing)

    Spec state from all examples



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rspec/rfc_helper/spec.rb', line 47

def status
  value = :unknown
  @examples.each do |example|
    return :failing if example.execution_result.status == :failed
    return :has_pending if example.execution_result.status == :pending
    raise "Unhandled example status: #{example.execution_result.status}" if example.execution_result.status != :passed

    value = :pass
  end

  value
end