percy-capybara 4.3.1 → 5.0.0.pre.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4fb6fdec485db075cfc8cf93eedf339ce2a51bd46e078bc524ce085736e07b3
4
- data.tar.gz: 8d1aaaf79805bdb3aa765aa7c9a6747a33e23f8c598a62c8e92a08c9690ca2c7
3
+ metadata.gz: cd3adc36ef52095eaaf1e602bc347163260eaf0763a31083cbdc0915dab9f741
4
+ data.tar.gz: 996139e8abb4148ef33dfdf53f253c5b63b5647c43c59d7efe2d9ee7e58ab8fc
5
5
  SHA512:
6
- metadata.gz: 04f23d009a4b53172d875385ecc85fca8b9de74976f43254d9a065a89df092e3ed01ebfe6890d84d36856feef12f0ef689797e4dbdad34f2e7d47ebf6a54c376
7
- data.tar.gz: 848fbd8b7f815673d4bd7ff3dcd581f5fa7e04bf5a7610be83b5c700a762b2ccf6af36ba989ac45a31712da7fdf5d8ebb14e0137ccee14b7469ce95102796021
6
+ metadata.gz: 848ffc7e381ab1527e64f97f4d259d4d9f2c39c82fb549bc610b31c586e75aae0f206900bd272885e475ac74a86eb82da45fd6f4261817e448958238d4ce2945
7
+ data.tar.gz: bff21021c4768cf46ba80b08ac26246013c37ec0e82c1cab7077e68ca0c44517c1455e34437e6c6b1cb8cf25b612e3eb854d4015c0ef09088894f87a017bf8f3
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/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,112 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'capybara/dsl'
4
+ require_relative './version'
5
+
6
+ module PercyCapybara
7
+ include Capybara::DSL
8
+
9
+ CLIENT_INFO = "percy-capybara/#{VERSION}".freeze
10
+ ENV_INFO = "capybara/#{Capybara::VERSION} ruby/#{RUBY_VERSION}".freeze
11
+
12
+ PERCY_DEBUG = ENV['PERCY_LOGLEVEL'] == 'debug'
13
+ PERCY_SERVER_ADDRESS = ENV['PERCY_SERVER_ADDRESS'] || 'http://localhost:5338'
14
+ PERCY_LABEL = "[\u001b[35m" + (PERCY_DEBUG ? 'percy:capybara' : 'percy') + "\u001b[39m]"
15
+
16
+ private_constant :CLIENT_INFO
17
+ private_constant :ENV_INFO
18
+
19
+ # Take a DOM snapshot and post it to the snapshot endpoint
20
+ def percy_snapshot(name, options = {})
21
+ return unless percy_enabled?
22
+
23
+ begin
24
+ page.evaluate_script(fetch_percy_dom)
25
+ dom_snapshot =
26
+ page.evaluate_script("(function() { return PercyDOM.serialize(#{options.to_json}) })()")
27
+
28
+ response = fetch('percy/snapshot',
29
+ name: name,
30
+ url: page.current_url,
31
+ dom_snapshot: dom_snapshot,
32
+ client_info: CLIENT_INFO,
33
+ environment_info: ENV_INFO,)
34
+
35
+ unless response.body.to_json['success']
36
+ raise StandardError, data['error']
37
+ end
38
+ rescue StandardError => e
39
+ log("Could not take DOM snapshot '#{name}'")
40
+
41
+ if PERCY_DEBUG then log(e) end
42
+ end
43
+ end
44
+
45
+ # Determine if the Percy server is running, caching the result so it is only checked once
46
+ private def percy_enabled?
47
+ return @percy_enabled unless @percy_enabled.nil?
48
+
49
+ begin
50
+ response = fetch('percy/healthcheck')
51
+ version = response['x-percy-core-version']
52
+
53
+ if version.nil?
54
+ log('You may be using @percy/agent ' \
55
+ 'which is no longer supported by this SDK. ' \
56
+ 'Please uninstall @percy/agent and install @percy/cli instead. ' \
57
+ 'https://docs.percy.io/docs/migrating-to-percy-cli')
58
+ @percy_enabled = false
59
+ return false
60
+ end
61
+
62
+ if version.split('.')[0] != '1'
63
+ log("Unsupported Percy CLI version, #{version}")
64
+ @percy_enabled = false
65
+ return false
66
+ end
67
+
68
+ @percy_enabled = true
69
+ true
70
+ rescue StandardError => e
71
+ log('Percy is not running, disabling snapshots')
72
+
73
+ if PERCY_DEBUG then log(e) end
74
+ @percy_enabled = false
75
+ false
76
+ end
77
+ end
78
+
79
+ # Fetch the @percy/dom script, caching the result so it is only fetched once
80
+ private def fetch_percy_dom
81
+ return @percy_dom unless @percy_dom.nil?
82
+
83
+ response = fetch('percy/dom.js')
84
+ @percy_dom = response.body
85
+ end
86
+
87
+ private def log(msg)
88
+ puts "#{PERCY_LABEL} #{msg}"
89
+ end
90
+
91
+ # Make an HTTP request (GET,POST) using Ruby's Net::HTTP. If `data` is present,
92
+ # `fetch` will POST as JSON.
93
+ private def fetch(url, data = nil)
94
+ uri = URI("#{PERCY_SERVER_ADDRESS}/#{url}")
95
+
96
+ response = if data
97
+ Net::HTTP.post(uri, data.to_json)
98
+ else
99
+ Net::HTTP.get_response(uri)
100
+ end
101
+
102
+ unless response.is_a? Net::HTTPSuccess
103
+ raise StandardError, "Failed with HTTP error code: #{response.code}"
104
+ end
105
+
106
+ response
107
+ end
108
+ end
109
+
110
+ # Add the `percy_snapshot` method to the the Capybara session class
111
+ # `page.percy_snapshot('name', { options })`
112
+ Capybara::Session.class_eval { include PercyCapybara }
@@ -0,0 +1,3 @@
1
+ module PercyCapybara
2
+ VERSION = '5.0.0.pre.3'.freeze
3
+ end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: percy-capybara
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.1
4
+ version: 5.0.0.pre.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Perceptual Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-01 00:00:00.000000000 Z
11
+ date: 2021-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capybara
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: selenium-webdriver
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 4.0.0.beta1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 4.0.0.beta1
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: bundler
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,20 +94,6 @@ dependencies:
66
94
  - - "~>"
