Module: LooksGood
- Defined in:
- lib/looks_good.rb,
lib/looks_good/image.rb,
lib/looks_good/version.rb,
lib/looks_good/comparison.rb,
lib/looks_good/configuration.rb,
lib/looks_good/capture_element.rb
Defined Under Namespace
Modules: CaptureElement, Configuration
Classes: Comparison, Image, ImageFromElement, ImageFromFile
Constant Summary
collapse
- VERSION =
"1.1.5"
Class Method Summary
collapse
Class Method Details
.check(expected_reference_filename, actual_element, within: LooksGood::Configuration.default_within) ⇒ Object
14
15
16
17
|
# File 'lib/looks_good.rb', line 14
def check(expected_reference_filename, actual_element, within: LooksGood::Configuration.default_within)
result = match_result(expected_reference_filename, actual_element, within: within)
result
end
|
.compare_until_match(actual_element, reference_file, within:, max_no_tries: LooksGood::Configuration.max_no_tries, sleep_time: LooksGood::Configuration.sleep_between_tries) ⇒ Object
.config(&block) ⇒ Object
89
90
91
92
93
94
95
96
97
|
# File 'lib/looks_good.rb', line 89
def config(&block)
begin
config_class = LooksGood::Configuration
raise "No block provied" unless block_given?
block.call(config_class)
rescue
raise "Config block has changed. Example: LooksGood.config {|c| c.reference_image_path = 'some/path'}. Please see README"
end
end
|
.match_result(expected_reference_filename, actual_element, within:) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/looks_good.rb', line 19
def match_result(expected_reference_filename, actual_element, within:)
result_hash = {}
@actual_element = actual_element
@expected_reference_filename = expected_reference_filename
@expected_reference_file = (File.join(LooksGood::Configuration.path(:reference), expected_reference_filename))
if !File.exists?(@expected_reference_file) || ENV["LOOKS_GOOD"]
save_reference
result_hash[:result] = true
return result_hash
else
reference_file = LooksGood::ImageFromFile.new(expected_reference_filename)
comparison = compare_until_match(actual_element, reference_file, within: within)
result_hash[:comparison] = comparison
result_hash[:percent_difference] = comparison.percent_difference
matches = comparison.matches?
if !matches
comparison.actual_image.save(:candidate)
result_hash[:message] = %Q[view a visual diff image: open #{comparison.diff_image.path(:diff)}\n
HOW TO FIX:\n
- cp #{comparison.diff_image.path(:candidate)} #{@expected_reference_file}
or
- LOOKS_GOOD=true rspec ...
--
#{LooksGood::LooksGood::Configuration.custom_failure_message}]
result_hash[:result] = false
result_hash
else
result_hash[:result] = true
result_hash
end
end
end
|
.save_image_as_candidate(image) ⇒ Object
71
72
73
74
75
|
# File 'lib/looks_good.rb', line 71
def save_image_as_candidate(image)
image.save(:candidate)
raise "The design reference #{image.file_name} does not exist, #{image.path(:candidate)} " +
"is now available to be used as a reference. Copy candidate to root reference_image_path to use as reference"
end
|