cypress-rails 0.0.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 +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +117 -0
- data/LICENSE.txt +21 -0
- data/README.md +232 -0
- data/Rakefile +11 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/cypress-rails.gemspec +33 -0
- data/exe/cypress-rails +16 -0
- data/lib/cypress-rails.rb +10 -0
- data/lib/cypress-rails/configures_test_server.rb +23 -0
- data/lib/cypress-rails/finds_bin.rb +16 -0
- data/lib/cypress-rails/init.rb +30 -0
- data/lib/cypress-rails/open.rb +20 -0
- data/lib/cypress-rails/railtie.rb +12 -0
- data/lib/cypress-rails/rake.rb +17 -0
- data/lib/cypress-rails/run.rb +20 -0
- data/lib/cypress-rails/starts_rails_server.rb +32 -0
- data/lib/cypress-rails/test_case.rb +34 -0
- data/lib/cypress-rails/version.rb +3 -0
- metadata +178 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ad072dcc77aecfd321d07b2a747bb72ae7f4bd9f77cd2b6831aad5ae4fac5375
|
|
4
|
+
data.tar.gz: 9fb63be63a4306b0f13ee3e942e10550ab83136e0abb59dd9e4864faa7e0a352
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 17ee6aa4c845b494ba9ba06599ee07b71a6fc297b9813aa9d3b6949dae4a93d9ea03d8c498395fc759e1906bcb7b38e2f2a17310e852124241d68d0d39bd5eb4
|
|
7
|
+
data.tar.gz: '09743583af8861b65d4c9512eb6cd0f521bcf76bbe735f904b77924c70c3b8c248d362d95823aa3c3972c94e5376c0481e85f698b496090fe9f4d99c3ed649dd'
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
cypress-rails (0.0.1)
|
|
5
|
+
railties (>= 5.2.0)
|
|
6
|
+
selenium-webdriver
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: https://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
actionpack (5.2.3)
|
|
12
|
+
actionview (= 5.2.3)
|
|
13
|
+
activesupport (= 5.2.3)
|
|
14
|
+
rack (~> 2.0)
|
|
15
|
+
rack-test (>= 0.6.3)
|
|
16
|
+
rails-dom-testing (~> 2.0)
|
|
17
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
18
|
+
actionview (5.2.3)
|
|
19
|
+
activesupport (= 5.2.3)
|
|
20
|
+
builder (~> 3.1)
|
|
21
|
+
erubi (~> 1.4)
|
|
22
|
+
rails-dom-testing (~> 2.0)
|
|
23
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
|
24
|
+
activesupport (5.2.3)
|
|
25
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
26
|
+
i18n (>= 0.7, < 2)
|
|
27
|
+
minitest (~> 5.1)
|
|
28
|
+
tzinfo (~> 1.1)
|
|
29
|
+
addressable (2.7.0)
|
|
30
|
+
public_suffix (>= 2.0.2, < 5.0)
|
|
31
|
+
ast (2.4.0)
|
|
32
|
+
builder (3.2.3)
|
|
33
|
+
capybara (3.29.0)
|
|
34
|
+
addressable
|
|
35
|
+
mini_mime (>= 0.1.3)
|
|
36
|
+
nokogiri (~> 1.8)
|
|
37
|
+
rack (>= 1.6.0)
|
|
38
|
+
rack-test (>= 0.6.3)
|
|
39
|
+
regexp_parser (~> 1.5)
|
|
40
|
+
xpath (~> 3.2)
|
|
41
|
+
childprocess (2.0.0)
|
|
42
|
+
rake (< 13.0)
|
|
43
|
+
concurrent-ruby (1.1.5)
|
|
44
|
+
crass (1.0.4)
|
|
45
|
+
erubi (1.8.0)
|
|
46
|
+
i18n (1.6.0)
|
|
47
|
+
concurrent-ruby (~> 1.0)
|
|
48
|
+
jaro_winkler (1.5.3)
|
|
49
|
+
loofah (2.2.3)
|
|
50
|
+
crass (~> 1.0.2)
|
|
51
|
+
nokogiri (>= 1.5.9)
|
|
52
|
+
method_source (0.9.2)
|
|
53
|
+
mini_mime (1.0.2)
|
|
54
|
+
mini_portile2 (2.4.0)
|
|
55
|
+
minitest (5.11.3)
|
|
56
|
+
nokogiri (1.10.4)
|
|
57
|
+
mini_portile2 (~> 2.4.0)
|
|
58
|
+
parallel (1.17.0)
|
|
59
|
+
parser (2.6.4.1)
|
|
60
|
+
ast (~> 2.4.0)
|
|
61
|
+
public_suffix (4.0.1)
|
|
62
|
+
rack (2.0.7)
|
|
63
|
+
rack-test (1.1.0)
|
|
64
|
+
rack (>= 1.0, < 3)
|
|
65
|
+
rails-dom-testing (2.0.3)
|
|
66
|
+
activesupport (>= 4.2.0)
|
|
67
|
+
nokogiri (>= 1.6)
|
|
68
|
+
rails-html-sanitizer (1.2.0)
|
|
69
|
+
loofah (~> 2.2, >= 2.2.2)
|
|
70
|
+
railties (5.2.3)
|
|
71
|
+
actionpack (= 5.2.3)
|
|
72
|
+
activesupport (= 5.2.3)
|
|
73
|
+
method_source
|
|
74
|
+
rake (>= 0.8.7)
|
|
75
|
+
thor (>= 0.19.0, < 2.0)
|
|
76
|
+
rainbow (3.0.0)
|
|
77
|
+
rake (10.5.0)
|
|
78
|
+
regexp_parser (1.6.0)
|
|
79
|
+
rubocop (0.72.0)
|
|
80
|
+
jaro_winkler (~> 1.5.1)
|
|
81
|
+
parallel (~> 1.10)
|
|
82
|
+
parser (>= 2.6)
|
|
83
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
84
|
+
ruby-progressbar (~> 1.7)
|
|
85
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
|
86
|
+
rubocop-performance (1.4.1)
|
|
87
|
+
rubocop (>= 0.71.0)
|
|
88
|
+
ruby-progressbar (1.10.1)
|
|
89
|
+
rubyzip (1.2.4)
|
|
90
|
+
selenium-webdriver (3.142.4)
|
|
91
|
+
childprocess (>= 0.5, < 3.0)
|
|
92
|
+
rubyzip (~> 1.2, >= 1.2.2)
|
|
93
|
+
standard (0.1.3)
|
|
94
|
+
rubocop (~> 0.72.0)
|
|
95
|
+
rubocop-performance (~> 1.4.0)
|
|
96
|
+
thor (0.20.3)
|
|
97
|
+
thread_safe (0.3.6)
|
|
98
|
+
tzinfo (1.2.5)
|
|
99
|
+
thread_safe (~> 0.1)
|
|
100
|
+
unicode-display_width (1.6.0)
|
|
101
|
+
xpath (3.2.0)
|
|
102
|
+
nokogiri (~> 1.8)
|
|
103
|
+
|
|
104
|
+
PLATFORMS
|
|
105
|
+
ruby
|
|
106
|
+
|
|
107
|
+
DEPENDENCIES
|
|
108
|
+
actionpack
|
|
109
|
+
bundler (~> 1.17)
|
|
110
|
+
capybara
|
|
111
|
+
cypress-rails!
|
|
112
|
+
minitest (~> 5.0)
|
|
113
|
+
rake (~> 10.0)
|
|
114
|
+
standard (~> 0.1.3)
|
|
115
|
+
|
|
116
|
+
BUNDLED WITH
|
|
117
|
+
1.17.3
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Test Double, LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
# cypress-rails
|
|
2
|
+
|
|
3
|
+
This is a simple gem to make it easier to start writing browser tests with
|
|
4
|
+
[Cypress](http://cypress.io) for your Rails apps, regardless of whether your app
|
|
5
|
+
is server-side rendered HTML, completely client-side JavaScript, or something in
|
|
6
|
+
between.
|
|
7
|
+
|
|
8
|
+
## Why?
|
|
9
|
+
|
|
10
|
+
Rails ships with a perfectly competent browser-testing facility called [system
|
|
11
|
+
tests](https://guides.rubyonrails.org/testing.html#system-testing) which depend
|
|
12
|
+
on [capybara](https://github.com/teamcapybara/capybara) to drive your tests,
|
|
13
|
+
most often with [Selenium](https://www.seleniumhq.org). All of these tools work,
|
|
14
|
+
are used by lots of people, and are a perfectly reasonable choice when writing
|
|
15
|
+
full-stack tests of your Rails application.
|
|
16
|
+
|
|
17
|
+
So why would you go off the Rails to use Cypress and this gem, adding two
|
|
18
|
+
additional layers to the Jenga tower of testing facilities that Rails ships
|
|
19
|
+
with? Really, it comes down to the potential for an improved development
|
|
20
|
+
experience. In particular:
|
|
21
|
+
|
|
22
|
+
* Cypress's IDE-like "open" command provides a highly visual, interactive,
|
|
23
|
+
inspectable test runner. Not only can you watch each test run and read the
|
|
24
|
+
commands as they're executed, Cypress takes a DOM snapshot before and after
|
|
25
|
+
each command, which makes rewinding and inspecting the state of the DOM
|
|
26
|
+
trivially easy, something that I regularly find myself losing 20 minutes
|
|
27
|
+
attempting to do with Capybara
|
|
28
|
+
* Cypress "open" enables an almost REPL-like feedback loop that is much faster
|
|
29
|
+
and more information dense than using Capybara and Selenium. Rather than
|
|
30
|
+
running a test from the command line, seeing it fail, then adding a debug
|
|
31
|
+
breakpoint to a test to try to manipulate the browser or tweaking a call to a
|
|
32
|
+
Capybara API method, failures to be rather obvious when using Cypress and
|
|
33
|
+
fixing it is usually as easy as tweaking a command, hitting save, and watching
|
|
34
|
+
it re-run
|
|
35
|
+
* Cypress selectors are just jQuery selectors, which makes them both more
|
|
36
|
+
familiar and more powerful than the CSS and XPath selectors offered by
|
|
37
|
+
Capybara. Additionally, Cypress makes it very easy to drop into a plain
|
|
38
|
+
synchronous JavaScript function for making more complex assertions or
|
|
39
|
+
composing repetitive tasks into custom commands
|
|
40
|
+
* Cypress commands are, generally, much faster than analogous tasks in Selenium.
|
|
41
|
+
Where certain clicks and form inputs will hang for 300-500ms for seemingly no
|
|
42
|
+
reason when running against Selenium WebDriver, Cypress commands tend to run
|
|
43
|
+
as fast as jQuery can select and fill an element (which is, of course, pretty
|
|
44
|
+
fast)
|
|
45
|
+
* By default, Cypress takes a video of every headless test run, taking a lot of
|
|
46
|
+
the mystery (and subsequent analysis & debugging) out of test failures in CI
|
|
47
|
+
|
|
48
|
+
Nevertheless, there are trade-offs (most notably around test data management),
|
|
49
|
+
and I wouldn't recommend adopting Cypress and writing a bunch of browser tests
|
|
50
|
+
for every application. But, if the above points sound like solutions to problems
|
|
51
|
+
you experience, you might consider trying it out.
|
|
52
|
+
|
|
53
|
+
## Installation
|
|
54
|
+
|
|
55
|
+
**tl;dr**:
|
|
56
|
+
|
|
57
|
+
1. Install the npm package `cypress`
|
|
58
|
+
2. Install this gem `cypress-rails`
|
|
59
|
+
3. Run `rake cypress:init`
|
|
60
|
+
|
|
61
|
+
### Installing Cypress itself
|
|
62
|
+
|
|
63
|
+
The first step is making sure Cypress is installed (that's up to you, this
|
|
64
|
+
library doesn't install Cypress, it just provides a little Rails specific glue).
|
|
65
|
+
|
|
66
|
+
If you're on newer versions of Rails and using
|
|
67
|
+
[webpacker](https://www.github.com/rails/webpacker) for your front-end assets,
|
|
68
|
+
then you're likely already using yarn to manage your JavaScript dependencies. If
|
|
69
|
+
that's the case, you can add Cypress with:
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
$ yarn add --dev cypress
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
If you're not using yarn in conjunction with your Rails app, check out the
|
|
76
|
+
Cypress docs on getting it installed. At the end of the day, this gem just needs
|
|
77
|
+
the `cypress` binary to exist someplace it can find.
|
|
78
|
+
|
|
79
|
+
### Installing the cypress-rails gem
|
|
80
|
+
|
|
81
|
+
Now, to install the cypress-rails gem, you'll want to add it to your development
|
|
82
|
+
& test gem groups of your Gemfile, so that you have easy access to its rake
|
|
83
|
+
tasks:
|
|
84
|
+
|
|
85
|
+
``` ruby
|
|
86
|
+
group :development, :test do
|
|
87
|
+
gem "cypress-rails"
|
|
88
|
+
end
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Once installed, you'll want to run:
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
$ bin/rake cypress:init
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
This will override a few configurations in your `cypress.json` configuration
|
|
98
|
+
file.
|
|
99
|
+
|
|
100
|
+
## Usage
|
|
101
|
+
|
|
102
|
+
### Develop tests interactively with `cypress open`
|
|
103
|
+
|
|
104
|
+
When writing tests with Cypress, you'll find the most pleasant experience (by
|
|
105
|
+
way of a faster feedback loop and an interactive, easy-to-inspect test runner)
|
|
106
|
+
using the `cypress open` command.
|
|
107
|
+
|
|
108
|
+
When using Rails, however, you'll also want your Rails test server to be running
|
|
109
|
+
so that there's something for Cypress to interact with. `cypress-rails` provides
|
|
110
|
+
a wrapper for running `cypress open` with a dedicated Rails test server.
|
|
111
|
+
|
|
112
|
+
So, by running either:
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
$ bundle exec cypress-rails open
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Or, if you don't mind the extra cost of loading rake just so it can call
|
|
119
|
+
`system`:
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
$ bin/rake cypress:open
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Add tests to `cypress/integration`. Simply click a test file in the Cypress
|
|
126
|
+
application window to launch the test in a browser. Each time you save the test
|
|
127
|
+
file, it will re-run itself.
|
|
128
|
+
|
|
129
|
+
### Run tests headlessly with `cypress run`
|
|
130
|
+
|
|
131
|
+
To run your tests headlessly (e.g. when you're in CI), you'll want the `run`
|
|
132
|
+
command
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
$ bundle exec cypress-rails run
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Or, with rake:
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
$ bin/rake cypress:run
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Write Ruby tests that wrap and invoke your cypress tests
|
|
145
|
+
|
|
146
|
+
You can also extend a provided `CypressRails::TestCase`, which itself inherits
|
|
147
|
+
from Rails' built-in `ActionDispatch::SystemTestCase`.
|
|
148
|
+
|
|
149
|
+
That means you can add a test named `test/system/cypress_test.rb`:
|
|
150
|
+
|
|
151
|
+
```ruby
|
|
152
|
+
require "test_helper"
|
|
153
|
+
|
|
154
|
+
class CypressTest < CypressRails::TestCase
|
|
155
|
+
test_locator "cypress/integration/**/*.js"
|
|
156
|
+
end
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
And it will run alongside all the rest of your system tests. Because this would
|
|
160
|
+
be invoked by your existing test scripts, you can benefit from whatever custom
|
|
161
|
+
test helpers (e.g. database setup, test coverage, etc.) your other full-stack
|
|
162
|
+
tests need, as well as specifying custom `setup` and `teardown` directives.
|
|
163
|
+
|
|
164
|
+
Each Cypress file matched by the `test_locator` is translated to a single test
|
|
165
|
+
case, which—while slightly inefficient, as it spools Cypress up and down
|
|
166
|
+
multiple times—also makes it easy to treat each Cypress file as you would any
|
|
167
|
+
other Ruby test, allowing for CLI usage like this:
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
$ bin/rails test test/system --name test_cypress_integration_send_invoice_js
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
(Where the test name is an expansion of the file location with the path
|
|
174
|
+
separators replaced with `_`.)
|
|
175
|
+
|
|
176
|
+
### Setting up continuous integration
|
|
177
|
+
|
|
178
|
+
#### Circle CI
|
|
179
|
+
|
|
180
|
+
Nowadays, Cypress and Circle get along pretty well without much customization.
|
|
181
|
+
The only tricky bit is that Cypress will install its large-ish binary to
|
|
182
|
+
`~/.cache/Cypress`, so if you cache your dependencies, you'll want to include
|
|
183
|
+
that path:
|
|
184
|
+
|
|
185
|
+
```yml
|
|
186
|
+
version: 2
|
|
187
|
+
jobs:
|
|
188
|
+
build:
|
|
189
|
+
docker:
|
|
190
|
+
- image: circleci/ruby:2.6-node-browsers
|
|
191
|
+
- image: circleci/postgres:9.4.12-alpine
|
|
192
|
+
environment:
|
|
193
|
+
POSTGRES_USER: circleci
|
|
194
|
+
steps:
|
|
195
|
+
- checkout
|
|
196
|
+
|
|
197
|
+
# Bundle install dependencies
|
|
198
|
+
- type: cache-restore
|
|
199
|
+
key: v1-gems-{{ checksum "Gemfile.lock" }}
|
|
200
|
+
|
|
201
|
+
- run: bundle install --path vendor/bundle
|
|
202
|
+
|
|
203
|
+
- type: cache-save
|
|
204
|
+
key: v1-gems-{{ checksum "Gemfile.lock" }}
|
|
205
|
+
paths:
|
|
206
|
+
- vendor/bundle
|
|
207
|
+
|
|
208
|
+
# Yarn dependencies
|
|
209
|
+
- restore_cache:
|
|
210
|
+
keys:
|
|
211
|
+
- v1-yarn-{{ checksum "package.json" }}
|
|
212
|
+
# fallback to using the latest cache if no exact match is found
|
|
213
|
+
- v1-yarn-
|
|
214
|
+
|
|
215
|
+
- run: yarn install
|
|
216
|
+
|
|
217
|
+
- save_cache:
|
|
218
|
+
paths:
|
|
219
|
+
- node_modules
|
|
220
|
+
- ~/.cache
|
|
221
|
+
key: v1-yarn-{{ checksum "package.json" }}
|
|
222
|
+
|
|
223
|
+
# Run your cypress tests
|
|
224
|
+
- run: bin/rake cypress:run
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Configuration
|
|
228
|
+
|
|
229
|
+
You can change the behavior of this gem by setting these environment variables:
|
|
230
|
+
|
|
231
|
+
* **RAILS_CYPRESS_PORT**: the port to run the Rails test server on (defaults to
|
|
232
|
+
a random available port
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "cypress/rails"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
+
require "cypress-rails/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "cypress-rails"
|
|
7
|
+
spec.version = CypressRails::VERSION
|
|
8
|
+
spec.authors = ["Justin Searls"]
|
|
9
|
+
spec.email = ["searls@gmail.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "Helps you write Cypress tests of your Rails app"
|
|
12
|
+
spec.homepage = "https://github.com/testdouble/cypress-rails"
|
|
13
|
+
spec.license = "MIT"
|
|
14
|
+
|
|
15
|
+
# Specify which files should be added to the gem when it is released.
|
|
16
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
17
|
+
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
|
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|example)/}) }
|
|
19
|
+
end
|
|
20
|
+
spec.bindir = "exe"
|
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
22
|
+
spec.require_paths = ["lib"]
|
|
23
|
+
|
|
24
|
+
spec.add_dependency "railties", ">= 5.2.0"
|
|
25
|
+
spec.add_dependency "selenium-webdriver"
|
|
26
|
+
|
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
29
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
|
30
|
+
spec.add_development_dependency "standard", "~> 0.1.3"
|
|
31
|
+
spec.add_development_dependency "actionpack"
|
|
32
|
+
spec.add_development_dependency "capybara"
|
|
33
|
+
end
|
data/exe/cypress-rails
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
ENV["RAILS_ENV"] = "test"
|
|
4
|
+
require "pathname"
|
|
5
|
+
require Pathname.new(Dir.pwd).join("config/environment")
|
|
6
|
+
require "cypress-rails"
|
|
7
|
+
|
|
8
|
+
command = ARGV[0]
|
|
9
|
+
case command
|
|
10
|
+
when "init"
|
|
11
|
+
CypressRails::Init.new.call
|
|
12
|
+
when "open"
|
|
13
|
+
CypressRails::Open.new.call
|
|
14
|
+
when "run"
|
|
15
|
+
CypressRails::Run.new.call
|
|
16
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module CypressRails
|
|
2
|
+
class ConfiguresTestServer
|
|
3
|
+
def call(port: ENV["RAILS_CYPRESS_PORT"])
|
|
4
|
+
require "capybara"
|
|
5
|
+
require "selenium-webdriver"
|
|
6
|
+
Capybara.server_port = port || find_available_port
|
|
7
|
+
Capybara.always_include_port = true
|
|
8
|
+
Capybara.server = :puma, {Silent: false}
|
|
9
|
+
Capybara.current_session
|
|
10
|
+
|
|
11
|
+
true
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def find_available_port
|
|
17
|
+
server = TCPServer.new(Capybara.server_host, 0)
|
|
18
|
+
server.addr[1]
|
|
19
|
+
ensure
|
|
20
|
+
server&.close
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require "pathname"
|
|
2
|
+
|
|
3
|
+
module CypressRails
|
|
4
|
+
class FindsBin
|
|
5
|
+
LOCAL_PATH = "node_modules/.bin/cypress"
|
|
6
|
+
|
|
7
|
+
def call(dir = Dir.pwd)
|
|
8
|
+
local_path = Pathname.new(dir).join(LOCAL_PATH)
|
|
9
|
+
if File.exist?(local_path)
|
|
10
|
+
local_path
|
|
11
|
+
else
|
|
12
|
+
"cypress"
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module CypressRails
|
|
2
|
+
class Init
|
|
3
|
+
DEFAULT_CONFIG = {
|
|
4
|
+
"screenshotsFolder" => "tmp/cypress_screenshots",
|
|
5
|
+
"videosFolder" => "tmp/cypress_videos",
|
|
6
|
+
"trashAssetsBeforeRuns" => false,
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
def call(dir = Dir.pwd)
|
|
10
|
+
config_path = File.join(dir, "cypress.json")
|
|
11
|
+
json = JSON.pretty_generate(determine_new_config(config_path))
|
|
12
|
+
File.write(config_path, json)
|
|
13
|
+
puts "Cypress config (re)initialized in #{config_path}"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def determine_new_config(config_path)
|
|
19
|
+
if File.exist?(config_path)
|
|
20
|
+
merge_existing_with_defaults(config_path)
|
|
21
|
+
else
|
|
22
|
+
DEFAULT_CONFIG
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def merge_existing_with_defaults(json_path)
|
|
27
|
+
Hash[JSON.parse(File.read(json_path)).merge(DEFAULT_CONFIG).sort]
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require_relative "finds_bin"
|
|
2
|
+
require_relative "starts_rails_server"
|
|
3
|
+
|
|
4
|
+
module CypressRails
|
|
5
|
+
class Open
|
|
6
|
+
def initialize
|
|
7
|
+
@starts_rails_server = StartsRailsServer.new
|
|
8
|
+
@finds_bin = FindsBin.new
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def call(dir: Dir.pwd, port: ENV["RAILS_CYPRESS_PORT"])
|
|
12
|
+
@starts_rails_server.call(dir: dir, port: port)
|
|
13
|
+
bin = @finds_bin.call(dir)
|
|
14
|
+
|
|
15
|
+
system <<~EXEC
|
|
16
|
+
CYPRESS_BASE_URL=http://#{Capybara.server_host}:#{Capybara.server_port} #{bin} open --project "#{dir}"
|
|
17
|
+
EXEC
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require "pathname"
|
|
2
|
+
CLI = Pathname.new(File.dirname(__FILE__)).join("../../exe/cypress-rails")
|
|
3
|
+
|
|
4
|
+
desc "Initialize cypress.json"
|
|
5
|
+
task :"cypress:init" do
|
|
6
|
+
system "#{CLI} init"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
desc "Open interactive Cypress app for developing tests"
|
|
10
|
+
task :"cypress:open" do
|
|
11
|
+
system "#{CLI} open"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
desc "Run Cypress tests headlessly"
|
|
15
|
+
task :"cypress:run" do
|
|
16
|
+
system "#{CLI} run"
|
|
17
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require_relative "finds_bin"
|
|
2
|
+
require_relative "starts_rails_server"
|
|
3
|
+
|
|
4
|
+
module CypressRails
|
|
5
|
+
class Run
|
|
6
|
+
def initialize
|
|
7
|
+
@starts_rails_server = StartsRailsServer.new
|
|
8
|
+
@finds_bin = FindsBin.new
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def call(dir: Dir.pwd, port: ENV["RAILS_CYPRESS_PORT"])
|
|
12
|
+
@starts_rails_server.call(dir: dir, port: port)
|
|
13
|
+
bin = @finds_bin.call(dir)
|
|
14
|
+
|
|
15
|
+
system <<~EXEC
|
|
16
|
+
CYPRESS_BASE_URL=http://#{Capybara.server_host}:#{Capybara.server_port} #{bin} run --project "#{dir}"
|
|
17
|
+
EXEC
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require_relative "configures_test_server"
|
|
2
|
+
|
|
3
|
+
module CypressRails
|
|
4
|
+
class StartsRailsServer
|
|
5
|
+
def initialize
|
|
6
|
+
@configures_test_server = ConfiguresTestServer.new
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def call(dir:, port:)
|
|
10
|
+
@configures_test_server.call(port: port)
|
|
11
|
+
|
|
12
|
+
require "action_dispatch/system_testing/driver"
|
|
13
|
+
require "action_dispatch/system_testing/browser"
|
|
14
|
+
ActionDispatch::SystemTesting::Driver.new(:selenium, {
|
|
15
|
+
using: :headless_chrome,
|
|
16
|
+
screen_size: [1400, 1400],
|
|
17
|
+
options: {},
|
|
18
|
+
}).use
|
|
19
|
+
|
|
20
|
+
Capybara.app = Rack::Builder.new do
|
|
21
|
+
map "/" do
|
|
22
|
+
run Rails.application
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
require "action_dispatch/system_testing/server"
|
|
27
|
+
ActionDispatch::SystemTesting::Server.new.run
|
|
28
|
+
|
|
29
|
+
Capybara.current_session
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require "action_dispatch/system_test_case"
|
|
2
|
+
|
|
3
|
+
require_relative "configures_test_server"
|
|
4
|
+
|
|
5
|
+
module CypressRails
|
|
6
|
+
class TestCase < ActionDispatch::SystemTestCase
|
|
7
|
+
driven_by :selenium_headless
|
|
8
|
+
|
|
9
|
+
def setup
|
|
10
|
+
@@__cypress_rails_configures_test_server ||= ConfiguresTestServer.new.call
|
|
11
|
+
ensure
|
|
12
|
+
super
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.test_locator(path_or_globs)
|
|
16
|
+
Dir[path_or_globs].map do |path|
|
|
17
|
+
test_name = "test_#{path.gsub(/[\/\.:\\]/, "_")}"
|
|
18
|
+
define_method test_name do
|
|
19
|
+
bin = FindsBin.new.call
|
|
20
|
+
command = "CYPRESS_BASE_URL=http://#{Capybara.server_host}:#{Capybara.server_port} #{bin} run --spec \"#{path}\""
|
|
21
|
+
unless system(command)
|
|
22
|
+
raise <<~ERROR
|
|
23
|
+
Cypress test failed. Try again with:
|
|
24
|
+
$ rails test test/system --name #{test_name}
|
|
25
|
+
|
|
26
|
+
Underlying Cypress command run was:
|
|
27
|
+
$ #{command}
|
|
28
|
+
ERROR
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: cypress-rails
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Justin Searls
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-09-15 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: railties
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 5.2.0
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 5.2.0
|
|
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: '0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: bundler
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '1.17'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '1.17'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rake
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '10.0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '10.0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: minitest
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '5.0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '5.0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: standard
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: 0.1.3
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: 0.1.3
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: actionpack
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - ">="
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - ">="
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: capybara
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - ">="
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '0'
|
|
118
|
+
type: :development
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - ">="
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '0'
|
|
125
|
+
description:
|
|
126
|
+
email:
|
|
127
|
+
- searls@gmail.com
|
|
128
|
+
executables:
|
|
129
|
+
- cypress-rails
|
|
130
|
+
extensions: []
|
|
131
|
+
extra_rdoc_files: []
|
|
132
|
+
files:
|
|
133
|
+
- ".gitignore"
|
|
134
|
+
- ".travis.yml"
|
|
135
|
+
- Gemfile
|
|
136
|
+
- Gemfile.lock
|
|
137
|
+
- LICENSE.txt
|
|
138
|
+
- README.md
|
|
139
|
+
- Rakefile
|
|
140
|
+
- bin/console
|
|
141
|
+
- bin/setup
|
|
142
|
+
- cypress-rails.gemspec
|
|
143
|
+
- exe/cypress-rails
|
|
144
|
+
- lib/cypress-rails.rb
|
|
145
|
+
- lib/cypress-rails/configures_test_server.rb
|
|
146
|
+
- lib/cypress-rails/finds_bin.rb
|
|
147
|
+
- lib/cypress-rails/init.rb
|
|
148
|
+
- lib/cypress-rails/open.rb
|
|
149
|
+
- lib/cypress-rails/railtie.rb
|
|
150
|
+
- lib/cypress-rails/rake.rb
|
|
151
|
+
- lib/cypress-rails/run.rb
|
|
152
|
+
- lib/cypress-rails/starts_rails_server.rb
|
|
153
|
+
- lib/cypress-rails/test_case.rb
|
|
154
|
+
- lib/cypress-rails/version.rb
|
|
155
|
+
homepage: https://github.com/testdouble/cypress-rails
|
|
156
|
+
licenses:
|
|
157
|
+
- MIT
|
|
158
|
+
metadata: {}
|
|
159
|
+
post_install_message:
|
|
160
|
+
rdoc_options: []
|
|
161
|
+
require_paths:
|
|
162
|
+
- lib
|
|
163
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
164
|
+
requirements:
|
|
165
|
+
- - ">="
|
|
166
|
+
- !ruby/object:Gem::Version
|
|
167
|
+
version: '0'
|
|
168
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
|
+
requirements:
|
|
170
|
+
- - ">="
|
|
171
|
+
- !ruby/object:Gem::Version
|
|
172
|
+
version: '0'
|
|
173
|
+
requirements: []
|
|
174
|
+
rubygems_version: 3.0.3
|
|
175
|
+
signing_key:
|
|
176
|
+
specification_version: 4
|
|
177
|
+
summary: Helps you write Cypress tests of your Rails app
|
|
178
|
+
test_files: []
|