cypress-on-rails 0.2.2 → 1.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -1
  3. data/.rspec +1 -0
  4. data/.travis.yml +29 -0
  5. data/CHANGELOG.md +6 -0
  6. data/README.md +155 -54
  7. data/Rakefile +8 -0
  8. data/cypress-on-rails.gemspec +10 -9
  9. data/lib/cypress-on-rails.rb +3 -1
  10. data/lib/cypress/smart_factory_wrapper.rb +3 -0
  11. data/lib/cypress_dev.rb +4 -0
  12. data/lib/cypress_dev/command_executor.rb +33 -0
  13. data/lib/cypress_dev/configuration.rb +37 -0
  14. data/lib/cypress_dev/middleware.rb +65 -0
  15. data/lib/{cypress → cypress_dev}/railtie.rb +5 -7
  16. data/lib/cypress_dev/simple_rails_factory.rb +17 -0
  17. data/lib/cypress_dev/smart_factory_wrapper.rb +79 -0
  18. data/lib/cypress_dev/version.rb +3 -0
  19. data/lib/generators/cypress_dev/install_generator.rb +59 -0
  20. data/lib/generators/cypress_dev/templates/config/initializers/cypress_dev.rb.erb +9 -0
  21. data/lib/generators/cypress_dev/templates/spec/cypress.json +4 -0
  22. data/lib/generators/cypress_dev/templates/spec/cypress/app_commands/clean.rb +7 -0
  23. data/lib/generators/cypress_dev/templates/spec/cypress/app_commands/eval.rb +1 -0
  24. data/lib/generators/cypress_dev/templates/spec/cypress/app_commands/factory_bot.rb +12 -0
  25. data/lib/generators/cypress_dev/templates/spec/cypress/app_commands/scenarios/basic.rb +2 -0
  26. data/lib/generators/cypress_dev/templates/spec/cypress/cypress_helper.rb +30 -0
  27. data/lib/generators/cypress_dev/templates/spec/cypress/integration/on_rails_spec.js +33 -0
  28. data/lib/generators/cypress_dev/templates/spec/cypress/support/commands.js +25 -0
  29. data/lib/generators/cypress_dev/templates/spec/cypress/support/index.js +21 -0
  30. data/lib/generators/cypress_dev/templates/spec/cypress/support/on-rails.js +33 -0
  31. data/spec/cypress_dev/command_executor/cypress_helper.rb +6 -0
  32. data/spec/cypress_dev/command_executor/test_command.rb +1 -0
  33. data/spec/cypress_dev/command_executor/test_command_with_options.rb +1 -0
  34. data/spec/cypress_dev/command_executor_spec.rb +33 -0
  35. data/spec/cypress_dev/configuration_spec.rb +23 -0
  36. data/spec/cypress_dev/middleware_spec.rb +104 -0
  37. data/spec/cypress_dev/railtie_spec.rb +22 -0
  38. data/spec/cypress_dev/smart_factory_wrapper_spec.rb +83 -0
  39. data/spec/integrations/rails_3_2/.gitignore +9 -0
  40. data/spec/integrations/rails_3_2/Gemfile +7 -0
  41. data/spec/integrations/rails_3_2/README.rdoc +261 -0
  42. data/spec/integrations/rails_3_2/Rakefile +7 -0
  43. data/spec/integrations/rails_3_2/app/assets/stylesheets/application.css +13 -0
  44. data/spec/integrations/rails_3_2/app/controllers/application_controller.rb +3 -0
  45. data/spec/integrations/rails_3_2/app/controllers/welcome_controller.rb +4 -0
  46. data/spec/integrations/rails_3_2/app/helpers/application_helper.rb +2 -0
  47. data/spec/integrations/rails_3_2/app/models/post.rb +13 -0
  48. data/spec/integrations/rails_3_2/app/views/layouts/application.html.erb +13 -0
  49. data/spec/integrations/rails_3_2/app/views/welcome/index.html.erb +5 -0
  50. data/spec/integrations/rails_3_2/bin/rails +6 -0
  51. data/spec/integrations/rails_3_2/config.ru +4 -0
  52. data/spec/integrations/rails_3_2/config/application.rb +69 -0
  53. data/spec/integrations/rails_3_2/config/boot.rb +6 -0
  54. data/spec/integrations/rails_3_2/config/environment.rb +5 -0
  55. data/spec/integrations/rails_3_2/config/environments/development.rb +31 -0
  56. data/spec/integrations/rails_3_2/config/environments/production.rb +64 -0
  57. data/spec/integrations/rails_3_2/config/environments/test.rb +35 -0
  58. data/spec/integrations/rails_3_2/config/initializers/backtrace_silencers.rb +7 -0
  59. data/spec/integrations/rails_3_2/config/initializers/inflections.rb +15 -0
  60. data/spec/integrations/rails_3_2/config/initializers/mime_types.rb +5 -0
  61. data/spec/integrations/rails_3_2/config/initializers/secret_token.rb +7 -0
  62. data/spec/integrations/rails_3_2/config/initializers/session_store.rb +8 -0
  63. data/spec/integrations/rails_3_2/config/initializers/wrap_parameters.rb +10 -0
  64. data/spec/integrations/rails_3_2/config/locales/en.yml +5 -0
  65. data/spec/integrations/rails_3_2/config/routes.rb +60 -0
  66. data/spec/integrations/rails_3_2/public/404.html +26 -0
  67. data/spec/integrations/rails_3_2/public/422.html +26 -0
  68. data/spec/integrations/rails_3_2/public/500.html +25 -0
  69. data/spec/integrations/rails_3_2/public/favicon.ico +0 -0
  70. data/spec/integrations/rails_3_2/public/robots.txt +5 -0
  71. data/spec/integrations/rails_3_2/test.sh +30 -0
  72. data/spec/integrations/rails_3_2/tmp/.keep +0 -0
  73. data/spec/integrations/rails_3_2/vendor/.gitkeep +0 -0
  74. data/spec/integrations/rails_4_2/.gitignore +10 -0
  75. data/spec/integrations/rails_4_2/Gemfile +8 -0
  76. data/spec/integrations/rails_4_2/README.rdoc +28 -0
  77. data/spec/integrations/rails_4_2/Rakefile +6 -0
  78. data/spec/integrations/rails_4_2/app/controllers/application_controller.rb +5 -0
  79. data/spec/integrations/rails_4_2/app/controllers/welcome_controller.rb +4 -0
  80. data/spec/integrations/rails_4_2/app/models/post.rb +13 -0
  81. data/spec/integrations/rails_4_2/app/views/layouts/application.html.erb +12 -0
  82. data/spec/integrations/rails_4_2/app/views/welcome/index.html.erb +5 -0
  83. data/spec/integrations/rails_4_2/bin/bundle +3 -0
  84. data/spec/integrations/rails_4_2/bin/rails +4 -0
  85. data/spec/integrations/rails_4_2/bin/rake +4 -0
  86. data/spec/integrations/rails_4_2/bin/setup +29 -0
  87. data/spec/integrations/rails_4_2/config.ru +4 -0
  88. data/spec/integrations/rails_4_2/config/application.rb +33 -0
  89. data/spec/integrations/rails_4_2/config/boot.rb +3 -0
  90. data/spec/integrations/rails_4_2/config/environment.rb +5 -0
  91. data/spec/integrations/rails_4_2/config/environments/development.rb +25 -0
  92. data/spec/integrations/rails_4_2/config/environments/production.rb +64 -0
  93. data/spec/integrations/rails_4_2/config/environments/test.rb +42 -0
  94. data/spec/integrations/rails_4_2/config/initializers/backtrace_silencers.rb +7 -0
  95. data/spec/integrations/rails_4_2/config/initializers/cookies_serializer.rb +3 -0
  96. data/spec/integrations/rails_4_2/config/initializers/filter_parameter_logging.rb +4 -0
  97. data/spec/integrations/rails_4_2/config/initializers/inflections.rb +16 -0
  98. data/spec/integrations/rails_4_2/config/initializers/mime_types.rb +4 -0
  99. data/spec/integrations/rails_4_2/config/initializers/session_store.rb +3 -0
  100. data/spec/integrations/rails_4_2/config/initializers/to_time_preserves_timezone.rb +10 -0
  101. data/spec/integrations/rails_4_2/config/initializers/wrap_parameters.rb +9 -0
  102. data/spec/integrations/rails_4_2/config/locales/en.yml +23 -0
  103. data/spec/integrations/rails_4_2/config/routes.rb +56 -0
  104. data/spec/integrations/rails_4_2/config/secrets.yml +22 -0
  105. data/spec/integrations/rails_4_2/public/404.html +67 -0
  106. data/spec/integrations/rails_4_2/public/422.html +67 -0
  107. data/spec/integrations/rails_4_2/public/500.html +66 -0
  108. data/spec/integrations/rails_4_2/public/favicon.ico +0 -0
  109. data/spec/integrations/rails_4_2/public/robots.txt +5 -0
  110. data/spec/integrations/rails_4_2/test.sh +31 -0
  111. data/spec/integrations/rails_4_2/vendor/.keep +0 -0
  112. data/spec/integrations/rails_5_2/.gitignore +10 -0
  113. data/spec/integrations/rails_5_2/Gemfile +12 -0
  114. data/spec/integrations/rails_5_2/README.md +24 -0
  115. data/spec/integrations/rails_5_2/Rakefile +6 -0
  116. data/spec/integrations/rails_5_2/app/controllers/application_controller.rb +2 -0
  117. data/spec/integrations/rails_5_2/app/controllers/welcome_controller.rb +4 -0
  118. data/spec/integrations/rails_5_2/app/jobs/application_job.rb +2 -0
  119. data/spec/integrations/rails_5_2/app/models/post.rb +13 -0
  120. data/spec/integrations/rails_5_2/app/views/layouts/application.html.erb +12 -0
  121. data/spec/integrations/rails_5_2/app/views/welcome/index.html.erb +5 -0
  122. data/spec/integrations/rails_5_2/bin/bundle +3 -0
  123. data/spec/integrations/rails_5_2/bin/rails +4 -0
  124. data/spec/integrations/rails_5_2/bin/rake +4 -0
  125. data/spec/integrations/rails_5_2/bin/setup +25 -0
  126. data/spec/integrations/rails_5_2/bin/update +25 -0
  127. data/spec/integrations/rails_5_2/config.ru +5 -0
  128. data/spec/integrations/rails_5_2/config/application.rb +37 -0
  129. data/spec/integrations/rails_5_2/config/boot.rb +4 -0
  130. data/spec/integrations/rails_5_2/config/credentials.yml.enc +1 -0
  131. data/spec/integrations/rails_5_2/config/environment.rb +5 -0
  132. data/spec/integrations/rails_5_2/config/environments/development.rb +40 -0
  133. data/spec/integrations/rails_5_2/config/environments/production.rb +68 -0
  134. data/spec/integrations/rails_5_2/config/environments/test.rb +36 -0
  135. data/spec/integrations/rails_5_2/config/initializers/application_controller_renderer.rb +8 -0
  136. data/spec/integrations/rails_5_2/config/initializers/backtrace_silencers.rb +7 -0
  137. data/spec/integrations/rails_5_2/config/initializers/content_security_policy.rb +25 -0
  138. data/spec/integrations/rails_5_2/config/initializers/cookies_serializer.rb +5 -0
  139. data/spec/integrations/rails_5_2/config/initializers/filter_parameter_logging.rb +4 -0
  140. data/spec/integrations/rails_5_2/config/initializers/inflections.rb +16 -0
  141. data/spec/integrations/rails_5_2/config/initializers/mime_types.rb +4 -0
  142. data/spec/integrations/rails_5_2/config/initializers/wrap_parameters.rb +9 -0
  143. data/spec/integrations/rails_5_2/config/locales/en.yml +33 -0
  144. data/spec/integrations/rails_5_2/config/master.key +1 -0
  145. data/spec/integrations/rails_5_2/config/routes.rb +4 -0
  146. data/spec/integrations/rails_5_2/public/404.html +67 -0
  147. data/spec/integrations/rails_5_2/public/422.html +67 -0
  148. data/spec/integrations/rails_5_2/public/500.html +66 -0
  149. data/spec/integrations/rails_5_2/public/apple-touch-icon-precomposed.png +0 -0
  150. data/spec/integrations/rails_5_2/public/apple-touch-icon.png +0 -0
  151. data/spec/integrations/rails_5_2/public/favicon.ico +0 -0
  152. data/spec/integrations/rails_5_2/public/robots.txt +1 -0
  153. data/spec/integrations/rails_5_2/test.sh +31 -0
  154. data/spec/integrations/rails_5_2/tmp/.keep +0 -0
  155. data/spec/integrations/rails_5_2/vendor/.keep +0 -0
  156. data/spec/spec_helper.rb +104 -0
  157. metadata +177 -25
  158. data/Gemfile.lock +0 -32
  159. data/bin/cypress +0 -3
  160. data/lib/cypress.rb +0 -27
  161. data/lib/cypress/configuration.rb +0 -41
  162. data/lib/cypress/middleware.rb +0 -69
  163. data/lib/cypress/runner.rb +0 -42
  164. data/lib/cypress/scenario_bank.rb +0 -21
  165. data/lib/cypress/scenario_context.rb +0 -23
  166. data/lib/cypress/version.rb +0 -3
  167. data/lib/generators/install_generator.rb +0 -77
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc1e2fe168cf290f95472c55f7519fd16ad606d3688c726ca0c6d2fb0a183914
4
- data.tar.gz: 1bb6916032e5bfb10b6198a76f2e1e31a344c5ae180f8aff15ce5bab1ada0785
3
+ metadata.gz: f03b1025928c7aaaba3a08b77efa93800e7c6c41466d31cbd7a28393c688eb51
4
+ data.tar.gz: 37ac42ef065a1395c74d85a657c255fdb227e60a081facbe1c02ddb7220cd773
5
5
  SHA512:
