cypress-rails 0.0.1 → 0.0.2

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: ad072dcc77aecfd321d07b2a747bb72ae7f4bd9f77cd2b6831aad5ae4fac5375
4
- data.tar.gz: 9fb63be63a4306b0f13ee3e942e10550ab83136e0abb59dd9e4864faa7e0a352
3
+ metadata.gz: 9a242d8e71274069fa20fd82ab8aa4ff31eea151ca621b6a36c53e862b3a90a2
4
+ data.tar.gz: 659cbc0bb3466e15b63ecfe4e951eb867d982325db45e17e7c8df175ffc3c1f9
5
5
  SHA512:
6
- metadata.gz: 17ee6aa4c845b494ba9ba06599ee07b71a6fc297b9813aa9d3b6949dae4a93d9ea03d8c498395fc759e1906bcb7b38e2f2a17310e852124241d68d0d39bd5eb4
7
- data.tar.gz: '09743583af8861b65d4c9512eb6cd0f521bcf76bbe735f904b77924c70c3b8c248d362d95823aa3c3972c94e5376c0481e85f698b496090fe9f4d99c3ed649dd'
6
+ metadata.gz: ffd03573f5a5d04ed75d760bf76caeaade986c7c0e58b3888212be4df8c17330089bdd251b4366d18aefad8f1a106952f759c27e17b2e54b12f3cd40bcf7dd03
7
+ data.tar.gz: 3d89d6bb37274c9cab66e72012828d9195125ae80f6e7726493a6d72e94d6d0db5780098988e9c58f91bb476e9d84e056a63d4d374b302efa42e8f46494c12bc
@@ -0,0 +1,52 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ docker:
5
+ - image: circleci/ruby:2.6-node-browsers
6
+ steps:
7
+ - checkout
8
+
9
+ # Bundle install dependencies
10
+ - type: cache-restore
11
+ key: v1-main-{{ checksum "Gemfile.lock" }}
12
+
13
+ - run: bundle install --path vendor/bundle
14
+
15
+ - type: cache-save
16
+ key: v1-main-{{ checksum "Gemfile.lock" }}
17
+ paths:
18
+ - vendor/bundle
19
+
20
+ # Bundle install dependencies for example app
21
+ - type: cache-restore
22
+ key: v1-example-{{ checksum "example/an_app/Gemfile.lock" }}
23
+
24
+ - run: |
25
+ cd example/an_app
26
+ bundle install --path vendor/bundle
27
+
28
+ - type: cache-save
29
+ key: v1-example-{{ checksum "example/an_app/Gemfile.lock" }}
30
+ paths:
31
+ - example/an_app/vendor/bundle
32
+
33
+ # Yarn dependencies
34
+ - restore_cache:
35
+ keys:
36
+ - v1-yarn-{{ checksum "example/an_app/package.json" }}
37
+ # fallback to using the latest cache if no exact match is found
38
+ - v1-yarn-
39
+
40
+ - run: |
41
+ cd example/an_app
42
+ yarn install
43
+
44
+ - save_cache:
45
+ paths:
46
+ - example/an_app/node_modules
47
+ - ~/.cache
48
+ key: v1-yarn-{{ checksum "example/an_app/package.json" }}
49
+
50
+ - run: bundle exec rake
51
+ - run: ./script/test_example_app
52
+
@@ -0,0 +1,4 @@
1
+ ignore:
2
+ - 'vendor/bundle/**/*'
3
+ - 'example/an_app/node_modules/**/*'
4
+ - 'example/an_app/vendor/bundle/**/*'
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cypress-rails (0.0.1)
4
+ cypress-rails (0.0.2)
5
+ capybara
5
6
  railties (>= 5.2.0)
6
7
  selenium-webdriver
7
8
 
data/README.md CHANGED
@@ -1,11 +1,13 @@
1
1
  # cypress-rails
2
2
 
