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.
Files changed (206) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +57 -0
  3. data/.gitignore +5 -1
  4. data/CHANGELOG.md +26 -0
  5. data/README.md +94 -17
  6. data/cypress-on-rails.gemspec +1 -0
  7. data/docs/factory_bot_associations.md +109 -0
  8. data/lib/cypress-on-rails.rb +2 -2
  9. data/lib/cypress_on_rails/configuration.rb +3 -0
  10. data/lib/cypress_on_rails/middleware.rb +7 -11
  11. data/lib/cypress_on_rails/middleware_config.rb +17 -0
  12. data/lib/cypress_on_rails/railtie.rb +5 -1
  13. data/lib/cypress_on_rails/smart_factory_wrapper.rb +26 -15
  14. data/lib/cypress_on_rails/vcr_middleware.rb +73 -0
  15. data/lib/cypress_on_rails/version.rb +1 -1
  16. data/lib/generators/cypress_on_rails/install_generator.rb +18 -24
  17. data/lib/generators/cypress_on_rails/templates/config/initializers/cypress_on_rails.rb.erb +1 -0
  18. data/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/clean.rb +8 -0
  19. data/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/log_fail.rb +2 -0
  20. data/lib/generators/cypress_on_rails/templates/spec/cypress/{cypress_helper.rb → cypress_helper.rb.erb} +6 -1
  21. 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
  22. data/lib/generators/cypress_on_rails/templates/spec/cypress/{integration/rails_examples/other_spec.js → e2e/rails_examples/other.cy.js} +0 -0
  23. 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
  24. 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
  25. 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
  26. data/lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/using_vcr.cy.js +24 -0
  27. data/lib/generators/cypress_on_rails/templates/spec/cypress/support/{index.js → index.js.erb} +1 -0
  28. data/lib/generators/cypress_on_rails/templates/spec/cypress/support/on-rails.js +1 -1
  29. data/lib/generators/cypress_on_rails/templates/spec/cypress.config.js +9 -0
  30. data/plugin/.gitignore +1 -0
  31. data/plugin/cypress/plugins/index.js +4 -0
  32. data/plugin/package.json +31 -0
  33. data/plugin/support/index.js +37 -0
  34. data/spec/cypress_on_rails/middleware_spec.rb +15 -13
  35. data/spec/cypress_on_rails/smart_factory_wrapper_spec.rb +7 -0
  36. data/spec/cypress_on_rails/vcr_middleware_spec.rb +119 -0
  37. data/specs_e2e/cypress.config.js +10 -0
  38. data/{spec/integrations → specs_e2e}/rails_3_2/.gitignore +1 -1
  39. data/specs_e2e/rails_3_2/.ruby_version +1 -0
  40. data/{spec/integrations → specs_e2e}/rails_3_2/Gemfile +1 -1
  41. data/{spec/integrations → specs_e2e}/rails_3_2/README.rdoc +0 -0
  42. data/{spec/integrations → specs_e2e}/rails_3_2/Rakefile +0 -0
  43. data/{spec/integrations → specs_e2e}/rails_3_2/app/assets/stylesheets/application.css +0 -0
  44. data/{spec/integrations → specs_e2e}/rails_3_2/app/controllers/application_controller.rb +0 -0
  45. data/{spec/integrations → specs_e2e}/rails_3_2/app/controllers/welcome_controller.rb +0 -0
  46. data/{spec/integrations → specs_e2e}/rails_3_2/app/helpers/application_helper.rb +0 -0
  47. data/{spec/integrations → specs_e2e}/rails_3_2/app/models/post.rb +0 -0
  48. data/{spec/integrations → specs_e2e}/rails_3_2/app/views/layouts/application.html.erb +0 -0
  49. data/{spec/integrations → specs_e2e}/rails_3_2/app/views/welcome/index.html.erb +0 -0
  50. data/{spec/integrations → specs_e2e}/rails_3_2/bin/rails +0 -0
  51. data/{spec/integrations → specs_e2e}/rails_3_2/config/application.rb +0 -0
  52. data/{spec/integrations → specs_e2e}/rails_3_2/config/boot.rb +0 -0
  53. data/{spec/integrations → specs_e2e}/rails_3_2/config/environment.rb +0 -0
  54. data/{spec/integrations → specs_e2e}/rails_3_2/config/environments/development.rb +0 -0
  55. data/{spec/integrations → specs_e2e}/rails_3_2/config/environments/production.rb +0 -0
  56. data/{spec/integrations → specs_e2e}/rails_3_2/config/environments/test.rb +0 -0
  57. data/{spec/integrations → specs_e2e}/rails_3_2/config/initializers/backtrace_silencers.rb +0 -0
  58. data/{spec/integrations → specs_e2e}/rails_3_2/config/initializers/inflections.rb +0 -0
  59. data/{spec/integrations → specs_e2e}/rails_3_2/config/initializers/mime_types.rb +0 -0
  60. data/{spec/integrations → specs_e2e}/rails_3_2/config/initializers/secret_token.rb +0 -0
  61. data/{spec/integrations → specs_e2e}/rails_3_2/config/initializers/session_store.rb +0 -0
  62. data/{spec/integrations → specs_e2e}/rails_3_2/config/initializers/wrap_parameters.rb +0 -0
  63. data/{spec/integrations → specs_e2e}/rails_3_2/config/locales/en.yml +0 -0
  64. data/{spec/integrations → specs_e2e}/rails_3_2/config/routes.rb +0 -0
  65. data/{spec/integrations → specs_e2e}/rails_3_2/config.ru +0 -0
  66. data/{spec/integrations → specs_e2e}/rails_3_2/log/.keep +0 -0
  67. data/{spec/integrations → specs_e2e}/rails_3_2/public/404.html +0 -0
  68. data/{spec/integrations → specs_e2e}/rails_3_2/public/422.html +0 -0
  69. data/{spec/integrations → specs_e2e}/rails_3_2/public/500.html +0 -0
  70. data/{spec/integrations → specs_e2e}/rails_3_2/public/favicon.ico +0 -0
  71. data/{spec/integrations → specs_e2e}/rails_3_2/public/robots.txt +0 -0
  72. data/{spec/integrations → specs_e2e}/rails_3_2/test.sh +11 -10
  73. data/{spec/integrations → specs_e2e}/rails_3_2/tmp/.keep +0 -0
  74. data/{spec/integrations → specs_e2e}/rails_3_2/vendor/.gitkeep +0 -0
  75. data/{spec/integrations → specs_e2e}/rails_4_2/.gitignore +3 -2
  76. data/{spec/integrations → specs_e2e}/rails_4_2/Gemfile +3 -1
  77. data/{spec/integrations → specs_e2e}/rails_4_2/README.rdoc +0 -0
  78. data/{spec/integrations → specs_e2e}/rails_4_2/Rakefile +0 -0
  79. data/{spec/integrations/rails_5_2/app/assets/javascripts/posts.js → specs_e2e/rails_4_2/app/assets/javascripts/using_vcr.js} +0 -0
  80. data/{spec/integrations/rails_5_2/app/assets/stylesheets/posts.css → specs_e2e/rails_4_2/app/assets/stylesheets/using_vcr.css} +0 -0
  81. data/{spec/integrations → specs_e2e}/rails_4_2/app/controllers/application_controller.rb +0 -0
  82. data/specs_e2e/rails_4_2/app/controllers/using_vcr_controller.rb +10 -0
  83. data/{spec/integrations → specs_e2e}/rails_4_2/app/controllers/welcome_controller.rb +0 -0
  84. data/{spec/integrations → specs_e2e}/rails_4_2/app/models/post.rb +3 -1
  85. data/{spec/integrations → specs_e2e}/rails_4_2/app/views/layouts/application.html.erb +0 -0
  86. data/specs_e2e/rails_4_2/app/views/using_vcr/index.html.erb +6 -0
  87. data/specs_e2e/rails_4_2/app/views/using_vcr/record_cats.html.erb +7 -0
  88. data/{spec/integrations → specs_e2e}/rails_4_2/app/views/welcome/index.html.erb +0 -0
  89. data/{spec/integrations → specs_e2e}/rails_4_2/bin/bundle +0 -0
  90. data/{spec/integrations → specs_e2e}/rails_4_2/bin/rails +0 -0
  91. data/{spec/integrations → specs_e2e}/rails_4_2/bin/rake +0 -0
  92. data/{spec/integrations → specs_e2e}/rails_4_2/bin/setup +0 -0
  93. data/{spec/integrations → specs_e2e}/rails_4_2/config/application.rb +0 -0
  94. data/{spec/integrations → specs_e2e}/rails_4_2/config/boot.rb +0 -0
  95. data/{spec/integrations → specs_e2e}/rails_4_2/config/environment.rb +0 -0
  96. data/{spec/integrations → specs_e2e}/rails_4_2/config/environments/development.rb +0 -0
  97. data/{spec/integrations → specs_e2e}/rails_4_2/config/environments/production.rb +0 -0
  98. data/{spec/integrations → specs_e2e}/rails_4_2/config/environments/test.rb +0 -0
  99. data/{spec/integrations → specs_e2e}/rails_4_2/config/initializers/backtrace_silencers.rb +0 -0
  100. data/{spec/integrations → specs_e2e}/rails_4_2/config/initializers/cookies_serializer.rb +0 -0
  101. data/{spec/integrations → specs_e2e}/rails_4_2/config/initializers/filter_parameter_logging.rb +0 -0
  102. data/{spec/integrations → specs_e2e}/rails_4_2/config/initializers/inflections.rb +0 -0
  103. data/{spec/integrations → specs_e2e}/rails_4_2/config/initializers/mime_types.rb +0 -0
  104. data/{spec/integrations → specs_e2e}/rails_4_2/config/initializers/session_store.rb +0 -0
  105. data/{spec/integrations → specs_e2e}/rails_4_2/config/initializers/to_time_preserves_timezone.rb +0 -0
  106. data/{spec/integrations → specs_e2e}/rails_4_2/config/initializers/wrap_parameters.rb +0 -0
  107. data/{spec/integrations → specs_e2e}/rails_4_2/config/locales/en.yml +0 -0
  108. data/{spec/integrations → specs_e2e}/rails_4_2/config/routes.rb +5 -0
  109. data/{spec/integrations → specs_e2e}/rails_4_2/config/secrets.yml +0 -0
  110. data/{spec/integrations → specs_e2e}/rails_4_2/config.ru +0 -0
  111. data/specs_e2e/rails_4_2/package.json +10 -0
  112. data/{spec/integrations → specs_e2e}/rails_4_2/public/404.html +0 -0
  113. data/{spec/integrations → specs_e2e}/rails_4_2/public/422.html +0 -0
  114. data/{spec/integrations → specs_e2e}/rails_4_2/public/500.html +0 -0
  115. data/{spec/integrations → specs_e2e}/rails_4_2/public/favicon.ico +0 -0
  116. data/{spec/integrations → specs_e2e}/rails_4_2/public/robots.txt +0 -0
  117. data/{spec/integrations/rails_4_2/log → specs_e2e/rails_4_2/spec}/.keep +0 -0
  118. data/specs_e2e/rails_4_2/test.sh +39 -0
  119. data/{spec/integrations/rails_4_2/spec → specs_e2e/rails_4_2/vendor}/.keep +0 -0
  120. data/{spec/integrations → specs_e2e}/rails_5_2/.gitignore +1 -1
  121. data/{spec/integrations → specs_e2e}/rails_5_2/Gemfile +1 -1
  122. data/{spec/integrations → specs_e2e}/rails_5_2/README.md +0 -0
  123. data/{spec/integrations → specs_e2e}/rails_5_2/Rakefile +0 -0
  124. data/specs_e2e/rails_5_2/app/assets/javascripts/posts.js +2 -0
  125. data/specs_e2e/rails_5_2/app/assets/stylesheets/posts.css +4 -0
  126. data/{spec/integrations → specs_e2e}/rails_5_2/app/assets/stylesheets/scaffold.css +0 -0
  127. data/{spec/integrations → specs_e2e}/rails_5_2/app/controllers/application_controller.rb +0 -0
  128. data/{spec/integrations → specs_e2e}/rails_5_2/app/controllers/posts_controller.rb +0 -0
  129. data/{spec/integrations → specs_e2e}/rails_5_2/app/helpers/posts_helper.rb +0 -0
  130. data/{spec/integrations → specs_e2e}/rails_5_2/app/jobs/application_job.rb +0 -0
  131. data/{spec/integrations → specs_e2e}/rails_5_2/app/models/application_record.rb +0 -0
  132. data/{spec/integrations → specs_e2e}/rails_5_2/app/models/post.rb +0 -0
  133. data/{spec/integrations → specs_e2e}/rails_5_2/app/views/layouts/application.html.erb +0 -0
  134. data/{spec/integrations → specs_e2e}/rails_5_2/app/views/posts/_form.html.erb +0 -0
  135. data/{spec/integrations → specs_e2e}/rails_5_2/app/views/posts/edit.html.erb +0 -0
  136. data/{spec/integrations → specs_e2e}/rails_5_2/app/views/posts/index.html.erb +0 -0
  137. data/{spec/integrations → specs_e2e}/rails_5_2/app/views/posts/new.html.erb +0 -0
  138. data/{spec/integrations → specs_e2e}/rails_5_2/app/views/posts/show.html.erb +0 -0
  139. data/{spec/integrations → specs_e2e}/rails_5_2/app/views/welcome/index.html.erb +0 -0
  140. data/{spec/integrations → specs_e2e}/rails_5_2/bin/bundle +0 -0
  141. data/{spec/integrations → specs_e2e}/rails_5_2/bin/rails +0 -0
  142. data/{spec/integrations → specs_e2e}/rails_5_2/bin/rake +0 -0
  143. data/{spec/integrations → specs_e2e}/rails_5_2/bin/setup +0 -0
  144. data/{spec/integrations → specs_e2e}/rails_5_2/bin/update +0 -0
  145. data/{spec/integrations → specs_e2e}/rails_5_2/config/application.rb +0 -0
  146. data/{spec/integrations → specs_e2e}/rails_5_2/config/boot.rb +0 -0
  147. data/{spec/integrations → specs_e2e}/rails_5_2/config/credentials.yml.enc +0 -0
  148. data/{spec/integrations → specs_e2e}/rails_5_2/config/database.yml +0 -0
  149. data/{spec/integrations → specs_e2e}/rails_5_2/config/environment.rb +0 -0
  150. data/{spec/integrations → specs_e2e}/rails_5_2/config/environments/development.rb +0 -0
  151. data/{spec/integrations → specs_e2e}/rails_5_2/config/environments/production.rb +0 -0
  152. data/{spec/integrations → specs_e2e}/rails_5_2/config/environments/test.rb +0 -0
  153. data/{spec/integrations → specs_e2e}/rails_5_2/config/initializers/application_controller_renderer.rb +0 -0
  154. data/{spec/integrations → specs_e2e}/rails_5_2/config/initializers/backtrace_silencers.rb +0 -0
  155. data/{spec/integrations → specs_e2e}/rails_5_2/config/initializers/content_security_policy.rb +0 -0
  156. data/{spec/integrations → specs_e2e}/rails_5_2/config/initializers/cookies_serializer.rb +0 -0
  157. data/{spec/integrations → specs_e2e}/rails_5_2/config/initializers/filter_parameter_logging.rb +0 -0
  158. data/{spec/integrations → specs_e2e}/rails_5_2/config/initializers/inflections.rb +0 -0
  159. data/{spec/integrations → specs_e2e}/rails_5_2/config/initializers/mime_types.rb +0 -0
  160. data/{spec/integrations → specs_e2e}/rails_5_2/config/initializers/wrap_parameters.rb +0 -0
  161. data/{spec/integrations → specs_e2e}/rails_5_2/config/locales/en.yml +0 -0
  162. data/{spec/integrations → specs_e2e}/rails_5_2/config/master.key +0 -0
  163. data/{spec/integrations → specs_e2e}/rails_5_2/config/routes.rb +0 -0
  164. data/{spec/integrations → specs_e2e}/rails_5_2/config.ru +0 -0
  165. data/{spec/integrations → specs_e2e}/rails_5_2/db/migrate/20180621085832_create_posts.rb +0 -0
  166. data/{spec/integrations → specs_e2e}/rails_5_2/public/404.html +0 -0
  167. data/{spec/integrations → specs_e2e}/rails_5_2/public/422.html +0 -0
  168. data/{spec/integrations → specs_e2e}/rails_5_2/public/500.html +0 -0
  169. data/{spec/integrations → specs_e2e}/rails_5_2/public/apple-touch-icon-precomposed.png +0 -0
  170. data/{spec/integrations → specs_e2e}/rails_5_2/public/apple-touch-icon.png +0 -0
  171. data/{spec/integrations → specs_e2e}/rails_5_2/public/favicon.ico +0 -0
  172. data/{spec/integrations → specs_e2e}/rails_5_2/public/robots.txt +0 -0
  173. data/{spec/integrations → specs_e2e}/rails_5_2/test/controllers/posts_controller_test.rb +0 -0
  174. data/{spec/integrations → specs_e2e}/rails_5_2/test/cypress_fixtures/posts.yml +0 -0
  175. data/{spec/integrations → specs_e2e}/rails_5_2/test/fixtures/posts.yml +0 -0
  176. data/{spec/integrations → specs_e2e}/rails_5_2/test/models/post_test.rb +0 -0
  177. data/{spec/integrations → specs_e2e}/rails_5_2/test.sh +13 -11
  178. data/{spec/integrations/rails_4_2 → specs_e2e/rails_5_2}/vendor/.keep +0 -0
  179. metadata +179 -172
  180. data/.travis.yml +0 -39
  181. data/lib/generators/cypress_on_rails/templates/spec/cypress/fixtures/example.json +0 -5
  182. data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/actions.spec.js +0 -272
  183. data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/aliasing.spec.js +0 -42
  184. data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/assertions.spec.js +0 -63
  185. data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/connectors.spec.js +0 -55
  186. data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/cookies.spec.js +0 -78
  187. data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/cypress_api.spec.js +0 -211
  188. data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/files.spec.js +0 -86
  189. data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/local_storage.spec.js +0 -52
  190. data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/location.spec.js +0 -32
  191. data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/misc.spec.js +0 -68
  192. data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/navigation.spec.js +0 -54
  193. data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/network_requests.spec.js +0 -108
  194. data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/querying.spec.js +0 -65
  195. data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/spies_stubs_clocks.spec.js +0 -62
  196. data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/traversal.spec.js +0 -121
  197. data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/utilities.spec.js +0 -89
  198. data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/viewport.spec.js +0 -59
  199. data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/waiting.spec.js +0 -34
  200. data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/window.spec.js +0 -22
  201. data/lib/generators/cypress_on_rails/templates/spec/cypress.json +0 -4
  202. data/spec/integrations/cypress.json +0 -5
  203. data/spec/integrations/rails_4_2/test.sh +0 -38
  204. data/spec/integrations/rails_5_2/log/.keep +0 -0
  205. data/spec/integrations/rails_5_2/tmp/.keep +0 -0
  206. data/spec/integrations/rails_5_2/vendor/.keep +0 -0