6
- metadata.gz: dc3852ba497d61a44b4f13b2b839a9d0c2ec75609419eb4abcbc44c48ef6f4263dc405ee126dfe63e7ae421a7c158ece2fa1edfd9e04523846eae80ca1e687e6
7
- data.tar.gz: 83812b71bfdfc4a85a217474274dc821dc5fe7cfbc670e52738f312b4734eeeabebef2562c1c943dc0fb63f4e0014f3257075629e51c1335dcf7ee325517f265
6
+ metadata.gz: 7c6618a706b569855650adff6a0e38cc249684ad2c06e48ac222b58f96c34cec3f82923b5db9fa1ee35d3ba4c7c6bae9aa10b6ecc23efe9a2f6d3defd7b5a462
7
+ data.tar.gz: c5e78bb8eed8bc326dd4063311f7d3167fe30db3d0b346f641429c095eb46a97ad32f44a04e4396570c93545ba820a06ce8d6312befcf84d56515f081e17a71c
data/.gitignore CHANGED
@@ -1 +1,6 @@
1
- .DS_Store
1
+ .DS_Store
2
+ Gemfile.lock
3
+ .ruby-version
4
+ spec/examples.txt
5
+ .idea
6
+ spec/test.log
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,29 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2
4
+
5
+ addons:
6
+ artifacts:
7
+ s3_region: "ap-southeast-2"
8
+ paths:
9
+ - $(ls spec/integrations/*/*/cypress/{screenshots,videos}/* | tr "\n" ":")
10
+ - $(ls spec/integrations/rails_3_2/cypress/{screenshots,videos}/* | tr "\n" ":")
11
+
12
+ cache:
13
+ directories:
14
+ - spec/integrations/rails_5_2/spec/node_modules
15
+ - spec/integrations/rails_5_2/vendor/bundle
16
+ - spec/integrations/rails_4_2/test/node_modules
17
+ - spec/integrations/rails_4_2/vendor/bundle
18
+ - spec/integrations/rails_3_2/node_modules
19
+ - spec/integrations/rails_3_2/vendor/bundle
20
+
21
+ before_install:
22
+ - sudo apt-get -qq update
23
+ - sudo apt-get install -y build-essential patch ruby-dev zlib1g-dev liblzma-dev libxml2-dev
24
+
25
+ script:
26
+ - bundle exec rake
27
+ - ./spec/integrations/rails_3_2/test.sh
28
+ - ./spec/integrations/rails_4_2/test.sh
29
+ - ./spec/integrations/rails_5_2/test.sh
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 1.0.0
2
+ * renamed to CypressDev
3
+ * middleware stripped down to make it more flexible and generic
4
+ * concept of generic commands introduced that can have any ruby in it
5
+ * and lots of other changes
6
+
1
7
  ## 0.2.2 (2018-03-24)
2
8
  ### Fixed
3
9
  * fix major bug when using scenarios
data/README.md CHANGED
@@ -1,9 +1,18 @@
1
- # cypress-on-rails
1
+ # CypressDev
2
2
 
3
- Proof-of-Concept gem for using [cypress.io](http://github.com/cypress-io/) in Rails applications. It provides the following features:
4
- * run ruby code in your application context before executing a test
5
- * database cleaning before test run (using database_cleaner)
6
- * ability to use RSpec Mocks for your Rails code
3
+ [![Build Status](https://travis-ci.org/grantspeelman/cypress_dev.svg?branch=master)](https://travis-ci.org/grantspeelman/cypress_dev)
4
+
5
+ Gem for using [cypress.io](http://github.com/cypress-io/) in Rails and ruby rack applications
6
+ with the goal of controlling State as mentioned in [Cypress Best Practices](https://docs.cypress.io/guides/references/best-practices.html#Organizing-Tests-Logging-In-Controlling-State)
7
+
8
+ It allows to run code in the application context when executing cypress tests.
9
+ Do things like:
10
+ * use database_cleaner before each test
11
+ * seed the database with default data for each test
12
+ * use factory_bot to setup data
13
+ * create scenario files used for specific tests
14
+
15
+ This gem is based off https://github.com/konvenit/cypress-on-rails
7
16
 
8
17
  ## Getting started
9
18
 
@@ -16,94 +25,186 @@ end
16
25
 
17
26
  The generate the boilerplate code using:
18
27
  ```
19
- rails g cypress:install
20
- ```
28
+ bin/rails g cypress_dev:install
21
29
 
22
- Finally add the `cypress` package using yarn:
23
- ```
24
- yarn add --dev cypress
30
+ # if you have/want a different cypress folder (default is spec/cypress)
31
+ bin/rails g cypress_dev:install --cypress_folder=test/cypress
32
+
33
+ # if you want to install cypress with npm
34
+ bin/rails g cypress_dev:install --install_cypress_with=npm
25
35
  ```
26
36
 
27
- If you are not using RSpec and/or database_cleaner look at `spec/cypress/cypress_helper.rb`.
37
+ The generator adds the following files/directory to your application:
38
+ * `config/initializers/cypress_dev` used to configure CypressDev
39
+ * `spec/cypress/integrations/` contains your cypress tests
40
+ * `spec/cypress/support/on-rails.js` contains CypressDev support code
41
+ * `spec/cypress/app_commands/scenarios/` contains your CypressDev scenario definitions
42
+ * `spec/cypress/cypress_helper.rb` contains helper code for CypressDev app commands
43
+
44
+ if you are not using database_cleaner look at `spec/cypress/app_commands/clean_db.rb`.
45
+ if you are not using factory_bot look at `spec/cypress/app_commands/factory_bot.rb`.
28
46
 
29
47
  ## Usage
30
48
 
31
- This gem provides the `cypress` command. When called without any arguments ie. `bundle exec cypress`, it will start the cypress.io UI. While running the UI you can edit both your application and test code and see the effects on the next test run. When run as `bundle exec cypress run` it runs headless for CI testing.
49
+ When writing End-to-End tests, you will probably want to prepare your database to a known state.
50
+ Maybe using a gem like factory_bot. This gem implements two methods to achieve this goal:
32
51
 
33
- The generator adds the following files/directory to your application:
34
- * `spec/cypress/cypress_helper.rb` contains your configuration
35
- * `spec/cypress/integrations/` contains your tests
36
- * `spec/cypress/scenarios/` contains your scenario definitions
37
- * `spec/cypress/support/setup.js` contains support code
52
+ example of getting started
53
+
54
+ ```
55
+ # start rails
56
+ RAILS_ENV=test bin/rake db:create db:schema:load
57
+ bin/rails server -e test -p 5002
58
+
59
+ # in separate window start cypress
60
+ cd spec
61
+ yarn run cypress open
62
+ ```
63
+
64
+ Now you can create scenarios and commands that are plan ruby files that get loaded
65
+ through middleware, the ruby sky is your limit.
66
+
67
+ ### WARNING
68
+ *WARNING!!:* cypress-on-rails can execute arbitrary ruby code
69
+ Please use with extra caution if starting your local server on 0.0.0.0 or running on a hosted server
38
70
 
39
- When writing End-to-End tests, you will probably want to prepare your database to a known state. Maybe using a gem like factory_girl. This gem implements two methods to achieve this goal:
71
+ ### Example of using scenarios
40
72
 
41
- ### Using embedded ruby
42
- You can embed ruby code in your test file. This code will then be executed in the context of your application. For example:
73
+ Scenarios are named `before` blocks that you can reference in your test.
74
+
75
+ You define a scenario in the `spec/cypress/app_commands/scenarios` directory:
76
+ ```ruby
77
+ # spec/cypress/app_commands/scenarios/basic.rb
78
+ Profile.create name: "Cypress Hill"
43
79
 
80
+ # or if you have factory_bot enabled in your cypress_helper
81
+ CypressDev::SmartFactoryWrapper.create(:profile, name: "Cypress Hill")
44
82
  ```
45
- // spec/cypress/integrations/simple_spec.js
83
+
84
+ Then reference the scenario in your test:
85
+ ```js
86
+ // spec/cypress/integrations/scenario_example_spec.js
46
87
  describe('My First Test', function() {
47
88
  it('visit root', function() {
48
89
  // This calls to the backend to prepare the application state
49
- cy.rails(`
50
- Profile.create name: "Cypress Hill"
51
- `)
90
+ cy.appScenario('basic')
52
91
 
53
- // The application unter test is available at SERVER_PORT
54
- cy.visit('http://localhost:'+Cypress.env("SERVER_PORT"))
92
+ cy.visit('/profiles')
55
93
 
56
94
  cy.contains("Cypress Hill")
57
95
  })
58
96
  })
59
97
  ```
60
98
 
61
- Use the (`) backtick string syntax to allow multiline strings.
99
+ ### Example of using factory bot
100
+ You can run your [factory_bot](https://github.com/thoughtbot/factory_bot) directly as well
62
101
 
63
- ### Using scenarios
102
+ ```ruby
103
+ # spec/cypress/app_commands/scenarios/basic.rb
104
+ require 'cypress_dev/smart_factory_wrapper'
64
105
 
65
- Scenarios are named `before` blocks that you can reference in your test.
66
-
67
- You define a scenario in the `spec/cypress/scenarios` directory:
68
- ```
69
- # spec/cypress/scenarios/basic.rb
70
- scenario :basic do
71
- Profile.create name: "Cypress Hill"
72
- end
106
+ CypressDev::SmartFactoryWrapper.configure(
107
+ always_reload: !Rails.configuration.cache_classes,
108
+ factory: FactoryBot,
109
+ files: Dir['./spec/factories/**/*.rb']
110
+ )
73
111
  ```
74
112
 
75
- Then reference the scenario in your test:
76
- ```
113
+ ```js
77
114
  // spec/cypress/integrations/simple_spec.js
78
115
  describe('My First Test', function() {
79
116
  it('visit root', function() {
80
117
  // This calls to the backend to prepare the application state
81
- cy.setupScenario('basic')
118
+ cy.appFactories([
119
+ ['create_list', 'post', 10],
120
+ ['create', 'post', {title: 'Hello World'} ]
121
+ ])
82
122
 
83
123
  // The application unter test is available at SERVER_PORT
84
- cy.visit('http://localhost:'+Cypress.env("SERVER_PORT"))
124
+ cy.visit('/')
85
125
 
86
- cy.contains("Cypress Hill")
126
+ cy.contains("Hello World")
87
127
  })
88
128
  })
89
129
  ```
