cypress-on-rails 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -6
  3. data/CHANGELOG.md +4 -0
  4. data/README.md +61 -27
  5. data/lib/cypress_dev/version.rb +1 -1
  6. data/lib/generators/cypress_dev/install_generator.rb +7 -5
  7. data/lib/generators/cypress_dev/templates/spec/cypress/app_commands/activerecord_fixtures.rb +21 -0
  8. data/lib/generators/cypress_dev/templates/spec/cypress/app_commands/clean.rb +1 -0
  9. data/lib/generators/cypress_dev/templates/spec/cypress/app_commands/scenarios/basic.rb +2 -1
  10. data/lib/generators/cypress_dev/templates/spec/cypress/fixtures/example.json +5 -0
  11. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/actions.spec.js +272 -0
  12. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/aliasing.spec.js +42 -0
  13. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/assertions.spec.js +63 -0
  14. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/connectors.spec.js +55 -0
  15. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/cookies.spec.js +78 -0
  16. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/cypress_api.spec.js +211 -0
  17. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/files.spec.js +86 -0
  18. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/local_storage.spec.js +52 -0
  19. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/location.spec.js +32 -0
  20. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/misc.spec.js +68 -0
  21. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/navigation.spec.js +54 -0
  22. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/network_requests.spec.js +108 -0
  23. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/querying.spec.js +65 -0
  24. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/spies_stubs_clocks.spec.js +62 -0
  25. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/traversal.spec.js +121 -0
  26. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/utilities.spec.js +89 -0
  27. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/viewport.spec.js +59 -0
  28. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/waiting.spec.js +34 -0
  29. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/window.spec.js +22 -0
  30. data/lib/generators/cypress_dev/templates/spec/cypress/integration/rails_examples/other_spec.js +25 -0
  31. data/lib/generators/cypress_dev/templates/spec/cypress/integration/rails_examples/using_factory_bot.js +31 -0
  32. data/lib/generators/cypress_dev/templates/spec/cypress/integration/rails_examples/using_fixtures.js +33 -0
  33. data/lib/generators/cypress_dev/templates/spec/cypress/integration/rails_examples/using_scenarios_spec.js +26 -0
  34. data/lib/generators/cypress_dev/templates/spec/cypress/support/on-rails.js +7 -3
  35. data/spec/integrations/cypress.json +5 -0
  36. data/spec/integrations/rails_3_2/app/models/post.rb +4 -0
  37. data/spec/integrations/rails_3_2/app/views/welcome/index.html.erb +24 -5
  38. data/spec/integrations/rails_3_2/test.sh +9 -3
  39. data/spec/integrations/rails_4_2/.gitignore +5 -5
  40. data/spec/integrations/rails_4_2/app/models/post.rb +4 -0
  41. data/spec/integrations/rails_4_2/app/views/welcome/index.html.erb +24 -5
  42. data/spec/integrations/rails_4_2/test.sh +11 -4
  43. data/spec/integrations/rails_5_2/.gitignore +7 -5
  44. data/spec/integrations/rails_5_2/Gemfile +2 -0
  45. data/spec/integrations/rails_5_2/app/assets/javascripts/posts.js +2 -0
  46. data/spec/integrations/rails_5_2/app/assets/stylesheets/posts.css +4 -0
  47. data/spec/integrations/rails_5_2/app/assets/stylesheets/scaffold.css +80 -0
  48. data/spec/integrations/rails_5_2/app/controllers/posts_controller.rb +58 -0
  49. data/spec/integrations/rails_5_2/app/helpers/posts_helper.rb +2 -0
  50. data/spec/integrations/rails_5_2/app/models/application_record.rb +3 -0
  51. data/spec/integrations/rails_5_2/app/models/post.rb +1 -12
  52. data/spec/integrations/rails_5_2/app/views/posts/_form.html.erb +32 -0
  53. data/spec/integrations/rails_5_2/app/views/posts/edit.html.erb +6 -0
  54. data/spec/integrations/rails_5_2/app/views/posts/index.html.erb +31 -0
  55. data/spec/integrations/rails_5_2/app/views/posts/new.html.erb +5 -0
  56. data/spec/integrations/rails_5_2/app/views/posts/show.html.erb +19 -0
  57. data/spec/integrations/rails_5_2/config/application.rb +2 -2
  58. data/spec/integrations/rails_5_2/config/database.yml +15 -0
  59. data/spec/integrations/rails_5_2/config/routes.rb +2 -1
  60. data/spec/integrations/rails_5_2/db/migrate/20180621085832_create_posts.rb +11 -0
  61. data/spec/integrations/rails_5_2/test.sh +14 -5
  62. data/spec/integrations/rails_5_2/test/controllers/posts_controller_test.rb +48 -0
  63. data/spec/integrations/rails_5_2/test/cypress_fixtures/posts.yml +11 -0
  64. data/spec/integrations/rails_5_2/test/fixtures/posts.yml +11 -0
  65. data/spec/integrations/rails_5_2/test/models/post_test.rb +7 -0
  66. metadata +45 -4
  67. data/lib/generators/cypress_dev/templates/spec/cypress/integration/on_rails_spec.js +0 -33
  68. data/spec/integrations/rails_5_2/app/controllers/welcome_controller.rb +0 -4
