lookbook_visual_tester 0.5.1 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 865c3eeb875ed336338493ccbd620fcfeba15be5410c7d605cf73d94e79e3756
4
- data.tar.gz: '081022c43fe54c60a95be903181d956223bb34800700a44a45baf3c69d7cc4a8'
3
+ metadata.gz: 61d8ae85e5897ffcb0dd53078b753a02cfc118e9cf5990ebbf27b40c5778bc4a
4
+ data.tar.gz: afcd716247590085bf7dbb99c36e146f45a350f349c1c2fda5dad9d7c8441192
5
5
  SHA512:
6
- metadata.gz: 4991161dee4f699f25517991abf504cc92ac8c229e4e61a985da90195d0238815423c9129f51cc5abf5ad0818f0bacfdf65a4aea087e93ad309fbe69ed3cbd9d
7
- data.tar.gz: 9e3d4f144424de70fc3754b5939d65ee3f327cab3ad2dcecc6dd1923adc77d88db834bfaacbf059deb051fe66546248346f01d90f20593d25cea01e0f1449860
6
+ metadata.gz: e22889eacb81f638d7ba65ab1e8682d0e1ec7e22903f67b950912ef5f670eb3ec13dca31ba21e52ef6cac3e73ce6da11179a7ec35e37eb44b5392e4f99ac6004
7
+ data.tar.gz: e5f18347bff022b59a7b6504c2a2cd0b64e279b587b9dc92f4a0001f7056cc63e8affa58167799cac8ef2fa434718d973ea6fbd375f54a6697240f5b1bc050bf
data/CHANGELOG.md CHANGED
@@ -1,4 +1,15 @@
1
1
  # Changelog
2
+ ## [0.5.3] - 2026-01-04
3
+
4
+ ### Fixed
5
+ - **Deep Check**: `rake lookbook:deep_check` now correctly detects and fails when a preview returns `nil` (implicit rendering) but the corresponding template is missing (`ViewComponent::MissingPreviewTemplateError`).
6
+ - **Deep Check**: `rake lookbook:deep_check` now exits with status 1 if any errors or failures are detected.
7
+
8
+ ## [0.5.2] - 2026-01-04
9
+
10
+ ### Fixed
11
+ - **Preview Checker**: Fixed a `NoMethodError` crash in `PreviewChecker` when encountering template-only Lookbook scenarios (scenarios without a corresponding method in the preview class).
12
+
2
13
  ## [0.5.1] - 2026-01-03
3
14
 
4
15
  ### Fixed
data/README.md CHANGED
@@ -29,7 +29,7 @@ sudo apt-get install imagemagick xclip
29
29
  Add to your application's Gemfile:
30
30
  ```ruby
31
31
  group :test do
32
- gem 'lookbook_visual_tester'
32
+ gem 'lookbook_visual_tester', '~> 0.5.3'
33
33
  end
34
34
  ```
35
35
 
@@ -153,7 +153,7 @@ bundle exec rake lookbook:check
153
153
  ```
154
154
 
155
155
  #### Deep Check (Render)
156
- effectively renders all previews to catch runtime and template errors.
156
+ effectively renders all previews to catch runtime errors, missing templates, and other failures. Exits with status 1 if any errors are found.
157
157
  ```bash
158
158
  bundle exec rake lookbook:deep_check