90
130
 
91
- The `setupScenario` call does the following things:
92
- * clears the database using database_cleaner (can be disabled)
93
- * calls the optional `before` block from `spec/cypress/cypress_helper.rb`
94
- * calls the scenario block associated with the name given
131
+ ### Example of using app commands
132
+
133
+ create a ruby file in `spec/cypress/app_commands` directory:
134
+ ```ruby
135
+ # spec/cypress/app_commands/load_seed.rb
136
+ load "#{Rails.root}/db/seeds.rb"
137
+ ```
138
+
139
+ Then reference the command in your test with `cy.app('load_seed')`:
140
+ ```js
141
+ // spec/cypress/integrations/simple_spec.js
142
+ describe('My First Test', function() {
143
+ beforeEach(() => { cy.app('load_seed') })
144
+
145
+ it('visit root', function() {
146
+ cy.visit('/')
95
147
 
96
- In the scenario you also have access to RSpec mocking functions. So you could do something like:
148
+ cy.contains("Seeds")
149
+ })
150
+ })
97
151
  ```
98
- scenario :basic do
99
- allow(ExternalService).to receive(:retrieve).and_return("result")
152
+
153
+ ## Usage with other rack applications
154
+
155
+ Add CypressDev to your config.ru
156
+
157
+ ```ruby
158
+ # an example config.ru
159
+ require File.expand_path('my_app', File.dirname(__FILE__))
160
+
161
+ require 'cypress_dev/middleware'
162
+ CypressDev.configure do |c|
163
+ c.cypress_folder = File.expand_path("#{__dir__}/test/cypress")
100
164
  end
165
+ use Cypress::Middleware
166
+
167
+ run MyApp
168
+ ```
169
+
170
+ add the following file to cypress
171
+
172
+ ```js
173
+ // test/cypress/support/on-rails.js
174
+ // CypressDev: dont remove these command
175
+ Cypress.Commands.add('appCommands', function (body) {
176
+ cy.request({
177
+ method: 'POST',
178
+ url: "/__cypress__/command",
179
+ body: JSON.stringify(body),
180
+ log: true,
181
+ failOnStatusCode: true
182
+ })
183
+ });
184
+
185
+ Cypress.Commands.add('app', function (name, command_options) {
186
+ cy.appCommands({name: name, options: command_options})
187
+ });
188
+
189
+ Cypress.Commands.add('appScenario', function (name) {
190
+ cy.app('scenarios/' + name)
191
+ });
192
+
193
+ Cypress.Commands.add('appFactories', function (options) {
194
+ cy.app('factory_bot', options)
195
+ });
196
+ // CypressDev: end
197
+
198
+ // The next is optional
199
+ beforeEach(() => {
200
+ cy.app('clean') // have a look at cypress/app_commands/clean.rb
201
+ });
101
202
  ```