@@ -1,3 +1,3 @@
1
1
  module CypressOnRails
2
- VERSION = '1.11.0'.freeze
2
+ VERSION = '1.13.0'.freeze
3
3
  end
@@ -3,42 +3,36 @@ module CypressOnRails
3
3
  class_option :cypress_folder, type: :string, default: 'cypress'
4
4
  class_option :install_cypress, type: :boolean, default: true
5
5
  class_option :install_cypress_with, type: :string, default: 'yarn'
6
- class_option :install_cypress_examples, type: :boolean, default: false
6
+ class_option :experimental, type: :boolean, default: false
7
7
  source_root File.expand_path('../templates', __FILE__)
8
8
 
9
9
  def install_cypress
10
- if !Dir.exists?(options.cypress_folder) || Dir["#{options.cypress_folder}/*"].empty?
11
- directories = options.cypress_folder.split('/')
12
- directories.pop
13
- install_dir = "#{Dir.pwd}/#{directories.join('/')}"
14
- command = nil
15
- if options.install_cypress
16
- if options.install_cypress_with == 'yarn'
17
- command = "yarn --cwd=#{install_dir} add cypress --dev"
18
- elsif options.install_cypress_with == 'npm'
19
- command = "cd #{install_dir}; npm install cypress --save-dev"
20
- end
21
- if command
22
- say command
23
- fail 'failed to install cypress' unless system(command)
24
- end
10
+ directories = options.cypress_folder.split('/')
11
+ directories.pop
12
+ install_dir = "#{Dir.pwd}/#{directories.join('/')}"
13
+ command = nil
14
+ if options.install_cypress
15
+ if options.install_cypress_with == 'yarn'
16
+ command = "yarn --cwd=#{install_dir} add cypress --dev"
17
+ elsif options.install_cypress_with == 'npm'
18
+ command = "cd #{install_dir}; npm install cypress --save-dev"
25
19
  end
