snap_diff-capybara 2.0.0.beta1 → 2.0.0.beta3

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 (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +89 -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/cucumber.rb +5 -1
  14. data/lib/capybara/screenshot/diff/image_compare.rb +17 -2
  15. data/lib/capybara/screenshot/diff/region.rb +3 -105
  16. data/lib/capybara/screenshot/diff/reporters/default.rb +13 -101
  17. data/lib/capybara_screenshot_diff/screenshot_assertion.rb +12 -24
  18. data/lib/capybara_screenshot_diff/static.rb +4 -0
  19. data/lib/capybara_screenshot_diff.rb +10 -4
  20. data/lib/snap_diff/area_calculator.rb +1 -3
  21. data/lib/snap_diff/browser_helpers.rb +1 -3
  22. data/lib/snap_diff/capture/viewport.rb +6 -7
  23. data/lib/snap_diff/comparison.rb +15 -28
  24. data/lib/snap_diff/config.rb +151 -29
  25. data/lib/snap_diff/deprecation.rb +26 -8
  26. data/lib/snap_diff/drivers.rb +20 -0
  27. data/lib/snap_diff/dsl.rb +20 -12
  28. data/lib/snap_diff/errors.rb +25 -0
  29. data/lib/snap_diff/integrations/cucumber.rb +5 -4
  30. data/lib/snap_diff/integrations/minitest.rb +11 -12
  31. data/lib/snap_diff/integrations/rspec.rb +7 -6
  32. data/lib/snap_diff/legacy_shims.rb +15 -0
  33. data/lib/snap_diff/region.rb +117 -0
  34. data/lib/snap_diff/reporters/default.rb +107 -0
  35. data/lib/snap_diff/reporters/html.rb +7 -9
  36. data/lib/snap_diff/reporting.rb +14 -5
  37. data/lib/snap_diff/screenshot_assertion.rb +37 -4
  38. data/lib/snap_diff/screenshot_matcher.rb +4 -4
  39. data/lib/snap_diff/screenshoter.rb +1 -1
  40. data/lib/snap_diff/snap_manager.rb +1 -2
  41. data/lib/snap_diff/stable_screenshoter.rb +2 -2
  42. data/lib/snap_diff/utils.rb +5 -3
  43. data/lib/snap_diff/version.rb +1 -1
  44. data/lib/snap_diff-capybara.rb +8 -0
  45. data/lib/snap_diff.rb +55 -15
  46. metadata +6 -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.beta3"
5
5
  end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Bundler.require entry point for `gem "snap_diff-capybara"`: Bundler
4
+ # requires the gem's own name, and its dash->slash fallback ("snap_diff/
5
+ # capybara") misses too, so without this file a Rails user gets a silent
6
+ # no-op and a confusing NameError later. Loads what the sibling
7
+ # capybara-screenshot-diff.rb loads.
8
+ require "capybara_screenshot_diff/minitest"
data/lib/snap_diff.rb CHANGED
@@ -1,7 +1,36 @@
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
+ #
10
+ # snap_diff/errors is pulled in first (two dependency-free files) so
11
+ # DualInstallError can sit under SnapDiff::Error like every other error the
12
+ # gem raises -- docs/snapdiff.md promises Error is the catch-all.
13
+ require "snap_diff/errors"
14
+
15
+ module SnapDiff
16
+ DualInstallError = Class.new(Error)
17
+
18
+ # @api private
19
+ def self.assert_single_gem!(loaded_specs = Gem.loaded_specs)
20
+ return unless loaded_specs.key?("capybara-screenshot-diff") && loaded_specs.key?("snap_diff-capybara")
21
+
22
+ raise DualInstallError,
23
+ "Both `capybara-screenshot-diff` and `snap_diff-capybara` gems are installed. " \
24
+ "They ship identical files, so files load from whichever gem activated first " \
25
+ "and versions can silently diverge. Remove one of them from your Gemfile."
26
+ end
27
+ end
28
+ SnapDiff.assert_single_gem!
29
+
30
+ # None of these requires ever leads back to this file: config_legacy sits
31
+ # just above the snap_diff/config leaf (see both headers -- since ADR-008
32
+ # step 1 the storage leaf is snap_diff/config, which config_legacy
33
+ # requires), the image_compare forwarder pulls in
5
34
  # snap_diff/comparison plus the legacy const_missing shims, and
6
35
  # "capybara/dsl" is the base gem. That keeps this file's require graph
7
36
  # acyclic -- it never requires "capybara_screenshot_diff" back, unlike the
@@ -11,13 +40,19 @@
11
40
  # stay resolvable (now with deprecation warnings) even in processes that
12
41
  # only ever require "snap_diff".
13
42
  # "capybara/dsl" is needed directly (not just transitively) so
14
- # `Capybara.default_max_wait_time` in Diff.default_options resolves even
43
+ # `Capybara.default_max_wait_time` in Config#default_options resolves even
15
44
  # when "snap_diff" is required standalone (SnapDiffTest's
16
45
  # "standalone-loadable in a fresh process" regression test).
17
46
  require "capybara/dsl"
18
47
  require "capybara/screenshot/diff/config_legacy"
19
48
  require "capybara/screenshot/diff/image_compare"
20
49
  require "snap_diff/config"
50
+ require "snap_diff/version"
51
+ # SnapDiff.session/.reset/.pending_screenshots_message are part of the
52
+ # documented core surface (docs/snapdiff.md object map lists them with no
53
+ # extra require), so the entry point owns them rather than leaving them to
54
+ # whichever integration happens to be loaded.
55
+ require "snap_diff/screenshot_assertion"
21
56
 
22
57
  # Forward-looking namespace for the gem, per ADR-004.
23
58
  #
@@ -27,22 +62,28 @@ require "snap_diff/config"
27
62
  # shims (snap_diff/legacy_shims) that emit a deprecation warning once per
28
63
  # constant per process. See ADR-004 for the full migration plan.
29
64
  module SnapDiff
30
- def self.compare(...)
31
- Capybara::Screenshot::Diff.compare(...)
65
+ # Compare two images on disk with the configured defaults. Canonical home
66
+ # since ADR-008 step 7b; +Capybara::Screenshot::Diff.compare+ now forwards
67
+ # here rather than the other way round.
68
+ #
69
+ # Note the argument order swap: callers pass baseline first (reading
70
+ # "compare baseline against current"), Comparison takes current first.
71
+ def self.compare(baseline_path, current_path, **options)
72
+ Comparison.new(current_path, baseline_path, config.default_options.merge(options))
32
73
  end
33
74
 
34
- # v1-style configuration: yields the two existing mattr_accessor holders
75
+ # v1-style configuration: yields the two legacy accessor holders
35
76
  # (+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.
77
+ # +Capybara::Screenshot::Diff.configure+ always has -- and, since ADR-008
78
+ # step 7b, this is where that yield actually happens; Diff.configure
79
+ # forwards here. Both names stay identical in call shape.
39
80
  #
40
81
  # SnapDiff.start do |screenshot, diff|
41
82
  # screenshot.window_size = [1280, 1024]
42
83
  # diff.tolerance = 0.0005
43
84
  # end
44
- def self.start(&block)
45
- Capybara::Screenshot::Diff.configure(&block)
85
+ def self.start
86
+ yield Capybara::Screenshot, Capybara::Screenshot::Diff
46
87
  end
47
88
 
48
89
  # Forward-looking configuration: yields the single consolidated
@@ -58,8 +99,7 @@ module SnapDiff
58
99
  yield config
59
100
  end
60
101
 
61
- # The single consolidated settings object. See {SnapDiff::Config}.
62
- def self.config
63
- @config ||= Config.new
64
- end
102
+ # SnapDiff.config itself is defined in snap_diff/config.rb (the storage
103
+ # leaf), where the Config instance is created eagerly at require time so
104
+ # the ENV["CI"] / Rails.root defaults evaluate at load, not first call.
65
105
  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.beta3
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
@@ -132,6 +133,7 @@ files:
132
133
  - lib/capybara_screenshot_diff/snap.rb
133
134
  - lib/capybara_screenshot_diff/snap_manager.rb
134
135
  - lib/capybara_screenshot_diff/static.rb
136
+ - lib/snap_diff-capybara.rb
135
137
  - lib/snap_diff.rb
136
138
  - lib/snap_diff/annotation_service.rb
137
139
  - lib/snap_diff/area_calculator.rb
@@ -148,12 +150,15 @@ files:
148
150
  - lib/snap_diff/drivers/vips_driver.rb
149
151
  - lib/snap_diff/dsl.rb
150
152
  - lib/snap_diff/error_with_filtered_backtrace.rb
153
+ - lib/snap_diff/errors.rb
151
154
  - lib/snap_diff/image_preprocessor.rb
152
155
  - lib/snap_diff/integrations/cucumber.rb
153
156
  - lib/snap_diff/integrations/minitest.rb
154
157
  - lib/snap_diff/integrations/rspec.rb
155
158
  - lib/snap_diff/legacy_shims.rb
156
159
  - lib/snap_diff/os.rb
160
+ - lib/snap_diff/region.rb
161
+ - lib/snap_diff/reporters/default.rb
157
162
  - lib/snap_diff/reporters/html.rb
158
163
  - lib/snap_diff/reporters/templates/report.html.erb
159
164
  - lib/snap_diff/reporting.rb