percy-capybara 4.2.0 → 5.0.0.pre.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a484d751642b64d97a1d5b40342b549c464c2ada8c8d6da1c45cdc889a4761b
4
- data.tar.gz: 7533abb8bd2ba365757776f6ca46f9864ad517accfabc4b9b26cef020ae5a997
3
+ metadata.gz: 41d7750c08015a049fe7e96a1bef9fa66e63ab4f8d46470745dca33785381938
4
+ data.tar.gz: 134b1bb862eddc96233205c664ec06e2573a6eff10aa17c8a182ca6740c98510
5
5
  SHA512:
6
- metadata.gz: b8dfffffc550d341b61a691b1302474dd8924d76a98e95e4d957aa9d28d600f227ccf04a4577f679c983eda7a3ab45934744d5a09eb450fbc135416894c4696f
7
- data.tar.gz: e0bfb29bfb9be2674679efbeb06573b98eea9f0a152b49d464750ba5b16649712c72913c76ca6af55d274fa4adcd252566f31c8e665b94ad6ddc56ebb90caa3f
6
+ metadata.gz: c136d0dab551741667317aad40b5309d6153bca15add7a12923327340b5810e181b0b6234e6f6c8b522a8ff6bc63f852fac3a1a76661e4b7b2775da985420e01
7
+ data.tar.gz: 90ff43e7d90292c828703b9220c03e798dfbffbe23f10a71317035605baed181fc4ece0d5720fca27fc41c966069243cd0e7a321afe9b7cd611092b1c62dc70c
@@ -0,0 +1,8 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: /
5
+ schedule:
6
+ interval: weekly
7
+ commit-message:
8
+ prefix: ⬆️
@@ -0,0 +1,31 @@
1
+ name-template: 'v$RESOLVED_VERSION'
2
+ tag-template: 'v$RESOLVED_VERSION'
3
+ categories:
4
+ - title: '💥 Breaking Changes'
5
+ labels:
6
+ - breaking
7
+ - title: '✨ Enhancements'
8
+ labels:
9
+ - feature
10
+ - enhancement
11
+ - title: '🐛 Bug Fixes'
12
+ labels:
13
+ - fix
14
+ - bugfix
15
+ - bug
16
+ - title: '🏗 Maintenance'
17
+ labels:
18
+ - chore
19
+ - dependencies
20
+ change-title-escapes: '\<*_&#@'
21
+ version-resolver:
22
+ major:
23
+ labels:
24
+ - breaking
25
+ minor:
26
+ labels:
27
+ - feature
28
+ - enhancement
29
+ default: patch
30
+ template: '$CHANGES'
31
+ prerelease: true
@@ -0,0 +1,11 @@
1
+ name: Changelog
2
+ on:
3
+ push:
4
+ branches: [master]
5
+ jobs:
6
+ update_draft:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: release-drafter/release-drafter@v5
10
+ env:
11
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -0,0 +1,22 @@
1
+ name: Lint
2
+ on:
3
+ push:
4
+ branches: [master]
5
+ pull_request:
6
+ workflow_dispatch:
7
+ jobs:
8
+ lint:
9
+ name: Lint
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: 2.6
16
+ bundler-cache: true
17
+ - uses: actions/cache@v2
18
+ with:
19
+ path: "./vendor/bundle"
20
+ key: v1/${{ runner.os }}/ruby-2.6/${{ hashFiles('**/Gemfile.lock') }}
21
+ restore-keys: v1/${{ runner.os }}/ruby-2.6/
22
+ - run: bundle exec rubocop
@@ -0,0 +1,22 @@
1
+ name: Release
2
+ on:
3
+ release:
4
+ types: [published]
5
+ jobs:
6
+ publish:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - uses: ruby/setup-ruby@v1
11
+ with:
12
+ ruby-version: 2.6
13
+ bundler-cache: true
14
+ - uses: actions/cache@v2
15
+ with:
16
+ path: "./vendor/bundle"
17
+ key: v1/${{ runner.os }}/ruby-2.6/${{ hashFiles('**/Gemfile.lock') }}
18
+ restore-keys: v1/${{ runner.os }}/ruby-2.6/
19
+ - uses: cadwallion/publish-rubygems-action@master
20
+ env:
21
+ RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
22
+ RELEASE_COMMAND: make release
@@ -0,0 +1,26 @@
1
+ name: Test
2
+ on:
3
+ push:
4
+ branches: [master]
5
+ pull_request:
6
+ workflow_dispatch:
7
+ jobs:
8
+ test:
9
+ name: Test
10
+ strategy:
11
+ matrix:
12
+ os: [ubuntu-latest]
13
+ ruby: ['2.6', '2.7']
14
+ runs-on: ${{ matrix.os }}
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: ${{matrix.ruby}}
20
+ bundler-cache: true
21
+ - uses: actions/cache@v2
22
+ with:
23
+ path: "./vendor/bundle"
24
+ key: v1/${{ runner.os }}/ruby-${{ matrix.ruby }}/${{ hashFiles('**/Gemfile.lock') }}
25
+ restore-keys: v1/${{ runner.os }}/ruby-${{ matrix.ruby }}/
26
+ - run: bundle exec rspec
data/.rubocop.yml CHANGED
@@ -1,14 +1,13 @@
1
1
  inherit_gem:
