snap_diff-capybara 2.0.0.beta1 → 2.0.0.beta2

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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +56 -0
  3. data/docs/UPGRADING.md +19 -4
  4. data/docs/architecture.md +38 -22
  5. data/docs/ci-integration.md +13 -3
  6. data/docs/configuration.md +31 -2
  7. data/docs/drivers.md +6 -0
  8. data/docs/framework-setup.md +21 -3
  9. data/docs/reporters.md +20 -5
  10. data/docs/snapdiff.md +326 -0
  11. data/docs/thread_safety.md +4 -3
  12. data/lib/capybara/screenshot/diff/config_legacy.rb +26 -72
  13. data/lib/capybara/screenshot/diff/image_compare.rb +5 -2
  14. data/lib/capybara/screenshot/diff/region.rb +3 -105
  15. data/lib/capybara/screenshot/diff/reporters/default.rb +4 -106
  16. data/lib/capybara_screenshot_diff/screenshot_assertion.rb +12 -24
  17. data/lib/capybara_screenshot_diff.rb +10 -4
  18. data/lib/snap_diff/area_calculator.rb +1 -3
  19. data/lib/snap_diff/browser_helpers.rb +1 -3
  20. data/lib/snap_diff/capture/viewport.rb +6 -7
  21. data/lib/snap_diff/comparison.rb +15 -28
  22. data/lib/snap_diff/config.rb +151 -29
  23. data/lib/snap_diff/deprecation.rb +26 -8
  24. data/lib/snap_diff/drivers.rb +20 -0
  25. data/lib/snap_diff/dsl.rb +12 -12
  26. data/lib/snap_diff/errors.rb +19 -0
  27. data/lib/snap_diff/integrations/cucumber.rb +5 -4
  28. data/lib/snap_diff/integrations/minitest.rb +11 -12
  29. data/lib/snap_diff/integrations/rspec.rb +7 -6
  30. data/lib/snap_diff/legacy_shims.rb +18 -0
  31. data/lib/snap_diff/region.rb +117 -0
  32. data/lib/snap_diff/reporters/default.rb +107 -0
  33. data/lib/snap_diff/reporters/html.rb +7 -9
  34. data/lib/snap_diff/reporting.rb +13 -4
  35. data/lib/snap_diff/screenshot_assertion.rb +37 -4
  36. data/lib/snap_diff/screenshot_matcher.rb +4 -4
  37. data/lib/snap_diff/screenshoter.rb +1 -1
  38. data/lib/snap_diff/snap_manager.rb +1 -2
  39. data/lib/snap_diff/stable_screenshoter.rb +2 -2
  40. data/lib/snap_diff/utils.rb +5 -3
  41. data/lib/snap_diff/version.rb +1 -1
  42. data/lib/snap_diff.rb +44 -15
  43. metadata +5 -1
@@ -34,7 +34,7 @@ module SnapDiff
34
34
  #
35
35
  # @param snapshot Snap The snapshot details to take a stable screenshot of.
36
36
  # @return [void]
37
- # @raise [CapybaraScreenshotDiff::UnstableImage] If a stable screenshot cannot be obtained within the specified `:wait` time.
37
+ # @raise [SnapDiff::UnstableImage] If a stable screenshot cannot be obtained within the specified `:wait` time.
38
38
  def take_comparison_screenshot(snapshot)
39
39
  result = take_stable_screenshot(snapshot)
40
40
 
@@ -43,7 +43,7 @@ module SnapDiff
43
43
  # The failed-stability outcome is data (the annotated attempts report); raising is this
44
44
  # boundary's decision, not the reporter's.
45
45
  # FIXME(uwe): Hand the failure to the verify path so it only reports after the test's own assertions run.
46
- raise CapybaraScreenshotDiff::UnstableImage.new(stability_failure_report(snapshot), caller)
46
+ raise SnapDiff::UnstableImage.new(stability_failure_report(snapshot), caller)
47
47
  end
48
48
 
49
49
  # store success attempt as actual screenshot
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "snap_diff/drivers"
4
+
3
5
  module SnapDiff
