cypress-rails 0.1.5 → 0.4.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: a314304d580f5b4b1a0e4632fe02ecade86b924240882743a8806185fade30ea
4
- data.tar.gz: f88f45fc724e133331239600e65ceb24e62bf6736d92334f7a16be609b17fbd1
3
+ metadata.gz: c66865f1f844c8e3bd6fc86a881db8059fe26db9ebe70b1eeb0fc05e6ace601a
4
+ data.tar.gz: b94c1d60432ba1cf738f43574ef5ee9a831a2420cfcc4091446d6c0837860b64
5
5
  SHA512:
6
- metadata.gz: 457925f6c08058685388d7413d92fc9545b2519e7ca5f21a37f0bc411bb861b7e5f67e5fb5bc58e12b1766462db8bf0b8e59c3cc9b65f5c07553a020a69f4459
7
- data.tar.gz: 28e164d2746bc88c2d24cb556a3d67dd9ea487483e913ec0af217c59a8b6f6b8a9993fe90d8e824978cd816900e0b11043a2d7a0aa5ab01779ce3589e9a37fa1
6
+ metadata.gz: e8878b2be16bd34dbcb4994a0d2cec648dc1fdf41ea88dea4b51092d9e882d7e199dbd189dbc1873f96b3c5834f04df05b08a7592de55b71649cd8f7720e3c07
7
+ data.tar.gz: 1f200193af7bdddc8e4c56f9d3a3f9b38eeed17fef9e7cd5a26fa0c31b93eb6ba04a4e62b73ed42c5d7c79d6382d9883754311a5a946d4cf8ef00861d1c1d609
@@ -10,6 +10,7 @@ jobs:
10
10
  - type: cache-restore
11
11
  key: v1-main-{{ checksum "Gemfile.lock" }}
12
12
 
13
+ - run: gem install bundler --version `tail -1 Gemfile.lock`
13
14
  - run: bundle install --path vendor/bundle
14
15
 
15
16
  - type: cache-save
@@ -33,9 +34,9 @@ jobs:
33
34
  # Yarn dependencies
34
35
  - restore_cache:
35
36
  keys:
36
- - v2-yarn-{{ checksum "example/an_app/package.json" }}
37
+ - v4-yarn-{{ checksum "example/an_app/yarn.lock" }}
37
38
  # fallback to using the latest cache if no exact match is found
38
- - v2-yarn-
39
+ - v4-yarn-
39
40
 
40
41
  - run: |
41
42
  cd example/an_app
@@ -45,7 +46,7 @@ jobs:
45
46
  paths:
46
47
  - example/an_app/node_modules
47
48
  - ~/.cache
48
- key: v2-yarn-{{ checksum "example/an_app/package.json" }}
49
+ key: v4-yarn-{{ checksum "example/an_app/yarn.lock" }}
49
50
 
50
51
  - run: bundle exec rake
51
52
  - run: ./script/test_example_app
