Skip to content

Commit

Permalink
📝 Update README with instructions
Browse files Browse the repository at this point in the history
Also made the linter happy (line length)
  • Loading branch information
Robdel12 committed May 5, 2021
1 parent d504cc6 commit 73f9048
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
release:
rake build
gem push pkg/percy-selenium-*
gem push pkg/percy-capybara-*
104 changes: 100 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,102 @@
# Percy Capybara
# percy-capybara
[![Gem Version](https://badge.fury.io/rb/percy-selenium.svg)](https://badge.fury.io/rb/percy-capybara)
![Test](https://github.com/percy/percy-capybara/workflows/Test/badge.svg)

[![CircleCI](https://circleci.com/gh/percy/percy-capybara.svg?style=svg)](https://circleci.com/gh/percy/percy-capybara)
[![Gem Version](https://badge.fury.io/rb/percy-capybara.svg)](http://badge.fury.io/rb/percy-capybara)
[Percy](https://percy.io) visual testing for Ruby Selenium.

#### Docs here: [https://docs.percy.io/docs/capybara](https://docs.percy.io/docs/capybara)
## Installation

npm install `@percy/cli`:

```sh-session
$ npm install --save-dev @percy/cli
```

gem install Percy selenium package:

```ssh-session
$ gem install percy-capybara
```

## Usage

In your test setup file, require `percy/capybara`. For example if you're using
rspec, you would add the following to your `spec_helper.rb` file:


``` ruby
require 'percy/capybara'
```

Now you can use `page.percy_snapshot` to capture snapshots.

> Note: Percy requires JS to be enabled for snapshots to be captured.
```ruby
describe 'my feature, type: :feature, js: true do
it 'renders the page' do
visit 'https://example.com'
page.percy_snapshot('Example snapshot')
end
end
```
Running the test above normally will result in the following log:
```sh-session
[percy] Percy is not running, disabling snapshots
```
When running with [`percy
exec`](https://github.com/percy/cli/tree/master/packages/cli-exec#percy-exec), and your project's
`PERCY_TOKEN`, a new Percy build will be created and snapshots will be uploaded to your project.

```sh-session
$ export PERCY_TOKEN=[your-project-token]
$ percy exec -- [test command]
[percy] Percy has started!
[percy] Created build #1: https://percy.io/[your-project]
[percy] Snapshot taken "Ruby example"
[percy] Stopping percy...
[percy] Finalized build #1: https://percy.io/[your-project]
[percy] Done!
```

## Configuration

`page.snapshot(name[, options])`

- `name` (**required**) - The snapshot name; must be unique to each snapshot
- `options` - [See per-snapshot configuration options](https://docs.percy.io/docs/cli-configuration#per-snapshot-configuration)

## Upgrading

### Manually

#### Require change

The name of the require has changed from `require 'percy'` to `require
'percy/capybara'`. This is to avoid conflict with our [Ruby Selenium SDK's require](https://github.com/percy/percy-selenium-ruby)
statement.
#### Installing `@percy/cli` & removing `@percy/agent`
If you're coming from a pre-3.0 version of this package, make sure to install `@percy/cli` after
upgrading to retain any existing scripts that reference the Percy CLI
command. You will also want to uninstall `@percy/agent`, as it's been replaced
by `@percy/cli`.
```sh-session
$ npm uninstall @percy/agent
$ npm install --save-dev @percy/cli
```
#### Migrating config
If you have a previous Percy configuration file, migrate it to the newest version with the
[`config:migrate`](https://github.com/percy/cli/tree/master/packages/cli-config#percy-configmigrate-filepath-output) command:
```sh-session
$ percy config:migrate
```
12 changes: 7 additions & 5 deletions spec/lib/percy/percy_capybara_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
LABEL = PercyCapybara::PERCY_LABEL

RSpec.describe PercyCapybara, type: :feature do
before(:each) do
WebMock.disable_net_connect!(allow: '127.0.0.1', disallow: 'localhost')
Expand All @@ -10,7 +12,7 @@
.to_return(status: 200, body: '', headers: {'x-percy-core-version': '0.1.0'})

expect { page.percy_snapshot('Name') }
.to output("#{PercyCapybara::PERCY_LABEL} Unsupported Percy CLI version, 0.1.0\n").to_stdout
.to output("#{LABEL} Unsupported Percy CLI version, 0.1.0\n").to_stdout
end

it 'disables when healthcheck version is missing' do
Expand All @@ -19,7 +21,7 @@

expect { page.percy_snapshot('Name') }
.to output(
"#{PercyCapybara::PERCY_LABEL} You may be using @percy/agent which" \
"#{LABEL} You may be using @percy/agent which" \
' is no longer supported by this SDK. Please uninstall' \
' @percy/agent and install @percy/cli instead.' \
" https://docs.percy.io/docs/migrating-to-percy-cli\n",
Expand All @@ -31,15 +33,15 @@
.to_return(status: 500, body: '', headers: {})

expect { page.percy_snapshot('Name') }
.to output("#{PercyCapybara::PERCY_LABEL} Percy is not running, disabling snapshots\n").to_stdout
.to output("#{LABEL} Percy is not running, disabling snapshots\n").to_stdout
end

it 'disables when healthcheck fails to connect' do
stub_request(:get, "#{PercyCapybara::PERCY_SERVER_ADDRESS}/percy/healthcheck")
.to_raise(StandardError)

expect { page.percy_snapshot('Name') }
.to output("#{PercyCapybara::PERCY_LABEL} Percy is not running, disabling snapshots\n").to_stdout
.to output("#{LABEL} Percy is not running, disabling snapshots\n").to_stdout
end

it 'throws an error when name is not provided' do
Expand All @@ -64,7 +66,7 @@
.to_return(status: 200, body: '', headers: {})

expect { page.percy_snapshot('Name') }
.to output("#{PercyCapybara::PERCY_LABEL} Could not take DOM snapshot 'Name'\n").to_stdout
.to output("#{LABEL} Could not take DOM snapshot 'Name'\n").to_stdout
end

it 'sends snapshots to the local server' do
Expand Down

0 comments on commit 73f9048

Please sign in to comment.