102
203
 
103
- An example application is available at https://github.com/konvenit/cypress-on-rails-example
204
+ ## Contributing
104
205
 
105
- # Limitations
106
- This code is very much at the proof-of-concept stage. The following limitations are known:
107
- * It requires yarn for the javascript dependency management
108
- * Only tested on Rails 5.1
109
- * Only works with RSpec and database_cleaner
206
+ 1. Fork it ( https://github.com/[my-github-username]/cypress-on-rails/fork )
207
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
208
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
209
+ 4. Push to the branch (`git push origin my-new-feature`)
210
+ 5. Create a new Pull Request
data/Rakefile CHANGED
@@ -1 +1,9 @@
1
1
  require 'bundler/gem_tasks'
2
+
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec) do |t|
6
+ t.pattern = 'spec/cypress/*_spec.rb'
7
+ end
8
+
9
+ task default: %w[spec build]
@@ -1,21 +1,22 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $LOAD_PATH.push File.expand_path("../lib", __FILE__)
3
- require "cypress/version"
3
+ require "cypress_dev/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "cypress-on-rails"
7
- s.version = Cypress::VERSION
8
- s.author = "miceportal team"
9
- s.email = "info@miceportal.de"
10
- s.homepage = "http://github.com/konvenit/cypress-on-rails"
11
- s.summary = "Integrates cypress with rails"
12
- s.description = "Integrates cypress with rails"
7
+ s.version = CypressDev::VERSION
8
+ s.author = ["miceportal team"]
9
+ s.email = ["info@miceportal.de"]
10
+ s.homepage = "http://github.com/grantspeelman/cypress-on-rails"
11
+ s.summary = "Integrates cypress with rails or rack applications"
12
+ s.description = "Integrates cypress with rails or rack applications"
13
13
  s.rubyforge_project = s.name