@@ -1,5 +1,34 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.4.2
4
+
5
+ * Add support to Rails 6.1 ([#52](https://github.com/testdouble/cypress-rails/issue/52))
6
+
7
+ ## 0.4.1
8
+
9
+ * Add backcompat for Ruby 2.4
10
+ ([#47](https://github.com/testdouble/cypress-rails/pull/47))
11
+
12
+ ## 0.4.0
13
+
14
+ * Add a `CYPRESS_RAILS_HOST` option that allows a hostname to be specified (as
15
+ opposed to 127.0.0.1). Puma will still bind to 127.0.0.1, but Cypress will use
16
+ the hostname in its `baseUrl`, which may be necessary for some folks' tests to
17
+ work
18
+
19
+ ## 0.3.0
20
+
21
+ * Add a `CYPRESS_RAILS_BASE_PATH` option which will be appended to the
22
+ `CYPRESS_BASE_URL` option that cypress-rails sets when launching cypress
23
+ commands. Apps that set `baseUrl` to something other than "/" can set this env
24
+ var to match for consistent behavior (or else set it using Cypress.config in a
25
+ support file)
26
+
27
+ ## 0.2.0
28
+
29
+ * If `RAILS_ENV` has been explicitly set when the CLI or rake task is run,
30
+ respect that set value instead of overriding it to "test"
31
+
3
32
  ## 0.1.3
4
33
 
5
34
  * Improve behavior of SIGINT (Ctrl-C) so a traceback isn't printed and stdout
@@ -1,55 +1,54 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cypress-rails (0.1.5)
4
+ cypress-rails (0.4.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.2.2)
12
- actionview (= 6.0.2.2)
13
- activesupport (= 6.0.2.2)
14
- rack (~> 2.0, >= 2.0.8)
11
+ actionpack (6.1.0)
12
+ actionview (= 6.1.0)
13
+ activesupport (= 6.1.0)
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.2.2)
19
- activesupport (= 6.0.2.2)
18
+ actionview (6.1.0)
19
+ activesupport (= 6.1.0)
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.2.2)
24
+ activesupport (6.1.0)
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)
30
- ast (2.4.0)
26
+ i18n (>= 1.6, < 2)
27
+ minitest (>= 5.1)
28
+ tzinfo (~> 2.0)
29
+ zeitwerk (~> 2.3)
30
+ ast (2.4.1)
31
31
  builder (3.2.4)
32
- concurrent-ruby (1.1.6)
32
+ concurrent-ruby (1.1.7)
33
33
  crass (1.0.6)
34
- erubi (1.9.0)
35
- i18n (1.8.2)
34
+ erubi (1.10.0)
35
+ i18n (1.8.5)
36
36
  concurrent-ruby (~> 1.0)
37
- jaro_winkler (1.5.4)
38
- loofah (2.4.0)
37
+ loofah (2.8.0)
39
38
  crass (~> 1.0.2)
40
39
  nokogiri (>= 1.5.9)
41
40
  method_source (1.0.0)
42
41
  mini_portile2 (2.4.0)
43
- minitest (5.14.0)
44
- nio4r (2.5.2)
45
- nokogiri (1.10.9)
42
+ minitest (5.14.2)
43
+ nio4r (2.5.4)
44
+ nokogiri (1.10.10)
46
45
  mini_portile2 (~> 2.4.0)
47
- parallel (1.19.1)
48
- parser (2.7.0.4)
49
- ast (~> 2.4.0)
50
- puma (4.3.3)
46
+ parallel (1.20.1)
47
+ parser (2.7.2.0)
48
+ ast (~> 2.4.1)
49
+ puma (5.1.1)
51
50
  nio4r (~> 2.0)
52
- rack (2.2.2)
51
+ rack (2.2.3)
53
52
  rack-test (1.1.0)
54
53
  rack (>= 1.0, < 3)
55
54
  rails-dom-testing (2.0.3)
@@ -57,33 +56,39 @@ GEM
57
56
  nokogiri (>= 1.6)
58
57
  rails-html-sanitizer (1.3.0)
59
58
  loofah (~> 2.3)
60
- railties (6.0.2.2)
61
- actionpack (= 6.0.2.2)
62
- activesupport (= 6.0.2.2)
59
+ railties (6.1.0)
60
+ actionpack (= 6.1.0)
61
+ activesupport (= 6.1.0)
63
62
  method_source
64
63
  rake (>= 0.8.7)
65
- thor (>= 0.20.3, < 2.0)
64
+ thor (~> 1.0)
66
65
  rainbow (3.0.0)
67
66
  rake (13.0.1)
68
- rubocop (0.79.0)
69
- jaro_winkler (~> 1.5.1)
67
+ regexp_parser (2.0.0)
68
+ rexml (3.2.4)
69
+ rubocop (1.4.2)
70
70
  parallel (~> 1.10)
71
- parser (>= 2.7.0.1)
71
+ parser (>= 2.7.1.5)
72
72
  rainbow (>= 2.2.2, < 4.0)
73
+ regexp_parser (>= 1.8)
74
+ rexml
75
+ rubocop-ast (>= 1.1.1)
73
76
  ruby-progressbar (~> 1.7)
74
- unicode-display_width (>= 1.4.0, < 1.7)
75
- rubocop-performance (1.5.2)
76
- rubocop (>= 0.71.0)
77
+ unicode-display_width (>= 1.4.0, < 2.0)
78
+ rubocop-ast (1.3.0)
79
+ parser (>= 2.7.1.5)
80
+ rubocop-performance (1.9.1)
81
+ rubocop (>= 0.90.0, < 2.0)
82
+ rubocop-ast (>= 0.4.0)
77
83
  ruby-progressbar (1.10.1)
78
- standard (0.2.1)
79
- rubocop (~> 0.79.0)
80
- rubocop-performance (~> 1.5.1)
84
+ standard (0.10.2)
85
+ rubocop (= 1.4.2)
86
+ rubocop-performance (= 1.9.1)
81
87
  thor (1.0.1)
82
- thread_safe (0.3.6)
83
- tzinfo (1.2.6)
84
- thread_safe (~> 0.1)
85
- unicode-display_width (1.6.1)
86
- zeitwerk (2.3.0)
88
+ tzinfo (2.0.4)
89
+ concurrent-ruby (~> 1.0)
90
+ unicode-display_width (1.7.0)
91
+ zeitwerk (2.4.2)
87
92
 
88
93
  PLATFORMS
89
94
  ruby
data/README.md CHANGED
@@ -25,7 +25,7 @@ If you're on newer versions of Rails and using
25
25
  then you're likely already using yarn to manage your JavaScript dependencies. If
26
26
  that's the case, you can add Cypress with:
27
27
 
28
- ```
28
+ ```sh
29
29
  $ yarn add --dev cypress
30
30
  ```
31
31
 
@@ -40,7 +40,7 @@ Now, to install the cypress-rails gem, you'll want to add it to your development
40
40
  & test gem groups of your Gemfile, so that you have easy access to its rake
41
41
  tasks:
42
42
 
43
- ``` ruby
43
+ ```ruby
44
44
  group :development, :test do
45
45
  gem "cypress-rails"
46
46
  end
@@ -48,7 +48,7 @@ end
48
48
 
49
49
  Once installed, you'll want to run:
50
50
 
51
- ```
51
+ ```sh
52
52
  $ rake cypress:init
53
53
  ```
54
54
 
@@ -69,7 +69,7 @@ a wrapper for running `cypress open` with a dedicated Rails test server.
69
69
 
70
70
  So, by running:
71
71
 
72
- ```
72
+ ```sh
73
73
  $ rake cypress:open
74
74
  ```
75
75
 
@@ -83,7 +83,7 @@ itself.
83
83
  To run your tests headlessly (e.g. when you're in CI), you'll want the `run`
84
84
  command:
85
85
 
86
- ```
86
+ ```sh
87
87
  $ rake cypress:run
88
88
  ```
89
89
 
@@ -102,7 +102,7 @@ like:
102
102
  return unless Rails.env.test?
103
103
 
104
104
  CypressRails.hooks.before_server_start do
105
- # Called once, before ether the transaction or the server is started
105
+ # Called once, before either the transaction or the server is started
106
106
  end
107
107
 
108
108
  CypressRails.hooks.after_transaction_start do
@@ -138,9 +138,9 @@ This way, you can easily instruct the server to reset its test state from your
138
138
  Cypress tests like so:
139
139
 
140
140
  ```js
141
- beforeEach(() =>
141
+ beforeEach(() => {
142
142
  cy.request('/cypress_rails_reset_state')
143
- )
143
+ })
144
144
  ```
145
145
 
146
146
  (Remember, in Cypress, `before` is a before-all hook and `beforeEach` is run
@@ -158,8 +158,13 @@ preferred environment variables project-wide using a tool like
158
158
 
159
159
 
160
160
  * **CYPRESS_RAILS_DIR** (default: `Dir.pwd`) the directory of your project
161
+ * **CYPRESS_RAILS_HOST** (default: `"127.0.0.1"`) the hostname to bind to
161
162
  * **CYPRESS_RAILS_PORT** (default: _a random available port_) the port to run
162
163
  the Rails test server on
164
+ * **CYPRESS_RAILS_BASE_PATH** (default: `"/"`) the base path for all Cypress's
165
+ requests to the app (e.g. via `cy.visit()`). If you've customized your
166
+ `baseUrl` setting (e.g. in `cypress.json`), you'll need to duplicate it with
167
+ this environment variable
163
168
  * **CYPRESS_RAILS_TRANSACTIONAL_SERVER** (default: `true`) when true, will start
164
169
  a transaction on all database connections before launching the server. In
165
170
  general this means anything done during `cypress open` or `cypress run` will
@@ -167,6 +172,15 @@ preferred environment variables project-wide using a tool like
167
172
  * **CYPRESS_RAILS_CYPRESS_OPTS** (default: _none_) any options you want to
168
173
  forward to the Cypress CLI when running its `open` or `run` commands
169
174
 
175
+ #### Example: Running a single spec from the command line
176
+
177
+ It's a little verbose, but an example of using the above options to run a single
178
+ Cypress test would look like this:
179
+
180
+ ```
181
+ $ CYPRESS_RAILS_CYPRESS_OPTS="--spec cypress/integration/a_test.js" bin/rake cypress:run
182
+ ```
183
+
170
184
  ### Initializer hooks
171
185
 
172
186
  ### before_server_start
@@ -198,6 +212,22 @@ pollute other test suites or scripts, you can use the `before_server_stop` to
198
212
  of your test database. To set up the hook, pass a block to
199
213
  `CypressRails.hooks.before_server_stop`.
200
214
 
215
+ ## Configuring Rails
216
+
217
+ Beyond the configuration options above, you'll probably also want to disable caching
218
+ in your Rails app's [config/environments/test.rb](/example/an_app/config/environments/test.rb#L9)
219
+ file, so that changes to your Ruby code are reflected in your tests while you
220
+ work on them with `rake cypress:open`. (If either option is set to
221
+ `true`, any changes to your Ruby code will require a server restart to be reflected as you work
222
+ on your tests.)
223
+
224
+ To illustrate, here's what that might look like in `config/environments/test.rb`:
225
+
226
+ ```ruby
227
+ config.cache_classes = false
228
+ config.action_view.cache_template_loading = false
229
+ ```
230
+
201
231
  ## Setting up continuous integration
202
232
 
203
233
  #### Circle CI
@@ -233,7 +263,7 @@ jobs:
233
263
  # Yarn dependencies
234
264
  - restore_cache:
235
265
  keys:
236
- - v1-yarn-{{ checksum "package.json" }}
266
+ - v1-yarn-{{ checksum "yarn.lock" }}
237
267
  # fallback to using the latest cache if no exact match is found
238
268
  - v1-yarn-
239
269
 
@@ -243,7 +273,7 @@ jobs:
243
273
  paths:
244
274
  - node_modules
245
275
  - ~/.cache
246
- key: v1-yarn-{{ checksum "package.json" }}
276
+ key: v1-yarn-{{ checksum "yarn.lock" }}
247
277
 
248
278
  # Run your cypress tests
249
279
  - run: bin/rake cypress:run
@@ -305,5 +335,12 @@ adopting Cypress and writing a bunch of browser tests for every application.
305
335
  But, if the above points sound like solutions to problems you experience, you
306
336
  might consider trying it out.
307
337
 
338
+ ## Code of Conduct
308
339
 
340
+ This project follows Test Double's [code of
341
+ conduct](https://testdouble.com/code-of-conduct) for all community interactions,
342
+ including (but not limited to) one-on-one communications, public posts/comments,
343
+ code reviews, pull requests, and GitHub issues. If violations occur, Test Double
344
+ will take any action they deem appropriate for the infraction, up to and
345
+ including blocking a user from the organization's repositories.
309
346
 
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- ENV["RAILS_ENV"] = "test"
3
+ ENV["RAILS_ENV"] ||= "test"
4
4
  require "pathname"
5
5
  require "cypress-rails"
6
6
  require Pathname.new(CypressRails::Config.new.dir).join("config/environment")
@@ -1,14 +1,23 @@
1
1
  require_relative "env"
2
2
 
3
3
  module CypressRails
4
- class Config < Struct.new(:dir, :port, :transactional_server, :cypress_cli_opts, keyword_init: true)
4
+ class Config
5
+ attr_accessor :dir, :host, :port, :base_path, :transactional_server, :cypress_cli_opts
6
+
5
7
  def initialize(
6
8
  dir: Env.fetch("CYPRESS_RAILS_DIR", default: Dir.pwd),
9
+ host: Env.fetch("CYPRESS_RAILS_HOST", default: "127.0.0.1"),
7
10
  port: Env.fetch("CYPRESS_RAILS_PORT"),
11
+ base_path: Env.fetch("CYPRESS_RAILS_BASE_PATH", default: "/"),
8
12
  transactional_server: Env.fetch("CYPRESS_RAILS_TRANSACTIONAL_SERVER", type: :boolean, default: true),
9
13
  cypress_cli_opts: Env.fetch("CYPRESS_RAILS_CYPRESS_OPTS", default: "")
10
14
  )
11
- super
15
+ @dir = dir
16
+ @host = host
17
+ @port = port
18
+ @base_path = base_path
19
+ @transactional_server = transactional_server
20
+ @cypress_cli_opts = cypress_cli_opts
12
21
  end
13
22
 
14
23
  def to_s
@@ -17,7 +26,9 @@ module CypressRails
17
26
  cypress-rails configuration:
18
27
  ============================
19
28
  CYPRESS_RAILS_DIR.....................#{dir.inspect}
29
+ CYPRESS_RAILS_HOST....................#{host.inspect}
20
30
  CYPRESS_RAILS_PORT....................#{port.inspect}
31
+ CYPRESS_RAILS_BASE_PATH...............#{base_path.inspect}
21
32
  CYPRESS_RAILS_TRANSACTIONAL_SERVER....#{transactional_server.inspect}
22
33
  CYPRESS_RAILS_CYPRESS_OPTS............#{cypress_cli_opts.inspect}
23
34
 
@@ -20,6 +20,7 @@ module CypressRails
20
20
  @manages_transactions.begin_transaction
21
21
  end
22
22
  server = @starts_rails_server.call(
23
+ host: config.host,
23
24
  port: config.port,
24
25
  transactional_server: config.transactional_server
25
26
  )
@@ -27,9 +28,12 @@ module CypressRails
27
28
 
28
29
  set_exit_hooks!(config)
29
30
 
30
- system <<~EXEC
31
- CYPRESS_BASE_URL=http://#{server.host}:#{server.port} "#{bin}" #{command} --project "#{config.dir}" #{config.cypress_cli_opts}
31
+ command = <<~EXEC
32
+ CYPRESS_BASE_URL="http://#{server.host}:#{server.port}#{config.base_path}" "#{bin}" #{command} --project "#{config.dir}" #{config.cypress_cli_opts}
32
33
  EXEC
34
+
35
+ puts "\nLaunching Cypress…\n$ #{command}\n"
36
+ system command
33
37
  end
34
38
 
35
39
  private
@@ -68,19 +68,7 @@ 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
+ ActiveRecord::TestFixtures.instance_method(:setup_shared_connection_pool).bind(self).call
84
72
  end
85
73
  end
86
74
  end
@@ -16,11 +16,11 @@ module CypressRails
16
16
  end
17
17
  end
18
18
 
19
- attr_reader :app, :port, :host
19
+ attr_reader :app, :host, :port
20
20
 
21
21
  def initialize(app,
22
+ host:,
22
23
  port:,
23
- host: "127.0.0.1",
24
24
  reportable_errors: [Exception],
25
25
  extra_middleware: [])
26
26
  @app = app
@@ -84,10 +84,6 @@ module CypressRails
84
84
  self
85
85
  end
86
86
 
87
- def base_url
88
- "http#{"s" if using_ssl?}://#{host}:#{port}"
89
- end
90
-
91
87
  private
92
88
 
93
89
  def middleware
@@ -3,10 +3,10 @@ require_relative "server"
3
3
 
4
4
  module CypressRails
5
5
  class StartsRailsServer
6
- def call(port:, transactional_server:)
6
+ def call(host:, port:, transactional_server:)
7
7
  configure_rails_to_run_our_state_reset_on_every_request!(transactional_server)
8
8
  app = create_rack_app
9
- Server.new(app, port: port).tap do |server|
9
+ Server.new(app, host: host, port: port).tap do |server|
10
10
  server.boot
11
11
  end
12
12
  end
@@ -1,3 +1,3 @@
1
1
  module CypressRails
2
- VERSION = "0.1.5"
2
+ VERSION = "0.4.2"
3
3
  end
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.1.5
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Searls
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-01 00:00:00.000000000 Z
11
+ date: 2020-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -94,7 +94,7 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.2.0
97
- description:
97
+ description:
98
98
  email:
99
99
  - searls@gmail.com
100
100
  executables:
@@ -142,7 +142,7 @@ homepage: https://github.com/testdouble/cypress-rails
142
142
  licenses:
143
143
  - MIT
144
144
  metadata: {}
145
- post_install_message:
145
+ post_install_message:
146
146
  rdoc_options: []
147
147
  require_paths:
148
148
  - lib
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  version: '0'
159
159
  requirements: []
160
160
  rubygems_version: 3.1.2
161
- signing_key:
161
+ signing_key:
162
162
  specification_version: 4
163
163
  summary: Helps you write Cypress tests of your Rails app
164
164
  test_files: []