Class: Spectre::Subject

Inherits:
Object show all
Defined in:
lib/spectre.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(desc) ⇒ Subject

Returns a new instance of Subject.



81
82
83
84
85
# File 'lib/spectre.rb', line 81

def initialize desc
  @desc = desc
  @specs = []
  @name = desc.downcase.gsub(/[^a-z0-9]+/, '_')
end

Instance Attribute Details

#descObject (readonly)

Returns the value of attribute desc.



79
80
81
# File 'lib/spectre.rb', line 79

def desc
  @desc
end

#nameObject (readonly)

Returns the value of attribute name.



79
80
81
# File 'lib/spectre.rb', line 79

def name
  @name
end

#specsObject (readonly)

Returns the value of attribute specs.



79
80
81
# File 'lib/spectre.rb', line 79

def specs
  @specs
end

Instance Method Details

#add_spec(desc, tags, data, block, context, file, line) ⇒ Object



87
88
89
90
# File 'lib/spectre.rb', line 87

def add_spec desc, tags, data, block, context, file, line
  name = @name + '-' + (@specs.length+1).to_s
  @specs << Spec.new(name, self, desc, tags, data, block, context, file, line)
end

#to_hObject



92
93
94
95
96
97
98
# File 'lib/spectre.rb', line 92

def to_h
  {
    name: @name,
    desc: @desc,
    specs: @specs.map { |x| x.to_h },
  }
end