percy-capybara 4.3.3 → 5.0.0.pre.5

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: 717ca7b919d62141b87ac78e8e4df1a8a47770456afbd41e03aa264fbb1d50c8
4
- data.tar.gz: 5056d828fa6d4780f135302346a9db2d1de372ccc79a12fd0c425ea95b0109ae
3
+ metadata.gz: cf51cb54687bfae9bea4339cf40dc1abc68c1c9f92978b5ed18e2d89ac794dde
4
+ data.tar.gz: ae1131aefeb90634c386029a452686de6128ec29e48002faf11a7d7da1414e76
5
5
  SHA512:
6
- metadata.gz: 39c1cb571277f052fd9650174b616f6fc1e35dab61a5aa54bd0cca9d9241ee056a3e92ba88d40a208792397c0fc64e4f3e54803104dea296ba85a365876d85b7
7
- data.tar.gz: bd59a0f4e2614cdc0c09f9ee9496ac0257d6743ae6b54e3168468f0bc13686f8fb0737722499e0fdff47e241624cd3ec66906769174348433a1bc60eee9e7cca
6
+ metadata.gz: f0c80b0a26341d17e18c1ed2b58b1abaa2e1cb975788c7a5bd363a8ea4c55dbe210f55fb92479321612e88db4afb14c0952d36999d0a23aced76b5f2c627257b
7
+ data.tar.gz: bda59318073be4794cb9ddb782ffdfc4b341e6134504a735cc60a41a54c73b25fcae2609f1702b97e15a2c534e8fdd1ff8ad0160ce9f0ebb2ba1c659fa2f2eb3
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,119 @@
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
+ #### API change
82
+
83
+ The previous version of this SDK had the following function signature:
84
+
85
+ ``` ruby
86
+ Percy.snapshot(driver, name, options)
87
+ ```
88
+
89
+ v5.x of this SDK has a significant change to the API. There no longer is a stand
90
+ alone module to call and you no longer need to pass the page/driver. It's
91
+ available on the current Capybara session (`page`):
92
+
93
+ ``` ruby
94
+ page.percy_snapshot(name, options)
95
+ ```
96
+
97
+ If you were using this SDK outside of Capybara, you'll likely find the [Ruby
98
+ Selenium SDK a better fit](https://github.com/percy/percy-selenium-ruby)
99
+
100
+ #### Installing `@percy/cli` & removing `@percy/agent`
101
+
102
+ If you're coming from a 4.x version of this package, make sure to install `@percy/cli` after
103
+ upgrading to retain any existing scripts that reference the Percy CLI
104
+ command. You will also want to uninstall `@percy/agent`, as it's been replaced
105
+ by `@percy/cli`.
106
+
107
+ ```sh-session
108
+ $ npm uninstall @percy/agent
109
+ $ npm install --save-dev @percy/cli
110
+ ```
111
+
112
+ #### Migrating config
113
+
114
+ If you have a previous Percy configuration file, migrate it to the newest version with the
115
+ [`config:migrate`](https://github.com/percy/cli/tree/master/packages/cli-config#percy-configmigrate-filepath-output) command:
116
+
117
+ ```sh-session
118
+ $ percy config:migrate
119
+ ```
@@ -0,0 +1,113 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'capybara/dsl'
4
+ require_relative './version'
5
+
6
+ module PercyCapybara
7
+ CLIENT_INFO = "percy-capybara/#{VERSION}".freeze
8
+ ENV_INFO = "capybara/#{Capybara::VERSION} ruby/#{RUBY_VERSION}".freeze
9
+
10
+ PERCY_DEBUG = ENV['PERCY_LOGLEVEL'] == 'debug'
11
+ PERCY_SERVER_ADDRESS = ENV['PERCY_SERVER_ADDRESS'] || 'http://localhost:5338'
12
+ PERCY_LABEL = "[\u001b[35m" + (PERCY_DEBUG ? 'percy:capybara' : 'percy') + "\u001b[39m]"
13
+
14
+ private_constant :CLIENT_INFO
15
+ private_constant :ENV_INFO
16
+
17
+ # Take a DOM snapshot and post it to the snapshot endpoint
18
+ def percy_snapshot(name, options = {})
19
+ return unless percy_enabled?
20
+
21
+ page = Capybara.current_session
22
+
23
+ begin
24
+ page.evaluate_script(fetch_percy_dom)
25
+ dom_snapshot = page
26
+ .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
+ **options,)
35
+
36
+ unless response.body.to_json['success']
37
+ raise StandardError, data['error']
38
+ end
39
+ rescue StandardError => e
40
+ log("Could not take DOM snapshot '#{name}'")
41
+
42
+ if PERCY_DEBUG then log(e) end
43
+ end
44
+ end
45
+
46
+ # Determine if the Percy server is running, caching the result so it is only checked once
47
+ private def percy_enabled?
48
+ return @percy_enabled unless @percy_enabled.nil?
49
+
50
+ begin
51
+ response = fetch('percy/healthcheck')
52
+ version = response['x-percy-core-version']
53
+
54
+ if version.nil?
55
+ log('You may be using @percy/agent ' \
56
+ 'which is no longer supported by this SDK. ' \
57
+ 'Please uninstall @percy/agent and install @percy/cli instead. ' \
58
+ 'https://docs.percy.io/docs/migrating-to-percy-cli')
59
+ @percy_enabled = false
60
+ return false
61
+ end
62
+
63
+ if version.split('.')[0] != '1'
64
+ log("Unsupported Percy CLI version, #{version}")
65
+ @percy_enabled = false
66
+ return false
67
+ end
68
+
69
+ @percy_enabled = true
70
+ true
71
+ rescue StandardError => e
72
+ log('Percy is not running, disabling snapshots')
73
+
74
+ if PERCY_DEBUG then log(e) end
75
+ @percy_enabled = false
76
+ false
77
+ end
78
+ end
79
+
80
+ # Fetch the @percy/dom script, caching the result so it is only fetched once
81
+ private def fetch_percy_dom
82
+ return @percy_dom unless @percy_dom.nil?
83
+
84
+ response = fetch('percy/dom.js')
85
+ @percy_dom = response.body
86
+ end
87
+
88
+ private def log(msg)
89
+ puts "#{PERCY_LABEL} #{msg}"
90
+ end
91
+
92
+ # Make an HTTP request (GET,POST) using Ruby's Net::HTTP. If `data` is present,
93
+ # `fetch` will POST as JSON.
94
+ private def fetch(url, data = nil)
95
+ uri = URI("#{PERCY_SERVER_ADDRESS}/#{url}")
96
+
97
+ response = if data
98
+ Net::HTTP.post(uri, data.to_json)
99
+ else
100
+ Net::HTTP.get_response(uri)
101
+ end
102
+
103
+ unless response.is_a? Net::HTTPSuccess
104
+ raise StandardError, "Failed with HTTP error code: #{response.code}"
105
+ end
106
+
107
+ response
108
+ end
109
+ end
110
+
111
+ # Add the `percy_snapshot` method to the the Capybara session class
112
+ # `page.percy_snapshot('name', { options })`
113
+ Capybara::Session.class_eval { include PercyCapybara }
@@ -0,0 +1,3 @@
1
+ module PercyCapybara
2
+ VERSION = '5.0.0.pre.5'.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.3
4
+ version: 5.0.0.pre.5
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-09 00:00:00.000000000 Z
11
+ date: 2021-06-10 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.2
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
-