2
2
  percy-style:
3
3
  - default.yml
4
-
5
-
6
4
  RSpec/InstanceVariable:
7
5
  Exclude:
8
- - spec/lib/percy/capybara_spec.rb
9
-
6
+ -
10
7
  RSpec/ContextWording:
11
8
  Enabled: false
12
-
13
9
  AllCops:
14
- TargetRubyVersion: 2.2
10
+ TargetRubyVersion: 2.4
11
+ Include:
12
+ - lib/**/*.rb
13
+ - spec/lib/**/*.rb
data/Gemfile CHANGED
@@ -10,4 +10,7 @@ gem 'guard-rspec', require: false
10
10
 
11
11
  group :test, :development do
12
12
  gem 'pry'
13
+ gem 'puma'
14
+ gem 'webmock'
15
+ gem 'simplecov', require: false
13
16
  end
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015 Perceptual Inc.
1
+ Copyright (c) 2021 Perceptual Inc.
2
2
 
3
3
  The MIT License (MIT)
4
4
 
data/Makefile ADDED
@@ -0,0 +1,3 @@
1
+ release:
2
+ rake build
3
+ gem push pkg/percy-capybara-*
data/README.md CHANGED
@@ -1,6 +1,100 @@
1
- # Percy Capybara
1
+ # percy-capybara
2
+ [![Gem Version](https://badge.fury.io/rb/percy-capybara.svg)](https://badge.fury.io/rb/percy-capybara)
3
+ ![Test](https://github.com/percy/percy-capybara/workflows/Test/badge.svg)
2
4
 
3
- [![CircleCI](https://circleci.com/gh/percy/percy-capybara.svg?style=svg)](https://circleci.com/gh/percy/percy-capybara)
4
- [![Gem Version](https://badge.fury.io/rb/percy-capybara.svg)](http://badge.fury.io/rb/percy-capybara)
5
+ [Percy](https://percy.io) visual testing for Ruby Selenium.
5
6
 
6
- #### Docs here: [https://docs.percy.io/docs/capybara](https://docs.percy.io/docs/capybara)
7
+ ## Installation
8
+
9
+ npm install `@percy/cli`:
10
+
11
+ ```sh-session
12
+ $ npm install --save-dev @percy/cli
13
+ ```
14
+
15
+ gem install `percy-capybara` package:
16
+
17
+ ```ssh-session
18
+ $ gem install percy-capybara
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ In your test setup file, require `percy/capybara`. For example if you're using
24
+ rspec, you would add the following to your `spec_helper.rb` file:
25
+
26
+ ``` ruby
27
+ require 'percy/capybara'
28
+ ```
29
+
30
+ Now you can use `page.percy_snapshot` to capture snapshots.
31
+
32
+ > Note: you may need to add `js: true` to your specs, depending on your driver setup
33
+
34
+ ```ruby
35
+ describe 'my feature, type: :feature do
36
+ it 'renders the page' do
37
+ visit 'https://example.com'
38
+ page.percy_snapshot('Capybara snapshot')
39
+ end
40
+ end
41
+ ```
42
+
43
+ Running the test above normally will result in the following log:
44
+
45
+ ```sh-session
46
+ [percy] Percy is not running, disabling snapshots
47
+ ```
48
+
49
+ When running with [`percy
50
+ exec`](https://github.com/percy/cli/tree/master/packages/cli-exec#percy-exec), and your project's
51
+ `PERCY_TOKEN`, a new Percy build will be created and snapshots will be uploaded to your project.
52
+
53
+ ```sh-session
54
+ $ export PERCY_TOKEN=[your-project-token]
55
+ $ percy exec -- [test command]
56
+ [percy] Percy has started!
57
+ [percy] Created build #1: https://percy.io/[your-project]
58
+ [percy] Snapshot taken "Capybara example"
59
+ [percy] Stopping percy...
60
+ [percy] Finalized build #1: https://percy.io/[your-project]
61
+ [percy] Done!
62
+ ```
63
+
64
+ ## Configuration
65
+
66
+ `page.snapshot(name[, options])`
67
+
68
+ - `name` (**required**) - The snapshot name; must be unique to each snapshot
69
+ - `options` - [See per-snapshot configuration options](https://docs.percy.io/docs/cli-configuration#per-snapshot-configuration)
70
+
71
+ ## Upgrading
72
+
73
+ ### Manually
74
+
75
+ #### Require change
76
+
77
+ The name of the require has changed from `require 'percy'` to `require
78
+ 'percy/capybara'`. This is to avoid conflict with our [Ruby Selenium SDK's](https://github.com/percy/percy-selenium-ruby)
79
+ require statement.
80
+
81
+ #### Installing `@percy/cli` & removing `@percy/agent`
82
+
83
+ If you're coming from a 4.x version of this package, make sure to install `@percy/cli` after
84
+ upgrading to retain any existing scripts that reference the Percy CLI
85
+ command. You will also want to uninstall `@percy/agent`, as it's been replaced
86
+ by `@percy/cli`.
87
+
88
+ ```sh-session
89
+ $ npm uninstall @percy/agent
90
+ $ npm install --save-dev @percy/cli
91
+ ```
92
+
93
+ #### Migrating config
94
+
95
+ If you have a previous Percy configuration file, migrate it to the newest version with the
96
+ [`config:migrate`](https://github.com/percy/cli/tree/master/packages/cli-config#percy-configmigrate-filepath-output) command:
97
+
98
+ ```sh-session
99
+ $ percy config:migrate
100
+ ```
@@ -0,0 +1,111 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'capybara/dsl'
4
+
5
+ module PercyCapybara
6
+ include Capybara::DSL
7
+
8
+ CLIENT_INFO = "percy-capybara/#{VERSION}".freeze
9
+ ENV_INFO = "capybara/#{Capybara::VERSION} ruby/#{RUBY_VERSION}".freeze
10
+
11
+ PERCY_DEBUG = ENV['PERCY_LOGLEVEL'] == 'debug'
12
+ PERCY_SERVER_ADDRESS = ENV['PERCY_SERVER_ADDRESS'] || 'http://localhost:5338'
13
+ PERCY_LABEL = "[\u001b[35m" + (PERCY_DEBUG ? 'percy:capybara' : 'percy') + "\u001b[39m]"
14
+
15
+ private_constant :CLIENT_INFO
16
+ private_constant :ENV_INFO
17
+
18
+ # Take a DOM snapshot and post it to the snapshot endpoint
19
+ def percy_snapshot(name, options = {})
20
+ return unless percy_enabled?
21
+
22
+ begin
23
+ page.evaluate_script(fetch_percy_dom)
24
+ dom_snapshot =
25
+ page.evaluate_script("(function() { return PercyDOM.serialize(#{options.to_json}) })()")
26
+
27
+ response = fetch('percy/snapshot',
28
+ name: name,
29
+ url: page.current_url,
30
+ dom_snapshot: dom_snapshot,
31
+ client_info: CLIENT_INFO,
32
+ environment_info: ENV_INFO,)
33
+
34
+ unless response.body.to_json['success']
35
+ raise StandardError, data['error']
36
+ end
37
+ rescue StandardError => e
38
+ log("Could not take DOM snapshot '#{name}'")
39
+
40
+ if PERCY_DEBUG then log(e) end
41
+ end
42
+ end
43
+
44
+ # Determine if the Percy server is running, caching the result so it is only checked once
45
+ private def percy_enabled?
46
+ return @percy_enabled unless @percy_enabled.nil?
47
+
48
+ begin
49
+ response = fetch('percy/healthcheck')
50
+ version = response['x-percy-core-version']
51
+
52
+ if version.nil?
53
+ log('You may be using @percy/agent ' \
54
+ 'which is no longer supported by this SDK. ' \
55
+ 'Please uninstall @percy/agent and install @percy/cli instead. ' \
56
+ 'https://docs.percy.io/docs/migrating-to-percy-cli')
57
+ @percy_enabled = false
58
+ return false
59
+ end
60
+
61
+ if version.split('.')[0] != '1'
62
+ log("Unsupported Percy CLI version, #{version}")
63
+ @percy_enabled = false
64
+ return false
65
+ end
66
+
67
+ @percy_enabled = true
68
+ true
69
+ rescue StandardError => e
70
+ log('Percy is not running, disabling snapshots')
71
+
72
+ if PERCY_DEBUG then log(e) end
73
+ @percy_enabled = false
74
+ false
75
+ end
76
+ end
77
+
78
+ # Fetch the @percy/dom script, caching the result so it is only fetched once
79
+ private def fetch_percy_dom
80
+ return @percy_dom unless @percy_dom.nil?
81
+
82
+ response = fetch('percy/dom.js')
83
+ @percy_dom = response.body
84
+ end
85
+
86
+ private def log(msg)
87
+ puts "#{PERCY_LABEL} #{msg}"
88
+ end
89
+
90
+ # Make an HTTP request (GET,POST) using Ruby's Net::HTTP. If `data` is present,
91
+ # `fetch` will POST as JSON.
92
+ private def fetch(url, data = nil)
93
+ uri = URI("#{PERCY_SERVER_ADDRESS}/#{url}")
94
+
95
+ response = if data
96
+ Net::HTTP.post(uri, data.to_json)
97
+ else
98
+ Net::HTTP.get_response(uri)
99
+ end
100
+
101
+ unless response.is_a? Net::HTTPSuccess
102
+ raise StandardError, "Failed with HTTP error code: #{response.code}"
103
+ end
104
+
105
+ response
106
+ end
107
+ end
108
+
109
+ # Add the `percy_snapshot` method to the the Capybara session class
110
+ # `page.percy_snapshot('name', { options })`
111
+ Capybara::Session.class_eval { include PercyCapybara }
@@ -0,0 +1,3 @@
1
+ module PercyCapybara
2
+ VERSION = '5.0.0.pre.1'.freeze
3
+ end
@@ -1,17 +1,18 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'version'
4
+ require 'percy/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'percy-capybara'
8
- spec.version = Percy::VERSION
8
+ spec.version = PercyCapybara::VERSION
9
9
  spec.authors = ['Perceptual Inc.']
10
10
  spec.email = ['team@percy.io']
11
11
  spec.summary = %q{Percy}
12
12
  spec.description = %q{}
13
13
  spec.homepage = ''
14
14
  spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 2.3.0'
15
16
 
16
17
  spec.metadata = {
17
18
  'bug_tracker_uri' => 'https://github.com/percy/percy-capybara/issues',
@@ -23,10 +24,12 @@ Gem::Specification.new do |spec|
23
24
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
24
25
  spec.require_paths = ['lib']
25
26
 
26
- spec.add_development_dependency 'bundler', '~> 1.7'
27
- spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_runtime_dependency 'capybara', '>= 3'
28
+
29
+ spec.add_development_dependency 'selenium-webdriver', '>= 4.0.0.beta1'
30
+ spec.add_development_dependency 'bundler', '>= 2.0'
31
+ spec.add_development_dependency 'rake', '~> 13.0'
28
32
  spec.add_development_dependency 'rspec', '~> 3.5'
29
- spec.add_development_dependency 'capybara', '~> 2.4'
30
- spec.add_development_dependency 'selenium-webdriver'
31
- spec.add_development_dependency 'percy-style'
33
+ spec.add_development_dependency 'capybara', '~> 3.31'
34
+ spec.add_development_dependency 'percy-style', '~> 0.7.0'
32
35
  end