4
6
  module Utils
5
7
  def self.detect_available_drivers
@@ -20,9 +22,9 @@ module SnapDiff
20
22
  end
21
23
 
22
24
  def self.find_driver_class_for(driver)
23
- driver = Capybara::Screenshot::Diff::AVAILABLE_DRIVERS.first if driver == :auto
25
+ driver = Drivers.available.first if driver == :auto
24
26
 
25
- Capybara::Screenshot::Diff::LOADED_DRIVERS[driver] ||=
27
+ Drivers.loaded[driver] ||=
26
28
  case driver
27
29
  when :chunky_png
28
30
  require "snap_diff/drivers/chunky_png_driver"
@@ -31,7 +33,7 @@ module SnapDiff
31
33
  require "snap_diff/drivers/vips_driver"
32
34
  SnapDiff::Drivers::VipsDriver
33
35
  else
34
- fail "Wrong adapter #{driver.inspect}. Available adapters: #{Capybara::Screenshot::Diff::AVAILABLE_DRIVERS.inspect}"
36
+ fail "Wrong adapter #{driver.inspect}. Available adapters: #{Drivers.available.inspect}"
35
37
  end
36
38
  end
37
39
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SnapDiff
4
- VERSION = "2.0.0.beta1"
4
+ VERSION = "2.0.0.beta2"
5
5
  end
data/lib/snap_diff.rb CHANGED
@@ -1,7 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # None of these requires ever leads back to this file: config_legacy is a
4
- # leaf (see its own header comment), the image_compare forwarder pulls in
3
+ # Dual-install guard: capybara-screenshot-diff and snap_diff-capybara ship
4
+ # identical files. With BOTH activated, every require silently resolves
5
+ # from whichever gem activated first, so version skew between the two is
6
+ # undetectable. Refuse that setup at the entry point. Local dev from
7
+ # source loads neither spec, so the guard fires only when both are
8
+ # genuinely installed as gems.
9
+ module SnapDiff
10
+ DualInstallError = Class.new(StandardError)
11
+
12
+ # @api private
13
+ def self.assert_single_gem!(loaded_specs = Gem.loaded_specs)
14
+ return unless loaded_specs.key?("capybara-screenshot-diff") && loaded_specs.key?("snap_diff-capybara")
15
+
16
+ raise DualInstallError,
17
+ "Both `capybara-screenshot-diff` and `snap_diff-capybara` gems are installed. " \
18
+ "They ship identical files, so files load from whichever gem activated first " \
19
+ "and versions can silently diverge. Remove one of them from your Gemfile."
20
+ end
21
+ end
22
+ SnapDiff.assert_single_gem!
23
+
24
+ # None of these requires ever leads back to this file: config_legacy sits
25
+ # just above the snap_diff/config leaf (see both headers -- since ADR-008
26
+ # step 1 the storage leaf is snap_diff/config, which config_legacy
27
+ # requires), the image_compare forwarder pulls in
5
28
  # snap_diff/comparison plus the legacy const_missing shims, and
6
29
  # "capybara/dsl" is the base gem. That keeps this file's require graph
7
30
  # acyclic -- it never requires "capybara_screenshot_diff" back, unlike the
@@ -11,12 +34,13 @@
11
34
  # stay resolvable (now with deprecation warnings) even in processes that
12
35
  # only ever require "snap_diff".
13
36
  # "capybara/dsl" is needed directly (not just transitively) so
14
- # `Capybara.default_max_wait_time` in Diff.default_options resolves even
37
+ # `Capybara.default_max_wait_time` in Config#default_options resolves even
15
38
  # when "snap_diff" is required standalone (SnapDiffTest's
16
39
  # "standalone-loadable in a fresh process" regression test).
17
40
  require "capybara/dsl"
18
41
  require "capybara/screenshot/diff/config_legacy"
19
42
  require "capybara/screenshot/diff/image_compare"
43
+ require "snap_diff/errors"
20
44
  require "snap_diff/config"
21
45
 
