cypress-rails 0.4.1 → 0.5.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: a14e87a5a70d81fe84303607d0927c51766fb088af7ec1939ba73e57319ecc8e
4
- data.tar.gz: 4afd968f15e3074ce55d7d24cedaa0362b9542d4661f061debc76fbd8ffa212e
3
+ metadata.gz: e53dca004e45ff69cd1b4564db925a7a2f90a51a0c6d1fd14474195fd56c4e50
4
+ data.tar.gz: 3c232334f4f475c57a3b7271f28789cdfcf3cbfcbf9af07ce36dd4d8b1364c5f
5
5
  SHA512:
6
- metadata.gz: 2fe07821acc26a46e1480caf536d03d69f77e400e53fe28672930ec16ae62e55ddda54d1f296f57f5e1535c75c06c74a6221a3ca87f5cbb239236f3e3b0850dc
7
- data.tar.gz: f3a026adf4ec214285eaf2fb004b9984d0bc2f1842495a7a6c6809e6363826ee951de8116380309e105ed887f541412aabe5a9c7980c4f2ce36e555ebcd567ee
6
+ metadata.gz: 64703f8568b020e2576e9d05a6e622e636ead09298d21850e224a140ae8bc20d5ddc2b7ecd68a42c9b17ebb9c3e174d52f450f92907582df399eb08531e79cf9
7
+ data.tar.gz: 8540df300675e162107d198c90cf947ee06154291db96799de82b0112cee745274787205da03963dd07e1780c330367367fa42ae7bcc7edece5b27841333186c
@@ -0,0 +1,21 @@
1
+ name: CI
2
+
3
+ on: [push, pull_request, workflow_dispatch]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+
9
+ strategy:
10
+ matrix:
11
+ ruby-version: ['2.7', '3.0']
12
+
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: ${{ matrix.ruby-version }}
18
+ bundler-cache: true
19
+
20
+ - name: Run tests
21
+ run: ./script/test
data/.standard.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ignore:
2
2
  - 'vendor/bundle/**/*'
