cypress-on-rails 1.4.1 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/FUNDING.yml +1 -0
- data/.gitignore +1 -0
- data/.travis.yml +9 -3
- data/CHANGELOG.md +44 -4
- data/README.md +35 -20
- data/cypress-on-rails.gemspec +8 -1
- data/lib/cypress_on_rails/command_executor.rb +1 -1
- data/lib/cypress_on_rails/middleware.rb +10 -2
- data/lib/cypress_on_rails/railtie.rb +1 -1
- data/lib/cypress_on_rails/smart_factory_wrapper.rb +8 -2
- data/lib/cypress_on_rails/version.rb +1 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress.json +1 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/activerecord_fixtures.rb +1 -0
- data/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/clean.rb +1 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/factory_bot.rb +1 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress/cypress_helper.rb +4 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/cypress_api.spec.js +1 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/advance_factory_bot_spec.js +27 -0
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/{using_factory_bot.js → using_factory_bot_spec.js} +0 -0
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/{using_fixtures.js → using_fixtures_spec.js} +0 -0
- data/lib/generators/cypress_on_rails/templates/spec/cypress/support/on-rails.js +10 -6
- data/lib/generators/cypress_on_rails/update_generator.rb +13 -0
- data/spec/cypress_on_rails/middleware_spec.rb +30 -7
- data/spec/cypress_on_rails/smart_factory_wrapper_spec.rb +16 -1
- data/spec/integrations/cypress.json +1 -1
- data/spec/integrations/rails_3_2/test.sh +2 -1
- data/spec/integrations/rails_4_2/Gemfile +2 -1
- data/spec/integrations/rails_4_2/test.sh +2 -2
- data/spec/integrations/rails_5_2/.gitignore +2 -2
- data/spec/integrations/rails_5_2/Gemfile +1 -0
- data/spec/integrations/rails_5_2/test.sh +1 -1
- metadata +15 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fdceb59a86819c5367bbdcf74e91a29a61a5b716
|
4
|
+
data.tar.gz: e900005562f5a7b6d921da8851dd78e8d8efbc80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eaf7e9782d23916147a28f8c83943143b688f3421a1f8985045255054898100abca0ec840b54b95744a0ead8f3fc0a980ebe38f6ab54f92f3cd48e44118ebb1d
|
7
|
+
data.tar.gz: 2266629a6a23dd8280123cf1f6f56660764ea1894f482603016e0e560afa094079086863809f5f3931da87d3efcb442aaba87ff0563c8f969cc48cd18721145a
|
data/.github/FUNDING.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
github: [shakacode]
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.
|
3
|
+
- 2.3
|
4
|
+
- 2.4
|
5
|
+
- 2.5
|
6
|
+
- 2.6
|
7
|
+
# - 2.7
|
4
8
|
|
5
9
|
#addons:
|
6
10
|
# artifacts:
|
@@ -25,6 +29,8 @@ before_install:
|
|
25
29
|
|
26
30
|
script:
|
27
31
|
- bundle exec rake
|
28
|
-
-
|
29
|
-
-
|
32
|
+
- gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
|
33
|
+
- gem install bundler -v '< 2'
|
30
34
|
- ./spec/integrations/rails_5_2/test.sh
|
35
|
+
- ./spec/integrations/rails_4_2/test.sh
|
36
|
+
- ./spec/integrations/rails_3_2/test.sh
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,45 @@
|
|
1
|
+
## [1.7.0]
|
2
|
+
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.6.0...v1.7.0
|
3
|
+
|
4
|
+
### Changed
|
5
|
+
* Improve eval() in command executor [PR 46](https://github.com/shakacode/cypress-on-rails/pull/46) by [Systho](https://github.com/Systho)
|
6
|
+
|
7
|
+
### Fixed
|
8
|
+
* Add middleware after load_config_initializers [PR 62](https://github.com/shakacode/cypress-on-rails/pull/62) by [duytd](https://github.com/duytd)
|
9
|
+
|
10
|
+
## [1.6.0]
|
11
|
+
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.5.1...v1.6.0
|
12
|
+
|
13
|
+
### Changed
|
14
|
+
* Change default port to 5017 [PR 49](https://github.com/shakacode/cypress-on-rails/pull/49) by [vfonic](https://github/vfonic)
|
15
|
+
|
16
|
+
### Fixed
|
17
|
+
* fix file location warning message in clean.rb [PR 54](https://github.com/shakacode/cypress-on-rails/pull/54) by [ootoovak](https://github.com/ootoovak)
|
18
|
+
|
19
|
+
## [1.5.1]
|
20
|
+
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.5.0...v1.5.1
|
21
|
+
|
22
|
+
### Fixed
|
23
|
+
* fix FactoryBot Trait not registered error [PR 43](https://github.com/shakacode/cypress-on-rails/pull/43)
|
24
|
+
|
25
|
+
## [1.5.0]
|
26
|
+
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.4.2...v1.5.0
|
27
|
+
|
28
|
+
### Added
|
29
|
+
* Serialize and return responses to be used in tests [PR 34](https://github.com/shakacode/cypress-on-rails/pull/34).
|
30
|
+
* Update generator to make it easier to update core generated files [PR 35](https://github.com/shakacode/cypress-on-rails/pull/35).
|
31
|
+
|
32
|
+
### Tasks
|
33
|
+
* Update integration tests [PR 36](https://github.com/shakacode/cypress-on-rails/pull/36).
|
34
|
+
|
35
|
+
## [1.4.2]
|
36
|
+
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.4.1...v1.4.2
|
37
|
+
|
38
|
+
### Fixed
|
39
|
+
* update generator to use full paths for Factory files [PR 33](https://github.com/shakacode/cypress-on-rails/pull/33).
|
40
|
+
|
1
41
|
## [1.4.1]
|
42
|
+
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.4.0...v1.4.1
|
2
43
|
|
3
44
|
### Fixed
|
4
45
|
* fix install generator when using npm [PR 22](https://github.com/shakacode/cypress-on-rails/pull/22) by [josephan](https://github.com/josephan).
|
@@ -9,7 +50,9 @@
|
|
9
50
|
* Update Travis CI badge in README [PR 31](https://github.com/shakacode/cypress-on-rails/pull/31)
|
10
51
|
* Fix CI by Installing cypress dependencies on Travis CI [PR 31](https://github.com/shakacode/cypress-on-rails/pull/31)
|
11
52
|
|
12
|
-
## [1.4.0]
|
53
|
+
## [1.4.0]
|
54
|
+
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.3.0...v1.4.0
|
55
|
+
|
13
56
|
* Accept an options argument for scenarios. [PR 18](https://github.com/shakacode/cypress-on-rails/pull/18) by [ericraio](https://github.com/ericraio).
|
14
57
|
|
15
58
|
### Changed
|
@@ -73,9 +116,6 @@
|
|
73
116
|
## 0.1.2 (2017-10-31)
|
74
117
|
* First release.
|
75
118
|
|
76
|
-
[Unreleased]: https://github.com/shakacode/cypress-on-rails/compare/v1.4.1...master
|
77
|
-
[1.4.1]: https://github.com/shakacode/cypress-on-rails/compare/v1.4.0...v1.4.1
|
78
|
-
[1.4.0]: https://github.com/shakacode/cypress-on-rails/compare/v1.3.0...v1.4.0
|
79
119
|
[1.3.0]: https://github.com/shakacode/cypress-on-rails/compare/v1.2.1...v1.3.0
|
80
120
|
[1.2.1]: https://github.com/shakacode/cypress-on-rails/compare/v1.2.0...v1.2.1
|
81
121
|
[1.2.0]: https://github.com/shakacode/cypress-on-rails/compare/v1.1.1...v1.2.0
|
data/README.md
CHANGED
@@ -2,7 +2,13 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.com/shakacode/cypress-on-rails.svg?branch=master)](https://travis-ci.org/shakacode/cypress-on-rails) [![Gem Version](https://badge.fury.io/rb/cypress-on-rails.svg)](https://badge.fury.io/rb/cypress-on-rails)
|
4
4
|
|
5
|
-
|
5
|
+
----
|
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. The best way to see what we do is to see the details of [our recent work](https://www.shakacode.com/recent-work). Feel free to engage in discussions around this gem at our [forum category for Cypress](https://forum.shakacode.com/c/cypress-on-rails/55).
|
8
|
+
|
9
|
+
----
|
10
|
+
|
11
|
+
Gem for using [cypress.io](http://github.com/cypress-io/) in Rails and ruby rack applications
|
6
12
|
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
13
|
|
8
14
|
It allows to run code in the application context when executing cypress tests.
|
@@ -18,21 +24,21 @@ Has examples of setting up state with:
|
|
18
24
|
* scenarios
|
19
25
|
* custom commands
|
20
26
|
|
21
|
-
This gem is based off https://github.com/konvenit/cypress-on-rails
|
22
|
-
|
23
27
|
Video of getting started with this gem https://grant-ps.blog/2018/08/10/getting-started-with-cypress-io-and-ruby-on-rails/
|
24
28
|
|
25
29
|
## Getting started
|
26
30
|
|
27
31
|
Add this to your Gemfile:
|
28
|
-
|
32
|
+
|
33
|
+
```ruby
|
29
34
|
group :test, :development do
|
30
35
|
gem 'cypress-on-rails', '~> 1.0'
|
31
36
|
end
|
32
37
|
```
|
33
38
|
|
34
|
-
|
35
|
-
|
39
|
+
Generate the boilerplate code using:
|
40
|
+
|
41
|
+
```shell
|
36
42
|
bin/rails g cypress_on_rails:install
|
37
43
|
|
38
44
|
# if you have/want a different cypress folder (default is spec/cypress)
|
@@ -40,19 +46,23 @@ bin/rails g cypress_on_rails:install --cypress_folder=test/cypress
|
|
40
46
|
|
41
47
|
# if you want to install cypress with npm
|
42
48
|
bin/rails g cypress_on_rails:install --install_cypress_with=npm
|
49
|
+
|
50
|
+
# to update the generated files run
|
51
|
+
bin/rails g cypress_on_rails:update
|
43
52
|
```
|
44
53
|
|
45
|
-
The generator adds the following files/directory
|
54
|
+
The generator modifies/adds the following files/directory in your application:
|
55
|
+
* `config/environments/test.rb`
|
46
56
|
* `config/initializers/cypress_on_rails` used to configure CypressDev
|
47
57
|
* `spec/cypress/integrations/` contains your cypress tests
|
48
58
|
* `spec/cypress/support/on-rails.js` contains CypressDev support code
|
49
59
|
* `spec/cypress/app_commands/scenarios/` contains your CypressDev scenario definitions
|
50
60
|
* `spec/cypress/cypress_helper.rb` contains helper code for CypressDev app commands
|
51
61
|
|
52
|
-
if you are not using database_cleaner look at `spec/cypress/app_commands/
|
62
|
+
if you are not using database_cleaner look at `spec/cypress/app_commands/clean.rb`.
|
53
63
|
if you are not using factory_bot look at `spec/cypress/app_commands/factory_bot.rb`.
|
54
64
|
|
55
|
-
Now you can create scenarios and commands that are
|
65
|
+
Now you can create scenarios and commands that are plain ruby files that get loaded through middleware, the ruby sky is your limit.
|
56
66
|
|
57
67
|
### WARNING
|
58
68
|
*WARNING!!:* cypress-on-rails can execute arbitrary ruby code
|
@@ -62,10 +72,10 @@ Please use with extra caution if starting your local server on 0.0.0.0 or runnin
|
|
62
72
|
|
63
73
|
Start the rails server in test mode and start cypress
|
64
74
|
|
65
|
-
```
|
75
|
+
```shell
|
66
76
|
# start rails
|
67
77
|
RAILS_ENV=test bin/rake db:create db:schema:load
|
68
|
-
bin/rails server -e test -p
|
78
|
+
bin/rails server -e test -p 5017
|
69
79
|
|
70
80
|
# in separate window start cypress
|
71
81
|
yarn cypress open --project ./spec
|
@@ -79,10 +89,10 @@ You can run your [factory_bot](https://github.com/thoughtbot/factory_bot) direct
|
|
79
89
|
require 'cypress_on_rails/smart_factory_wrapper'
|
80
90
|
|
81
91
|
CypressOnRails::SmartFactoryWrapper.configure(
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
)
|
92
|
+
always_reload: !Rails.configuration.cache_classes,
|
93
|
+
factory: FactoryBot,
|
94
|
+
files: Dir['./spec/factories/**/*.rb']
|
95
|
+
)
|
86
96
|
```
|
87
97
|
|
88
98
|
```js
|
@@ -99,6 +109,11 @@ describe('My First Test', function() {
|
|
99
109
|
cy.visit('/')
|
100
110
|
|
101
111
|
cy.contains("Hello World")
|
112
|
+
|
113
|
+
// Accessing result
|
114
|
+
cy.appFactories([['create', 'invoice', { paid: false }]]).then((records) => {
|
115
|
+
cy.visit(`/invoices/${records[0].id}`);
|
116
|
+
});
|
102
117
|
})
|
103
118
|
})
|
104
119
|
```
|
@@ -141,7 +156,7 @@ You define a scenario in the `spec/cypress/app_commands/scenarios` directory:
|
|
141
156
|
Profile.create name: "Cypress Hill"
|
142
157
|
|
143
158
|
# or if you have factory_bot enabled in your cypress_helper
|
144
|
-
CypressOnRails::SmartFactoryWrapper.create(:profile, name: "Cypress Hill")
|
159
|
+
CypressOnRails::SmartFactoryWrapper.create(:profile, name: "Cypress Hill")
|
145
160
|
```
|
146
161
|
|
147
162
|
Then reference the scenario in your test:
|
@@ -163,8 +178,8 @@ describe('My First Test', function() {
|
|
163
178
|
|
164
179
|
create a ruby file in `spec/cypress/app_commands` directory:
|
165
180
|
```ruby
|
166
|
-
# spec/cypress/app_commands/load_seed.rb
|
167
|
-
load "#{Rails.root}/db/seeds.rb"
|
181
|
+
# spec/cypress/app_commands/load_seed.rb
|
182
|
+
load "#{Rails.root}/db/seeds.rb"
|
168
183
|
```
|
169
184
|
|
170
185
|
Then reference the command in your test with `cy.app('load_seed')`:
|
@@ -172,7 +187,7 @@ Then reference the command in your test with `cy.app('load_seed')`:
|
|
172
187
|
// spec/cypress/integrations/simple_spec.js
|
173
188
|
describe('My First Test', function() {
|
174
189
|
beforeEach(() => { cy.app('load_seed') })
|
175
|
-
|
190
|
+
|
176
191
|
it('visit root', function() {
|
177
192
|
cy.visit('/')
|
178
193
|
|
@@ -195,7 +210,7 @@ CypressOnRails.configure do |c|
|
|
195
210
|
end
|
196
211
|
use CypressOnRails::Middleware
|
197
212
|
|
198
|
-
run MyApp
|
213
|
+
run MyApp
|
199
214
|
```
|
200
215
|
|
201
216
|
add the following file to cypress
|
data/cypress-on-rails.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = CypressOnRails::VERSION
|
8
8
|
s.author = ["miceportal team", 'Grant Petersen-Speelman']
|
9
9
|
s.email = ["info@miceportal.de", 'grantspeelman@gmail.com']
|
10
|
-
s.homepage = "http://github.com/
|
10
|
+
s.homepage = "http://github.com/shakacode/cypress-on-rails"
|
11
11
|
s.summary = "Integrates cypress with rails or rack applications"
|
12
12
|
s.description = "Integrates cypress with rails or rack applications"
|
13
13
|
s.post_install_message = 'The CypressDev constant is being deprecated and will be completely removed and replaced with CypressOnRails.'
|
@@ -19,4 +19,11 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.add_development_dependency 'rake'
|
20
20
|
s.add_development_dependency 'rspec'
|
21
21
|
s.add_development_dependency 'railties', '>= 3.2'
|
22
|
+
s.metadata = {
|
23
|
+
"bug_tracker_uri" => "https://github.com/shakacode/cypress-on-rails/issues",
|
24
|
+
"changelog_uri" => "https://github.com/shakacode/cypress-on-rails/blob/master/CHANGELOG.md",
|
25
|
+
"documentation_uri" => "https://github.com/shakacode/cypress-on-rails/blob/master/README.md",
|
26
|
+
"homepage_uri" => "http://github.com/shakacode/cypress-on-rails",
|
27
|
+
"source_code_uri" => "http://github.com/shakacode/cypress-on-rails"
|
28
|
+
}
|
22
29
|
end
|
@@ -6,7 +6,7 @@ module CypressOnRails
|
|
6
6
|
def self.load(file,command_options = nil)
|
7
7
|
load_cypress_helper
|
8
8
|
file_data = File.read(file)
|
9
|
-
eval file_data
|
9
|
+
eval file_data, binding, file
|
10
10
|
rescue => e
|
11
11
|
logger.error("fail to execute #{file}: #{e.message}")
|
12
12
|
logger.error(e.backtrace.join("\n"))
|
@@ -54,9 +54,17 @@ module CypressOnRails
|
|
54
54
|
logger.info "handle_command: #{body}"
|
55
55
|
commands = Command.from_body(body, configuration)
|
56
56
|
missing_command = commands.find {|command| !@file.exists?(command.file_path) }
|
57
|
+
|
57
58
|
if missing_command.nil?
|
58
|
-
commands.
|
59
|
-
|
59
|
+
results = commands.map { |command| @command_executor.load(command.file_path, command.options) }
|
60
|
+
|
61
|
+
begin
|
62
|
+
output = results.to_json
|
63
|
+
rescue NoMethodError
|
64
|
+
output = {"message" => "Cannot convert to json"}.to_json
|
65
|
+
end
|
66
|
+
|
67
|
+
[201, {'Content-Type' => 'application/json'}, [output]]
|
60
68
|
else
|
61
69
|
[404, {}, ["could not find command file: #{missing_command.file_path}"]]
|
62
70
|
end
|
@@ -4,7 +4,7 @@ require 'cypress_on_rails/middleware'
|
|
4
4
|
|
5
5
|
module CypressOnRails
|
6
6
|
class Railtie < Rails::Railtie
|
7
|
-
initializer :setup_cypress_middleware do |app|
|
7
|
+
initializer :setup_cypress_middleware, after: :load_config_initializers do |app|
|
8
8
|
if CypressOnRails.configuration.use_middleware?
|
9
9
|
app.middleware.use Middleware
|
10
10
|
end
|
@@ -45,9 +45,15 @@ module CypressOnRails
|
|
45
45
|
@dir_system = dir_system
|
46
46
|
end
|
47
47
|
|
48
|
-
def create(*
|
48
|
+
def create(*options)
|
49
49
|
load_files
|
50
|
-
|
50
|
+
factory_name = options.shift
|
51
|
+
if options.last.is_a?(Hash)
|
52
|
+
args = options.pop
|
53
|
+
else
|
54
|
+
args = {}
|
55
|
+
end
|
56
|
+
factory.create(factory_name,*options.map(&:to_sym),args.symbolize_keys)
|
51
57
|
end
|
52
58
|
|
53
59
|
def create_list(*args)
|
data/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/activerecord_fixtures.rb
CHANGED
@@ -12,6 +12,7 @@ if defined?(ActiveRecord)
|
|
12
12
|
logger.debug "loading fixtures: { dir: #{fixtures_dir}, files: #{fixture_files} }"
|
13
13
|
ActiveRecord::FixtureSet.reset_cache
|
14
14
|
ActiveRecord::FixtureSet.create_fixtures(fixtures_dir, fixture_files)
|
15
|
+
"Fixtures Done" # this gets returned
|
15
16
|
else # this else part can be removed
|
16
17
|
logger.error "Looks like activerecord_fixtures has to be modified to suite your need"
|
17
18
|
Post.create(title: 'MyCypressFixtures')
|
@@ -3,7 +3,7 @@ if defined?(DatabaseCleaner)
|
|
3
3
|
DatabaseCleaner.strategy = :truncation
|
4
4
|
DatabaseCleaner.clean
|
5
5
|
else
|
6
|
-
logger.warn "add database_cleaner or update
|
6
|
+
logger.warn "add database_cleaner or update cypress/app_commands/clean.rb"
|
7
7
|
Post.delete_all if defined?(Post)
|
8
8
|
end
|
9
9
|
|
@@ -26,5 +26,8 @@ factory = FactoryGirl if defined?(FactoryGirl)
|
|
26
26
|
CypressOnRails::SmartFactoryWrapper.configure(
|
27
27
|
always_reload: !Rails.configuration.cache_classes,
|
28
28
|
factory: factory,
|
29
|
-
files:
|
29
|
+
files: [
|
30
|
+
Rails.root.join('spec', 'factories.rb'),
|
31
|
+
Rails.root.join('spec', 'factories', '**', '*.rb')
|
32
|
+
]
|
30
33
|
)
|
data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/cypress_api.spec.js
CHANGED
@@ -112,7 +112,7 @@ context('Cypress.config()', () => {
|
|
112
112
|
let myConfig = Cypress.config()
|
113
113
|
|
114
114
|
expect(myConfig).to.have.property('animationDistanceThreshold', 5)
|
115
|
-
expect(myConfig).to.have.property('baseUrl', 'http://localhost:
|
115
|
+
expect(myConfig).to.have.property('baseUrl', 'http://localhost:5017')
|
116
116
|
expect(myConfig).to.have.property('defaultCommandTimeout', 10000)
|
117
117
|
expect(myConfig).to.have.property('requestTimeout', 5000)
|
118
118
|
expect(myConfig).to.have.property('responseTimeout', 30000)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
describe('More Rails using factory bot examples', function() {
|
2
|
+
beforeEach(() => {
|
3
|
+
cy.app('clean') // have a look at cypress/app_commands/clean.rb
|
4
|
+
})
|
5
|
+
|
6
|
+
it('using response from factory bot', function() {
|
7
|
+
cy.appFactories([['create', 'post', { title: 'Good bye Mars'} ]]).then((results) => {
|
8
|
+
const record = results[0];
|
9
|
+
|
10
|
+
cy.visit(`/posts/${record.id}`);
|
11
|
+
});
|
12
|
+
cy.contains("Good bye Mars")
|
13
|
+
})
|
14
|
+
|
15
|
+
it('using response from multiple factory bot', function() {
|
16
|
+
cy.appFactories([
|
17
|
+
['create', 'post', { title: 'My First Post'} ],
|
18
|
+
['create', 'post', { title: 'My Second Post'} ]
|
19
|
+
]).then((results) => {
|
20
|
+
cy.visit(`/posts/${results[0].id}`);
|
21
|
+
cy.contains("My First Post")
|
22
|
+
|
23
|
+
cy.visit(`/posts/${results[1].id}`);
|
24
|
+
cy.contains("My Second Post")
|
25
|
+
});
|
26
|
+
})
|
27
|
+
})
|
File without changes
|
File without changes
|
@@ -1,29 +1,33 @@
|
|
1
1
|
// CypressOnRails: dont remove these command
|
2
2
|
Cypress.Commands.add('appCommands', function (body) {
|
3
3
|
cy.log("APP: " + JSON.stringify(body))
|
4
|
-
cy.request({
|
4
|
+
return cy.request({
|
5
5
|
method: 'POST',
|
6
6
|
url: "/__cypress__/command",
|
7
7
|
body: JSON.stringify(body),
|
8
8
|
log: true,
|
9
9
|
failOnStatusCode: true
|
10
|
-
})
|
10
|
+
}).then((response) => {
|
11
|
+
return response.body
|
12
|
+
});
|
11
13
|
});
|
12
14
|
|
13
15
|
Cypress.Commands.add('app', function (name, command_options) {
|
14
|
-
cy.appCommands({name: name, options: command_options})
|
16
|
+
return cy.appCommands({name: name, options: command_options}).then((body) => {
|
17
|
+
return body[0]
|
18
|
+
});
|
15
19
|
});
|
16
20
|
|
17
21
|
Cypress.Commands.add('appScenario', function (name, options = {}) {
|
18
|
-
cy.app('scenarios/' + name, options)
|
22
|
+
return cy.app('scenarios/' + name, options)
|
19
23
|
});
|
20
24
|
|
21
25
|
Cypress.Commands.add('appEval', function (code) {
|
22
|
-
cy.app('eval', code)
|
26
|
+
return cy.app('eval', code)
|
23
27
|
});
|
24
28
|
|
25
29
|
Cypress.Commands.add('appFactories', function (options) {
|
26
|
-
cy.app('factory_bot', options)
|
30
|
+
return cy.app('factory_bot', options)
|
27
31
|
});
|
28
32
|
|
29
33
|
Cypress.Commands.add('appFixtures', function (options) {
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module CypressOnRails
|
2
|
+
class UpdateGenerator < Rails::Generators::Base
|
3
|
+
class_option :cypress_folder, type: :string, default: 'spec/cypress'
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
def update_generated_files
|
7
|
+
template "config/initializers/cypress_on_rails.rb.erb", "config/initializers/cypress_on_rails.rb"
|
8
|
+
copy_file "spec/cypress/cypress_helper.rb", "#{options.cypress_folder}/cypress_helper.rb"
|
9
|
+
copy_file "spec/cypress/support/on-rails.js", "#{options.cypress_folder}/support/on-rails.js"
|
10
|
+
directory 'spec/cypress/app_commands', "#{options.cypress_folder}/app_commands"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -16,17 +16,20 @@ RSpec.describe CypressOnRails::Middleware do
|
|
16
16
|
|
17
17
|
context '/__cypress__/command' do
|
18
18
|
before do
|
19
|
-
allow(command_executor).to receive(:load)
|
19
|
+
allow(command_executor).to receive(:load).and_return({ id: 1, title: 'some result' })
|
20
20
|
allow(file).to receive(:exists?)
|
21
21
|
env['PATH_INFO'] = '/__cypress__/command'
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'command file exists' do
|
25
|
+
allow(command_executor).to receive(:load).and_return({ id: 1, title: 'some result' })
|
25
26
|
env['rack.input'] = rack_input(name: 'seed')
|
26
27
|
allow(file).to receive(:exists?).with('spec/cypress/app_commands/seed.rb').and_return(true)
|
27
28
|
|
28
29
|
aggregate_failures do
|
29
|
-
expect(response).to eq([201,
|
30
|
+
expect(response).to eq([201,
|
31
|
+
{"Content-Type"=>"application/json"},
|
32
|
+
["[{\"id\":1,\"title\":\"some result\"}]"]])
|
30
33
|
expect(command_executor).to have_received(:load).with('spec/cypress/app_commands/seed.rb', nil)
|
31
34
|
end
|
32
35
|
end
|
@@ -36,18 +39,36 @@ RSpec.describe CypressOnRails::Middleware do
|
|
36
39
|
allow(file).to receive(:exists?).with('spec/cypress/app_commands/seed.rb').and_return(true)
|
37
40
|
|
38
41
|
aggregate_failures do
|
39
|
-
expect(response).to eq([201,
|
42
|
+
expect(response).to eq([201,
|
43
|
+
{"Content-Type"=>"application/json"},
|
44
|
+
["[{\"id\":1,\"title\":\"some result\"}]"]])
|
40
45
|
expect(command_executor).to have_received(:load).with('spec/cypress/app_commands/seed.rb', ['my_options'])
|
41
46
|
end
|
42
47
|
end
|
43
48
|
|
44
49
|
it 'command file does not exists' do
|
50
|
+
object = BasicObject.new
|
51
|
+
allow(command_executor).to receive(:load).and_return(object)
|
45
52
|
env['rack.input'] = rack_input(name: 'seed')
|
46
|
-
allow(file).to receive(:exists?).with('spec/cypress/app_commands/seed.rb').and_return(
|
53
|
+
allow(file).to receive(:exists?).with('spec/cypress/app_commands/seed.rb').and_return(true)
|
47
54
|
|
48
55
|
aggregate_failures do
|
49
|
-
expect(response).to eq([
|
50
|
-
|
56
|
+
expect(response).to eq([201,
|
57
|
+
{"Content-Type"=>"application/json"},
|
58
|
+
["{\"message\":\"Cannot convert to json\"}"]])
|
59
|
+
expect(command_executor).to have_received(:load).with('spec/cypress/app_commands/seed.rb', nil)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'command result does not respond to to_json' do
|
64
|
+
env['rack.input'] = rack_input(name: 'seed')
|
65
|
+
allow(file).to receive(:exists?).with('spec/cypress/app_commands/seed.rb').and_return(true)
|
66
|
+
|
67
|
+
aggregate_failures do
|
68
|
+
expect(response).to eq([201,
|
69
|
+
{"Content-Type"=>"application/json"},
|
70
|
+
["[{\"id\":1,\"title\":\"some result\"}]"]])
|
71
|
+
expect(command_executor).to have_received(:load).with('spec/cypress/app_commands/seed.rb', nil)
|
51
72
|
end
|
52
73
|
end
|
53
74
|
|
@@ -58,7 +79,9 @@ RSpec.describe CypressOnRails::Middleware do
|
|
58
79
|
allow(file).to receive(:exists?).with('spec/cypress/app_commands/load_sample.rb').and_return(true)
|
59
80
|
|
60
81
|
aggregate_failures do
|
61
|
-
expect(response).to eq([201,
|
82
|
+
expect(response).to eq([201,
|
83
|
+
{"Content-Type"=>"application/json"},
|
84
|
+
["[{\"id\":1,\"title\":\"some result\"},{\"id\":1,\"title\":\"some result\"}]"]])
|
62
85
|
expect(command_executor).to have_received(:load).with('spec/cypress/app_commands/load_user.rb', nil)
|
63
86
|
expect(command_executor).to have_received(:load).with('spec/cypress/app_commands/load_sample.rb', {'all' => 'true'})
|
64
87
|
end
|
@@ -43,7 +43,22 @@ RSpec.describe CypressOnRails::SmartFactoryWrapper do
|
|
43
43
|
|
44
44
|
it 'it sends delegates create to the factory' do
|
45
45
|
subject.create(:user)
|
46
|
-
expect(factory_double).to have_received(:create).with(:user)
|
46
|
+
expect(factory_double).to have_received(:create).with(:user, {})
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'it sends delegates create to the factory and symbolize keys' do
|
50
|
+
subject.create(:user, {'name' => "name"})
|
51
|
+
expect(factory_double).to have_received(:create).with(:user, {name: 'name'})
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'it sends delegates create to the factory and symbolize keys with trait' do
|
55
|
+
subject.create(:user, 'trait1', {'name' => "name"})
|
56
|
+
expect(factory_double).to have_received(:create).with(:user, :trait1, {name: 'name'})
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'it sends delegates create to the factory and symbolize keys with only trait' do
|
60
|
+
subject.create(:user, 'trait2')
|
61
|
+
expect(factory_double).to have_received(:create).with(:user, :trait2, {})
|
47
62
|
end
|
48
63
|
|
49
64
|
it 'it sends delegates create_list to the factory' do
|
@@ -15,12 +15,13 @@ bundle install --quiet --gemfile="$DIR/Gemfile" --retry 2 --path vendor/bundle
|
|
15
15
|
|
16
16
|
echo '-- cypress install'
|
17
17
|
bundle exec ./bin/rails g cypress_on_rails:install --cypress_folder=cypress --install_cypress_with=npm --no-install-cypress-examples
|
18
|
+
rm -vf cypress/integration/rails_examples/advance_factory_bot_spec.js
|
18
19
|
|
19
20
|
echo '-- start rails server'
|
20
21
|
# make sure the server is not running
|
21
22
|
(kill -9 `cat tmp/pids/server.pid` || true )
|
22
23
|
|
23
|
-
bundle exec ./bin/rails server -p
|
24
|
+
bundle exec ./bin/rails server -p 5017 -e test &
|
24
25
|
sleep 2 # give rails a chance to start up correctly
|
25
26
|
|
26
27
|
echo '-- cypress run'
|
@@ -15,12 +15,13 @@ bundle install --quiet --gemfile="$DIR/Gemfile" --retry 2 --path vendor/bundle
|
|
15
15
|
|
16
16
|
echo '-- cypress install'
|
17
17
|
bundle exec ./bin/rails g cypress_on_rails:install --no-install-cypress-examples
|
18
|
+
rm -vf spec/cypress/integration/rails_examples/advance_factory_bot_spec.js
|
18
19
|
|
19
20
|
echo '-- start rails server'
|
20
21
|
# make sure the server is not running
|
21
22
|
(kill -9 `cat tmp/pids/server.pid` || true )
|
22
23
|
|
23
|
-
bundle exec ./bin/rails server -p
|
24
|
+
bundle exec ./bin/rails server -p 5017 -e test &
|
24
25
|
sleep 2 # give rails a chance to start up correctly
|
25
26
|
|
26
27
|
echo '-- cypress run'
|
@@ -33,6 +34,5 @@ else
|
|
33
34
|
yarn run cypress run --record
|
34
35
|
fi
|
35
36
|
|
36
|
-
|
37
37
|
echo '-- stop rails server'
|
38
38
|
kill -9 `cat ../tmp/pids/server.pid`
|
@@ -3,6 +3,7 @@ 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 'sprockets', '~> 3.7.2'
|
6
7
|
gem 'sqlite3', '~> 1.3.6'
|
7
8
|
|
8
9
|
# Reduces boot times through caching; required in config/boot.rb
|
@@ -23,7 +23,7 @@ echo '-- start rails server'
|
|
23
23
|
# make sure the server is not running
|
24
24
|
(kill -9 `cat tmp/pids/server.pid` || true )
|
25
25
|
|
26
|
-
bundle exec ./bin/rails server -p
|
26
|
+
bundle exec ./bin/rails server -p 5017 -e test &
|
27
27
|
sleep 2 # give rails a chance to start up correctly
|
28
28
|
|
29
29
|
echo '-- cypress run'
|
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.7.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:
|
12
|
+
date: 2020-07-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -75,6 +75,7 @@ executables: []
|
|
75
75
|
extensions: []
|
76
76
|
extra_rdoc_files: []
|
77
77
|
files:
|
78
|
+
- ".github/FUNDING.yml"
|
78
79
|
- ".gitignore"
|
79
80
|
- ".rspec"
|
80
81
|
- ".travis.yml"
|
@@ -127,13 +128,15 @@ files:
|
|
127
128
|
- lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/viewport.spec.js
|
128
129
|
- lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/waiting.spec.js
|
129
130
|
- lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/window.spec.js
|
131
|
+
- lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/advance_factory_bot_spec.js
|
130
132
|
- lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/other_spec.js
|
131
|
-
- lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/
|
132
|
-
- lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/
|
133
|
+
- lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_factory_bot_spec.js
|
134
|
+
- lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_fixtures_spec.js
|
133
135
|
- lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_scenarios_spec.js
|
134
136
|
- lib/generators/cypress_on_rails/templates/spec/cypress/support/commands.js
|
135
137
|
- lib/generators/cypress_on_rails/templates/spec/cypress/support/index.js
|
136
138
|
- lib/generators/cypress_on_rails/templates/spec/cypress/support/on-rails.js
|
139
|
+
- lib/generators/cypress_on_rails/update_generator.rb
|
137
140
|
- spec/cypress_on_rails/command_executor/cypress_helper.rb
|
138
141
|
- spec/cypress_on_rails/command_executor/test_command.rb
|
139
142
|
- spec/cypress_on_rails/command_executor/test_command_with_options.rb
|
@@ -282,9 +285,14 @@ files:
|
|
282
285
|
- spec/integrations/rails_5_2/tmp/.keep
|
283
286
|
- spec/integrations/rails_5_2/vendor/.keep
|
284
287
|
- spec/spec_helper.rb
|
285
|
-
homepage: http://github.com/
|
288
|
+
homepage: http://github.com/shakacode/cypress-on-rails
|
286
289
|
licenses: []
|
287
|
-
metadata:
|
290
|
+
metadata:
|
291
|
+
bug_tracker_uri: https://github.com/shakacode/cypress-on-rails/issues
|
292
|
+
changelog_uri: https://github.com/shakacode/cypress-on-rails/blob/master/CHANGELOG.md
|
293
|
+
documentation_uri: https://github.com/shakacode/cypress-on-rails/blob/master/README.md
|
294
|
+
homepage_uri: http://github.com/shakacode/cypress-on-rails
|
295
|
+
source_code_uri: http://github.com/shakacode/cypress-on-rails
|
288
296
|
post_install_message: The CypressDev constant is being deprecated and will be completely
|
289
297
|
removed and replaced with CypressOnRails.
|
290
298
|
rdoc_options: []
|
@@ -302,7 +310,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
302
310
|
version: '0'
|
303
311
|
requirements: []
|
304
312
|
rubyforge_project:
|
305
|
-
rubygems_version: 2.
|
313
|
+
rubygems_version: 2.6.14.4
|
306
314
|
signing_key:
|
307
315
|
specification_version: 4
|
308
316
|
summary: Integrates cypress with rails or rack applications
|