159
159
  ```
@@ -111,6 +111,11 @@ module LookbookVisualTester
111
111
 
112
112
  begin
113
113
  preview_instance = preview_class.new
114
+ unless preview_instance.respond_to?(example_name)
115
+ return CheckResult.new(preview_name: preview.name, example_name: example_name,
116
+ status: :passed)
117
+ end
118
+
114
119
  preview_instance.public_send(example_name)
115
120
 
116
121
  # We don't render, just verify we can call it.
@@ -126,8 +131,21 @@ module LookbookVisualTester
126
131
  example_name = example.name
127
132
 
128
133
  begin
129
- preview_instance = preview_class.new
130
- result = preview_instance.public_send(example_name)
134
+ # Use ViewComponent::Preview logic to get the component to render
135
+ # This handles the case where the method returns nil (implicit template)
136
+ # and returns a component that renders the template.
137
+ if preview_class.respond_to?(:preview_example)
138
+ result = preview_class.preview_example(example_name)
139
+ puts "DEBUG: preview_example('#{example_name}') returned: #{result.inspect} (class: #{result.class})"
140
+ else
141
+ # Fallback for older VC or non-standard setups
142
+ preview_instance = preview_class.new
143
+ unless preview_instance.respond_to?(example_name)
144
+ return CheckResult.new(preview_name: preview.name, example_name: example_name,
145
+ status: :passed)
146
+ end
147
+ result = preview_instance.public_send(example_name)
148
+ end
131
149
 
132
150
  if result.respond_to?(:render_in)
133
151
  # Mock current_user/pundit if needed on the component itself if possible
@@ -147,6 +165,36 @@ module LookbookVisualTester
147
165
  result.render_in(view_context)
148
166
  elsif result.is_a?(String)
149
167
  # Rendered string, good.
168
+ elsif result.nil?
169
+ # If result is nil, it implies an implicit template rendering.
170
+ # We need to verify that the template exists.
171
+
172
+ # Try to find the template file based on conventions
173
+ # Convention: preview_file_dir/preview_file_name/example_name.html.erb
174
+
175
+ # We need the preview file path. Lookbook::Preview might not expose it easily
176
+ # but the class might have source_location.
177
+
178
+ method = preview_class.instance_method(example_name)
179
+ source_file = method.source_location&.first
180
+
181
+ found_template = false
182
+ if source_file
183
+ dir = File.dirname(source_file)
184
+ filename = File.basename(source_file, '.rb')
185
+ template_dir = File.join(dir, filename)
186
+
187
+ extensions = ['.html.erb', '.html.haml', '.html.slim']
188
+ path = File.join(template_dir, "#{example_name}")
189
+
190
+ found_template = extensions.any? { |ext| File.exist?("#{path}#{ext}") }
191
+ end
192
+
193
+ unless found_template
194
+ raise ViewComponent::MissingPreviewTemplateError.new("Preview #{example_name} returned nil and no template found at #{path}.* (checked erb, haml, slim)") if defined?(ViewComponent::MissingPreviewTemplateError)
195
+
196
+ raise "Preview returned nil and no template found at #{path}.*"
197
+ end
150
198
  end
151
199
 
152
200
  CheckResult.new(preview_name: preview.name, example_name: example_name, status: :passed)
@@ -179,6 +179,8 @@ module LookbookVisualTester
179
179
  if result[:error] == 'Baseline not found'
180
180
  # First run, maybe auto-approve or just report
181
181
  puts ' [NEW] Baseline not found. Saved current as potential baseline.'
182
+ FileUtils.mkdir_p(File.dirname(baseline_path))
183
+ FileUtils.cp(current_path, baseline_path)
182
184
  status = :new
183
185
  else
184
186
  puts " [ERROR] #{result[:error]}"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LookbookVisualTester
4
- VERSION = '0.5.1'
4
+ VERSION = '0.5.3'
5
5
  end
@@ -21,6 +21,7 @@ namespace :lookbook do
21
21
  checker = LookbookVisualTester::PreviewChecker.new
22
22
  results = checker.deep_check
23
23
  LookbookVisualTester::CheckReporter.start([results])
24
+ exit 1 if results.any? { |r| r.status == :failed }
24
25
  end
25
26
 
26
27
  desc 'Find components missing previews'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lookbook_visual_tester
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Murilo Vasconcelos
@@ -9,6 +9,20 @@ bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: benchmark
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
12
26
  - !ruby/object:Gem::Dependency
13
27
  name: chunky_png
14
28
  requirement: !ruby/object:Gem::Requirement
@@ -173,7 +187,6 @@ files:
173
187
  - lib/lookbook_visual_tester/configuration.rb
174
188
  - lib/lookbook_visual_tester/driver.rb
175
189
  - lib/lookbook_visual_tester/drivers/ferrum_driver.rb
176
- - lib/lookbook_visual_tester/image_comparator.rb
177
190
  - lib/lookbook_visual_tester/json_output_handler.rb
178
191
  - lib/lookbook_visual_tester/preview_checker.rb
179
192
  - lib/lookbook_visual_tester/railtie.rb
@@ -1,49 +0,0 @@
1
- require 'lookbook_visual_tester/configuration'
2
-
3
- module LookbookVisualTester
4
- class ImageComparator
5
- attr_reader :baseline_dir, :current_dir, :diff_dir
6
-
7
- def initialize
8
- @baseline_dir = LookbookVisualTester.config.baseline_dir
9
- @current_dir = LookbookVisualTester.config.current_dir
10
- @diff_dir = LookbookVisualTester.config.diff_dir
11
- end
12
-
13
- def compare(scenario_run)
14
- filename = scenario_run.filename
15
-
16
- current_path = current_dir.join(filename)
17
- baseline_path = baseline_dir.join(filename)
18
- diff_path = diff_dir.join(scenario_run.diff_filename)
19
-
20
- if baseline_path.exist?
21
- baseline_image = MiniMagick::Image.open(baseline_path)
22
- current_image = MiniMagick::Image.open(current_path)
23
-
24
- unless baseline_image.dimensions == current_image.dimensions
25
- puts ' Image dimensions do not match. Skipping comparison.'
26
- return
27
- end
28
-
29
- begin
30
- compare_command = "compare -metric AE \"#{baseline_path}\" \"#{current_path}\" \"#{diff_path}\" 2>&1"
31
- result = `#{compare_command}`
32
- distortion = result.strip.to_i
33
-
34
- if distortion > 0
35
- puts " Differences found! Diff image saved to #{diff_path}"
36
- else
37
- puts ' No differences detected.'
38
- File.delete(diff_path) if diff_path.exist?
39
- end
40
- rescue StandardError => e
41
- puts " Error comparing images: #{e.message}"
42
- end
43
- else
44
- FileUtils.cp(current_path, baseline_path)
45
- puts " Baseline image created at #{baseline_path}"
46
- end
47
- end
48
- end
49
- end