Class: Simulacrum::Component

Inherits:
Object
  • Object
show all
Defined in:
lib/simulacrum/component.rb

Overview

Component Class is responsible for managing the testing of a component defined in a test suite

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Component

Returns a new instance of Component.



14
15
16
17
18
# File 'lib/simulacrum/component.rb', line 14

def initialize(name, options = {})
  @name = name
  @options = options
  @renderer = Simulacrum::Renderer.new(options.url)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/simulacrum/component.rb', line 12

def name
  @name
end

#optionsObject

Returns the value of attribute options.



11
12
13
# File 'lib/simulacrum/component.rb', line 11

def options
  @options
end

Instance Method Details

#candidate?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/simulacrum/component.rb', line 34

def candidate?
  File.exist?(candidate_path)
end

#candidate_pathObject



53
54
55
56
57
# File 'lib/simulacrum/component.rb', line 53

def candidate_path
  # TODO: These should probably be `configuration.defaults....`
  filename = Simulacrum.configuration.candidate_filename
  File.join(root_path, "#{filename}.png")
end

#delta_thresholdObject



42
43
44
45
# File 'lib/simulacrum/component.rb', line 42

def delta_threshold
  # TODO: These should probably be `configuration.defaults....`
  options.delta_threshold || Simulacrum.configuration.delta_threshold
end

#diff?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/simulacrum/component.rb', line 38

def diff?
  File.exist?(diff_path)
end

#diff_pathObject



59
60
61
62
63
# File 'lib/simulacrum/component.rb', line 59

def diff_path
  # TODO: These should probably be `configuration.defaults....`
  filename = Simulacrum.configuration.diff_filename
  File.join(root_path, "#{filename}.png")
end

#reference?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/simulacrum/component.rb', line 30

def reference?
  File.exist?(reference_path)
end

#reference_pathObject



47
48
49
50
51
# File 'lib/simulacrum/component.rb', line 47

def reference_path
  # TODO: These should probably be `configuration.defaults....`
  filename = Simulacrum.configuration.reference_filename
  File.join(root_path, "#{filename}.png")
end

#remove_candidateObject



65
66
67
# File 'lib/simulacrum/component.rb', line 65

def remove_candidate
  FileUtils.rm(candidate_path) if candidate?
end

#remove_diffObject



69
70
71
# File 'lib/simulacrum/component.rb', line 69

def remove_diff
  FileUtils.rm(diff_path) if diff?
end

#renderObject



20
21
22
23
24
25
26
27
28
# File 'lib/simulacrum/component.rb', line 20

def render
  ensure_example_path
  tmp_path = @renderer.render
  save_candidate(tmp_path)
  crop_candidate_to_selector
  true
ensure
  cleanup
end