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,42 @@
1
+ /// <reference types="Cypress" />
2
+
3
+ context('Aliasing', () => {
4
+ beforeEach(() => {
5
+ cy.visit('https://example.cypress.io/commands/aliasing')
6
+ })
7
+
8
+ it('.as() - alias a DOM element for later use', () => {
9
+ // https://on.cypress.io/as
10
+
11
+ // Alias a DOM element for use later
12
+ // We don't have to traverse to the element
13
+ // later in our code, we reference it with @
14
+
15
+ cy.get('.as-table').find('tbody>tr')
16
+ .first().find('td').first()
17
+ .find('button').as('firstBtn')
18
+
19
+ // when we reference the alias, we place an
20
+ // @ in front of its name
21
+ cy.get('@firstBtn').click()
22
+
23
+ cy.get('@firstBtn')
24
+ .should('have.class', 'btn-success')
25
+ .and('contain', 'Changed')
26
+ })
27
+
28
+ it('.as() - alias a route for later use', () => {
29
+
30
+ // Alias the route to wait for its response
31
+ cy.server()
32
+ cy.route('GET', 'comments/*').as('getComment')
33
+
34
+ // we have code that gets a comment when
35
+ // the button is clicked in scripts.js
36
+ cy.get('.network-btn').click()
37
+
38
+ // https://on.cypress.io/wait
39
+ cy.wait('@getComment').its('status').should('eq', 200)
40
+
41
+ })
42
+ })
@@ -0,0 +1,63 @@
1
+ /// <reference types="Cypress" />
2
+
3
+ context('Assertions', () => {
4
+ beforeEach(() => {
5
+ cy.visit('https://example.cypress.io/commands/assertions')
6
+ })
7
+
8
+ describe('Implicit Assertions', () => {
9
+
10
+ it('.should() - make an assertion about the current subject', () => {
11
+ // https://on.cypress.io/should
12
+ cy.get('.assertion-table')
13
+ .find('tbody tr:last').should('have.class', 'success')
14
+ })
15
+
16
+ it('.and() - chain multiple assertions together', () => {
17
+ // https://on.cypress.io/and
18
+ cy.get('.assertions-link')
19
+ .should('have.class', 'active')
20
+ .and('have.attr', 'href')
21
+ .and('include', 'cypress.io')
22
+ })
23
+ })
24
+
25
+ describe('Explicit Assertions', () => {
26
+ // https://on.cypress.io/assertions
27
+ it('expect - make an assertion about a specified subject', () => {
28
+ // We can use Chai's BDD style assertions
29
+ expect(true).to.be.true
30
+
31
+ // Pass a function to should that can have any number
32
+ // of explicit assertions within it.
33
+ cy.get('.assertions-p').find('p')
34
+ .should(($p) => {
35
+ // return an array of texts from all of the p's
36
+ let texts = $p.map((i, el) => // https://on.cypress.io/$
37
+ Cypress.$(el).text())
38
+
39
+ // jquery map returns jquery object
40
+ // and .get() convert this to simple array
41
+ texts = texts.get()
42
+
43
+ // array should have length of 3
44
+ expect(texts).to.have.length(3)
45
+
46
+ // set this specific subject
47
+ expect(texts).to.deep.eq([
48
+ 'Some text from first p',
49
+ 'More text from second p',
50
+ 'And even more text from third p',
51
+ ])
52
+ })
53
+ })
54
+
55
+ it('assert - assert shape of an object', () => {
56
+ const person = {
57
+ name: 'Joe',
58
+ age: 20,
59
+ }
60
+ assert.isObject(person, 'value is object')
61
+ })
62
+ })
63
+ })
@@ -0,0 +1,55 @@
1
+ /// <reference types="Cypress" />
2
+
3
+ context('Connectors', () => {
4
+ beforeEach(() => {
5
+ cy.visit('https://example.cypress.io/commands/connectors')
6
+ })
7
+
8
+ it('.each() - iterate over an array of elements', () => {
9
+ // https://on.cypress.io/each
10
+ cy.get('.connectors-each-ul>li')
11
+ .each(($el, index, $list) => {
12
+ console.log($el, index, $list)
13
+ })
14
+ })
15
+
16
+ it('.its() - get properties on the current subject', () => {
17
+ // https://on.cypress.io/its
18
+ cy.get('.connectors-its-ul>li')
19
+ // calls the 'length' property yielding that value
20
+ .its('length')
21
+ .should('be.gt', 2)
22
+ })
23
+
24
+ it('.invoke() - invoke a function on the current subject', () => {
25
+ // our div is hidden in our script.js
26
+ // $('.connectors-div').hide()
27
+
28
+ // https://on.cypress.io/invoke
29
+ cy.get('.connectors-div').should('be.hidden')
30
+ // call the jquery method 'show' on the 'div.container'
31
+ .invoke('show')
32
+ .should('be.visible')
33
+ })
34
+
35
+ it('.spread() - spread an array as individual args to callback function', () => {
36
+ // https://on.cypress.io/spread
37
+ const arr = ['foo', 'bar', 'baz']
38
+
39
+ cy.wrap(arr).spread((foo, bar, baz) => {
40
+ expect(foo).to.eq('foo')
41
+ expect(bar).to.eq('bar')
42
+ expect(baz).to.eq('baz')
43
+ })
44
+ })
45
+
46
+ it('.then() - invoke a callback function with the current subject', () => {
47
+ // https://on.cypress.io/then
48
+ cy.get('.connectors-list>li').then(($lis) => {
49
+ expect($lis).to.have.length(3)
50
+ expect($lis.eq(0)).to.contain('Walk the dog')
51
+ expect($lis.eq(1)).to.contain('Feed the cat')
52
+ expect($lis.eq(2)).to.contain('Write JavaScript')
53
+ })
54
+ })
55
+ })
@@ -0,0 +1,78 @@
1
+ /// <reference types="Cypress" />
2
+
3
+ context('Cookies', () => {
4
+ beforeEach(() => {
5
+ Cypress.Cookies.debug(true)
6
+
7
+ cy.visit('https://example.cypress.io/commands/cookies')
8
+
9
+ // clear cookies again after visiting to remove
10
+ // any 3rd party cookies picked up such as cloudflare
11
+ cy.clearCookies()
12
+ })
13
+
14
+ it('cy.getCookie() - get a browser cookie', () => {
15
+ // https://on.cypress.io/getcookie
16
+ cy.get('#getCookie .set-a-cookie').click()
17
+
18
+ // cy.getCookie() yields a cookie object
19
+ cy.getCookie('token').should('have.property', 'value', '123ABC')
20
+ })
21
+
22
+ it('cy.getCookies() - get browser cookies', () => {
23
+ // https://on.cypress.io/getcookies
24
+ cy.getCookies().should('be.empty')
25
+
26
+ cy.get('#getCookies .set-a-cookie').click()
27
+
28
+ // cy.getCookies() yields an array of cookies
29
+ cy.getCookies().should('have.length', 1).should((cookies) => {
30
+
31
+ // each cookie has these properties
32
+ expect(cookies[0]).to.have.property('name', 'token')
33
+ expect(cookies[0]).to.have.property('value', '123ABC')
34
+ expect(cookies[0]).to.have.property('httpOnly', false)
35
+ expect(cookies[0]).to.have.property('secure', false)
36
+ expect(cookies[0]).to.have.property('domain')
37
+ expect(cookies[0]).to.have.property('path')
38
+ })
39
+ })
40
+
41
+ it('cy.setCookie() - set a browser cookie', () => {
42
+ // https://on.cypress.io/setcookie
43
+ cy.getCookies().should('be.empty')
44
+
45
+ cy.setCookie('foo', 'bar')
46
+
47
+ // cy.getCookie() yields a cookie object
48
+ cy.getCookie('foo').should('have.property', 'value', 'bar')
49
+ })
50
+
51
+ it('cy.clearCookie() - clear a browser cookie', () => {
52
+ // https://on.cypress.io/clearcookie
53
+ cy.getCookie('token').should('be.null')
54
+
55
+ cy.get('#clearCookie .set-a-cookie').click()
56
+
57
+ cy.getCookie('token').should('have.property', 'value', '123ABC')
58
+
59
+ // cy.clearCookies() yields null
60
+ cy.clearCookie('token').should('be.null')
61
+
62
+ cy.getCookie('token').should('be.null')
63
+ })
64
+
65
+ it('cy.clearCookies() - clear browser cookies', () => {
66
+ // https://on.cypress.io/clearcookies
67
+ cy.getCookies().should('be.empty')
68
+
69
+ cy.get('#clearCookies .set-a-cookie').click()
70
+
71
+ cy.getCookies().should('have.length', 1)
72
+
73
+ // cy.clearCookies() yields null
74
+ cy.clearCookies()
75
+
76
+ cy.getCookies().should('be.empty')
77
+ })
78
+ })
@@ -0,0 +1,211 @@
1
+ /// <reference types="Cypress" />
2
+
3
+ context('Cypress.Commands', () => {
4
+ beforeEach(() => {
5
+ cy.visit('https://example.cypress.io/cypress-api')
6
+ })
7
+
8
+ // https://on.cypress.io/custom-commands
9
+
10
+ it('.add() - create a custom command', () => {
11
+ Cypress.Commands.add('console', {
12
+ prevSubject: true,
13
+ }, (subject, method) => {
14
+ // the previous subject is automatically received
15
+ // and the commands arguments are shifted
16
+
17
+ // allow us to change the console method used
18
+ method = method || 'log'
19
+
20
+ // log the subject to the console
21
+ console[method]('The subject is', subject)
22
+
23
+ // whatever we return becomes the new subject
24
+ // we don't want to change the subject so
25
+ // we return whatever was passed in
26
+ return subject
27
+ })
28
+
29
+ cy.get('button').console('info').then(($button) => {
30
+ // subject is still $button
31
+ })
32
+ })
33
+ })
34
+
35
+
36
+ context('Cypress.Cookies', () => {
37
+ beforeEach(() => {
38
+ cy.visit('https://example.cypress.io/cypress-api')
39
+ })
40
+
41
+ // https://on.cypress.io/cookies
42
+ it('.debug() - enable or disable debugging', () => {
43
+ Cypress.Cookies.debug(true)
44
+
45
+ // Cypress will now log in the console when
46
+ // cookies are set or cleared
47
+ cy.setCookie('fakeCookie', '123ABC')
48
+ cy.clearCookie('fakeCookie')
49
+ cy.setCookie('fakeCookie', '123ABC')
50
+ cy.clearCookie('fakeCookie')
51
+ cy.setCookie('fakeCookie', '123ABC')
52
+ })
53
+
54
+ it('.preserveOnce() - preserve cookies by key', () => {
55
+ // normally cookies are reset after each test
56
+ cy.getCookie('fakeCookie').should('not.be.ok')
57
+
58
+ // preserving a cookie will not clear it when
59
+ // the next test starts
60
+ cy.setCookie('lastCookie', '789XYZ')
61
+ Cypress.Cookies.preserveOnce('lastCookie')
62
+ })
63
+
64
+ it('.defaults() - set defaults for all cookies', () => {
65
+ // now any cookie with the name 'session_id' will
66
+ // not be cleared before each new test runs
67
+ Cypress.Cookies.defaults({
68
+ whitelist: 'session_id',
69
+ })
70
+ })
71
+ })
72
+
73
+
74
+ context('Cypress.Server', () => {
75
+ beforeEach(() => {
76
+ cy.visit('https://example.cypress.io/cypress-api')
77
+ })
78
+
79
+ // Permanently override server options for
80
+ // all instances of cy.server()
81
+
82
+ // https://on.cypress.io/cypress-server
83
+ it('.defaults() - change default config of server', () => {
84
+ Cypress.Server.defaults({
85
+ delay: 0,
86
+ force404: false,
87
+ whitelist (xhr) {
88
+ // handle custom logic for whitelisting
89
+ },
90
+ })
91
+ })
92
+ })
93
+
94
+ context('Cypress.arch', () => {
95
+ beforeEach(() => {
96
+ cy.visit('https://example.cypress.io/cypress-api')
97
+ })
98
+
99
+ it('Get CPU architecture name of underlying OS', () => {
100
+ // https://on.cypress.io/arch
101
+ expect(Cypress.arch).to.exist
102
+ })
103
+ })
104
+
105
+ context('Cypress.config()', () => {
106
+ beforeEach(() => {
107
+ cy.visit('https://example.cypress.io/cypress-api')
108
+ })
109
+
110
+ it('Get and set configuration options', () => {
111
+ // https://on.cypress.io/config
112
+ let myConfig = Cypress.config()
113
+
114
+ expect(myConfig).to.have.property('animationDistanceThreshold', 5)
115
+ expect(myConfig).to.have.property('baseUrl', 'http://localhost:5002')
116
+ expect(myConfig).to.have.property('defaultCommandTimeout', 10000)
117
+ expect(myConfig).to.have.property('requestTimeout', 5000)
118
+ expect(myConfig).to.have.property('responseTimeout', 30000)
119
+ expect(myConfig).to.have.property('viewportHeight', 660)
120
+ expect(myConfig).to.have.property('viewportWidth', 1000)
121
+ expect(myConfig).to.have.property('pageLoadTimeout', 60000)
122
+ expect(myConfig).to.have.property('waitForAnimations', true)
123
+
124
+ expect(Cypress.config('pageLoadTimeout')).to.eq(60000)
125
+
126
+ // this will change the config for the rest of your tests!
127
+ Cypress.config('pageLoadTimeout', 20000)
128
+
129
+ expect(Cypress.config('pageLoadTimeout')).to.eq(20000)
130
+
131
+ Cypress.config('pageLoadTimeout', 60000)
132
+ })
133
+ })
134
+
135
+ context('Cypress.dom', () => {
136
+ beforeEach(() => {
137
+ cy.visit('https://example.cypress.io/cypress-api')
138
+ })
139
+
140
+ // https://on.cypress.io/dom
141
+ it('.isHidden() - determine if a DOM element is hidden', () => {
142
+ let hiddenP = Cypress.$('.dom-p p.hidden').get(0)
143
+ let visibleP = Cypress.$('.dom-p p.visible').get(0)
144
+
145
+ // our first paragraph has css class 'hidden'
146
+ expect(Cypress.dom.isHidden(hiddenP)).to.be.true
147
+ expect(Cypress.dom.isHidden(visibleP)).to.be.false
148
+ })
149
+ })
150
+
151
+ context('Cypress.env()', () => {
152
+ beforeEach(() => {
153
+ cy.visit('https://example.cypress.io/cypress-api')
154
+ })
155
+
156
+ // We can set environment variables for highly dynamic values
157
+
158
+ // https://on.cypress.io/environment-variables
159
+ it('Get environment variables', () => {
160
+ // https://on.cypress.io/env
161
+ // set multiple environment variables
162
+ Cypress.env({
163
+ host: 'veronica.dev.local',
164
+ api_server: 'http://localhost:8888/v1/',
165
+ })
166
+
167
+ // get environment variable
168
+ expect(Cypress.env('host')).to.eq('veronica.dev.local')
169
+
170
+ // set environment variable
171
+ Cypress.env('api_server', 'http://localhost:8888/v2/')
172
+ expect(Cypress.env('api_server')).to.eq('http://localhost:8888/v2/')
173
+
174
+ // get all environment variable
175
+ expect(Cypress.env()).to.have.property('host', 'veronica.dev.local')
176
+ expect(Cypress.env()).to.have.property('api_server', 'http://localhost:8888/v2/')
177
+ })
178
+ })
179
+
180
+ context('Cypress.log', () => {
181
+ beforeEach(() => {
182
+ cy.visit('https://example.cypress.io/cypress-api')
183
+ })
184
+
185
+ it('Control what is printed to the Command Log', () => {
186
+ // https://on.cypress.io/cypress-log
187
+ })
188
+ })
189
+
190
+
191
+ context('Cypress.platform', () => {
192
+ beforeEach(() => {
193
+ cy.visit('https://example.cypress.io/cypress-api')
194
+ })
195
+
196
+ it('Get underlying OS name', () => {
197
+ // https://on.cypress.io/platform
198
+ expect(Cypress.platform).to.be.exist
199
+ })
200
+ })
201
+
202
+ context('Cypress.version', () => {
203
+ beforeEach(() => {
204
+ cy.visit('https://example.cypress.io/cypress-api')
205
+ })
206
+
207
+ it('Get current version of Cypress being run', () => {
208
+ // https://on.cypress.io/version
209
+ expect(Cypress.version).to.be.exist
210
+ })
211
+ })