26
- if options.install_cypress_examples
27
- directory 'spec/cypress/integration/examples', "#{options.cypress_folder}/integration/examples"
28
- directory 'spec/cypress/fixtures', "#{options.cypress_folder}/fixtures"
20
+ if command
21
+ say command
22
+ fail 'failed to install cypress' unless system(command)
29
23
  end
30
- copy_file "spec/cypress/support/index.js", "#{options.cypress_folder}/support/index.js"
31
- copy_file "spec/cypress/support/commands.js", "#{options.cypress_folder}/support/commands.js"
32
- copy_file "spec/cypress.json", "#{options.cypress_folder}/../cypress.json"
33
24
  end
25
+ template "spec/cypress/support/index.js.erb", "#{options.cypress_folder}/support/index.js"
26
+ copy_file "spec/cypress/support/commands.js", "#{options.cypress_folder}/support/commands.js"
27
+ copy_file "spec/cypress.config.js", "#{options.cypress_folder}/../cypress.config.js"
34
28
  end
35
29
 
36
30
  def add_initial_files
37
31
  template "config/initializers/cypress_on_rails.rb.erb", "config/initializers/cypress_on_rails.rb"
38
- copy_file "spec/cypress/cypress_helper.rb", "#{options.cypress_folder}/cypress_helper.rb"
32
+ template "spec/cypress/cypress_helper.rb.erb", "#{options.cypress_folder}/cypress_helper.rb"
39
33
  copy_file "spec/cypress/support/on-rails.js", "#{options.cypress_folder}/support/on-rails.js"
