Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix css_selector option #49

Merged
merged 3 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest

strategy:
matrix: { ruby: ['2.7', '3.0', '3.1', '3.2', head] }
matrix: { ruby: ['3.0', '3.1', '3.2', head] }

steps:
- name: Checkout code
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
/snapcrawl.pstore
/snaps
/tmp
sinatra.pid
sinatra.pid
spec/status.txt
4 changes: 2 additions & 2 deletions lib/snapcrawl/screenshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def webshot_capture!(url, image_path)
def webshot_options
result = { allowed_status_codes: [404, 401, 403] }

if Config.selector
result[:selector] = Config.selector
if Config.css_selector
result[:selector] = Config.css_selector
result[:full] = false
end

Expand Down
2 changes: 1 addition & 1 deletion snapcrawl.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Gem::Specification.new do |s|
s.executables = ['snapcrawl']
s.homepage = 'https://github.com/DannyBen/snapcrawl'
s.license = 'MIT'
s.required_ruby_version = '>= 2.7'
s.required_ruby_version = '>= 3.0'

s.add_runtime_dependency 'addressable', '~> 2.7'
s.add_runtime_dependency 'colsole', '>= 0.8.1', '< 2'
Expand Down
8 changes: 4 additions & 4 deletions spec/approvals/config/defaults
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ cache_life: 86400
cache_dir: cache
snaps_dir: snaps
name_template: "%{url}"
url_whitelist:
url_blacklist:
css_selector:
url_whitelist:
url_blacklist:
css_selector:
log_level: 1
log_color: auto
skip_ssl_verification: false
screenshot_delay:
screenshot_delay:
8 changes: 4 additions & 4 deletions spec/approvals/config/minimal
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ cache_life: 86400
cache_dir: cache
snaps_dir: snaps
name_template: "%{url}"
url_whitelist:
url_blacklist:
css_selector:
url_whitelist:
url_blacklist:
css_selector:
log_level: 3
log_color: false
skip_ssl_verification: false
screenshot_delay:
screenshot_delay:
6 changes: 3 additions & 3 deletions spec/snapcrawl/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
subject { described_class }

describe '#load' do
it 'has defaults' do
it 'has defaults', :focus do
subject.load
expect(subject.settings.to_yaml).to match_approval('config/defaults')
expect(subject.settings.to_yaml).to match_approval('config/defaults').diff(4)
end

it 'loads file if it exists and merges it with the defaults' do
subject.load 'spec/fixtures/config/minimal'
expect(subject.settings.to_yaml).to match_approval('config/minimal')
expect(subject.settings.to_yaml).to match_approval('config/minimal').diff(4)
end

context 'when the config file is not found' do
Expand Down
8 changes: 4 additions & 4 deletions spec/snapcrawl/screenshot_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
expect(File.size outfile).to be > 22_000
end

context 'when Config.selector is set' do
context 'when Config.css_selector is set' do
let(:url) { 'http://localhost:3000/selector' }

before do
Config.selector = nil
Config.css_selector = nil
subject.save 'tmp/full-page.png'
end

after do
Config.selector = nil
Config.css_selector = nil
end

it 'only captures the selected area' do
Config.selector = '.select-me'
Config.css_selector = '.select-me'
subject.save 'tmp/selected-area.png'
full_size = File.size('tmp/full-page.png')
selected_size = File.size('tmp/selected-area.png')
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
require_relative 'spec_mixin'
RSpec.configure do |config|
config.include SpecMixin
config.example_status_persistence_file_path = 'spec/status.txt'
end