Skip to content

Commit

Permalink
Cleanup code & configurations (#86)
Browse files Browse the repository at this point in the history
* Auto-fix standardrb errors

* Adds rails 7.1 to CI/CD

* Drops unreachable code
  • Loading branch information
pftg authored Nov 7, 2023
1 parent 6a113e2 commit 7d1d087
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ on:
pull_request:
branches: [ master ]
paths:
- '*.rb'
- '*.yml'
- '**.rb'
- '**.yml'
- '.github/workflows/lint.yml'
- '!bin/**'

Expand Down
18 changes: 11 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:
workflow_dispatch:

env:
BUNDLE_GEMFILE: gemfiles/rails70_gems.rb
BUNDLE_GEMFILE: gemfiles/rails71_gems.rb
DEBIAN_FRONTEND: noninteractive
FERRUM_PROCESS_TIMEOUT: 40
RUBY_YJIT_ENABLE: 1
Expand All @@ -35,7 +35,7 @@ jobs:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0
ruby-version: 3.2
bundler-cache: true
- name: Cache Webdrivers
uses: actions/cache@v3
Expand Down Expand Up @@ -137,29 +137,33 @@ jobs:
matrix:
ruby-version: [ 3.2, 3.1, 3.0, jruby ]
gemfile:
- rails71_gems.rb
- rails70_gems.rb
- rails61_gems.rb
experimental: [ false ]
exclude:
# We already tested last version
- ruby-version: 3.2
gemfile: gemfiles/rails70_gems.rb
gemfile: rails71_gems.rb
experimental: false
include:
- ruby-version: 3.2
gemfile: edge_gems.rb
experimental: true
- ruby-version: ruby-head
gemfile: rails70_gems.rb
gemfile: rails71_gems.rb
experimental: true
- ruby-version: 3.3.0-preview2
gemfile: rails71_gems.rb
experimental: true
- ruby-version: jruby-head
gemfile: rails70_gems.rb
gemfile: rails71_gems.rb
experimental: true
- ruby-version: truffleruby
gemfile: rails70_gems.rb
gemfile: rails71_gems.rb
experimental: true
- ruby-version: truffleruby+graalvm
gemfile: rails70_gems.rb
gemfile: rails71_gems.rb
experimental: true

env:
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ task "clobber" do
end

task "test:benchmark" do
require_relative "./scripts/benchmark/find_region_benchmark"
require_relative "scripts/benchmark/find_region_benchmark"
benchmark = Capybara::Screenshot::Diff::Drivers::FindRegionBenchmark.new

puts "For Medium Screen Size: 800x600"
Expand Down
7 changes: 7 additions & 0 deletions gemfiles/rails71_gems.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

gems = "#{File.dirname __dir__}/gems.rb"
eval File.read(gems), binding, gems

gem "actionpack", "~> 7.1", "< 7.2"
gem "capybara", ">= 3.26"
9 changes: 2 additions & 7 deletions lib/capybara/screenshot/diff/image_compare.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,6 @@ def preprocess_images(images)
def preprocess_image(image)
result = image

# FIXME: How can we access to this method from public interface? Is this not documented feature?
if dimensions && driver.inscribed?(dimensions, result)
result = driver.crop(dimensions, result)
end

if skip_area
result = ignore_skipped_area(result)
end
Expand Down Expand Up @@ -209,14 +204,14 @@ def annotate_and_save_image(difference, image, image_path)
DIFF_COLOR = [255, 0, 0, 255].freeze

def annotate_difference(image, region)
driver.draw_rectangles(Array[image], region, DIFF_COLOR, offset: 1).first
driver.draw_rectangles([image], region, DIFF_COLOR, offset: 1).first
end

SKIP_COLOR = [255, 192, 0, 255].freeze

def annotate_skip_areas(image, skip_areas)
skip_areas.reduce(image) do |memo, region|
driver.draw_rectangles(Array[memo], region, SKIP_COLOR).first
driver.draw_rectangles([memo], region, SKIP_COLOR).first
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions test/capybara/screenshot/diff/image_compare_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require "capybara/screenshot/diff/drivers/chunky_png_driver"
if defined?(Vips)
require "capybara/screenshot/diff/drivers/vips_driver"
elsif ENV['SCREENSHOT_DRIVER'] == 'vips'
elsif ENV["SCREENSHOT_DRIVER"] == "vips"
raise 'Required `ruby-vips` gem or `vips` library is missing. Ensure "ruby-vips" gem and "vips" library is installed.'
end

Expand Down Expand Up @@ -43,10 +43,10 @@ class ImageCompareTest < ActionDispatch::IntegrationTest

test "it can handle very long input filenames" do
skip "VIPS not present. Skipping VIPS driver tests." unless defined?(Vips)
filename = %w(this-0000000000000000000000000000000000000000000000000-path/is/extremely/
filename = %w[this-0000000000000000000000000000000000000000000000000-path/is/extremely/
long/and/if/the/directories/are/flattened/in/
the_temporary_they_will_cause_the_filename_to_exceed_
the_limit_on_most_unix_systems_which_nobody_wants.png).join
the_limit_on_most_unix_systems_which_nobody_wants.png].join
comparison = make_comparison(:a, :b, destination: (Rails.root / filename), driver: :vips)

assert comparison.different?
Expand Down
2 changes: 1 addition & 1 deletion test/integration/browser_screenshot_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def test_screenshot_selected_element
def test_await_all_images_are_loaded
visit "/index.html"
assert_raises Minitest::Assertion do
BrowserHelpers.stub(:pending_image_to_load, 'http://127.0.0.1:62815/image.png') do
BrowserHelpers.stub(:pending_image_to_load, "http://127.0.0.1:62815/image.png") do
screenshot :index
end
end
Expand Down

0 comments on commit 7d1d087

Please sign in to comment.