Class: Simulacrum::Component
- Inherits:
-
Object
- Object
- Simulacrum::Component
- 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
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #candidate? ⇒ Boolean
- #candidate_path ⇒ Object
- #delta_threshold ⇒ Object
- #diff? ⇒ Boolean
- #diff_path ⇒ Object
-
#initialize(name, options = {}) ⇒ Component
constructor
A new instance of Component.
- #reference? ⇒ Boolean
- #reference_path ⇒ Object
- #remove_candidate ⇒ Object
- #remove_diff ⇒ Object
- #render ⇒ Object
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, = {}) @name = name @options = @renderer = Simulacrum::Renderer.new(.url) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/simulacrum/component.rb', line 12 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
11 12 13 |
# File 'lib/simulacrum/component.rb', line 11 def @options end |
Instance Method Details
#candidate? ⇒ Boolean
34 35 36 |
# File 'lib/simulacrum/component.rb', line 34 def candidate? File.exist?(candidate_path) end |
#candidate_path ⇒ Object
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_threshold ⇒ Object
42 43 44 45 |
# File 'lib/simulacrum/component.rb', line 42 def delta_threshold # TODO: These should probably be `configuration.defaults....` .delta_threshold || Simulacrum.configuration.delta_threshold end |
#diff? ⇒ Boolean
38 39 40 |
# File 'lib/simulacrum/component.rb', line 38 def diff? File.exist?(diff_path) end |
#diff_path ⇒ Object
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
30 31 32 |
# File 'lib/simulacrum/component.rb', line 30 def reference? File.exist?(reference_path) end |
#reference_path ⇒ Object
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_candidate ⇒ Object
65 66 67 |
# File 'lib/simulacrum/component.rb', line 65 def remove_candidate FileUtils.rm(candidate_path) if candidate? end |
#remove_diff ⇒ Object
69 70 71 |
# File 'lib/simulacrum/component.rb', line 69 def remove_diff FileUtils.rm(diff_path) if diff? end |
#render ⇒ Object
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 |