3
- - 'example/an_app/node_modules/**/*'
4
- - 'example/an_app/vendor/bundle/**/*'
3
+ - 'example/node_modules/**/*'
4
+ - 'example/vendor/bundle/**/*'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.5.2
4
+
5
+ * Fixes a puma deprecation warning
6
+ [#95](https://github.com/testdouble/cypress-rails/pull/95)
7
+
8
+ ## 0.5.1
9
+
10
+ * Sprinkles two instance variables to the custom transaction manager that cribs
11
+ its implementation from ActiveRecord::TestFixtures (see f75f280)
12
+ [#88](https://github.com/testdouble/cypress-rails/issues/88)
13
+ [#89](https://github.com/testdouble/cypress-rails/pull/89)
14
+
15
+ ## 0.5.0
16
+
17
+ * Add hook `after_server_start`
18
+ [#63](https://github.com/testdouble/cypress-rails/pull/63)
19
+ * Fix namespace bug
20
+ [#64](https://github.com/testdouble/cypress-rails/pull/64)
21
+
22
+ ## 0.4.2
23
+
24
+ * Add support to Rails 6.1 ([#52](https://github.com/testdouble/cypress-rails/issue/52))
25
+
3
26
  ## 0.4.1
4
27
 
5
28
  * Add backcompat for Ruby 2.4
data/Gemfile.lock CHANGED
@@ -1,97 +1,96 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cypress-rails (0.4.1)
4
+ cypress-rails (0.5.2)
5
5
  puma (>= 3.8.0)
6
6
  railties (>= 5.2.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actionpack (6.0.3.4)
12
- actionview (= 6.0.3.4)
13
- activesupport (= 6.0.3.4)
14
- rack (~> 2.0, >= 2.0.8)
11
+ actionpack (6.1.4)
12
+ actionview (= 6.1.4)
13
+ activesupport (= 6.1.4)
14
+ rack (~> 2.0, >= 2.0.9)
15
15
  rack-test (>= 0.6.3)
16
16
  rails-dom-testing (~> 2.0)
17
17
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
18
- actionview (6.0.3.4)
19
- activesupport (= 6.0.3.4)
18
+ actionview (6.1.4)
19
+ activesupport (= 6.1.4)
20
20
  builder (~> 3.1)
21
21
  erubi (~> 1.4)
22
22
  rails-dom-testing (~> 2.0)
23
23
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
24
- activesupport (6.0.3.4)
24
+ activesupport (6.1.4)
25
25
  concurrent-ruby (~> 1.0, >= 1.0.2)
26
- i18n (>= 0.7, < 2)
27
- minitest (~> 5.1)
28
- tzinfo (~> 1.1)
29
- zeitwerk (~> 2.2, >= 2.2.2)
30
- ast (2.4.1)
26
+ i18n (>= 1.6, < 2)
27
+ minitest (>= 5.1)
28
+ tzinfo (~> 2.0)
29
+ zeitwerk (~> 2.3)
30
+ ast (2.4.2)
31
31
  builder (3.2.4)
32
- concurrent-ruby (1.1.7)
32
+ concurrent-ruby (1.1.9)
33
33
  crass (1.0.6)
34
- erubi (1.9.0)
35
- i18n (1.8.5)
34
+ erubi (1.10.0)
35
+ i18n (1.8.10)
36
36
  concurrent-ruby (~> 1.0)
37
- loofah (2.7.0)
37
+ loofah (2.12.0)
38
38
  crass (~> 1.0.2)
39
39
  nokogiri (>= 1.5.9)
40
40
  method_source (1.0.0)
41
- mini_portile2 (2.4.0)
42
- minitest (5.14.2)
43
- nio4r (2.5.4)
44
- nokogiri (1.10.10)
45
- mini_portile2 (~> 2.4.0)
46
- parallel (1.19.2)
47
- parser (2.7.1.5)
41
+ mini_portile2 (2.6.1)
42
+ minitest (5.14.4)
43
+ nio4r (2.5.8)
44
+ nokogiri (1.12.3)
45
+ mini_portile2 (~> 2.6.1)
46
+ racc (~> 1.4)
47
+ parallel (1.20.1)
48
+ parser (3.0.1.1)
48
49
  ast (~> 2.4.1)
49
- puma (5.0.2)
50
+ puma (5.4.0)
50
51
  nio4r (~> 2.0)
52
+ racc (1.5.2)
51
53
  rack (2.2.3)
52
54
  rack-test (1.1.0)
53
55
  rack (>= 1.0, < 3)
54
56
  rails-dom-testing (2.0.3)
55
57
  activesupport (>= 4.2.0)
56
58
  nokogiri (>= 1.6)
57
- rails-html-sanitizer (1.3.0)
59
+ rails-html-sanitizer (1.4.1)
58
60
  loofah (~> 2.3)
59
- railties (6.0.3.4)
60
- actionpack (= 6.0.3.4)
61
- activesupport (= 6.0.3.4)
61
+ railties (6.1.4)
62
+ actionpack (= 6.1.4)
63
+ activesupport (= 6.1.4)
62
64
  method_source
63
- rake (>= 0.8.7)
64
- thor (>= 0.20.3, < 2.0)
65
+ rake (>= 0.13)
66
+ thor (~> 1.0)
65
67
  rainbow (3.0.0)
66
- rake (13.0.1)
67
- regexp_parser (1.8.1)
68
- rexml (3.2.4)
69
- rubocop (0.92.0)
68
+ rake (13.0.4)
69
+ regexp_parser (2.1.1)
70
+ rexml (3.2.5)
71
+ rubocop (1.18.2)
70
72
  parallel (~> 1.10)
71
- parser (>= 2.7.1.5)
73
+ parser (>= 3.0.0.0)
72
74
  rainbow (>= 2.2.2, < 4.0)
73
- regexp_parser (>= 1.7)
75
+ regexp_parser (>= 1.8, < 3.0)
74
76
  rexml
75
- rubocop-ast (>= 0.5.0)
77
+ rubocop-ast (>= 1.7.0, < 2.0)
76
78
  ruby-progressbar (~> 1.7)
77
- unicode-display_width (>= 1.4.0, < 2.0)
78
- rubocop-ast (0.7.0)
79
- parser (>= 2.7.1.5)
80
- strscan (>= 1.0.0)
81
- rubocop-performance (1.8.1)
82
- rubocop (>= 0.87.0)
79
+ unicode-display_width (>= 1.4.0, < 3.0)
80
+ rubocop-ast (1.7.0)
81
+ parser (>= 3.0.1.1)
82
+ rubocop-performance (1.11.3)
83
+ rubocop (>= 1.7.0, < 2.0)
83
84
  rubocop-ast (>= 0.4.0)
84
- ruby-progressbar (1.10.1)
85
- standard (0.7)
86
- rubocop (= 0.92)
87
- rubocop-performance (= 1.8.1)
88
- strscan (1.0.3)
89
- thor (1.0.1)
90
- thread_safe (0.3.6)
91
- tzinfo (1.2.7)
92
- thread_safe (~> 0.1)
93
- unicode-display_width (1.7.0)
94
- zeitwerk (2.4.0)
85
+ ruby-progressbar (1.11.0)
86
+ standard (1.1.4)
87
+ rubocop (= 1.18.2)
88
+ rubocop-performance (= 1.11.3)
89
+ thor (1.1.0)
90
+ tzinfo (2.0.4)
91
+ concurrent-ruby (~> 1.0)
92
+ unicode-display_width (2.0.0)
93
+ zeitwerk (2.4.2)
95
94
 
96
95
  PLATFORMS
97
96
  ruby
@@ -104,4 +103,4 @@ DEPENDENCIES
104
103
  standard (>= 0.2.0)
105
104
 
106
105
  BUNDLED WITH
107
- 2.1.4
106
+ 2.2.15
data/README.md CHANGED
@@ -1,7 +1,5 @@
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
-
5
3
  This is a simple gem to make it easier to start writing browser tests with
6
4
  [Cypress](http://cypress.io) for your [Rails](https://rubyonrails.org) apps,
7
5
  regardless of whether your app is server-side rendered HTML, completely
@@ -120,7 +118,7 @@ end
120
118
 
121
119
  (You can find [an
122
120
  example
123
- initializer](/example/an_app/config/initializers/cypress_rails_initializer.rb)
121
+ initializer](/example/config/initializers/cypress_rails_initializer.rb)
124
122
  in this repo.)
125
123
 
126
124
  The gem also provides a special route on the test server:
@@ -138,9 +136,9 @@ This way, you can easily instruct the server to reset its test state from your
138
136
  Cypress tests like so:
139
137
 
140
138
  ```js
141
- beforeEach(() =>
139
+ beforeEach(() => {
142
140
  cy.request('/cypress_rails_reset_state')
143
- )
141
+ })
144
142
  ```
145
143
 
146
144
  (Remember, in Cypress, `before` is a before-all hook and `beforeEach` is run
@@ -170,7 +168,24 @@ preferred environment variables project-wide using a tool like
170
168
  general this means anything done during `cypress open` or `cypress run` will
171
169
  be rolled back on exit (similar to running a Rails System test)
172
170
  * **CYPRESS_RAILS_CYPRESS_OPTS** (default: _none_) any options you want to
173
- forward to the Cypress CLI when running its `open` or `run` commands
171
+ forward to the Cypress CLI when running its `open` or `run` commands.
172
+
173
+ #### Example: Running a single spec from the command line
174
+
175
+ It's a little verbose, but an example of using the above options to run a single
176
+ Cypress test would look like this:
177
+
178
+ ```
179
+ $ CYPRESS_RAILS_CYPRESS_OPTS="--spec cypress/integration/a_test.js" bin/rake cypress:run
180
+ ```
181
+
182
+ #### Example: Running your tests in Chromium
183
+
184
+ By default, Cypress will run its tests in its packaged Electron app, unless you've configured it globally. To choose which browser it will run from the command line, try this:
185
+
186
+ ```
187
+ $ CYPRESS_RAILS_CYPRESS_OPTS="--browser chromium" bin/rake cypress:run
188
+ ```
174
189
 
175
190
  ### Initializer hooks
176
191
 
@@ -181,6 +196,11 @@ will execute before the server or any transaction has been started. If you use
181
196
  Rails fixtures, it may make sense to load them here, so they don't need to be
182
197
  re-inserted for each request
183
198
 
199
+ ### after_server_start
200
+
201
+ Pass a block to `CypressRails.hooks.after_server_start` to register a hook that
202
+ will execute after the server has booted.
203
+
184
204
  ### after_transaction_start
185
205
 
186
206
  If there's any custom behavior or state management you want to do inside the
@@ -206,7 +226,7 @@ of your test database. To set up the hook, pass a block to
206
226
  ## Configuring Rails
207
227
 
208
228
  Beyond the configuration options above, you'll probably also want to disable caching
209
- in your Rails app's [config/environments/test.rb](/example/an_app/config/environments/test.rb#L9)
229
+ in your Rails app's [config/environments/test.rb](/example/config/environments/test.rb#L9)
210
230
  file, so that changes to your Ruby code are reflected in your tests while you
211
231
  work on them with `rake cypress:open`. (If either option is set to
212
232
  `true`, any changes to your Ruby code will require a server restart to be reflected as you work
@@ -295,7 +315,7 @@ experience. In particular:
295
315
  and more information dense than using Capybara and Selenium. Rather than
296
316
  running a test from the command line, seeing it fail, then adding a debug
297
317
  breakpoint to a test to try to manipulate the browser or tweaking a call to a
298
- Capybara API method, failures to be rather obvious when using Cypress and
318
+ Capybara API method, failures tend to be rather obvious when using Cypress and
299
319
  fixing it is usually as easy as tweaking a command, hitting save, and watching
300
320
  it re-run
301
321
  * With very few exceptions, a Cypress test that works in a browser window will
@@ -4,11 +4,8 @@ module CypressRails
4
4
  return default unless ENV.key?(name)
5
5
 
6
6
  if type == :boolean
7
- if ["", "0", "n", "no", "false"].include?(ENV.fetch(name))
8
- false
9
- else
10
- true
11
- end
7
+ no_like_flag = ["", "0", "n", "no", "false"].include?(ENV.fetch(name))
8
+ !no_like_flag
12
9
  else
13
10
  ENV.fetch(name)
14
11
  end
@@ -24,7 +24,7 @@ module CypressRails
24
24
  end
25
25
 
26
26
  def merge_existing_with_defaults(json_path)
27
- Hash[JSON.parse(File.read(json_path)).merge(DEFAULT_CONFIG).sort]
27
+ JSON.parse(File.read(json_path)).merge(DEFAULT_CONFIG).sort.to_h
28
28
  end
29
29
  end
30
30
  end
@@ -12,6 +12,10 @@ module CypressRails
12
12
  register(:before_server_start, blk)
13
13
  end
14
14
 
15
+ def after_server_start(&blk)
16
+ register(:after_server_start, blk)
17
+ end
18
+
15
19
  def after_transaction_start(&blk)
16
20
  register(:after_transaction_start, blk)
17
21
  end
@@ -20,7 +20,7 @@ module CypressRails
20
20
 
21
21
  begin
22
22
  connection = ActiveRecord::Base.connection_handler.retrieve_connection(spec_name)
23
- rescue ConnectionNotEstablished
23
+ rescue ActiveRecord::ConnectionNotEstablished
24
24
  connection = nil
25
25
  end
26
26
 
@@ -68,19 +68,10 @@ module CypressRails
68
68
  # need to share a connection pool so that the reading connection
69
69
  # can see data in the open transaction on the writing connection.
70
70
  def setup_shared_connection_pool
71
- return unless ActiveRecord::Base.respond_to?(:connection_handlers)
72
-
73
- writing_handler = ActiveRecord::Base.connection_handler
74
- ActiveRecord::Base.connection_handlers.values.each do |handler|
75
- if handler != writing_handler
76
- handler.connection_pool_list.each do |pool|
77
- name = pool.spec.name
78
- writing_connection = writing_handler.retrieve_connection_pool(name)
79
- return nil unless writing_connection
80
- handler.send(:owner_to_pool)[name] = writing_connection
81
- end
82
- end
83
- end
71
+ @legacy_saved_pool_configs ||= Hash.new { |hash, key| hash[key] = {} }
72
+ @saved_pool_configs ||= Hash.new { |hash, key| hash[key] = {} }
73
+
74
+ ActiveRecord::TestFixtures.instance_method(:setup_shared_connection_pool).bind_call(self)
84
75
  end
85
76
  end
86
77
  end
@@ -3,6 +3,7 @@
3
3
  require "uri"
4
4
  require "net/http"
5
5
  require "rack"
6
+ require_relative "initializer_hooks"
6
7
  require_relative "server/middleware"
7
8
  require_relative "server/checker"
8
9
  require_relative "server/timer"
@@ -32,6 +33,7 @@ module CypressRails
32
33
  @port ||= Server.ports[port_key]
33
34
  @port ||= find_available_port(host)
34
35
  @checker = Checker.new(@host, @port)
36
+ @initializer_hooks = InitializerHooks.instance
35
37
  end
36
38
 
37
39
  def reset_error!
@@ -78,6 +80,7 @@ module CypressRails
78
80
  raise "Rack application timed out during boot" if timer.expired?
79
81
 
80
82
  @server_thread.join(0.1)
83
+ @initializer_hooks.run(:after_server_start)
81
84
  end
82
85
  end
83
86
 
@@ -11,6 +11,7 @@ module CypressRails
11
11
  options = default_options # .merge(options)
12
12
 
13
13
  conf = Rack::Handler::Puma.config(app, options)
14
+ conf.clamp
14
15
  events = ::Puma::Events.stdio
15
16
 
16
17
  puma_ver = Gem::Version.new(::Puma::Const::PUMA_VERSION)
@@ -1,3 +1,3 @@
1
1
  module CypressRails
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.2"
3
3
  end
data/script/test ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env bash
2
+
3
+ PS4='[script/test:${LINENO}] $ '
4
+ set -euo pipefail
5
+ set -x
6
+
7
+ echo "---> Installing dependencies"
8
+ bundle
9
+ cd example
10
+ bundle
11
+ yarn
12
+ cd ..
13
+
14
+ echo "---> Running tests"
15
+ bundle exec rake
16
+ ./script/test_example_app
17
+
18
+ echo "---> Job's done!"
19
+
@@ -4,7 +4,7 @@ set -e
4
4
 
5
5
  directory=$1
6
6
 
7
- cd example/an_app
7
+ cd example
8
8
  bundle
9
9
  yarn install
10
10
 
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.4.1
4
+ version: 0.5.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: 2020-10-13 00:00:00.000000000 Z
11
+ date: 2021-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -102,7 +102,7 @@ executables:
102
102
  extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
- - ".circleci/config.yml"
105
+ - ".github/workflows/main.yml"
106
106
  - ".gitignore"
107
107
  - ".standard.yml"
108
108
  - ".travis.yml"
@@ -137,6 +137,7 @@ files:
137
137
  - lib/cypress-rails/starts_rails_server.rb
138
138
  - lib/cypress-rails/tracks_resets.rb
139
139
  - lib/cypress-rails/version.rb
140
+ - script/test
140
141
  - script/test_example_app
141
142
  homepage: https://github.com/testdouble/cypress-rails
142
143
  licenses:
@@ -157,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
158
  - !ruby/object:Gem::Version
158
159
  version: '0'
159
160
  requirements: []
160
- rubygems_version: 3.1.2
161
+ rubygems_version: 3.2.15
161
162
  signing_key:
162
163
  specification_version: 4
163
164
  summary: Helps you write Cypress tests of your Rails app
data/.circleci/config.yml DELETED
@@ -1,53 +0,0 @@
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: gem install bundler --version `tail -1 Gemfile.lock`
14
- - run: bundle install --path vendor/bundle
15
-
16
- - type: cache-save
17
- key: v1-main-{{ checksum "Gemfile.lock" }}
18
- paths:
19
- - vendor/bundle
20
-
21
- # Bundle install dependencies for example app
22
- - type: cache-restore
23
- key: v1-example-{{ checksum "example/an_app/Gemfile.lock" }}
24
-
25
- - run: |
26
- cd example/an_app
27
- bundle install --path vendor/bundle
28
-
29
- - type: cache-save
30
- key: v1-example-{{ checksum "example/an_app/Gemfile.lock" }}
31
- paths:
32
- - example/an_app/vendor/bundle
33
-
34
- # Yarn dependencies
35
- - restore_cache:
36
- keys:
37
- - v4-yarn-{{ checksum "example/an_app/yarn.lock" }}
38
- # fallback to using the latest cache if no exact match is found
39
- - v4-yarn-
40
-
41
- - run: |
42
- cd example/an_app
43
- yarn install
44
-
45
- - save_cache:
46
- paths:
47
- - example/an_app/node_modules
48
- - ~/.cache
49
- key: v4-yarn-{{ checksum "example/an_app/yarn.lock" }}
50
-
51
- - run: bundle exec rake
52
- - run: ./script/test_example_app
53
-