22
46
  # Forward-looking namespace for the gem, per ADR-004.
@@ -27,22 +51,28 @@ require "snap_diff/config"
27
51
  # shims (snap_diff/legacy_shims) that emit a deprecation warning once per
28
52
  # constant per process. See ADR-004 for the full migration plan.
29
53
  module SnapDiff
30
- def self.compare(...)
31
- Capybara::Screenshot::Diff.compare(...)
54
+ # Compare two images on disk with the configured defaults. Canonical home
55
+ # since ADR-008 step 7b; +Capybara::Screenshot::Diff.compare+ now forwards
56
+ # here rather than the other way round.
57
+ #
58
+ # Note the argument order swap: callers pass baseline first (reading
59
+ # "compare baseline against current"), Comparison takes current first.
60
+ def self.compare(baseline_path, current_path, **options)
61
+ Comparison.new(current_path, baseline_path, config.default_options.merge(options))
32
62
  end
33
63
 
34
- # v1-style configuration: yields the two existing mattr_accessor holders
64
+ # v1-style configuration: yields the two legacy accessor holders
35
65
  # (+Capybara::Screenshot+, +Capybara::Screenshot::Diff+) exactly as
36
- # +Capybara::Screenshot::Diff.configure+ always has. Kept byte-for-byte
37
- # identical to +Diff.configure+ for existing callers migrating namespaces
38
- # without changing call shape.
66
+ # +Capybara::Screenshot::Diff.configure+ always has -- and, since ADR-008
67
+ # step 7b, this is where that yield actually happens; Diff.configure
68
+ # forwards here. Both names stay identical in call shape.
39
69
  #
40
70
  # SnapDiff.start do |screenshot, diff|
41
71
  # screenshot.window_size = [1280, 1024]
42
72
  # diff.tolerance = 0.0005
43
73
  # end
44
- def self.start(&block)
45
- Capybara::Screenshot::Diff.configure(&block)
74
+ def self.start
75
+ yield Capybara::Screenshot, Capybara::Screenshot::Diff
46
76
  end
47
77
 
48
78
  # Forward-looking configuration: yields the single consolidated
@@ -58,8 +88,7 @@ module SnapDiff
58
88
  yield config
59
89
  end
60
90
 
61
- # The single consolidated settings object. See {SnapDiff::Config}.
62
- def self.config
63
- @config ||= Config.new
64
- end
91
+ # SnapDiff.config itself is defined in snap_diff/config.rb (the storage
92
+ # leaf), where the Config instance is created eagerly at require time so
93
+ # the ENV["CI"] / Rails.root defaults evaluate at load, not first call.
65
94
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snap_diff-capybara
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta1
4
+ version: 2.0.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Uwe Kubosch
@@ -94,6 +94,7 @@ files:
94
94
  - docs/migration-guide.md
95
95
  - docs/organization.md
96
96
  - docs/reporters.md
97
+ - docs/snapdiff.md
97
98
  - docs/thread_safety.md
98
99
  - gems.rb
99
100
  - lib/capybara-screenshot-diff.rb
@@ -148,12 +149,15 @@ files:
148
149
  - lib/snap_diff/drivers/vips_driver.rb
149
150
  - lib/snap_diff/dsl.rb
150
151
  - lib/snap_diff/error_with_filtered_backtrace.rb
152
+ - lib/snap_diff/errors.rb
151
153
  - lib/snap_diff/image_preprocessor.rb
152
154
  - lib/snap_diff/integrations/cucumber.rb
153
155
  - lib/snap_diff/integrations/minitest.rb
154
156
  - lib/snap_diff/integrations/rspec.rb
155
157
  - lib/snap_diff/legacy_shims.rb
156
158
  - lib/snap_diff/os.rb
159
+ - lib/snap_diff/region.rb
160
+ - lib/snap_diff/reporters/default.rb
157
161
  - lib/snap_diff/reporters/html.rb
158
162
  - lib/snap_diff/reporters/templates/report.html.erb
159
163
  - lib/snap_diff/reporting.rb