40
34
  directory 'spec/cypress/app_commands', "#{options.cypress_folder}/app_commands"
41
- directory 'spec/cypress/integration/rails_examples', "#{options.cypress_folder}/integration/rails_examples"
35
+ directory 'spec/cypress/e2e/rails_examples', "#{options.cypress_folder}/e2e/rails_examples"
42
36
  end
43
37
 
44
38
  def update_files
@@ -4,6 +4,7 @@ if defined?(CypressOnRails)
4
4
  # WARNING!! CypressOnRails can execute arbitrary ruby code
5
5
  # please use with extra caution if enabling on hosted servers or starting your local server on 0.0.0.0
6
6
  c.use_middleware = !Rails.env.production?
7
+ <% unless options.experimental %># <% end %> c.use_vcr_middleware = !Rails.env.production?
7
8
  c.logger = Rails.logger
8
9
  end
9
10
 
@@ -7,4 +7,12 @@ else
7
7
  Post.delete_all if defined?(Post)
8
8
  end
9
9
 
10
+ CypressOnRails::SmartFactoryWrapper.reload
11
+
12
+ if defined?(VCR)
13
+ VCR.eject_cassette # make sure we no cassette inserted before the next test starts
14
+ VCR.turn_off!
15
+ WebMock.disable! if defined?(WebMock)
16
+ end
17
+
10
18
  Rails.logger.info "APPCLEANED" # used by log_fail.rb
