Skip to content

Commit 341ed2b

Browse files
committed
wip
1 parent 160fe9e commit 341ed2b

14 files changed

Lines changed: 113 additions & 78 deletions

File tree

test/capybara/screenshot/diff/image_compare_refactor_test.rb

Lines changed: 0 additions & 61 deletions
This file was deleted.
8.32 KB
Loading
8.28 KB
Loading
6.11 KB
Loading
8.28 KB
Loading
5.69 KB
Loading

test/fixtures/rspec_spec.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# frozen_string_literal: true
2+
3+
require "capybara/rspec"
4+
5+
require "capybara_screenshot_diff/rspec"
6+
require "support/stub_test_methods"
7+
8+
unless defined?(SCREEN_SIZE)
9+
require "test_helper"
10+
require "support/setup_capybara_drivers"
11+
end
12+
13+
RSpec.describe "capybara_screenshot_diff/rspec", type: :feature do
14+
before do
15+
Capybara.current_driver = Capybara.javascript_driver
16+
Capybara.page.current_window.resize_to(*SCREEN_SIZE)
17+
Capybara::Screenshot.window_size = SCREEN_SIZE
18+
19+
Capybara::Screenshot.save_path = "doc/screenshots"
20+
Capybara::Screenshot.root = Rails.root / "../test/fixtures/app"
21+
Capybara::Screenshot.add_os_path = true
22+
Capybara::Screenshot.add_driver_path = true
23+
Capybara::Screenshot::Diff.driver = ENV.fetch("SCREENSHOT_DRIVER", "chunky_png").to_sym
24+
Capybara::Screenshot::Diff.tolerance = 0.5
25+
end
26+
27+
it "should include CapybaraScreenshotDiff in rspec" do
28+
expect(self.class.ancestors).to include CapybaraScreenshotDiff::DSL
29+
end
30+
31+
it "visits and compare screenshot on teardown" do
32+
visit "/"
33+
screenshot "index"
34+
end
35+
36+
it "use custom matcher" do
37+
visit "/"
38+
39+
expect(page).to match_screenshot("index", skip_stack_frames: 1, driver: :chunky_png)
40+
end
41+
42+
it "does not conflicts with rspec methods" do
43+
expect { raise StandardError }.to raise_error(StandardError)
44+
end
45+
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class RspecTest < SystemTestCase
1010

1111
# Run the RSpec spec file
1212
capture_output = StringIO.new
13-
spec_file = (ActiveSupport::TestCase.file_fixture_path / "files/rspec_spec.rb").to_s
13+
spec_file = file_fixture("rspec_spec.rb").to_s
1414
rspec_status = RSpec::Core::Runner.run([spec_file], capture_output, capture_output)
1515

1616
assert_equal 0, rspec_status, "RSpec tests failed:\n#{capture_output.string}"

test/support/capybara_screenshot_diff/dsl_stub.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require "active_support/concern"
2+
13
module CapybaraScreenshotDiff
24
module DSLStub
35
extend ActiveSupport::Concern

test/test_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def fixture_image_path_from(original_new_image, ext = "png")
5757
end
5858

5959
def assert_same_images(expected_image_name, image_path)
60-
expected_image_path = file_fixture("files/comparisons/#{expected_image_name}")
60+
expected_image_path = file_fixture("comparisons/#{expected_image_name}")
6161
assert_predicate(Capybara::Screenshot::Diff::ImageCompare.new(image_path, expected_image_path), :quick_equal?)
6262
end
6363

0 commit comments

Comments
 (0)