cypress-on-rails 1.11.0 → 1.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +57 -0
- data/.gitignore +5 -1
- data/CHANGELOG.md +26 -0
- data/README.md +94 -17
- data/cypress-on-rails.gemspec +1 -0
- data/docs/factory_bot_associations.md +109 -0
- data/lib/cypress-on-rails.rb +2 -2
- data/lib/cypress_on_rails/configuration.rb +3 -0
- data/lib/cypress_on_rails/middleware.rb +7 -11
- data/lib/cypress_on_rails/middleware_config.rb +17 -0
- data/lib/cypress_on_rails/railtie.rb +5 -1
- data/lib/cypress_on_rails/smart_factory_wrapper.rb +26 -15
- data/lib/cypress_on_rails/vcr_middleware.rb +73 -0
- data/lib/cypress_on_rails/version.rb +1 -1
- data/lib/generators/cypress_on_rails/install_generator.rb +18 -24
- data/lib/generators/cypress_on_rails/templates/config/initializers/cypress_on_rails.rb.erb +1 -0
- data/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/clean.rb +8 -0
- data/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/log_fail.rb +2 -0
- data/lib/generators/cypress_on_rails/templates/spec/cypress/{cypress_helper.rb → cypress_helper.rb.erb} +6 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress/{integration/rails_examples/advance_factory_bot_spec.js → e2e/rails_examples/advance_factory_bot.cy.js} +0 -0
- data/lib/generators/cypress_on_rails/templates/spec/cypress/{integration/rails_examples/other_spec.js → e2e/rails_examples/other.cy.js} +0 -0
- data/lib/generators/cypress_on_rails/templates/spec/cypress/{integration/rails_examples/using_factory_bot_spec.js → e2e/rails_examples/using_factory_bot.cy.js} +0 -0
- data/lib/generators/cypress_on_rails/templates/spec/cypress/{integration/rails_examples/using_fixtures_spec.js → e2e/rails_examples/using_fixtures.cy.js} +0 -0
- data/lib/generators/cypress_on_rails/templates/spec/cypress/{integration/rails_examples/using_scenarios_spec.js → e2e/rails_examples/using_scenarios.cy.js} +0 -0
- data/lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/using_vcr.cy.js +24 -0
- data/lib/generators/cypress_on_rails/templates/spec/cypress/support/{index.js → index.js.erb} +1 -0
- data/lib/generators/cypress_on_rails/templates/spec/cypress/support/on-rails.js +1 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress.config.js +9 -0
- data/plugin/.gitignore +1 -0
- data/plugin/cypress/plugins/index.js +4 -0
- data/plugin/package.json +31 -0
- data/plugin/support/index.js +37 -0
- data/spec/cypress_on_rails/middleware_spec.rb +15 -13
- data/spec/cypress_on_rails/smart_factory_wrapper_spec.rb +7 -0
- data/spec/cypress_on_rails/vcr_middleware_spec.rb +119 -0
- data/specs_e2e/cypress.config.js +10 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/.gitignore +1 -1
- data/specs_e2e/rails_3_2/.ruby_version +1 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/Gemfile +1 -1
- data/{spec/integrations → specs_e2e}/rails_3_2/README.rdoc +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/Rakefile +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/app/assets/stylesheets/application.css +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/app/controllers/application_controller.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/app/controllers/welcome_controller.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/app/helpers/application_helper.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/app/models/post.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/app/views/layouts/application.html.erb +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/app/views/welcome/index.html.erb +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/bin/rails +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/config/application.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/config/boot.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/config/environment.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/config/environments/development.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/config/environments/production.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/config/environments/test.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/config/initializers/backtrace_silencers.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/config/initializers/inflections.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/config/initializers/mime_types.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/config/initializers/secret_token.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/config/initializers/session_store.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/config/initializers/wrap_parameters.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/config/locales/en.yml +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/config/routes.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/config.ru +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/log/.keep +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/public/404.html +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/public/422.html +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/public/500.html +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/public/favicon.ico +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/public/robots.txt +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/test.sh +11 -10
- data/{spec/integrations → specs_e2e}/rails_3_2/tmp/.keep +0 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/vendor/.gitkeep +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/.gitignore +3 -2
- data/{spec/integrations → specs_e2e}/rails_4_2/Gemfile +3 -1
- data/{spec/integrations → specs_e2e}/rails_4_2/README.rdoc +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/Rakefile +0 -0
- data/{spec/integrations/rails_5_2/app/assets/javascripts/posts.js → specs_e2e/rails_4_2/app/assets/javascripts/using_vcr.js} +0 -0
- data/{spec/integrations/rails_5_2/app/assets/stylesheets/posts.css → specs_e2e/rails_4_2/app/assets/stylesheets/using_vcr.css} +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/app/controllers/application_controller.rb +0 -0
- data/specs_e2e/rails_4_2/app/controllers/using_vcr_controller.rb +10 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/app/controllers/welcome_controller.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/app/models/post.rb +3 -1
- data/{spec/integrations → specs_e2e}/rails_4_2/app/views/layouts/application.html.erb +0 -0
- data/specs_e2e/rails_4_2/app/views/using_vcr/index.html.erb +6 -0
- data/specs_e2e/rails_4_2/app/views/using_vcr/record_cats.html.erb +7 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/app/views/welcome/index.html.erb +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/bin/bundle +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/bin/rails +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/bin/rake +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/bin/setup +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/config/application.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/config/boot.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/config/environment.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/config/environments/development.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/config/environments/production.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/config/environments/test.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/config/initializers/backtrace_silencers.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/config/initializers/cookies_serializer.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/config/initializers/filter_parameter_logging.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/config/initializers/inflections.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/config/initializers/mime_types.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/config/initializers/session_store.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/config/initializers/to_time_preserves_timezone.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/config/initializers/wrap_parameters.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/config/locales/en.yml +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/config/routes.rb +5 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/config/secrets.yml +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/config.ru +0 -0
- data/specs_e2e/rails_4_2/package.json +10 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/public/404.html +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/public/422.html +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/public/500.html +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/public/favicon.ico +0 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/public/robots.txt +0 -0
- data/{spec/integrations/rails_4_2/log → specs_e2e/rails_4_2/spec}/.keep +0 -0
- data/specs_e2e/rails_4_2/test.sh +39 -0
- data/{spec/integrations/rails_4_2/spec → specs_e2e/rails_4_2/vendor}/.keep +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/.gitignore +1 -1
- data/{spec/integrations → specs_e2e}/rails_5_2/Gemfile +1 -1
- data/{spec/integrations → specs_e2e}/rails_5_2/README.md +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/Rakefile +0 -0
- data/specs_e2e/rails_5_2/app/assets/javascripts/posts.js +2 -0
- data/specs_e2e/rails_5_2/app/assets/stylesheets/posts.css +4 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/app/assets/stylesheets/scaffold.css +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/app/controllers/application_controller.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/app/controllers/posts_controller.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/app/helpers/posts_helper.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/app/jobs/application_job.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/app/models/application_record.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/app/models/post.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/app/views/layouts/application.html.erb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/app/views/posts/_form.html.erb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/app/views/posts/edit.html.erb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/app/views/posts/index.html.erb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/app/views/posts/new.html.erb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/app/views/posts/show.html.erb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/app/views/welcome/index.html.erb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/bin/bundle +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/bin/rails +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/bin/rake +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/bin/setup +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/bin/update +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/config/application.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/config/boot.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/config/credentials.yml.enc +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/config/database.yml +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/config/environment.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/config/environments/development.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/config/environments/production.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/config/environments/test.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/config/initializers/application_controller_renderer.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/config/initializers/backtrace_silencers.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/config/initializers/content_security_policy.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/config/initializers/cookies_serializer.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/config/initializers/filter_parameter_logging.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/config/initializers/inflections.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/config/initializers/mime_types.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/config/initializers/wrap_parameters.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/config/locales/en.yml +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/config/master.key +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/config/routes.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/config.ru +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/db/migrate/20180621085832_create_posts.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/public/404.html +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/public/422.html +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/public/500.html +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/public/apple-touch-icon-precomposed.png +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/public/apple-touch-icon.png +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/public/favicon.ico +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/public/robots.txt +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/test/controllers/posts_controller_test.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/test/cypress_fixtures/posts.yml +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/test/fixtures/posts.yml +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/test/models/post_test.rb +0 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/test.sh +13 -11
- data/{spec/integrations/rails_4_2 → specs_e2e/rails_5_2}/vendor/.keep +0 -0
- metadata +179 -172
- data/.travis.yml +0 -39
- data/lib/generators/cypress_on_rails/templates/spec/cypress/fixtures/example.json +0 -5
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/actions.spec.js +0 -272
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/aliasing.spec.js +0 -42
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/assertions.spec.js +0 -63
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/connectors.spec.js +0 -55
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/cookies.spec.js +0 -78
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/cypress_api.spec.js +0 -211
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/files.spec.js +0 -86
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/local_storage.spec.js +0 -52
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/location.spec.js +0 -32
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/misc.spec.js +0 -68
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/navigation.spec.js +0 -54
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/network_requests.spec.js +0 -108
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/querying.spec.js +0 -65
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/spies_stubs_clocks.spec.js +0 -62
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/traversal.spec.js +0 -121
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/utilities.spec.js +0 -89
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/viewport.spec.js +0 -59
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/waiting.spec.js +0 -34
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/window.spec.js +0 -22
- data/lib/generators/cypress_on_rails/templates/spec/cypress.json +0 -4
- data/spec/integrations/cypress.json +0 -5
- data/spec/integrations/rails_4_2/test.sh +0 -38
- data/spec/integrations/rails_5_2/log/.keep +0 -0
- data/spec/integrations/rails_5_2/tmp/.keep +0 -0
- data/spec/integrations/rails_5_2/vendor/.keep +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e692aca2d9231cc396238b157013e6208ab5522dcfc9de9a6db13eab6f2e432
|
4
|
+
data.tar.gz: 9e131491dc1bbbdefeead03eda472b20bc2e2b9fb4c92e55a76fdda3cbb547a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb3f7b9e0496cd4033bd97b7c5c218f28af991fae0ab42e4fec7b23fad7a71103ea3a33cd0cf8c17c16095f7eacc0aca296b547bc559b8a833a688a62d9be88a
|
7
|
+
data.tar.gz: 6cf57ee05e4b8f04000671969af5bf96c337ae2d69ff9df8cfaf1d99efac4d28f3f38cce1f7bf518db491b7a88a10265b82b1d8e0f96033de509f060d1e20b88
|
@@ -0,0 +1,57 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
rails_3_2:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v2
|
15
|
+
- name: Set up Ruby
|
16
|
+
uses: ruby/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
ruby-version: 2.3
|
19
|
+
bundler-cache: true
|
20
|
+
- name: Run tests
|
21
|
+
run: bundle exec rake
|
22
|
+
- run: gem uninstall -v '>= 2' -ax bundler || true
|
23
|
+
- run: gem install bundler -v '< 2'
|
24
|
+
- name: Run interaction tests
|
25
|
+
run: ./specs_e2e/rails_3_2/test.sh
|
26
|
+
|
27
|
+
rails_4_2:
|
28
|
+
runs-on: ubuntu-latest
|
29
|
+
|
30
|
+
steps:
|
31
|
+
- uses: actions/checkout@v2
|
32
|
+
- name: Set up Ruby
|
33
|
+
uses: ruby/setup-ruby@v1
|
34
|
+
with:
|
35
|
+
ruby-version: 2.5
|
36
|
+
bundler-cache: true
|
37
|
+
- name: Run tests
|
38
|
+
run: bundle exec rake
|
39
|
+
- run: gem uninstall -v '>= 2' -ax bundler || true
|
40
|
+
- run: gem install bundler -v '< 2'
|
41
|
+
- name: Run interaction tests
|
42
|
+
run: ./specs_e2e/rails_4_2/test.sh
|
43
|
+
|
44
|
+
rails_5_2:
|
45
|
+
runs-on: ubuntu-latest
|
46
|
+
|
47
|
+
steps:
|
48
|
+
- uses: actions/checkout@v2
|
49
|
+
- name: Set up Ruby
|
50
|
+
uses: ruby/setup-ruby@v1
|
51
|
+
with:
|
52
|
+
ruby-version: 2.6
|
53
|
+
bundler-cache: true
|
54
|
+
- name: Run tests
|
55
|
+
run: bundle exec rake
|
56
|
+
- name: Run interaction tests
|
57
|
+
run: ./specs_e2e/rails_5_2/test.sh
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,29 @@
|
|
1
|
+
## [1.13.0]
|
2
|
+
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.12.1...v1.13.0
|
3
|
+
|
4
|
+
### Changed
|
5
|
+
* Add support for matching npm package and VCR
|
6
|
+
* generate for cypress 10 [PR 108](https://github.com/shakacode/cypress-on-rails/pull/108)
|
7
|
+
|
8
|
+
## [1.12.1]
|
9
|
+
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.12.0...v1.12.1
|
10
|
+
|
11
|
+
### Tasks
|
12
|
+
* Documenting how to setup Factory Associations [PR 100](https://github.com/shakacode/cypress-on-rails/pull/100)
|
13
|
+
|
14
|
+
### Fixed
|
15
|
+
* keep track of factory manual reloads to prevent auto_reload from reloading again [PR 98](https://github.com/shakacode/cypress-on-rails/pull/98)
|
16
|
+
|
17
|
+
## [1.12.0]
|
18
|
+
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.11.0...v1.12.0
|
19
|
+
|
20
|
+
### Changed
|
21
|
+
* only reload factories on clean instead of every factory create request [PR 95](https://github.com/shakacode/cypress-on-rails/pull/95)
|
22
|
+
* alternative command added for get tail of logs [PR 89](https://github.com/shakacode/cypress-on-rails/pull/89) by [ccrockett]
|
23
|
+
|
24
|
+
### Tasks
|
25
|
+
* switch from travis to github actions [PR 96]
|
26
|
+
|
1
27
|
## [1.11.0]
|
2
28
|
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.10.1...v1.11.0
|
3
29
|
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# CypressOnRails
|
2
2
|
|
3
|
-
|
3
|
+
![Build Status](https://github.com/shakacode/cypress-on-rails/actions/workflows/ruby.yml/badge.svg)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/cypress-on-rails.svg)](https://badge.fury.io/rb/cypress-on-rails)
|
4
5
|
|
5
6
|
----
|
6
7
|
|
@@ -8,6 +9,8 @@ This project is sponsored by the software consulting firm [ShakaCode](https://ww
|
|
8
9
|
|
9
10
|
Interested in joining a small team that loves open source? Check our [careers page](https://www.shakacode.com/career/).
|
10
11
|
|
12
|
+
Need help with cypress-on-rails? Contact [ShakaCode](mailto:justin@shakacode.com).
|
13
|
+
|
11
14
|
----
|
12
15
|
|
13
16
|
# Totally new to Cypress?
|
@@ -68,7 +71,7 @@ bin/rails g cypress_on_rails:update
|
|
68
71
|
The generator modifies/adds the following files/directory in your application:
|
69
72
|
* `config/environments/test.rb`
|
70
73
|
* `config/initializers/cypress_on_rails` used to configure CypressDev
|
71
|
-
* `spec/cypress/
|
74
|
+
* `spec/cypress/e2e/` contains your cypress tests
|
72
75
|
* `spec/cypress/support/on-rails.js` contains CypressDev support code
|
73
76
|
* `spec/cypress/app_commands/scenarios/` contains your CypressDev scenario definitions
|
74
77
|
* `spec/cypress/cypress_helper.rb` contains helper code for CypressDev app commands
|
@@ -131,19 +134,8 @@ node_modules/.bin/cypress run
|
|
131
134
|
|
132
135
|
You can run your [factory_bot](https://github.com/thoughtbot/factory_bot) directly as well
|
133
136
|
|
134
|
-
```ruby
|
135
|
-
# spec/cypress/app_commands/factory_bot.rb
|
136
|
-
require 'cypress_on_rails/smart_factory_wrapper'
|
137
|
-
|
138
|
-
CypressOnRails::SmartFactoryWrapper.configure(
|
139
|
-
always_reload: !Rails.configuration.cache_classes,
|
140
|
-
factory: FactoryBot,
|
141
|
-
files: Dir['./spec/factories/**/*.rb']
|
142
|
-
)
|
143
|
-
```
|
144
|
-
|
145
137
|
```js
|
146
|
-
// spec/cypress/
|
138
|
+
// spec/cypress/e2e/simple.cy.js
|
147
139
|
describe('My First Test', function() {
|
148
140
|
it('visit root', function() {
|
149
141
|
// This calls to the backend to prepare the application state
|
@@ -165,6 +157,7 @@ describe('My First Test', function() {
|
|
165
157
|
})
|
166
158
|
})
|
167
159
|
```
|
160
|
+
You can check the [association Docs](https://github.com/shakacode/cypress-on-rails/blob/master/docs/factory_bot_associations.md) on more ways to setup association with the correct data.
|
168
161
|
|
169
162
|
In some cases, using static Cypress fixtures may not provide sufficient flexibility when mocking HTTP response bodies - it's possible to use `FactoryBot.build` to generate Ruby hashes that can then be used as mock JSON responses:
|
170
163
|
```ruby
|
@@ -216,7 +209,7 @@ ActiveRecord::FixtureSet.create_fixtures(fixtures_dir, fixture_files)
|
|
216
209
|
```
|
217
210
|
|
218
211
|
```js
|
219
|
-
// spec/cypress/
|
212
|
+
// spec/cypress/e2e/simple.cy.js
|
220
213
|
describe('My First Test', function() {
|
221
214
|
it('visit root', function() {
|
222
215
|
// This calls to the backend to prepare the application state
|
@@ -245,7 +238,7 @@ CypressOnRails::SmartFactoryWrapper.create(:profile, name: "Cypress Hill")
|
|
245
238
|
|
246
239
|
Then reference the scenario in your test:
|
247
240
|
```js
|
248
|
-
// spec/cypress/
|
241
|
+
// spec/cypress/e2e/scenario_example.cy.js
|
249
242
|
describe('My First Test', function() {
|
250
243
|
it('visit root', function() {
|
251
244
|
// This calls to the backend to prepare the application state
|
@@ -268,7 +261,7 @@ load "#{Rails.root}/db/seeds.rb"
|
|
268
261
|
|
269
262
|
Then reference the command in your test with `cy.app('load_seed')`:
|
270
263
|
```js
|
271
|
-
// spec/cypress/
|
264
|
+
// spec/cypress/e2e/simple.cy.js
|
272
265
|
describe('My First Test', function() {
|
273
266
|
beforeEach(() => { cy.app('load_seed') })
|
274
267
|
|
@@ -280,6 +273,78 @@ describe('My First Test', function() {
|
|
280
273
|
})
|
281
274
|
```
|
282
275
|
|
276
|
+
## Expermintal Features (matching npm package)
|
277
|
+
|
278
|
+
Please test and give feedback
|
279
|
+
|
280
|
+
add the npm package:
|
281
|
+
|
282
|
+
```
|
283
|
+
yarn add cypress-on-rails --dev
|
284
|
+
```
|
285
|
+
|
286
|
+
### for VCR
|
287
|
+
|
288
|
+
This only works when you start the rails server with a single worker and single thread
|
289
|
+
|
290
|
+
#### setup
|
291
|
+
|
292
|
+
Add your VCR configuration to your `cypress_helper.rb`
|
293
|
+
|
294
|
+
```ruby
|
295
|
+
require 'vcr'
|
296
|
+
VCR.configure do |config|
|
297
|
+
config.hook_into :webmock
|
298
|
+
end
|
299
|
+
```
|
300
|
+
|
301
|
+
Add to you `cypress/support/index.js`
|
302
|
+
|
303
|
+
```js
|
304
|
+
import 'cypress-on-rails/support/index'
|
305
|
+
```
|
306
|
+
|
307
|
+
Add to you `clean.rb`
|
308
|
+
|
309
|
+
```ruby
|
310
|
+
VCR.eject_cassette # make sure we no cassettes inserted before the next test starts
|
311
|
+
VCR.turn_off!
|
312
|
+
WebMock.disable! if defined?(WebMock)
|
313
|
+
```
|
314
|
+
|
315
|
+
Add to you `config/cypress_on_rails.rb`
|
316
|
+
|
317
|
+
```ruby
|
318
|
+
c.use_vcr_middleware = !Rails.env.production? && ENV['CYPRESS'].present?
|
319
|
+
```
|
320
|
+
|
321
|
+
#### usage
|
322
|
+
|
323
|
+
You have `vcr_insert_cassette` and `vcr_eject_cassette` available. https://www.rubydoc.info/github/vcr/vcr/VCR:insert_cassette
|
324
|
+
|
325
|
+
|
326
|
+
```js
|
327
|
+
describe('My First Test', function() {
|
328
|
+
beforeEach(() => { cy.app('load_seed') })
|
329
|
+
|
330
|
+
it('visit root', function() {
|
331
|
+
cy.app('clean') // have a look at cypress/app_commands/clean.rb
|
332
|
+
|
333
|
+
cy.vcr_insert_cassette('cats', { record: "new_episodes" })
|
334
|
+
cy.visit('/using_vcr/index')
|
335
|
+
|
336
|
+
cy.get('a').contains('Cats').click()
|
337
|
+
cy.contains('Wikipedia has a recording of a cat meowing, because why not?')
|
338
|
+
|
339
|
+
cy.vcr_eject_cassette();
|
340
|
+
|
341
|
+
cy.vcr_insert_cassette('cats')
|
342
|
+
cy.visit('/using_vcr/record_cats')
|
343
|
+
cy.contains('Wikipedia has a recording of a cat meowing, because why not?')
|
344
|
+
})
|
345
|
+
})
|
346
|
+
```
|
347
|
+
|
283
348
|
## Usage with other rack applications
|
284
349
|
|
285
350
|
Add CypressOnRails to your config.ru
|
@@ -338,3 +403,15 @@ beforeEach(() => {
|
|
338
403
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
339
404
|
4. Push to the branch (`git push origin my-new-feature`)
|
340
405
|
5. Create a new Pull Request
|
406
|
+
|
407
|
+
# Supporters
|
408
|
+
|
409
|
+
The following companies support this open source project, and ShakaCode uses their products! Justin writes React on Rails on [RubyMine](https://www.jetbrains.com/ruby/). We use [Scout](https://scoutapp.com/) to monitor the live performance of [HiChee.com](https://HiChee.com), [Rails AutoScale](https://railsautoscale.com) to scale the dynos of HiChee, and [HoneyBadger](https://www.honeybadger.io/) to monitor application errors. We love [BrowserStack](https://www.browserstack.com) to solve problems with oddball browsers.
|
410
|
+
|
411
|
+
[![RubyMine](https://user-images.githubusercontent.com/1118459/114100597-3b0e3000-9860-11eb-9b12-73beb1a184b2.png)](https://www.jetbrains.com/ruby/)
|
412
|
+
[![Scout](https://user-images.githubusercontent.com/1118459/171088197-81555b69-9ed0-4235-9acf-fcb37ecfb949.png)](https://scoutapp.com/)
|
413
|
+
[![Rails AutoScale](https://user-images.githubusercontent.com/1118459/103197530-48dc0e80-488a-11eb-8b1b-a16664b30274.png)](https://railsautoscale.com/)
|
414
|
+
[![BrowserStack](https://cloud.githubusercontent.com/assets/1118459/23203304/1261e468-f886-11e6-819e-93b1a3f17da4.png)](https://www.browserstack.com)
|
415
|
+
[![HoneyBadger](https://user-images.githubusercontent.com/1118459/114100696-63962a00-9860-11eb-8ac1-75ca02856d8e.png)](https://www.honeybadger.io/)
|
416
|
+
|
417
|
+
ShakaCode's favorite project tracking tool is [Shortcut](https://shortcut.com/). If you want to **try Shortcut and get 2 months free beyond the 14-day trial period**, click [here to use ShakaCode's referral code](http://r.clbh.se/mvfoNeH). We're participating in their awesome triple-sided referral program, which you can read about [here](https://shortcut.com/referral/). By using our [referral code](http://r.clbh.se/mvfoNeH) you'll be supporting ShakaCode and, thus, React on Rails!
|
data/cypress-on-rails.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.add_development_dependency 'rspec'
|
21
21
|
s.add_development_dependency 'railties', '>= 3.2'
|
22
22
|
s.add_development_dependency 'factory_bot'
|
23
|
+
s.add_development_dependency 'vcr'
|
23
24
|
s.metadata = {
|
24
25
|
"bug_tracker_uri" => "https://github.com/shakacode/cypress-on-rails/issues",
|
25
26
|
"changelog_uri" => "https://github.com/shakacode/cypress-on-rails/blob/master/CHANGELOG.md",
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# Setting up associations with the correct data
|
2
|
+
|
3
|
+
You cannot access associations directly from Cypress like you can do with ruby tests.
|
4
|
+
So setting up associations has to be done differently from within Cypress.
|
5
|
+
|
6
|
+
There are a few ways you can setup associations with the correct data using Cypress and FactoryBot.
|
7
|
+
1. Setting the foreign keys
|
8
|
+
2. Using transient attributes
|
9
|
+
3. Using Nested Attributes
|
10
|
+
4. Combination of the above depending on your situation
|
11
|
+
|
12
|
+
Assuming you have the following models
|
13
|
+
|
14
|
+
```rb
|
15
|
+
class Post < ApplicationRecord
|
16
|
+
belongs_to :author
|
17
|
+
accepts_nested_attributes_for :author
|
18
|
+
end
|
19
|
+
|
20
|
+
class Author < ApplicationRecord
|
21
|
+
has_many :posts
|
22
|
+
accepts_nested_attributes_for :posts
|
23
|
+
end
|
24
|
+
```
|
25
|
+
|
26
|
+
You can do the following:
|
27
|
+
|
28
|
+
## 1. Setting the foreign keys
|
29
|
+
|
30
|
+
factories.rb
|
31
|
+
```rb
|
32
|
+
FactoryBot.define do
|
33
|
+
factory :author do
|
34
|
+
name { 'Taylor' }
|
35
|
+
end
|
36
|
+
|
37
|
+
factory :post do
|
38
|
+
title { 'Cypress on Rails is Awesome' }
|
39
|
+
author_id { create(:author).id }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
then in Cypress
|
45
|
+
```js
|
46
|
+
// example with overriding the defaults
|
47
|
+
cy.appFactories([['create', 'author', { name: 'James' }]]).then((records) => {
|
48
|
+
cy.appFactories([['create', 'post', { title: 'Cypress is cool', author_id: records[0].id }]]
|
49
|
+
});
|
50
|
+
|
51
|
+
// example without overriding anything
|
52
|
+
cy.appFactories([['create', 'author']]).then((records) => {
|
53
|
+
cy.appFactories([['create', 'post', { author_id: records[0].id }]]
|
54
|
+
});
|
55
|
+
```
|
56
|
+
|
57
|
+
## 2. Using transient attributes
|
58
|
+
|
59
|
+
```rb
|
60
|
+
FactoryBot.define do
|
61
|
+
factory :author do
|
62
|
+
name { 'Taylor' }
|
63
|
+
end
|
64
|
+
|
65
|
+
factory :post do
|
66
|
+
transient do
|
67
|
+
author_name { 'Taylor' }
|
68
|
+
end
|
69
|
+
title { 'Cypress on Rails is Awesome' }
|
70
|
+
author { create(:author, name: author_name ) }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
then in Cypress
|
76
|
+
```js
|
77
|
+
// example with overriding the defaults
|
78
|
+
cy.appFactories([['create', 'post', { title: 'Cypress is cool', author_name: 'James' }]]
|
79
|
+
|
80
|
+
// example without overriding
|
81
|
+
cy.appFactories([['create', 'post']]
|
82
|
+
```
|
83
|
+
|
84
|
+
## 3. Using Nested Attributes
|
85
|
+
|
86
|
+
```rb
|
87
|
+
FactoryBot.define do
|
88
|
+
factory :author do
|
89
|
+
name { 'Taylor' }
|
90
|
+
end
|
91
|
+
|
92
|
+
factory :post do
|
93
|
+
title { 'Cypress on Rails is Awesome' }
|
94
|
+
author_attributes { { name: 'Taylor' } }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
```
|
98
|
+
|
99
|
+
then in Cypress
|
100
|
+
```js
|
101
|
+
// example with overriding the defaults
|
102
|
+
cy.appFactories([['create', 'post', { title: 'Cypress is cool', author_attributes: { name: 'James' } }]]
|
103
|
+
|
104
|
+
// example without overriding
|
105
|
+
cy.appFactories([['create', 'post']]
|
106
|
+
|
107
|
+
// example of creating author with multiple posts
|
108
|
+
cy.appFactories([['create', 'author', { name: 'James', posts_attributes: [{ name: 'Cypress is cool' }, {name: 'Rails is awesome' }] ]]
|
109
|
+
```
|
data/lib/cypress-on-rails.rb
CHANGED
@@ -3,5 +3,5 @@ require 'cypress_on_rails/configuration'
|
|
3
3
|
require_relative './cypress_on_rails/railtie' if defined?(Rails)
|
4
4
|
|
5
5
|
# maintain backward compatibility
|
6
|
-
CypressDev = CypressOnRails
|
7
|
-
Cypress = CypressDev
|
6
|
+
CypressDev = CypressOnRails unless defined?(CypressDev)
|
7
|
+
Cypress = CypressDev unless defined?(Cypress)
|
@@ -4,6 +4,7 @@ module CypressOnRails
|
|
4
4
|
class Configuration
|
5
5
|
attr_accessor :cypress_folder
|
6
6
|
attr_accessor :use_middleware
|
7
|
+
attr_accessor :use_vcr_middleware
|
7
8
|
attr_accessor :logger
|
8
9
|
|
9
10
|
def initialize
|
@@ -11,10 +12,12 @@ module CypressOnRails
|
|
11
12
|
end
|
12
13
|
|
13
14
|
alias :use_middleware? :use_middleware
|
15
|
+
alias :use_vcr_middleware? :use_vcr_middleware
|
14
16
|
|
15
17
|
def reset
|
16
18
|
self.cypress_folder = 'spec/cypress'
|
17
19
|
self.use_middleware = true
|
20
|
+
self.use_vcr_middleware = true
|
18
21
|
self.logger = Logger.new(STDOUT)
|
19
22
|
end
|
20
23
|
|
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'rack'
|
3
|
-
require 'cypress_on_rails/
|
3
|
+
require 'cypress_on_rails/middleware_config'
|
4
4
|
require 'cypress_on_rails/command_executor'
|
5
5
|
|
6
6
|
module CypressOnRails
|
7
7
|
# Middleware to handle cypress commands and eval
|
8
8
|
class Middleware
|
9
|
+
include MiddlewareConfig
|
10
|
+
|
9
11
|
def initialize(app, command_executor = CommandExecutor, file = ::File)
|
10
12
|
@app = app
|
11
13
|
@command_executor = command_executor
|
@@ -23,14 +25,6 @@ module CypressOnRails
|
|
23
25
|
|
24
26
|
private
|
25
27
|
|
26
|
-
def configuration
|
27
|
-
CypressOnRails.configuration
|
28
|
-
end
|
29
|
-
|
30
|
-
def logger
|
31
|
-
configuration.logger
|
32
|
-
end
|
33
|
-
|
34
28
|
Command = Struct.new(:name, :options, :cypress_folder) do
|
35
29
|
# @return [Array<Cypress::Middleware::Command>]
|
36
30
|
def self.from_body(body, configuration)
|
@@ -53,7 +47,7 @@ module CypressOnRails
|
|
53
47
|
body = JSON.parse(req.body.read)
|
54
48
|
logger.info "handle_command: #{body}"
|
55
49
|
commands = Command.from_body(body, configuration)
|
56
|
-
missing_command = commands.find {|command| !@file.
|
50
|
+
missing_command = commands.find {|command| !@file.exist?(command.file_path) }
|
57
51
|
|
58
52
|
if missing_command.nil?
|
59
53
|
begin
|
@@ -65,13 +59,15 @@ module CypressOnRails
|
|
65
59
|
output = {"message" => "Cannot convert to json"}.to_json
|
66
60
|
end
|
67
61
|
|
62
|
+
logger.debug "output: #{output}"
|
68
63
|
[201, {'Content-Type' => 'application/json'}, [output]]
|
69
64
|
rescue => e
|
70
65
|
output = {"message" => e.message, "class" => e.class.to_s}.to_json
|
71
66
|
[500, {'Content-Type' => 'application/json'}, [output]]
|
72
67
|
end
|
73
68
|
else
|
74
|
-
|
69
|
+
output = {"message" => "could not find command file: #{missing_command.file_path}"}.to_json
|
70
|
+
[404, {'Content-Type' => 'application/json'}, [output]]
|
75
71
|
end
|
76
72
|
end
|
77
73
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'rack'
|
3
|
+
require 'cypress_on_rails/configuration'
|
4
|
+
|
5
|
+
module CypressOnRails
|
6
|
+
module MiddlewareConfig
|
7
|
+
protected
|
8
|
+
|
9
|
+
def configuration
|
10
|
+
CypressOnRails.configuration
|
11
|
+
end
|
12
|
+
|
13
|
+
def logger
|
14
|
+
configuration.logger
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,13 +1,17 @@
|
|
1
1
|
require 'rails/railtie'
|
2
2
|
require 'cypress_on_rails/configuration'
|
3
|
-
require 'cypress_on_rails/middleware'
|
4
3
|
|
5
4
|
module CypressOnRails
|
6
5
|
class Railtie < Rails::Railtie
|
7
6
|
initializer :setup_cypress_middleware, after: :load_config_initializers do |app|
|
8
7
|
if CypressOnRails.configuration.use_middleware?
|
8
|
+
require 'cypress_on_rails/middleware'
|
9
9
|
app.middleware.use Middleware
|
10
10
|
end
|
11
|
+
if CypressOnRails.configuration.use_vcr_middleware?
|
12
|
+
require 'cypress_on_rails/vcr_middleware'
|
13
|
+
app.middleware.use VCRMiddleware
|
14
|
+
end
|
11
15
|
end
|
12
16
|
end
|
13
17
|
end
|
@@ -27,6 +27,10 @@ module CypressOnRails
|
|
27
27
|
instance.build_list(*args)
|
28
28
|
end
|
29
29
|
|
30
|
+
def self.reload
|
31
|
+
instance.reload
|
32
|
+
end
|
33
|
+
|
30
34
|
# @return [Array]
|
31
35
|
attr_accessor :factory
|
32
36
|
attr_accessor :always_reload
|
@@ -44,7 +48,7 @@ module CypressOnRails
|
|
44
48
|
end
|
45
49
|
|
46
50
|
def create(*options)
|
47
|
-
|
51
|
+
auto_reload
|
48
52
|
factory_name = options.shift
|
49
53
|
if options.last.is_a?(Hash)
|
50
54
|
args = options.pop
|
@@ -55,12 +59,12 @@ module CypressOnRails
|
|
55
59
|
end
|
56
60
|
|
57
61
|
def create_list(*args)
|
58
|
-
|
62
|
+
auto_reload
|
59
63
|
factory.create_list(*args)
|
60
64
|
end
|
61
65
|
|
62
66
|
def build(*options)
|
63
|
-
|
67
|
+
auto_reload
|
64
68
|
factory_name = options.shift
|
65
69
|
if options.last.is_a?(Hash)
|
66
70
|
args = options.pop
|
@@ -71,10 +75,20 @@ module CypressOnRails
|
|
71
75
|
end
|
72
76
|
|
73
77
|
def build_list(*args)
|
74
|
-
|
78
|
+
auto_reload
|
75
79
|
factory.build_list(*args)
|
76
80
|
end
|
77
81
|
|
82
|
+
def reload
|
83
|
+
@latest_mtime = current_latest_mtime
|
84
|
+
logger.info 'Loading Factories'
|
85
|
+
factory.reload
|
86
|
+
files.each do |file|
|
87
|
+
logger.debug "-- Loading: #{file}"
|
88
|
+
@kernel.load(file)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
78
92
|
private
|
79
93
|
|
80
94
|
# @param [String,Array] arg
|
@@ -92,19 +106,16 @@ module CypressOnRails
|
|
92
106
|
CypressOnRails.configuration.logger
|
93
107
|
end
|
94
108
|
|
95
|
-
def
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
logger.debug "-- Loading: #{file}"
|
103
|
-
@kernel.load(file)
|
104
|
-
end
|
109
|
+
def current_latest_mtime
|
110
|
+
files.map{|file| @file_system.mtime(file) }.max
|
111
|
+
end
|
112
|
+
|
113
|
+
def auto_reload
|
114
|
+
return unless should_reload?
|
115
|
+
reload
|
105
116
|
end
|
106
117
|
|
107
|
-
def should_reload?
|
118
|
+
def should_reload?
|
108
119
|
@always_reload || @latest_mtime.nil? || @latest_mtime < current_latest_mtime
|
109
120
|
end
|
110
121
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'rack'
|
3
|
+
require 'cypress_on_rails/middleware_config'
|
4
|
+
|
5
|
+
module CypressOnRails
|
6
|
+
# Middleware to handle vcr
|
7
|
+
class VCRMiddleware
|
8
|
+
include MiddlewareConfig
|
9
|
+
|
10
|
+
def initialize(app, vcr = nil)
|
11
|
+
@app = app
|
12
|
+
@vcr = vcr
|
13
|
+
@first_call = false
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
request = Rack::Request.new(env)
|
18
|
+
if request.path.start_with?('/__cypress__/vcr/insert')
|
19
|
+
configuration.tagged_logged { handle_insert(request) }
|
20
|
+
elsif request.path.start_with?('/__cypress__/vcr/eject')
|
21
|
+
configuration.tagged_logged { handle_eject }
|
22
|
+
else
|
23
|
+
do_first_call unless @first_call
|
24
|
+
@app.call(env)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def handle_insert(req)
|
31
|
+
WebMock.enable! if defined?(WebMock)
|
32
|
+
vcr.turn_on!
|
33
|
+
body = JSON.parse(req.body.read)
|
34
|
+
logger.info "vcr insert cassette: #{body}"
|
35
|
+
cassette_name = body[0]
|
36
|
+
options = (body[1] || {}).symbolize_keys
|
37
|
+
options[:record] = options[:record].to_sym if options[:record]
|
38
|
+
options[:match_requests_on] = options[:match_requests_on].map(&:to_sym) if options[:match_requests_on]
|
39
|
+
options[:serialize_with] = options[:serialize_with].to_sym if options[:serialize_with]
|
40
|
+
options[:persist_with] = options[:persist_with].to_sym if options[:persist_with]
|
41
|
+
vcr.insert_cassette(cassette_name, options)
|
42
|
+
[201, {'Content-Type' => 'application/json'}, [{'message': 'OK'}.to_json]]
|
43
|
+
rescue LoadError, ArgumentError => e
|
44
|
+
[501, {'Content-Type' => 'application/json'}, [{'message': e.message}.to_json]]
|
45
|
+
end
|
46
|
+
|
47
|
+
def handle_eject
|
48
|
+
logger.info "vcr eject cassette"
|
49
|
+
vcr.eject_cassette
|
50
|
+
do_first_call
|
51
|
+
[201, {'Content-Type' => 'application/json'}, [{'message': 'OK'}.to_json]]
|
52
|
+
rescue LoadError, ArgumentError => e
|
53
|
+
[501, {'Content-Type' => 'application/json'}, [{'message': e.message}.to_json]]
|
54
|
+
end
|
55
|
+
|
56
|
+
def vcr
|
57
|
+
return @vcr if @vcr
|
58
|
+
require 'vcr'
|
59
|
+
VCR.configure do |config|
|
60
|
+
config.cassette_library_dir = "#{configuration.cypress_folder}/fixtures/vcr_cassettes"
|
61
|
+
end
|
62
|
+
@vcr = VCR
|
63
|
+
end
|
64
|
+
|
65
|
+
def do_first_call
|
66
|
+
@first_call = true
|
67
|
+
vcr.turn_off!
|
68
|
+
WebMock.disable! if defined?(WebMock)
|
69
|
+
rescue LoadError
|
70
|
+
# nop
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|