Class: CSpec::Spec

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Spec

Returns a new instance of Spec.



13
14
15
16
17
18
19
20
21
# File 'lib/cspec/spec.rb', line 13

def initialize(hash)
  @class = hash['class']
  @name = hash['name']
  @type = hash['type']
  @method = hash['method']
  @method_args = ::CSpec::DataType.convert_all(hash['method_args'])
  @initialization_args = ::CSpec::DataType.convert_all(hash['initialization_args'])
  @expected = hash['expected']
end

Instance Attribute Details

#classObject (readonly)

Returns the value of attribute class.



5
6
7
# File 'lib/cspec/spec.rb', line 5

def class
  @class
end

#expectedObject (readonly)

Returns the value of attribute expected.



5
6
7
# File 'lib/cspec/spec.rb', line 5

def expected
  @expected
end

#initialization_argsObject (readonly)

Returns the value of attribute initialization_args.



5
6
7
# File 'lib/cspec/spec.rb', line 5

def initialization_args
  @initialization_args
end

#methodObject (readonly)

Returns the value of attribute method.



5
6
7
# File 'lib/cspec/spec.rb', line 5

def method
  @method
end

#method_argsObject (readonly)

Returns the value of attribute method_args.



5
6
7
# File 'lib/cspec/spec.rb', line 5

def method_args
  @method_args
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/cspec/spec.rb', line 5

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/cspec/spec.rb', line 5

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/cspec/spec.rb', line 23

def ==(other)
  name == other&.name &&
    self.class == other&.class &&
    method == other&.method &&
    type == other&.type &&
    method_args == other&.method_args &&
    initialization_args == other&.initialization_args
end

#errorObject



32
33
34
35
36
37
38
39
40
# File 'lib/cspec/spec.rb', line 32

def error
  return ["#{self.class} does not exist"] unless Object.const_defined?(self.class)

  errors = []

  errors += send("#{type}_errors")

  errors.size.positive? ? errors.flatten : nil
end

#to_sObject



42
43
44
# File 'lib/cspec/spec.rb', line 42

def to_s
  "name: #{name}, class: #{self.class}, method: #{method}, method_args: #{method_args}"
end