14
14
  s.files = `git ls-files`.split("\n")
15
15
  s.test_files = `git ls-files -- {spec}/*`.split("\n")
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
17
17
  s.require_paths = ["lib"]
18
- s.add_dependency 'activesupport'
19
- s.add_dependency 'selenium-webdriver' # to be replaced
18
+ s.add_dependency 'rack'
19
+ s.add_development_dependency 'rake'
20
20
  s.add_development_dependency 'rspec'
21
+ s.add_development_dependency 'railties', '>= 3.2'
21
22
  end
@@ -1 +1,3 @@
1
- require_relative './cypress'
1
+ require 'cypress_dev'
2
+
3
+ Cypress = CypressDev
@@ -0,0 +1,3 @@
1
+ require 'cypress-on-rails'
2
+ require 'cypress_dev/smart_factory_wrapper'
3
+ # for backward compatibility
@@ -0,0 +1,4 @@
1
+ require 'cypress_dev/version'
2
+ require 'cypress_dev/configuration'
3
+ require_relative './cypress_dev/railtie' if defined?(Rails)
4
+
@@ -0,0 +1,33 @@
1
+ require 'cypress_dev/configuration'
2
+
3
+ module CypressDev
4
+ # loads and evals the command files
5
+ class CommandExecutor
6
+ def self.load(file,command_options = nil)
7
+ load_cypress_helper
8
+ file_data = File.read(file)
9
+ eval file_data
10
+ rescue => e
11
+ logger.error("fail to execute #{file}: #{e.message}")
12
+ logger.error(e.backtrace.join("\n"))
13
+ raise e
14
+ end
15
+
16
+ def self.load_cypress_helper
17
+ cypress_helper_file = "#{configuration.cypress_folder}/cypress_helper"
18
+ if File.exist?("#{cypress_helper_file}.rb")
19
+ Kernel.require cypress_helper_file
20
+ else
21
+ logger.warn "could not find #{cypress_helper_file}.rb"
22
+ end
23
+ end
24
+
25
+ def self.logger
26
+ configuration.logger
27
+ end
28
+
29
+ def self.configuration
30
+ CypressDev.configuration
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,37 @@
1
+ require 'logger'
2
+
3
+ module CypressDev
4
+ class Configuration
5
+ attr_accessor :cypress_folder
6
+ attr_accessor :use_middleware
7
+ attr_accessor :logger
8
+
9
+ def initialize
10
+ reset
11
+ end
12
+
13
+ alias :use_middleware? :use_middleware
14
+
15
+ def reset
16
+ self.cypress_folder = 'spec/cypress'
17
+ self.use_middleware = true
18
+ self.logger = Logger.new(STDOUT)
19
+ end
20
+
21
+ def tagged_logged
22
+ if logger.respond_to?(:tagged)
23
+ logger.tagged('CY_DEV') { yield }
24
+ else
25
+ yield
26
+ end
27
+ end
28
+ end
29
+
30
+ def self.configuration
31
+ @configuration ||= Configuration.new
32
+ end
33
+
34
+ def self.configure
35
+ yield configuration if block_given?
36
+ end
37
+ end