cypress-on-rails 1.10.1 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -2
- data/README.md +39 -1
- data/lib/cypress_on_rails/smart_factory_wrapper.rb +25 -1
- data/lib/cypress_on_rails/version.rb +1 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress/support/on-rails.js +6 -4
- data/spec/cypress_on_rails/smart_factory_wrapper_spec.rb +26 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b8019daab6920154502f30e3a0bc5acb508d3e54cb7befe5274442b70724e02
|
4
|
+
data.tar.gz: 626901503a647087b14785b8d0df09c1033a01be4cf4f8456beeed376880f5a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7379070d5df5642e4d9c45dcd3b935784278b409dde546dd9d8e334d54c473f5b3daf1b0061edc9dcabf2b15d3e1b0a6cf4fb9e75ce7d3bf2bf527f0af29dd85
|
7
|
+
data.tar.gz: 65dde5afa09ef3a862a19928cd76ead9c5f2755c4c15d22c3b978882ae58393ffbbe8799c4e1e6641301fcd20bb82342220029679443249bf8f1671b91c25c83
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
|
-
## [1.
|
2
|
-
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.
|
1
|
+
## [1.11.0]
|
2
|
+
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.10.1...v1.11.0
|
3
|
+
|
4
|
+
### Changed
|
5
|
+
* improve app command logging on cypress
|
6
|
+
* Allow build and build_list commands to be executed against factory bot [PR 87](https://github.com/shakacode/cypress-on-rails/pull/87) by [Alexander-Blair]
|
7
|
+
|
8
|
+
## [1.10.1]
|
9
|
+
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.9.1...v1.10.1
|
3
10
|
|
4
11
|
### Changed
|
5
12
|
* improve error message received from failed command
|
data/README.md
CHANGED
@@ -4,7 +4,9 @@
|
|
4
4
|
|
5
5
|
----
|
6
6
|
|
7
|
-
This project is sponsored by the software consulting firm [ShakaCode](https://www.shakacode.com), creator of the [React on Rails Gem](https://github.com/shakacode/react_on_rails). We focus on React front-ends, often with Ruby on Rails or Gatsby.
|
7
|
+
This project is sponsored by the software consulting firm [ShakaCode](https://www.shakacode.com), creator of the [React on Rails Gem](https://github.com/shakacode/react_on_rails). We focus on React (with TS or ReScript) front-ends, often with Ruby on Rails or Gatsby. See [our recent work](https://www.shakacode.com/recent-work) and [client engagement model](https://www.shakacode.com/blog/client-engagement-model/). Feel free to engage in discussions around this gem at our [Slack Channel](https://join.slack.com/t/reactrails/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE) or our [forum category for Cypress](https://forum.shakacode.com/c/cypress-on-rails/55).
|
8
|
+
|
9
|
+
Interested in joining a small team that loves open source? Check our [careers page](https://www.shakacode.com/career/).
|
8
10
|
|
9
11
|
----
|
10
12
|
|
@@ -164,6 +166,42 @@ describe('My First Test', function() {
|
|
164
166
|
})
|
165
167
|
```
|
166
168
|
|
169
|
+
In some cases, using static Cypress fixtures may not provide sufficient flexibility when mocking HTTP response bodies - it's possible to use `FactoryBot.build` to generate Ruby hashes that can then be used as mock JSON responses:
|
170
|
+
```ruby
|
171
|
+
FactoryBot.define do
|
172
|
+
factory :some_web_response, class: Hash do
|
173
|
+
initialize_with { attributes.deep_stringify_keys }
|
174
|
+
|
175
|
+
id { 123 }
|
176
|
+
name { 'Mr Blobby' }
|
177
|
+
occupation { 'Evil pink clown' }
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
FactoryBot.build(:some_web_response) => { 'id' => 123, 'name' => 'Mr Blobby', 'occupation' => 'Evil pink clown' }
|
182
|
+
```
|
183
|
+
|
184
|
+
This can then be combined with Cypress mocks:
|
185
|
+
```js
|
186
|
+
describe('My First Test', function() {
|
187
|
+
it('visit root', function() {
|
188
|
+
// This calls to the backend to generate the mocked response
|
189
|
+
cy.appFactories([
|
190
|
+
['build', 'some_web_response', { name: 'Baby Blobby' }]
|
191
|
+
]).then(([responseBody]) => {
|
192
|
+
cy.intercept('http://some-external-url.com/endpoint', {
|
193
|
+
body: responseBody
|
194
|
+
});
|
195
|
+
|
196
|
+
// Visit the application under test
|
197
|
+
cy.visit('/')
|
198
|
+
})
|
199
|
+
|
200
|
+
cy.contains("Hello World")
|
201
|
+
})
|
202
|
+
})
|
203
|
+
```
|
204
|
+
|
167
205
|
### Example of loading rails test fixtures
|
168
206
|
```ruby
|
169
207
|
# spec/cypress/app_commands/activerecord_fixtures.rb
|
@@ -19,6 +19,14 @@ module CypressOnRails
|
|
19
19
|
instance.create_list(*args)
|
20
20
|
end
|
21
21
|
|
22
|
+
def self.build(*args)
|
23
|
+
instance.build(*args)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.build_list(*args)
|
27
|
+
instance.build_list(*args)
|
28
|
+
end
|
29
|
+
|
22
30
|
# @return [Array]
|
23
31
|
attr_accessor :factory
|
24
32
|
attr_accessor :always_reload
|
@@ -51,6 +59,22 @@ module CypressOnRails
|
|
51
59
|
factory.create_list(*args)
|
52
60
|
end
|
53
61
|
|
62
|
+
def build(*options)
|
63
|
+
load_files
|
64
|
+
factory_name = options.shift
|
65
|
+
if options.last.is_a?(Hash)
|
66
|
+
args = options.pop
|
67
|
+
else
|
68
|
+
args = {}
|
69
|
+
end
|
70
|
+
factory.build(factory_name, *options.map(&:to_sym), args.symbolize_keys)
|
71
|
+
end
|
72
|
+
|
73
|
+
def build_list(*args)
|
74
|
+
load_files
|
75
|
+
factory.build_list(*args)
|
76
|
+
end
|
77
|
+
|
54
78
|
private
|
55
79
|
|
56
80
|
# @param [String,Array] arg
|
@@ -84,4 +108,4 @@ module CypressOnRails
|
|
84
108
|
@always_reload || @latest_mtime.nil? || @latest_mtime < current_latest_mtime
|
85
109
|
end
|
86
110
|
end
|
87
|
-
end
|
111
|
+
end
|
@@ -1,16 +1,18 @@
|
|
1
1
|
// CypressOnRails: dont remove these command
|
2
2
|
Cypress.Commands.add('appCommands', function (body) {
|
3
|
-
|
3
|
+
Object.keys(body).forEach(key => body[key] === undefined ? delete body[key] : {});
|
4
|
+
const log = Cypress.log({ name: "APP", message: body, autoEnd: false })
|
4
5
|
return cy.request({
|
5
6
|
method: 'POST',
|
6
7
|
url: "/__cypress__/command",
|
7
8
|
body: JSON.stringify(body),
|
8
|
-
log:
|
9
|
+
log: false,
|
9
10
|
failOnStatusCode: false
|
10
11
|
}).then((response) => {
|
11
|
-
|
12
|
+
log.end();
|
13
|
+
if (response.status !== 201) {
|
12
14
|
expect(response.body.message).to.be.empty
|
13
|
-
expect(response.
|
15
|
+
expect(response.status).to.be.equal(201)
|
14
16
|
}
|
15
17
|
return response.body
|
16
18
|
});
|
@@ -12,7 +12,7 @@ RSpec.describe CypressOnRails::SmartFactoryWrapper do
|
|
12
12
|
let(:mtime_hash) { {'file1.rb' => time_now, 'file2.rb' => time_now } }
|
13
13
|
let(:files) { %w(file1.rb file2.rb) }
|
14
14
|
let(:factory_double) do
|
15
|
-
class_double(FactoryBot, create: nil, create_list: nil, "definition_file_paths=": nil, reload: nil)
|
15
|
+
class_double(FactoryBot, create: nil, create_list: nil, build: nil, build_list: nil, "definition_file_paths=": nil, reload: nil)
|
16
16
|
end
|
17
17
|
let(:kernel_double) { class_double(Kernel, load: true) }
|
18
18
|
let(:file_double) { FileSystemDummy.new(mtime_hash) }
|
@@ -67,6 +67,31 @@ RSpec.describe CypressOnRails::SmartFactoryWrapper do
|
|
67
67
|
expect(factory_double).to have_received(:create_list).with(:note, 10)
|
68
68
|
end
|
69
69
|
|
70
|
+
it 'delegates build to the factory' do
|
71
|
+
subject.build(:user)
|
72
|
+
expect(factory_double).to have_received(:build).with(:user, {})
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'delegates build to the factory and symbolize keys' do
|
76
|
+
subject.build(:user, {'name' => "name"})
|
77
|
+
expect(factory_double).to have_received(:build).with(:user, {name: 'name'})
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'delegates build to the factory and symbolize keys with trait' do
|
81
|
+
subject.build(:user, 'trait1', {'name' => "name"})
|
82
|
+
expect(factory_double).to have_received(:build).with(:user, :trait1, {name: 'name'})
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'delegates build to the factory and symbolize keys with only trait' do
|
86
|
+
subject.build(:user, 'trait2')
|
87
|
+
expect(factory_double).to have_received(:build).with(:user, :trait2, {})
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'delegates build_list to the factory' do
|
91
|
+
subject.build_list(:note, 10)
|
92
|
+
expect(factory_double).to have_received(:build_list).with(:note, 10)
|
93
|
+
end
|
94
|
+
|
70
95
|
it 'wont load the files if they have not changed' do
|
71
96
|
subject.create(:user)
|
72
97
|
subject.create_list(:user, 2)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cypress-on-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- miceportal team
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-08-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -323,7 +323,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
323
323
|
- !ruby/object:Gem::Version
|
324
324
|
version: '0'
|
325
325
|
requirements: []
|
326
|
-
rubygems_version: 3.2.
|
326
|
+
rubygems_version: 3.2.25
|
327
327
|
signing_key:
|
328
328
|
specification_version: 4
|
329
329
|
summary: Integrates cypress with rails or rack applications
|