3
+ [![CircleCI](https://circleci.com/gh/testdouble/cypress-rails/tree/master.svg?style=svg)](https://circleci.com/gh/testdouble/cypress-rails/tree/master)
4
+
3
5
  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.
6
+ [Cypress](http://cypress.io) for your [Rails](https://rubyonrails.org) apps,
7
+ regardless of whether your app is server-side rendered HTML, completely
8
+ client-side JavaScript, or something in-between.
7
9
 
8
- ## Why?
10
+ ## Why do this?
9
11
 
10
12
  Rails ships with a perfectly competent browser-testing facility called [system
11
13
  tests](https://guides.rubyonrails.org/testing.html#system-testing) which depend
@@ -19,36 +21,47 @@ additional layers to the Jenga tower of testing facilities that Rails ships
19
21
  with? Really, it comes down to the potential for an improved development
20
22
  experience. In particular:
21
23
 
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
24
+ * Cypress's [IDE-like `open`
25
+ command](https://docs.cypress.io/guides/getting-started/writing-your-first-test.html#Add-a-test-file)
26
+ provides a highly visual, interactive, inspectable test runner. Not only can
27
+ you watch each test run and read the commands as they're executed, Cypress
28
+ takes a DOM snapshot before and after each command, which makes rewinding and
29
+ inspecting the state of the DOM trivially easy, something that I regularly
30
+ find myself losing 20 minutes attempting to do with Capybara
31
+ * `cypress open` enables an almost REPL-like feedback loop that is much faster
29
32
  and more information dense than using Capybara and Selenium. Rather than
30
33
  running a test from the command line, seeing it fail, then adding a debug
31
34
  breakpoint to a test to try to manipulate the browser or tweaking a call to a
32
35
  Capybara API method, failures to be rather obvious when using Cypress and
33
36
  fixing it is usually as easy as tweaking a command, hitting save, and watching
34
37
  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
38
+ * With very few exceptions, a Cypress test that works in a browser window will
39
+ also pass when run headlessly in CI
40
+ * Cypress selectors are [just jQuery
41
+ selectors](https://api.jquery.com/category/selectors/), which makes them both
42
+ more familiar and more powerful than the CSS and XPath selectors offered by
37
43
  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
44
+ synchronous JavaScript function for [making more complex
45
+ assertions](https://docs.cypress.io/guides/references/assertions.html#Should-callback)
46
+ or composing repetitive tasks into [custom
47
+ commands](https://docs.cypress.io/api/cypress-api/custom-commands.html#Syntax#article)
40
48
  * Cypress commands are, generally, much faster than analogous tasks in Selenium.
41
49
  Where certain clicks and form inputs will hang for 300-500ms for seemingly no
42
50
  reason when running against Selenium WebDriver, Cypress commands tend to run
43
51
  as fast as jQuery can select and fill an element (which is, of course, pretty
44
52
  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.
53
+ * By default, Cypress [takes a
54
+ video](https://docs.cypress.io/guides/guides/screenshots-and-videos.html#Screenshots#article)
55
+ of every headless test run, taking a lot of the mystery (and subsequent
56
+ analysis & debugging) out of test failures in CI
57
+
58
+ Nevertheless, there are trade-offs to attempting this (most notably around
59
+ Cypress's [limited browser
60
+ support](https://docs.cypress.io/guides/guides/launching-browsers.html#Browsers)
61
+ and the complications to test data management), and I wouldn't recommend
62
+ adopting Cypress and writing a bunch of browser tests for every application.
63
+ But, if the above points sound like solutions to problems you experience, you
64
+ might consider trying it out.
52
65
 
53
66
  ## Installation
54
67
 
@@ -61,7 +74,7 @@ you experience, you might consider trying it out.
61
74
  ### Installing Cypress itself
62
75
 
63
76
  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).
77
+ library doesn't install Cypress, it just provides a little Rails-specific glue).
65
78
 
66
79
  If you're on newer versions of Rails and using
67
80
  [webpacker](https://www.github.com/rails/webpacker) for your front-end assets,
@@ -74,7 +87,8 @@ $ yarn add --dev cypress
74
87
 
75
88
  If you're not using yarn in conjunction with your Rails app, check out the
76
89
  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.
90
+ the `cypress` binary to exist either in `./node_modules/.bin/cypress` or on your
91
+ `PATH`.
78
92
 
79
93
  ### Installing the cypress-rails gem
80
94
 
@@ -91,7 +105,7 @@ end
91
105
  Once installed, you'll want to run:
92
106
 
93
107
  ```
94
- $ bin/rake cypress:init
108
+ $ rake cypress:init
95
109
  ```
96
110
 
97
111
  This will override a few configurations in your `cypress.json` configuration
@@ -112,14 +126,14 @@ a wrapper for running `cypress open` with a dedicated Rails test server.
112
126
  So, by running either:
113
127
 
114
128
  ```
115
- $ bundle exec cypress-rails open
129
+ $ cypress-rails open
116
130
  ```
117
131
 
118
132
  Or, if you don't mind the extra cost of loading rake just so it can call
119
133
  `system`:
120
134
 
121
135
  ```
122
- $ bin/rake cypress:open
136
+ $ rake cypress:open
123
137
  ```
124
138
 
125
139
  Add tests to `cypress/integration`. Simply click a test file in the Cypress
@@ -132,13 +146,13 @@ To run your tests headlessly (e.g. when you're in CI), you'll want the `run`
132
146
  command
133
147
 
134
148
  ```
135
- $ bundle exec cypress-rails run
149
+ $ cypress-rails run
136
150
  ```
137
151
 
138
152
  Or, with rake:
139
153
 
140
154
  ```
141
- $ bin/rake cypress:run
155
+ $ rake cypress:run
142
156
  ```
143
157
 
144
158
  ### Write Ruby tests that wrap and invoke your cypress tests
@@ -163,15 +177,19 @@ tests need, as well as specifying custom `setup` and `teardown` directives.
163
177
 
164
178
  Each Cypress file matched by the `test_locator` is translated to a single test
165
179
  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:
180
+ multiple times—also makes it easy to handle each Cypress file as you would any
181
+ other Ruby test. It also allows for CLI usage like this (where the test name is
182
+ an expansion of the file location with the path separators replaced with `_`):
168
183
 
169
184
  ```
170
- $ bin/rails test test/system --name test_cypress_integration_send_invoice_js
185
+ $ rails test test/system --name test_cypress_integration_send_invoice_js
171
186
  ```
172
187
 
173
- (Where the test name is an expansion of the file location with the path
174
- separators replaced with `_`.)
188
+ **WARNING**: keep in mind that any custom Ruby code you add before or after each
189
+ Cypress test is run in the context of a `CypressRails::TestCase` will _not_ be
190
+ run when developing with `cypress open`! That means this is probably not the
191
+ most rock-solid strategy for consistent test behavior when it comes to things
192
+ like test data management.
175
193
 
176
194
  ### Setting up continuous integration
177
195
 
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.require_paths = ["lib"]
23
23
 
24
24
  spec.add_dependency "railties", ">= 5.2.0"
25
+ spec.add_dependency "capybara"
25
26
  spec.add_dependency "selenium-webdriver"
26
27
 
27
28
  spec.add_development_dependency "bundler", "~> 1.17"
@@ -1,3 +1,3 @@
1
1
  module CypressRails
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ directory=$1
6
+
7
+ cd example/an_app
8
+ bundle
9
+ yarn install
10
+ bundle exec rake cypress:run
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cypress-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Searls
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-15 00:00:00.000000000 Z
11
+ date: 2019-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 5.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: capybara
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'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: selenium-webdriver
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -130,7 +144,9 @@ executables:
130
144
  extensions: []
131
145
  extra_rdoc_files: []
132
146
  files:
147
+ - ".circleci/config.yml"
133
148
  - ".gitignore"
149
+ - ".standard.yml"
134
150
  - ".travis.yml"
135
151
  - Gemfile
136
152
  - Gemfile.lock
@@ -152,6 +168,7 @@ files:
152
168
  - lib/cypress-rails/starts_rails_server.rb
153
169
  - lib/cypress-rails/test_case.rb
154
170
  - lib/cypress-rails/version.rb
171
+ - script/test_example_app
155
172
  homepage: https://github.com/testdouble/cypress-rails
156
173
  licenses:
157
174
  - MIT