Class: Simulacrum::Component

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ Component

Returns a new instance of Component.



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

def initialize(name, options)
  @name = name
  @options = options
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/simulacrum/component.rb', line 8

def name
  @name
end

Instance Method Details

#acceptable_deltaObject



52
53
54
# File 'lib/simulacrum/component.rb', line 52

def acceptable_delta
  @options.acceptable_delta || Simulacrum.configuration.acceptable_delta
end

#candidate?Boolean

Returns:

  • (Boolean)


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

def candidate?
  File.exists?(candidate_path)
end

#candidate_pathObject



36
37
38
# File 'lib/simulacrum/component.rb', line 36

def candidate_path
  File.join(root_path, Simulacrum.configuration.candidate_filename)
end

#capture_candidateObject

Load up the component url and capture an image, returns a File object



16
17
18
19
20
21
22
# File 'lib/simulacrum/component.rb', line 16

def capture_candidate
  ensure_example_path
  visit(@options.url)
  within(capture_selector) do
    page.save_screenshot(candidate_path)
  end
end

#diff_pathObject



40
41
42
# File 'lib/simulacrum/component.rb', line 40

def diff_path
  File.join(root_path, Simulacrum.configuration.diff_filename)
end

#reference?Boolean

Returns:

  • (Boolean)


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

def reference?
  File.exists?(reference_path)
end

#reference_pathObject



32
33
34
# File 'lib/simulacrum/component.rb', line 32

def reference_path
  File.join(root_path, Simulacrum.configuration.reference_filename)
end

#remove_candidateObject



24
25
26
# File 'lib/simulacrum/component.rb', line 24

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

#root_pathObject



28
29
30
# File 'lib/simulacrum/component.rb', line 28

def root_path
  File.join(Simulacrum.configuration.images_path, name.to_s)
end