67
95
  - !ruby/object:Gem::Version
68
96
  version: '3.31'
69
- - !ruby/object:Gem::Dependency
70
- name: selenium-webdriver
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: percy-style
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -101,28 +115,10 @@ executables: []
101
115
  extensions: []
102
116
  extra_rdoc_files: []
103
117
  files:
104
- - ".circleci/config.yml"
105
- - ".gitignore"
106
- - ".rspec"
107
- - ".rubocop.yml"
108
- - ".yardopts"
109
- - CHANGELOG.md
110
- - DEVELOPING.md
111
- - Gemfile
112
- - Guardfile
113
118
  - LICENSE
114
119
  - README.md
115
- - RELEASING.md
116
- - Rakefile
117
- - lib/environment.rb
118
- - lib/percy.rb
119
- - lib/version.rb
120
- - package.json
121
- - percy-capybara.gemspec
122
- - spec/lib/percy/environment_spec.rb
123
- - spec/lib/percy/percy_spec.rb
124
- - spec/spec_helper.rb
125
- - yarn.lock
120
+ - lib/percy/capybara.rb
121
+ - lib/percy/version.rb
126
122
  homepage: ''
127
123
  licenses:
128
124
  - MIT
@@ -137,18 +133,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
133
  requirements:
138
134
  - - ">="
139
135
  - !ruby/object:Gem::Version
140
- version: '0'
136
+ version: 2.3.0
141
137
  required_rubygems_version: !ruby/object:Gem::Requirement
142
138
  requirements:
143
- - - ">="
139
+ - - ">"
144
140
  - !ruby/object:Gem::Version
145
- version: '0'
141
+ version: 1.3.1
146
142
  requirements: []
147
- rubygems_version: 3.1.4
143
+ rubygems_version: 3.0.3
148
144
  signing_key:
149
145
  specification_version: 4
150
- summary: Percy
151
- test_files:
152
- - spec/lib/percy/environment_spec.rb
153
- - spec/lib/percy/percy_spec.rb
154
- - spec/spec_helper.rb
146
+ summary: Percy visual testing for Capybara
147
+ test_files: []
data/.circleci/config.yml DELETED
@@ -1,38 +0,0 @@
1
- version: 2.1
2
-
3
- default_steps: &default_steps
4
- steps:
5
- - checkout
6
- - run: sudo gem update --system
7
- - run: ruby -v
8
- - run: yarn
9
- - run: bundle install
10
- - run: yarn percy exec -- bundle exec rspec
11
- - run: bundle exec rubocop -D
12
-
13
- jobs:
14
- ruby_latest_with_percy:
15
- # This is the one environment where we'll capture and upload snapshots in CI.
16
- docker:
17
- - image: circleci/ruby:latest-node-browsers
18
- <<: *default_steps
19
- ruby_25:
20
- docker:
21
- - image: circleci/ruby:2.5-node-browsers
22
- environment:
23
- PERCY_ENABLE: 0
24
- <<: *default_steps
25
- ruby_24:
26
- docker:
27
- - image: circleci/ruby:2.4-node-browsers
28
- environment:
29
- PERCY_ENABLE: 0
30
- <<: *default_steps
31
-
32
- workflows:
33
- version: 2
34
- test:
35
- jobs:
36
- - ruby_latest_with_percy
37
- - ruby_25
38
- - ruby_24
data/.gitignore DELETED
@@ -1,17 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
- *.bundle
10
- *.so
11
- *.o
12
- *.a
13
- *.rbc
14
- mkmf.log
15
- .DS_Store
16
- Gemfile.lock
17
- node_modules/
data/.rspec DELETED
@@ -1,4 +0,0 @@
1
- --color
2
- --require spec_helper
3
- --format d
4
-
data/.rubocop.yml DELETED
@@ -1,14 +0,0 @@
1
- inherit_gem:
2
- percy-style:
3
- - default.yml
4
-
5
-
6
- RSpec/InstanceVariable:
7
- Exclude:
8
- - spec/lib/percy/capybara_spec.rb
9
-
10
- RSpec/ContextWording:
11
- Enabled: false
12
-
13
- AllCops:
14
- TargetRubyVersion: 2.4
data/.yardopts DELETED
@@ -1,2 +0,0 @@
1
- --protected
2
- --no-private