@@ -3,6 +3,8 @@ filename = command_options.fetch('runnable_full_title', 'no title').gsub(/[^[:pr
3
3
 
4
4
  # grab last lines until "APPCLEANED" (Make sure in clean.rb to log the text "APPCLEANED")
5
5
  system "tail -n 10000 -r log/#{Rails.env}.log | sed \"/APPCLEANED/ q\" | sed 'x;1!H;$!d;x' > 'log/#{filename}.log'"
6
+ # Alternative command if the above does not work
7
+ # system "tail -n 10000 log/#{Rails.env}.log | tac | sed \"/APPCLEANED/ q\" | sed 'x;1!H;$!d;x' > 'log/#{filename}.log'"
6
8
 
7
9
  # create a json debug file for server debugging
8
10
  json_result = {}
@@ -29,10 +29,15 @@ factory = FactoryBot if defined?(FactoryBot)
29
29
  factory = FactoryGirl if defined?(FactoryGirl)
30
30
 
31
31
  CypressOnRails::SmartFactoryWrapper.configure(
32
- always_reload: !Rails.configuration.cache_classes,
32
+ always_reload: false,
33
33
  factory: factory,
34
34
  files: [
35
35
  Rails.root.join('spec', 'factories.rb'),
36
36
  Rails.root.join('spec', 'factories', '**', '*.rb')
37
37
  ]
38
38
  )
39
+
40
+ <% unless options.experimental %># <% end %>require 'vcr'
41
+ <% unless options.experimental %># <% end %>VCR.configure do |config|
42
+ <% unless options.experimental %># <% end %> config.hook_into :webmock
43
+ <% unless options.experimental %># <% end %>end
@@ -0,0 +1,24 @@
1
+ describe('Rails Other examples', function() {
2
+ it('Inserting a cassette', function() {
3
+ cy.app('clean') // have a look at cypress/app_commands/clean.rb
4
+
5
+ cy.vcr_insert_cassette('cats', { record: "new_episodes" })
6
+ cy.visit('/using_vcr/index')
7
+
8
+ cy.get('a').contains('Cats').click()
9
+ cy.contains('Record from Cats API');
10
+
11
+ cy.vcr_eject_cassette();
12
+ })
13
+
14
+ it('Using previous a cassette', function() {
15
+ cy.app('clean') // have a look at cypress/app_commands/clean.rb
16
+
17
+ cy.vcr_insert_cassette('cats')
18
+ cy.visit('/using_vcr/index')
19
+ cy.get('a').contains('Cats').click()
20
+ cy.contains('Record from Cats API');
21
+
22
+ cy.vcr_eject_cassette();
23
+ })
24
+ })
@@ -14,6 +14,7 @@
14
14
  // ***********************************************************
15
15
 
16
16
  // Import commands.js using ES2015 syntax:
17
+ <% unless options.experimental %>// <% end %>import 'cypress-on-rails/support/index'
17
18
  import './commands'
18
19
  import './on-rails'
19
20
 
@@ -11,7 +11,7 @@ Cypress.Commands.add('appCommands', function (body) {
11
11
  }).then((response) => {
12
12
  log.end();
13
13
  if (response.status !== 201) {
14
- expect(response.body.message).to.be.empty
14
+ expect(response.body.message).to.equal('')
15
15
  expect(response.status).to.be.equal(201)
16
16
  }
17
17
  return response.body
@@ -0,0 +1,9 @@
1
+ const { defineConfig } = require('cypress')
2
+
3
+ module.exports = defineConfig({
4
+ e2e: {
5
+ baseUrl: "http://localhost:5017",
6
+ defaultCommandTimeout: 10000,
7
+ supportFile: "cypress/support/index.js",
8
+ }
9
+ })
data/plugin/.gitignore ADDED
@@ -0,0 +1 @@
1
+ node_modules
@@ -0,0 +1,4 @@
1
+ // export a function
2
+ module.exports = (on, config) => {
3
+ // configure plugins here
4
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "cypress-on-rails",
3
+ "version": "0.1.0",
4
+ "description": "Integrates cypress with rails or rack applications",
5
+ "main": "cypress/index.js",
6
+ "directories": {
7
+ "src": "cypress"
8
+ },
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1",
11
+ "build": "tsc"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/shakacode/cypress-on-rails.git"
16
+ },
17
+ "keywords": [
18
+ "cypress",
19
+ "ruby",
20
+ "rails"
21
+ ],
22
+ "author": "Grant Petersen-Speelman",
23
+ "license": "MIT",
24
+ "bugs": {
25
+ "url": "https://github.com/shakacode/cypress-on-rails/issues"
26
+ },
27
+ "homepage": "https://github.com/shakacode/cypress-on-rails#readme",
28
+ "dependencies": {
29
+ "cypress": "*"
30
+ }
31
+ }
@@ -0,0 +1,37 @@
1
+ Cypress.Commands.add("vcr_insert_cassette", (cassette_name, options) => {
2
+ if (!options) options = {};
3
+
4
+ Object.keys(options).forEach(key => options[key] === undefined ? delete options[key] : {});
5
+ const log = Cypress.log({ name: "VCR Insert", message: cassette_name, autoEnd: false })
6
+ return cy.request({
7
+ method: 'POST',
8
+ url: "/__cypress__/vcr/insert",
9
+ body: JSON.stringify([cassette_name,options]),
10
+ log: false,
11
+ failOnStatusCode: false
12
+ }).then((response) => {
13
+ log.end();
14
+ if (response.status !== 201) {
15
+ expect(response.body.message).to.equal('')
16
+ expect(response.status).to.be.equal(201)
17
+ }
18
+ return response.body
19
+ });
20
+ });
21
+
22
+ Cypress.Commands.add("vcr_eject_cassette", () => {
23
+ const log = Cypress.log({ name: "VCR Eject", autoEnd: false })
24
+ return cy.request({
25
+ method: 'POST',
26
+ url: "/__cypress__/vcr/eject",
27
+ log: false,
28
+ failOnStatusCode: false
29
+ }).then((response) => {
30
+ log.end();
31
+ if (response.status !== 201) {
32
+ expect(response.body.message).to.equal('')
33
+ expect(response.status).to.be.equal(201)
34
+ }
35
+ return response.body
36
+ });
37
+ });
@@ -17,14 +17,14 @@ RSpec.describe CypressOnRails::Middleware do
17
17
  context '/__cypress__/command' do
18
18
  before do
19
19
  allow(command_executor).to receive(:perform).and_return({ id: 1, title: 'some result' })
20
- allow(file).to receive(:exists?)
20
+ allow(file).to receive(:exist?)
21
21
  env['PATH_INFO'] = '/__cypress__/command'
22
22
  end
23
23
 
24
- it 'command file exists' do
24
+ it 'command file exist' do
25
25
  allow(command_executor).to receive(:perform).and_return({ id: 1, title: 'some result' })
26
26
  env['rack.input'] = rack_input(name: 'seed')
27
- allow(file).to receive(:exists?).with('spec/cypress/app_commands/seed.rb').and_return(true)
27
+ allow(file).to receive(:exist?).with('spec/cypress/app_commands/seed.rb').and_return(true)
28
28
 
29
29
  aggregate_failures do
30
30
  expect(response).to eq([201,
@@ -34,9 +34,9 @@ RSpec.describe CypressOnRails::Middleware do
34
34
  end
35
35
  end
36
36
 
37
- it 'command file exists with options' do
37
+ it 'command file exist with options' do
38
38
  env['rack.input'] = rack_input(name: 'seed', options: ['my_options'])
39
- allow(file).to receive(:exists?).with('spec/cypress/app_commands/seed.rb').and_return(true)
39
+ allow(file).to receive(:exist?).with('spec/cypress/app_commands/seed.rb').and_return(true)
40
40
 
41
41
  aggregate_failures do
42
42
  expect(response).to eq([201,
@@ -46,11 +46,11 @@ RSpec.describe CypressOnRails::Middleware do
46
46
  end
47
47
  end
48
48
 
49
- it 'command file does not exists' do
49
+ it 'command file does not exist' do
50
50
  object = BasicObject.new
51
51
  allow(command_executor).to receive(:perform).and_return(object)
52
52
  env['rack.input'] = rack_input(name: 'seed')
53
- allow(file).to receive(:exists?).with('spec/cypress/app_commands/seed.rb').and_return(true)
53
+ allow(file).to receive(:exist?).with('spec/cypress/app_commands/seed.rb').and_return(true)
54
54
 
55
55
  aggregate_failures do
56
56
  expect(response).to eq([201,
@@ -62,7 +62,7 @@ RSpec.describe CypressOnRails::Middleware do
62
62
 
63
63
  it 'command result does not respond to to_json' do
64
64
  env['rack.input'] = rack_input(name: 'seed')
65
- allow(file).to receive(:exists?).with('spec/cypress/app_commands/seed.rb').and_return(true)
65
+ allow(file).to receive(:exist?).with('spec/cypress/app_commands/seed.rb').and_return(true)
66
66
 
67
67
  aggregate_failures do
68
68
  expect(response).to eq([201,
@@ -75,8 +75,8 @@ RSpec.describe CypressOnRails::Middleware do
75
75
  it 'running multiple commands' do
76
76
  env['rack.input'] = rack_input([{name: 'load_user'},
77
77
  {name: 'load_sample', options: {'all' => 'true'}}])
78
- allow(file).to receive(:exists?).with('spec/cypress/app_commands/load_user.rb').and_return(true)
79
- allow(file).to receive(:exists?).with('spec/cypress/app_commands/load_sample.rb').and_return(true)
78
+ allow(file).to receive(:exist?).with('spec/cypress/app_commands/load_user.rb').and_return(true)
79
+ allow(file).to receive(:exist?).with('spec/cypress/app_commands/load_sample.rb').and_return(true)
80
80
 
81
81
  aggregate_failures do
82
82
  expect(response).to eq([201,
@@ -89,11 +89,13 @@ RSpec.describe CypressOnRails::Middleware do
89
89
 
90
90
  it 'running multiple commands but one missing' do
91
91
  env['rack.input'] = rack_input([{name: 'load_user'}, {name: 'load_sample'}])
92
- allow(file).to receive(:exists?).with('spec/cypress/app_commands/load_user.rb').and_return(true)
93
- allow(file).to receive(:exists?).with('spec/cypress/app_commands/load_sample.rb').and_return(false)
92
+ allow(file).to receive(:exist?).with('spec/cypress/app_commands/load_user.rb').and_return(true)
93
+ allow(file).to receive(:exist?).with('spec/cypress/app_commands/load_sample.rb').and_return(false)
94
94
 
95
95
  aggregate_failures do
96
- expect(response).to eq([404, {}, ['could not find command file: spec/cypress/app_commands/load_sample.rb']])
96
+ expect(response).to eq([404,
97
+ {"Content-Type"=>"application/json"},
98
+ ["{\"message\":\"could not find command file: spec/cypress/app_commands/load_sample.rb\"}"]])
97
99
  expect(command_executor).to_not have_received(:perform)
98
100
  end
99
101
  end
@@ -140,6 +140,13 @@ RSpec.describe CypressOnRails::SmartFactoryWrapper do
140
140
  expect(kernel_double).to have_received(:load).with('file2.rb').twice
141
141
  end
142
142
 
143
+ it 'can manually reload' do
144
+ subject.reload
145
+ expect(factory_double).to have_received(:reload)
146
+ expect(kernel_double).to have_received(:load).with('file1.rb')
147
+ expect(kernel_double).to have_received(:load).with('file2.rb')
148
+ end
149
+
143
150
  context 'files is a string' do
144
151
  let(:files) { 'file*.rb' }
145
152
 
@@ -0,0 +1,119 @@
1
+ require 'cypress_on_rails/vcr_middleware'
2
+ require 'vcr'
3
+ require 'active_support/core_ext/hash' unless Hash.new.respond_to?(:symbolize_keys)
4
+
5
+ module CypressOnRails
6
+ RSpec.describe VCRMiddleware do
7
+ let(:app) { ->(env) { [200, {}, ["app did #{env['PATH_INFO']}"]] } }
8
+ let(:vcr) { class_double(VCR, turn_on!: true, turn_off!: true, insert_cassette: true, eject_cassette: true) }
9
+ subject { described_class.new(app, vcr) }
10
+
11
+ let(:env) { {} }
12
+
13
+ let(:response) { subject.call(env) }
14
+
15
+ def rack_input(json_value)
16
+ StringIO.new(JSON.generate(json_value))
17
+ end
18
+
19
+ describe '/__cypress__/vcr/insert' do
20
+ before do
21
+ env['PATH_INFO'] = '/__cypress__/vcr/insert'
22
+ end
23
+
24
+ it do
25
+ env['rack.input'] = rack_input(['cas1'])
26
+
27
+ aggregate_failures do
28
+ expect(response).to eq([201,
29
+ {"Content-Type"=>"application/json"},
30
+ ["{\"message\":\"OK\"}"]])
31
+ expect(vcr).to have_received(:turn_on!)
32
+ expect(vcr).to have_received(:insert_cassette).with('cas1', {})
33
+ end
34
+ end
35
+
36
+ it 'works with record' do
37
+ env['rack.input'] = rack_input(['cas1', { "record" => "new_episodes" }])
38
+
39
+ aggregate_failures do
40
+ expect(response).to eq([201,
41
+ {"Content-Type"=>"application/json"},
42
+ ["{\"message\":\"OK\"}"]])
43
+ expect(vcr).to have_received(:insert_cassette).with('cas1', record: :new_episodes)
44
+ end
45
+ end
46
+
47
+ it 'works with match_requests_on' do
48
+ env['rack.input'] = rack_input(['cas1', { "match_requests_on" => ["method", "uri"] }])
49
+
50
+ aggregate_failures do
51
+ expect(response).to eq([201,
52
+ {"Content-Type"=>"application/json"},
53
+ ["{\"message\":\"OK\"}"]])
54
+ expect(vcr).to have_received(:insert_cassette).with('cas1', match_requests_on: [:method, :uri])
55
+ end
56
+ end
57
+
58
+ it 'works with serialize_with' do
59
+ env['rack.input'] = rack_input(['cas1', { "serialize_with" => "yaml" }])
60
+
61
+ aggregate_failures do
62
+ expect(response).to eq([201,
63
+ {"Content-Type"=>"application/json"},
64
+ ["{\"message\":\"OK\"}"]])
65
+ expect(vcr).to have_received(:insert_cassette).with('cas1', serialize_with: :yaml)
66
+ end
67
+ end
68
+
69
+ it 'works with persist_with' do
70
+ env['rack.input'] = rack_input(['cas1', { "persist_with" => "file_system" }])
71
+
72
+ aggregate_failures do
73
+ expect(response).to eq([201,
74
+ {"Content-Type"=>"application/json"},
75
+ ["{\"message\":\"OK\"}"]])
76
+ expect(vcr).to have_received(:insert_cassette).with('cas1', persist_with: :file_system)
77
+ end
78
+ end
79
+ end
80
+
81
+ describe '/__cypress__/vcr/eject' do
82
+ before do
83
+ env['PATH_INFO'] = '/__cypress__/vcr/eject'
84
+ end
85
+
86
+ it do
87
+ aggregate_failures do
88
+ expect(response).to eq([201,
89
+ {"Content-Type"=>"application/json"},
90
+ ["{\"message\":\"OK\"}"]])
91
+ expect(vcr).to have_received(:turn_off!)
92
+ expect(vcr).to have_received(:eject_cassette)
93
+ end
94
+ end
95
+ end
96
+
97
+ describe '"Other paths"' do
98
+ it 'calls vcr turn off the first time' do
99
+ env['PATH_INFO'] = '/test'
100
+
101
+ expect(response).to eq([200, {}, ["app did /test"]])
102
+ expect(vcr).to have_received(:turn_off!)
103
+ end
104
+
105
+ it 'runs app' do
106
+ aggregate_failures do
107
+ %w(/ /__cypress__/login command /cypress_command /).each do |path|
108
+ env['PATH_INFO'] = path
109
+
110
+ response = subject.call(env)
111
+
112
+ expect(response).to eq([200, {}, ["app did #{path}"]])
113
+ expect(vcr).to have_received(:turn_off!)
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,10 @@
1
+ const { defineConfig } = require('cypress')
2
+
3
+ module.exports = defineConfig({
4
+ projectId: "2b6cjr",
5
+ e2e: {
6
+ baseUrl: "http://localhost:5017",
7
+ defaultCommandTimeout: 10000,
8
+ supportFile: "cypress/support/index.js"
9
+ }
10
+ })
@@ -1,6 +1,6 @@
1
1
  .bundle
2
2
  node_modules
3
- cypress.json
3
+ cypress.config.js
4
4
  package-lock.json
5
5
  cypress/
6
6
  config/initializers/cypress_on_rails.rb
@@ -0,0 +1 @@
1
+ 2.3.8
@@ -3,5 +3,5 @@ source 'https://rubygems.org'
3
3
  gem 'rails', '~> 3.2.22'
4
4
 
5
5
  group :development, :test do
6
- gem 'cypress-on-rails', path: '../../../'
6
+ gem 'cypress-on-rails', path: '../../'
7
7
  end
File without changes
@@ -4,9 +4,9 @@ set -eo pipefail
4
4
  echo '--- testing rails 3.2'
5
5
 
6
6
  echo '-- setting environment'
7
- DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
8
- RAILS_ENV=test
9
- BUNDLE_GEMFILE="$DIR/Gemfile"
7
+ export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
8
+ export RAILS_ENV=test
9
+ export BUNDLE_GEMFILE="$DIR/Gemfile"
10
10
  cd $DIR
11
11
 
12
12
  echo '-- bundle install'
@@ -15,7 +15,8 @@ bundle install --quiet --gemfile="$DIR/Gemfile" --retry 2 --path vendor/bundle
15
15
 
16
16
  echo '-- cypress install'
17
17
  bundle exec ./bin/rails g cypress_on_rails:install --install_cypress_with=npm
18
- rm -vf cypress/integration/rails_examples/advance_factory_bot_spec.js
18
+ rm -vf cypress/e2e/rails_examples/advance_factory_bot.cy.js
19
+ rm -vf cypress/e2e/rails_examples/using_vcr.cy.js
19
20
 
20
21
  echo '-- start rails server'
21
22
  # make sure the server is not running
@@ -25,13 +26,13 @@ bundle exec ./bin/rails server -p 5017 -e test &
25
26
  sleep 2 # give rails a chance to start up correctly
26
27
 
27
28
  echo '-- cypress run'
28
- cp -fv ../cypress.json .
29
- if [ -z $CYPRESS_RECORD_KEY ]
30
- then
31
- node_modules/.bin/cypress run
32
- else
29
+ cp -fv ../cypress.config.js .
30
+ # if [ -z $CYPRESS_RECORD_KEY ]
31
+ # then
32
+ # node_modules/.bin/cypress run
33
+ # else
33
34
  node_modules/.bin/cypress run --record
34
- fi
35
+ # fi
35
36
 
36
37
  echo '-- stop rails server'
37
38
  kill -9 `cat tmp/pids/server.pid`