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.
- checksums.yaml +4 -4
- data/.gitignore +6 -1
- data/.rspec +1 -0
- data/.travis.yml +29 -0
- data/CHANGELOG.md +6 -0
- data/README.md +155 -54
- data/Rakefile +8 -0
- data/cypress-on-rails.gemspec +10 -9
- data/lib/cypress-on-rails.rb +3 -1
- data/lib/cypress/smart_factory_wrapper.rb +3 -0
- data/lib/cypress_dev.rb +4 -0
- data/lib/cypress_dev/command_executor.rb +33 -0
- data/lib/cypress_dev/configuration.rb +37 -0
- data/lib/cypress_dev/middleware.rb +65 -0
- data/lib/{cypress → cypress_dev}/railtie.rb +5 -7
- data/lib/cypress_dev/simple_rails_factory.rb +17 -0
- data/lib/cypress_dev/smart_factory_wrapper.rb +79 -0
- data/lib/cypress_dev/version.rb +3 -0
- data/lib/generators/cypress_dev/install_generator.rb +59 -0
- data/lib/generators/cypress_dev/templates/config/initializers/cypress_dev.rb.erb +9 -0
- data/lib/generators/cypress_dev/templates/spec/cypress.json +4 -0
- data/lib/generators/cypress_dev/templates/spec/cypress/app_commands/clean.rb +7 -0
- data/lib/generators/cypress_dev/templates/spec/cypress/app_commands/eval.rb +1 -0
- data/lib/generators/cypress_dev/templates/spec/cypress/app_commands/factory_bot.rb +12 -0
- data/lib/generators/cypress_dev/templates/spec/cypress/app_commands/scenarios/basic.rb +2 -0
- data/lib/generators/cypress_dev/templates/spec/cypress/cypress_helper.rb +30 -0
- data/lib/generators/cypress_dev/templates/spec/cypress/integration/on_rails_spec.js +33 -0
- data/lib/generators/cypress_dev/templates/spec/cypress/support/commands.js +25 -0
- data/lib/generators/cypress_dev/templates/spec/cypress/support/index.js +21 -0
- data/lib/generators/cypress_dev/templates/spec/cypress/support/on-rails.js +33 -0
- data/spec/cypress_dev/command_executor/cypress_helper.rb +6 -0
- data/spec/cypress_dev/command_executor/test_command.rb +1 -0
- data/spec/cypress_dev/command_executor/test_command_with_options.rb +1 -0
- data/spec/cypress_dev/command_executor_spec.rb +33 -0
- data/spec/cypress_dev/configuration_spec.rb +23 -0
- data/spec/cypress_dev/middleware_spec.rb +104 -0
- data/spec/cypress_dev/railtie_spec.rb +22 -0
- data/spec/cypress_dev/smart_factory_wrapper_spec.rb +83 -0
- data/spec/integrations/rails_3_2/.gitignore +9 -0
- data/spec/integrations/rails_3_2/Gemfile +7 -0
- data/spec/integrations/rails_3_2/README.rdoc +261 -0
- data/spec/integrations/rails_3_2/Rakefile +7 -0
- data/spec/integrations/rails_3_2/app/assets/stylesheets/application.css +13 -0
- data/spec/integrations/rails_3_2/app/controllers/application_controller.rb +3 -0
- data/spec/integrations/rails_3_2/app/controllers/welcome_controller.rb +4 -0
- data/spec/integrations/rails_3_2/app/helpers/application_helper.rb +2 -0
- data/spec/integrations/rails_3_2/app/models/post.rb +13 -0
- data/spec/integrations/rails_3_2/app/views/layouts/application.html.erb +13 -0
- data/spec/integrations/rails_3_2/app/views/welcome/index.html.erb +5 -0
- data/spec/integrations/rails_3_2/bin/rails +6 -0
- data/spec/integrations/rails_3_2/config.ru +4 -0
- data/spec/integrations/rails_3_2/config/application.rb +69 -0
- data/spec/integrations/rails_3_2/config/boot.rb +6 -0
- data/spec/integrations/rails_3_2/config/environment.rb +5 -0
- data/spec/integrations/rails_3_2/config/environments/development.rb +31 -0
- data/spec/integrations/rails_3_2/config/environments/production.rb +64 -0
- data/spec/integrations/rails_3_2/config/environments/test.rb +35 -0
- data/spec/integrations/rails_3_2/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/integrations/rails_3_2/config/initializers/inflections.rb +15 -0
- data/spec/integrations/rails_3_2/config/initializers/mime_types.rb +5 -0
- data/spec/integrations/rails_3_2/config/initializers/secret_token.rb +7 -0
- data/spec/integrations/rails_3_2/config/initializers/session_store.rb +8 -0
- data/spec/integrations/rails_3_2/config/initializers/wrap_parameters.rb +10 -0
- data/spec/integrations/rails_3_2/config/locales/en.yml +5 -0
- data/spec/integrations/rails_3_2/config/routes.rb +60 -0
- data/spec/integrations/rails_3_2/public/404.html +26 -0
- data/spec/integrations/rails_3_2/public/422.html +26 -0
- data/spec/integrations/rails_3_2/public/500.html +25 -0
- data/spec/integrations/rails_3_2/public/favicon.ico +0 -0
- data/spec/integrations/rails_3_2/public/robots.txt +5 -0
- data/spec/integrations/rails_3_2/test.sh +30 -0
- data/spec/integrations/rails_3_2/tmp/.keep +0 -0
- data/spec/integrations/rails_3_2/vendor/.gitkeep +0 -0
- data/spec/integrations/rails_4_2/.gitignore +10 -0
- data/spec/integrations/rails_4_2/Gemfile +8 -0
- data/spec/integrations/rails_4_2/README.rdoc +28 -0
- data/spec/integrations/rails_4_2/Rakefile +6 -0
- data/spec/integrations/rails_4_2/app/controllers/application_controller.rb +5 -0
- data/spec/integrations/rails_4_2/app/controllers/welcome_controller.rb +4 -0
- data/spec/integrations/rails_4_2/app/models/post.rb +13 -0
- data/spec/integrations/rails_4_2/app/views/layouts/application.html.erb +12 -0
- data/spec/integrations/rails_4_2/app/views/welcome/index.html.erb +5 -0
- data/spec/integrations/rails_4_2/bin/bundle +3 -0
- data/spec/integrations/rails_4_2/bin/rails +4 -0
- data/spec/integrations/rails_4_2/bin/rake +4 -0
- data/spec/integrations/rails_4_2/bin/setup +29 -0
- data/spec/integrations/rails_4_2/config.ru +4 -0
- data/spec/integrations/rails_4_2/config/application.rb +33 -0
- data/spec/integrations/rails_4_2/config/boot.rb +3 -0
- data/spec/integrations/rails_4_2/config/environment.rb +5 -0
- data/spec/integrations/rails_4_2/config/environments/development.rb +25 -0
- data/spec/integrations/rails_4_2/config/environments/production.rb +64 -0
- data/spec/integrations/rails_4_2/config/environments/test.rb +42 -0
- data/spec/integrations/rails_4_2/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/integrations/rails_4_2/config/initializers/cookies_serializer.rb +3 -0
- data/spec/integrations/rails_4_2/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/integrations/rails_4_2/config/initializers/inflections.rb +16 -0
- data/spec/integrations/rails_4_2/config/initializers/mime_types.rb +4 -0
- data/spec/integrations/rails_4_2/config/initializers/session_store.rb +3 -0
- data/spec/integrations/rails_4_2/config/initializers/to_time_preserves_timezone.rb +10 -0
- data/spec/integrations/rails_4_2/config/initializers/wrap_parameters.rb +9 -0
- data/spec/integrations/rails_4_2/config/locales/en.yml +23 -0
- data/spec/integrations/rails_4_2/config/routes.rb +56 -0
- data/spec/integrations/rails_4_2/config/secrets.yml +22 -0
- data/spec/integrations/rails_4_2/public/404.html +67 -0
- data/spec/integrations/rails_4_2/public/422.html +67 -0
- data/spec/integrations/rails_4_2/public/500.html +66 -0
- data/spec/integrations/rails_4_2/public/favicon.ico +0 -0
- data/spec/integrations/rails_4_2/public/robots.txt +5 -0
- data/spec/integrations/rails_4_2/test.sh +31 -0
- data/spec/integrations/rails_4_2/vendor/.keep +0 -0
- data/spec/integrations/rails_5_2/.gitignore +10 -0
- data/spec/integrations/rails_5_2/Gemfile +12 -0
- data/spec/integrations/rails_5_2/README.md +24 -0
- data/spec/integrations/rails_5_2/Rakefile +6 -0
- data/spec/integrations/rails_5_2/app/controllers/application_controller.rb +2 -0
- data/spec/integrations/rails_5_2/app/controllers/welcome_controller.rb +4 -0
- data/spec/integrations/rails_5_2/app/jobs/application_job.rb +2 -0
- data/spec/integrations/rails_5_2/app/models/post.rb +13 -0
- data/spec/integrations/rails_5_2/app/views/layouts/application.html.erb +12 -0
- data/spec/integrations/rails_5_2/app/views/welcome/index.html.erb +5 -0
- data/spec/integrations/rails_5_2/bin/bundle +3 -0
- data/spec/integrations/rails_5_2/bin/rails +4 -0
- data/spec/integrations/rails_5_2/bin/rake +4 -0
- data/spec/integrations/rails_5_2/bin/setup +25 -0
- data/spec/integrations/rails_5_2/bin/update +25 -0
- data/spec/integrations/rails_5_2/config.ru +5 -0
- data/spec/integrations/rails_5_2/config/application.rb +37 -0
- data/spec/integrations/rails_5_2/config/boot.rb +4 -0
- data/spec/integrations/rails_5_2/config/credentials.yml.enc +1 -0
- data/spec/integrations/rails_5_2/config/environment.rb +5 -0
- data/spec/integrations/rails_5_2/config/environments/development.rb +40 -0
- data/spec/integrations/rails_5_2/config/environments/production.rb +68 -0
- data/spec/integrations/rails_5_2/config/environments/test.rb +36 -0
- data/spec/integrations/rails_5_2/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/integrations/rails_5_2/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/integrations/rails_5_2/config/initializers/content_security_policy.rb +25 -0
- data/spec/integrations/rails_5_2/config/initializers/cookies_serializer.rb +5 -0
- data/spec/integrations/rails_5_2/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/integrations/rails_5_2/config/initializers/inflections.rb +16 -0
- data/spec/integrations/rails_5_2/config/initializers/mime_types.rb +4 -0
- data/spec/integrations/rails_5_2/config/initializers/wrap_parameters.rb +9 -0
- data/spec/integrations/rails_5_2/config/locales/en.yml +33 -0
- data/spec/integrations/rails_5_2/config/master.key +1 -0
- data/spec/integrations/rails_5_2/config/routes.rb +4 -0
- data/spec/integrations/rails_5_2/public/404.html +67 -0
- data/spec/integrations/rails_5_2/public/422.html +67 -0
- data/spec/integrations/rails_5_2/public/500.html +66 -0
- data/spec/integrations/rails_5_2/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/integrations/rails_5_2/public/apple-touch-icon.png +0 -0
- data/spec/integrations/rails_5_2/public/favicon.ico +0 -0
- data/spec/integrations/rails_5_2/public/robots.txt +1 -0
- data/spec/integrations/rails_5_2/test.sh +31 -0
- data/spec/integrations/rails_5_2/tmp/.keep +0 -0
- data/spec/integrations/rails_5_2/vendor/.keep +0 -0
- data/spec/spec_helper.rb +104 -0
- metadata +177 -25
- data/Gemfile.lock +0 -32
- data/bin/cypress +0 -3
- data/lib/cypress.rb +0 -27
- data/lib/cypress/configuration.rb +0 -41
- data/lib/cypress/middleware.rb +0 -69
- data/lib/cypress/runner.rb +0 -42
- data/lib/cypress/scenario_bank.rb +0 -21
- data/lib/cypress/scenario_context.rb +0 -23
- data/lib/cypress/version.rb +0 -3
- data/lib/generators/install_generator.rb +0 -77
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f03b1025928c7aaaba3a08b77efa93800e7c6c41466d31cbd7a28393c688eb51
|
4
|
+
data.tar.gz: 37ac42ef065a1395c74d85a657c255fdb227e60a081facbe1c02ddb7220cd773
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c6618a706b569855650adff6a0e38cc249684ad2c06e48ac222b58f96c34cec3f82923b5db9fa1ee35d3ba4c7c6bae9aa10b6ecc23efe9a2f6d3defd7b5a462
|
7
|
+
data.tar.gz: c5e78bb8eed8bc326dd4063311f7d3167fe30db3d0b346f641429c095eb46a97ad32f44a04e4396570c93545ba820a06ce8d6312befcf84d56515f081e17a71c
|
data/.gitignore
CHANGED
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
|
-
#
|
1
|
+
# CypressDev
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
20
|
-
```
|
28
|
+
bin/rails g cypress_dev:install
|
21
29
|
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
71
|
+
### Example of using scenarios
|
40
72
|
|
41
|
-
|
42
|
-
|
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
|
-
|
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.
|
50
|
-
Profile.create name: "Cypress Hill"
|
51
|
-
`)
|
90
|
+
cy.appScenario('basic')
|
52
91
|
|
53
|
-
|
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
|
-
|
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
|
-
|
102
|
+
```ruby
|
103
|
+
# spec/cypress/app_commands/scenarios/basic.rb
|
104
|
+
require 'cypress_dev/smart_factory_wrapper'
|
64
105
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
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.
|
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('
|
124
|
+
cy.visit('/')
|
85
125
|
|
86
|
-
cy.contains("
|
126
|
+
cy.contains("Hello World")
|
87
127
|
})
|
88
128
|
})
|
89
129
|
```
|
90
130
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
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
|
-
|
148
|
+
cy.contains("Seeds")
|
149
|
+
})
|
150
|
+
})
|
97
151
|
```
|
98
|
-
|
99
|
-
|
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
|
-
|
204
|
+
## Contributing
|
104
205
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
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
data/cypress-on-rails.gemspec
CHANGED
@@ -1,21 +1,22 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
$LOAD_PATH.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "
|
3
|
+
require "cypress_dev/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "cypress-on-rails"
|
7
|
-
s.version =
|
8
|
-
s.author = "miceportal team"
|
9
|
-
s.email = "info@miceportal.de"
|
10
|
-
s.homepage = "http://github.com/
|
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 '
|
19
|
-
s.
|
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
|
data/lib/cypress-on-rails.rb
CHANGED
data/lib/cypress_dev.rb
ADDED
@@ -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
|