@@ -0,0 +1,33 @@
1
+ describe('Rails using rails fixtures examples', function() {
2
+ beforeEach(() => {
3
+ cy.app('clean') // have a look at cypress/app_commands/clean.rb
4
+ })
5
+
6
+ it('loading all fixtures', function() {
7
+ cy.appFixtures()
8
+ cy.visit('/')
9
+ cy.get('table').find('tbody').should(($tbody) => {
10
+ expect($tbody).to.contain('MyRailsFixtures')
11
+ expect($tbody).to.contain('MyRailsFixtures2')
12
+ })
13
+ })
14
+
15
+ it('using single rails fixtures', function() {
16
+ cy.appFixtures({fixtures: ['posts']})
17
+ cy.visit('/')
18
+ cy.get('table').find('tbody').should(($tbody) => {
19
+ expect($tbody).to.contain('MyRailsFixtures')
20
+ expect($tbody).to.contain('MyRailsFixtures2')
21
+ })
22
+ })
23
+
24
+ it('loading another folder of fixtures', function() {
25
+ cy.appFixtures({fixtures_dir: 'test/cypress_fixtures' })
26
+ cy.visit('/')
27
+ cy.get('table').find('tbody').should(($tbody) => {
28
+ expect($tbody).to.contain('MyCypressFixtures')
29
+ expect($tbody).to.contain('MyCypressFixtures2')
30
+ })
31
+ })
32
+ })
33
+
@@ -0,0 +1,26 @@
1
+ describe('Rails using scenarios examples', function() {
2
+ beforeEach(() => {
3
+ cy.app('clean') // have a look at cypress/app_commands/clean.rb
4
+ })
5
+
6
+ it('setup basic scenario', function() {
7
+ cy.appScenario('basic')
8
+ cy.visit('/')
9
+ cy.get('table').find('tbody').should(($tbody) => {
10
+ // clean should of removed these from other tests
11
+ expect($tbody).not.to.contain('Good bye Mars')
12
+ expect($tbody).not.to.contain('Hello World')
13
+
14
+ expect($tbody).to.contain('I am a Postman')
15
+ })
16
+ })
17
+
18
+ // uncomment these if you want to see what happens
19
+ // it('example of missing scenario failure', function() {
20
+ // cy.appScenario('missing')
21
+ // })
22
+ //
23
+ // it('example of missing app failure', function() {
24
+ // cy.app('run_me')
25
+ // })
26
+ })
@@ -25,9 +25,13 @@ Cypress.Commands.add('appEval', function (code) {
25
25
  Cypress.Commands.add('appFactories', function (options) {
26
26
  cy.app('factory_bot', options)
27
27
  });
28
+
29
+ Cypress.Commands.add('appFixtures', function (options) {
30
+ cy.app('activerecord_fixtures', options)
31
+ });
28
32
  // CypressDev: end
29
33
 
30
34
  // The next is optional
31
- beforeEach(() => {
32
- cy.app('clean') // have a look at cypress/app_commands/clean.rb
33
- });
35
+ // beforeEach(() => {
36
+ // cy.app('clean') // have a look at cypress/app_commands/clean.rb
37
+ // });
@@ -0,0 +1,5 @@
1
+ {
2
+ "baseUrl": "http://localhost:5002",
3
+ "defaultCommandTimeout": 10000,
4
+ "projectId": "qvzwep"
5
+ }
@@ -10,4 +10,8 @@ class Post < OpenStruct
10
10
  @all ||= []
11
11
  @all
12
12
  end
13
+
14
+ def self.delete_all
15
+ @all = []
16
+ end
13
17
  end
@@ -1,5 +1,24 @@
1
- <h1>Welcome</h1>
2
- <p>Posts:</p>
3
- <% Post.all.each do |post| %>
4
- <p><%= post.inspect %></p>
5
- <% end %>
1
+ <h1>Posts</h1>
2
+
3
+ <table>
4
+ <thead>
5
+ <tr>
6
+ <th>Title</th>
7
+ <th>Body</th>
8
+ <th>Published</th>
9
+ <th colspan="3"></th>
10
+ </tr>
11
+ </thead>
12
+
13
+ <tbody>
14
+ <% Post.all.each do |post| %>
15
+ <tr>
16
+ <td><%= post.title %></td>
17
+ <td><%= post.body %></td>
18
+ <td><%= post.published %></td>
19
+ </tr>
20
+ <% end %>
21
+ </tbody>
22
+ </table>
23
+
24
+ <br>
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env bash
2
- set -euo pipefail
2
+ set -eo pipefail
3
3
 
4
4
  echo '--- testing rails 3.2'
5
5
 
@@ -14,7 +14,7 @@ bundle --version
14
14
  bundle install --quiet --gemfile="$DIR/Gemfile" --retry 2 --path vendor/bundle
15
15
 
16
16
  echo '-- cypress install'
17
- bundle exec ./bin/rails g cypress_dev:install --cypress_folder=cypress --install_cypress_with=npm
17
+ bundle exec ./bin/rails g cypress_dev:install --cypress_folder=cypress --install_cypress_with=npm --no-install-cypress-examples
18
18
 
19
19
  echo '-- start rails server'
20
20
  # make sure the server is not running
@@ -24,7 +24,13 @@ bundle exec ./bin/rails server -p 5002 -e test &
24
24
  sleep 2 # give rails a chance to start up correctly
25
25
 
26
26
  echo '-- cypress run'
27
- node_modules/.bin/cypress run
27
+ cp -fv ../cypress.json .
28
+ if [ -z $CYPRESS_RECORD_KEY ]
29
+ then
30
+ node_modules/.bin/cypress run
31
+ else
32
+ node_modules/.bin/cypress run --record
33
+ fi
28
34
 
29
35
  echo '-- stop rails server'
30
36
  kill -9 `cat tmp/pids/server.pid`
@@ -1,9 +1,9 @@
1
1
  .bundle
2
- test/node_modules
3
- test/cypress.json
4
- test/package.json
5
- test/yarn.lock
6
- test/cypress
2
+ spec/node_modules
3
+ spec/cypress.json
4
+ spec/package.json
5
+ spec/yarn.lock
6
+ spec/cypress
7
7
  config/initializers/cypress_dev.rb
8
8
  vendor/bundle
9
9
  tmp/pids
@@ -10,4 +10,8 @@ class Post < OpenStruct
10
10
  @all ||= []
11
11
  @all
12
12
  end
13
+
14
+ def self.delete_all
15
+ @all = []
16
+ end
13
17
  end
@@ -1,5 +1,24 @@
1
- <h1>Welcome</h1>
2
- <p>Posts:</p>
3
- <% Post.all.each do |post| %>
4
- <p><%= post.inspect %></p>
5
- <% end %>
1
+ <h1>Posts</h1>
2
+
3
+ <table>
4
+ <thead>
5
+ <tr>
6
+ <th>Title</th>
7
+ <th>Body</th>
8
+ <th>Published</th>
9
+ <th colspan="3"></th>
10
+ </tr>
11
+ </thead>
12
+
13
+ <tbody>
14
+ <% Post.all.each do |post| %>
15
+ <tr>
16
+ <td><%= post.title %></td>
17
+ <td><%= post.body %></td>
18
+ <td><%= post.published %></td>
19
+ </tr>
20
+ <% end %>
21
+ </tbody>
22
+ </table>
23
+
24
+ <br>
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env bash
2
- set -euo pipefail
2
+ set -eo pipefail
3
3
 
4
4
  echo '--- testing rails 4.2'
5
5
 
@@ -14,7 +14,7 @@ bundle --version
14
14
  bundle install --quiet --gemfile="$DIR/Gemfile" --retry 2 --path vendor/bundle
15
15
 
16
16
  echo '-- cypress install'
17
- bundle exec ./bin/rails g cypress_dev:install --cypress_folder=test/cypress
17
+ bundle exec ./bin/rails g cypress_dev:install
18
18
 
19
19
  echo '-- start rails server'
20
20
  # make sure the server is not running
@@ -24,8 +24,15 @@ bundle exec ./bin/rails server -p 5002 -e test &
24
24
  sleep 2 # give rails a chance to start up correctly
25
25
 
26
26
  echo '-- cypress run'
27
- cd test
28
- yarn run cypress run
27
+ cp -fv ../cypress.json spec/
28
+ cd spec
29
+ if [ -z $CYPRESS_RECORD_KEY ]
30
+ then
31
+ yarn run cypress run
32
+ else
33
+ yarn run cypress run --record
34
+ fi
35
+
29
36
 
30
37
  echo '-- stop rails server'
31
38
  kill -9 `cat ../tmp/pids/server.pid`
@@ -1,10 +1,12 @@
1
1
  .bundle
2
- spec/node_modules
3
- spec/cypress.json
4
- spec/package.json
5
- spec/yarn.lock
6
- spec/cypress/
2
+ test/node_modules
3
+ test/cypress.json
4
+ test/package.json
5
+ test/yarn.lock
6
+ test/cypress/
7
7
  config/initializers/cypress_dev.rb
8
8
  vendor/bundle
9
9
  tmp/pids
10
+ db/*.sqlite3
11
+ db/schema.rb
10
12
  tmp/cache
@@ -3,10 +3,12 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
3
 
4
4
  # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
5
5
  gem 'rails', '~> 5.2.0'
6
+ gem 'sqlite3'
6
7
 
7
8
  # Reduces boot times through caching; required in config/boot.rb
8
9
  gem 'bootsnap', '>= 1.1.0', require: false
9
10
 
10
11
  group :development, :test do
12
+ gem 'database_cleaner'
11
13
  gem 'cypress-on-rails', path: '../../../'
12
14
  end
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,80 @@
1
+ body {
2
+ background-color: #fff;
3
+ color: #333;
4
+ margin: 33px;
5
+ }
6
+
7
+ body, p, ol, ul, td {
8
+ font-family: verdana, arial, helvetica, sans-serif;
9
+ font-size: 13px;
10
+ line-height: 18px;
11
+ }
12
+
13
+ pre {
14
+ background-color: #eee;
15
+ padding: 10px;
16
+ font-size: 11px;
17
+ }
18
+
19
+ a {
20
+ color: #000;
21
+ }
22
+
23
+ a:visited {
24
+ color: #666;
25
+ }
26
+
27
+ a:hover {
28
+ color: #fff;
29
+ background-color: #000;
30
+ }
31
+
32
+ th {
33
+ padding-bottom: 5px;
34
+ }
35
+
36
+ td {
37
+ padding: 0 5px 7px;
38
+ }
39
+
40
+ div.field,
41
+ div.actions {
42
+ margin-bottom: 10px;
43
+ }
44
+
45
+ #notice {
46
+ color: green;
47
+ }
48
+
49
+ .field_with_errors {
50
+ padding: 2px;
51
+ background-color: red;
52
+ display: table;
53
+ }
54
+
55
+ #error_explanation {
56
+ width: 450px;
57
+ border: 2px solid red;
58
+ padding: 7px 7px 0;
59
+ margin-bottom: 20px;
60
+ background-color: #f0f0f0;
61
+ }
62
+
63
+ #error_explanation h2 {
64
+ text-align: left;
65
+ font-weight: bold;
66
+ padding: 5px 5px 5px 15px;
67
+ font-size: 12px;
68
+ margin: -7px -7px 0;
69
+ background-color: #c00;
70
+ color: #fff;
71
+ }
72
+
73
+ #error_explanation ul li {
74
+ font-size: 12px;
75
+ list-style: square;
76
+ }
77
+
78
+ label {
79
+ display: block;
80
+ }
@@ -0,0 +1,58 @@
1
+ class PostsController < ApplicationController
2
+ before_action :set_post, only: [:show, :edit, :update, :destroy]
3
+
4
+ # GET /posts
5
+ def index
6
+ @posts = Post.all
7
+ end
8
+
9
+ # GET /posts/1
10
+ def show
11
+ end
12
+
13
+ # GET /posts/new
14
+ def new
15
+ @post = Post.new
16
+ end
17
+
18
+ # GET /posts/1/edit
19
+ def edit
20
+ end
21
+
22
+ # POST /posts
23
+ def create
24
+ @post = Post.new(post_params)
25
+
26
+ if @post.save
27
+ redirect_to @post, notice: 'Post was successfully created.'
28
+ else
29
+ render :new
30
+ end
31
+ end
32
+
33
+ # PATCH/PUT /posts/1
34
+ def update
35
+ if @post.update(post_params)
36
+ redirect_to @post, notice: 'Post was successfully updated.'
37
+ else
38
+ render :edit
39
+ end
40
+ end
41
+
42
+ # DELETE /posts/1
43
+ def destroy
44
+ @post.destroy
45
+ redirect_to posts_url, notice: 'Post was successfully destroyed.'
46
+ end
47
+
48
+ private
49
+ # Use callbacks to share common setup or constraints between actions.
50
+ def set_post
51
+ @post = Post.find(params[:id])
52
+ end
53
+
54
+ # Only allow a trusted parameter "white list" through.
55
+ def post_params
56
+ params.require(:post).permit(:title, :body, :published)
57
+ end
58
+ end
@@ -0,0 +1,2 @@
1
+ module PostsHelper
2
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end
@@ -1,13 +1,2 @@
1
- class Post < OpenStruct
2
- def self.create(attributes)
3
- @all ||= []
4
- post = new(attributes)
5
- @all << post
6
- attributes['all'] = @all.index(post)
7
- end
8
-
9
- def self.all
10
- @all ||= []
11
- @all
12
- end
1
+ class Post < ApplicationRecord
13
2
  end