cypress-on-rails 1.4.2 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +5 -5
  2. data/.github/FUNDING.yml +1 -0
  3. data/.gitignore +2 -0
  4. data/.travis.yml +9 -3
  5. data/CHANGELOG.md +45 -5
  6. data/README.md +35 -20
  7. data/cypress-on-rails.gemspec +9 -1
  8. data/lib/cypress_on_rails/command_executor.rb +1 -1
  9. data/lib/cypress_on_rails/middleware.rb +10 -2
  10. data/lib/cypress_on_rails/railtie.rb +1 -1
  11. data/lib/cypress_on_rails/simple_rails_factory.rb +4 -0
  12. data/lib/cypress_on_rails/smart_factory_wrapper.rb +11 -15
  13. data/lib/cypress_on_rails/version.rb +1 -1
  14. data/lib/generators/cypress_on_rails/templates/spec/cypress.json +1 -1
  15. data/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/activerecord_fixtures.rb +1 -0
  16. data/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/clean.rb +1 -1
  17. data/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/factory_bot.rb +1 -1
  18. data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/cypress_api.spec.js +1 -1
  19. data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/advance_factory_bot_spec.js +27 -0
  20. data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/{using_factory_bot.js → using_factory_bot_spec.js} +0 -0
  21. data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/{using_fixtures.js → using_fixtures_spec.js} +0 -0
  22. data/lib/generators/cypress_on_rails/templates/spec/cypress/support/on-rails.js +10 -6
  23. data/lib/generators/cypress_on_rails/update_generator.rb +13 -0
  24. data/spec/cypress_on_rails/middleware_spec.rb +30 -7
  25. data/spec/cypress_on_rails/smart_factory_wrapper_spec.rb +29 -13
  26. data/spec/integrations/cypress.json +1 -1
  27. data/spec/integrations/rails_3_2/test.sh +2 -1
  28. data/spec/integrations/rails_4_2/Gemfile +2 -1
  29. data/spec/integrations/rails_4_2/test.sh +2 -2
  30. data/spec/integrations/rails_5_2/.gitignore +2 -2
  31. data/spec/integrations/rails_5_2/Gemfile +1 -0
  32. data/spec/integrations/rails_5_2/test.sh +1 -1
  33. metadata +29 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: c3539179f3a9e5d659797959cb90076cc26fab30195d4692f5c6baa01adf44b0
4
- data.tar.gz: d87eca7c08735de0fa4ab81a107e924b2e61d21857df79bd56c92afaca3ac1c9
2
+ SHA1:
3
+ metadata.gz: 7aec96956fcdd7eedf0d5f734cc81e134724c6e5
4
+ data.tar.gz: 300cecad4faa328db420de5d0a2b598f38f2506a
5
5
  SHA512:
6
- metadata.gz: 3059da5ecf3664939b2151609f921a434863725e716606a681bec9f74e677319d9e7a3078830a63262a8805c9584120d0d05f7bce08ad2f7101e2f3363bcf29e
7
- data.tar.gz: 032c375f6ed7b145f7f6aa9a496f7d123a346c9efa084936f86f0f0b27cc3ac335c5d2b0bb07015b3a4abc7edfe745fbc2f65fb1b5872bbbfd69c7949acc0b86
6
+ metadata.gz: 6e132c239e673c30b9b4beeeabed6888a05663d3aac596efaa65bfd914f3f3529bf31951e65d3194283f36cd53fd1834e309eb71d5383040fd4135c34beab94e
7
+ data.tar.gz: 5c34509322e7262d239f5185490c737109e10af613e1e869edec42cc394f792656c598a19b297d93b6026f0d004622416d425b48a71c54c7dfeadc30d90bd8fa
@@ -0,0 +1 @@
1
+ github: [shakacode]
data/.gitignore CHANGED
@@ -4,3 +4,5 @@ Gemfile.lock
4
4
  spec/examples.txt
5
5
  .idea
6
6
  spec/test.log
7
+ pkg/*.gem
8
+ vendor/bundle
@@ -1,6 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.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
- - ./spec/integrations/rails_3_2/test.sh
29
- - ./spec/integrations/rails_4_2/test.sh
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
@@ -1,9 +1,51 @@
1
+ ## [1.8.0]
2
+ [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.7.0...v1.8.0
3
+
4
+ ### Changed
5
+ * Use `FactoryBo#reload` to reset factory bot
6
+
7
+ ## [1.7.0]
8
+ [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.6.0...v1.7.0
9
+
10
+ ### Changed
11
+ * Improve eval() in command executor [PR 46](https://github.com/shakacode/cypress-on-rails/pull/46) by [Systho](https://github.com/Systho)
12
+
13
+ ### Fixed
14
+ * Add middleware after load_config_initializers [PR 62](https://github.com/shakacode/cypress-on-rails/pull/62) by [duytd](https://github.com/duytd)
15
+
16
+ ## [1.6.0]
17
+ [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.5.1...v1.6.0
18
+
19
+ ### Changed
20
+ * Change default port to 5017 [PR 49](https://github.com/shakacode/cypress-on-rails/pull/49) by [vfonic](https://github/vfonic)
21
+
22
+ ### Fixed
23
+ * 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)
24
+
25
+ ## [1.5.1]
26
+ [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.5.0...v1.5.1
27
+
28
+ ### Fixed
29
+ * fix FactoryBot Trait not registered error [PR 43](https://github.com/shakacode/cypress-on-rails/pull/43)
30
+
31
+ ## [1.5.0]
32
+ [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.4.2...v1.5.0
33
+
34
+ ### Added
35
+ * Serialize and return responses to be used in tests [PR 34](https://github.com/shakacode/cypress-on-rails/pull/34).
36
+ * Update generator to make it easier to update core generated files [PR 35](https://github.com/shakacode/cypress-on-rails/pull/35).
37
+
38
+ ### Tasks
39
+ * Update integration tests [PR 36](https://github.com/shakacode/cypress-on-rails/pull/36).
40
+
1
41
  ## [1.4.2]
42
+ [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.4.1...v1.4.2
2
43
 
3
44
  ### Fixed
4
45
  * update generator to use full paths for Factory files [PR 33](https://github.com/shakacode/cypress-on-rails/pull/33).
5
46
 
6
47
  ## [1.4.1]
48
+ [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.4.0...v1.4.1
7
49
 
8
50
  ### Fixed
9
51
  * fix install generator when using npm [PR 22](https://github.com/shakacode/cypress-on-rails/pull/22) by [josephan](https://github.com/josephan).
@@ -14,7 +56,9 @@
14
56
  * Update Travis CI badge in README [PR 31](https://github.com/shakacode/cypress-on-rails/pull/31)
15
57
  * Fix CI by Installing cypress dependencies on Travis CI [PR 31](https://github.com/shakacode/cypress-on-rails/pull/31)
16
58
 
17
- ## [1.4.0]
59
+ ## [1.4.0]
60
+ [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.3.0...v1.4.0
61
+
18
62
  * Accept an options argument for scenarios. [PR 18](https://github.com/shakacode/cypress-on-rails/pull/18) by [ericraio](https://github.com/ericraio).
19
63
 
20
64
  ### Changed
@@ -78,10 +122,6 @@
78
122
  ## 0.1.2 (2017-10-31)
79
123
  * First release.
80
124
 
81
- [Unreleased]: https://github.com/shakacode/cypress-on-rails/compare/v1.4.2...master
82
- [1.4.2]: https://github.com/shakacode/cypress-on-rails/compare/v1.4.1...v1.4.2
83
- [1.4.1]: https://github.com/shakacode/cypress-on-rails/compare/v1.4.0...v1.4.1
84
- [1.4.0]: https://github.com/shakacode/cypress-on-rails/compare/v1.3.0...v1.4.0
85
125
  [1.3.0]: https://github.com/shakacode/cypress-on-rails/compare/v1.2.1...v1.3.0
86
126
  [1.2.1]: https://github.com/shakacode/cypress-on-rails/compare/v1.2.0...v1.2.1
87
127
  [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
- Gem for using [cypress.io](http://github.com/cypress-io/) in Rails and ruby rack applications
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
- The generate the boilerplate code using:
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 to your application:
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/clean_db.rb`.
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 plan ruby files that get loaded through middleware, the ruby sky is your limit.
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 5002
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
- always_reload: !Rails.configuration.cache_classes,
83
- factory: FactoryBot,
84
- files: Dir['./spec/factories/**/*.rb']
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
@@ -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/grantspeelman/cypress-on-rails"
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,12 @@ 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.add_development_dependency 'factory_bot'
23
+ s.metadata = {
24
+ "bug_tracker_uri" => "https://github.com/shakacode/cypress-on-rails/issues",
25
+ "changelog_uri" => "https://github.com/shakacode/cypress-on-rails/blob/master/CHANGELOG.md",
26
+ "documentation_uri" => "https://github.com/shakacode/cypress-on-rails/blob/master/README.md",
27
+ "homepage_uri" => "http://github.com/shakacode/cypress-on-rails",
28
+ "source_code_uri" => "http://github.com/shakacode/cypress-on-rails"
29
+ }
22
30
  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.each { |command| @command_executor.load(command.file_path, command.options) }
59
- [201, {}, ['success']]
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
@@ -12,5 +12,9 @@ module CypressOnRails
12
12
  create(type,*params)
13
13
  end
14
14
  end
15
+
16
+ # to be API compatible with factorybot
17
+ def self.definition_file_paths=(*); end
18
+ def self.reload; end
15
19
  end
16
20
  end
@@ -3,15 +3,6 @@ require 'cypress_on_rails/simple_rails_factory'
3
3
 
4
4
  module CypressOnRails
5
5
  class SmartFactoryWrapper
6
- module FactoryCleaner
7
- def self.clean(f = FactoryBot)
8
- f.factories.clear if f.respond_to?(:factories)
9
- f.traits.clear if f.respond_to?(:traits)
10
- f.callbacks.clear if f.respond_to?(:callbacks)
11
- f.sequences.clear if f.respond_to?(:sequences)
12
- end
13
- end
14
-
15
6
  def self.instance
16
7
  @instance ||= new(files: [], factory: SimpleRailsFactory)
17
8
  end
@@ -33,21 +24,26 @@ module CypressOnRails
33
24
  attr_accessor :always_reload
34
25
 
35
26
  def initialize(files:, factory:, always_reload: false,
36
- factory_cleaner: FactoryCleaner, kernel: Kernel, file_system: File,
37
- dir_system: Dir)
27
+ kernel: Kernel, file_system: File, dir_system: Dir)
38
28
  self.files = files
39
29
  self.factory = factory
30
+ factory.definition_file_paths = []
40
31
  self.always_reload = always_reload
41
32
  @kernel = kernel
42
33
  @file_system = file_system
43
- @factory_cleaner = factory_cleaner
44
34
  @latest_mtime = nil
45
35
  @dir_system = dir_system
46
36
  end
47
37
 
48
- def create(*args)
38
+ def create(*options)
49
39
  load_files
50
- factory.create(*args)
40
+ factory_name = options.shift
41
+ if options.last.is_a?(Hash)
42
+ args = options.pop
43
+ else
44
+ args = {}
45
+ end
46
+ factory.create(factory_name,*options.map(&:to_sym),args.symbolize_keys)
51
47
  end
52
48
 
53
49
  def create_list(*args)
@@ -77,7 +73,7 @@ module CypressOnRails
77
73
  return unless should_reload?(current_latest_mtime)
78
74
  logger.info 'Loading Factories'
79
75
  @latest_mtime = current_latest_mtime
80
- @factory_cleaner.clean(factory)
76
+ factory.reload
81
77
  files.each do |file|
82
78
  logger.debug "-- Loading: #{file}"
83
79
  @kernel.load(file)
@@ -1,3 +1,3 @@
1
1
  module CypressOnRails
2
- VERSION = '1.4.2'
2
+ VERSION = '1.8.0'
3
3
  end
@@ -1,4 +1,4 @@
1
1
  {
2
- "baseUrl": "http://localhost:5002",
2
+ "baseUrl": "http://localhost:5017",
3
3
  "defaultCommandTimeout": 10000
4
4
  }
@@ -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 clean_db"
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
 
@@ -1,4 +1,4 @@
1
- Array.wrap(command_options).each do |factory_options|
1
+ Array.wrap(command_options).map do |factory_options|
2
2
  factory_method = factory_options.shift
3
3
  begin
4
4
  logger.debug "running #{factory_method}, #{factory_options}"
@@ -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:5002')
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
+ })
@@ -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, {}, ['success']])
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, {}, ['success']])
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(false)
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([404, {}, ['could not find command file: spec/cypress/app_commands/seed.rb']])
50
- expect(command_executor).to_not have_received(:load)
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, {}, ['success']])
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
@@ -1,4 +1,5 @@
1
1
  require 'cypress_on_rails/smart_factory_wrapper'
2
+ require 'factory_bot'
2
3
 
3
4
  RSpec.describe CypressOnRails::SmartFactoryWrapper do
4
5
  FileSystemDummy = Struct.new(:file_hash) do
@@ -10,8 +11,9 @@ RSpec.describe CypressOnRails::SmartFactoryWrapper do
10
11
  let(:time_now) { Time.now }
11
12
  let(:mtime_hash) { {'file1.rb' => time_now, 'file2.rb' => time_now } }
12
13
  let(:files) { %w(file1.rb file2.rb) }
13
- let(:factory_double) { double('FactoryBot', create: true, create_list: true) }
14
- let(:factory_cleaner) { class_double(CypressOnRails::SmartFactoryWrapper::FactoryCleaner, clean: true) }
14
+ let(:factory_double) do
15
+ class_double(FactoryBot, create: nil, create_list: nil, "definition_file_paths=": nil, reload: nil)
16
+ end
15
17
  let(:kernel_double) { class_double(Kernel, load: true) }
16
18
  let(:file_double) { FileSystemDummy.new(mtime_hash) }
17
19
  let(:dir_double) { class_double(Dir) }
@@ -25,8 +27,7 @@ RSpec.describe CypressOnRails::SmartFactoryWrapper do
25
27
  factory: factory_double,
26
28
  kernel: kernel_double,
27
29
  file_system: file_double,
28
- dir_system: dir_double,
29
- factory_cleaner: factory_cleaner)
30
+ dir_system: dir_double)
30
31
  end
31
32
 
32
33
  it 'loads all the files on first create it' do
@@ -43,7 +44,22 @@ RSpec.describe CypressOnRails::SmartFactoryWrapper do
43
44
 
44
45
  it 'it sends delegates create to the factory' do
45
46
  subject.create(:user)
46
- expect(factory_double).to have_received(:create).with(:user)
47
+ expect(factory_double).to have_received(:create).with(:user, {})
48
+ end
49
+
50
+ it 'it sends delegates create to the factory and symbolize keys' do
51
+ subject.create(:user, {'name' => "name"})
52
+ expect(factory_double).to have_received(:create).with(:user, {name: 'name'})
53
+ end
54
+
55
+ it 'it sends delegates create to the factory and symbolize keys with trait' do
56
+ subject.create(:user, 'trait1', {'name' => "name"})
57
+ expect(factory_double).to have_received(:create).with(:user, :trait1, {name: 'name'})
58
+ end
59
+
60
+ it 'it sends delegates create to the factory and symbolize keys with only trait' do
61
+ subject.create(:user, 'trait2')
62
+ expect(factory_double).to have_received(:create).with(:user, :trait2, {})
47
63
  end
48
64
 
49
65
  it 'it sends delegates create_list to the factory' do
@@ -53,7 +69,7 @@ RSpec.describe CypressOnRails::SmartFactoryWrapper do
53
69
 
54
70
  it 'wont load the files if they have not changed' do
55
71
  subject.create(:user)
56
- subject.create_list(:user)
72
+ subject.create_list(:user, 2)
57
73
  expect(kernel_double).to have_received(:load).with('file1.rb').once
58
74
  expect(kernel_double).to have_received(:load).with('file2.rb').once
59
75
  end
@@ -64,7 +80,7 @@ RSpec.describe CypressOnRails::SmartFactoryWrapper do
64
80
  expect(kernel_double).to have_received(:load).with('file2.rb').once
65
81
 
66
82
  mtime_hash['file1.rb'] = Time.now
67
- subject.create_list(:user)
83
+ subject.create_list(:user, 2)
68
84
  expect(kernel_double).to have_received(:load).with('file1.rb').twice
69
85
  expect(kernel_double).to have_received(:load).with('file2.rb').twice
70
86
  end
@@ -76,24 +92,24 @@ RSpec.describe CypressOnRails::SmartFactoryWrapper do
76
92
  expect(kernel_double).to have_received(:load).with('file2.rb').once
77
93
 
78
94
  mtime_hash.delete('file1.rb')
79
- subject.create_list(:user)
95
+ subject.create_list(:user, 2)
80
96
  expect(kernel_double).to have_received(:load).with('file1.rb').once
81
97
  expect(kernel_double).to have_received(:load).with('file2.rb').twice
82
98
  end
83
99
 
84
- it 'will reset factory if a has changed' do
100
+ it 'will reset factory if a file has changed' do
85
101
  subject.create(:user)
86
- expect(factory_cleaner).to have_received(:clean).with(factory_double)
102
+ expect(factory_double).to have_received(:reload)
87
103
 
88
104
  mtime_hash['file1.rb'] = Time.now
89
- subject.create_list(:user)
105
+ subject.create_list(:user, 2)
90
106
 
91
- expect(factory_cleaner).to have_received(:clean).with(factory_double).twice
107
+ expect(factory_double).to have_received(:reload).twice
92
108
  end
93
109
 
94
110
  it 'will always reload the files enabled' do
95
111
  subject.always_reload = true
96
- subject.create_list(:user)
112
+ subject.create_list(:user, 2)
97
113
  subject.create(:user)
98
114
  expect(kernel_double).to have_received(:load).with('file1.rb').twice
99
115
  expect(kernel_double).to have_received(:load).with('file2.rb').twice
@@ -1,5 +1,5 @@
1
1
  {
2
- "baseUrl": "http://localhost:5002",
2
+ "baseUrl": "http://localhost:5017",
3
3
  "defaultCommandTimeout": 10000,
4
4
  "projectId": "qvzwep"
5
5
  }
@@ -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 5002 -e test &
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'
@@ -1,7 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
4
- gem 'rails', '4.2.10'
4
+ gem 'rails', '~> 4.2.10'
5
+ gem 'sprockets', '~> 3.7.2'
5
6
 
6
7
  group :development, :test do
7
8
  gem 'cypress-on-rails', path: '../../../'
@@ -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 5002 -e test &
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`
@@ -6,7 +6,7 @@ test/yarn.lock
6
6
  test/cypress/
7
7
  config/initializers/cypress_on_rails.rb
8
8
  vendor/bundle
9
- tmp/pids
10
9
  db/*.sqlite3
11
10
  db/schema.rb
12
- tmp/cache
11
+ tmp/*
12
+ log/*
@@ -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 5002 -e test &
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.2
4
+ version: 1.8.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: 2019-08-23 00:00:00.000000000 Z
12
+ date: 2020-07-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -67,6 +67,20 @@ dependencies:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: '3.2'
70
+ - !ruby/object:Gem::Dependency
71
+ name: factory_bot
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
70
84
  description: Integrates cypress with rails or rack applications
71
85
  email:
72
86
  - info@miceportal.de
@@ -75,6 +89,7 @@ executables: []
75
89
  extensions: []
76
90
  extra_rdoc_files: []
77
91
  files:
92
+ - ".github/FUNDING.yml"
78
93
  - ".gitignore"
79
94
  - ".rspec"
80
95
  - ".travis.yml"
@@ -127,13 +142,15 @@ files:
127
142
  - lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/viewport.spec.js
128
143
  - lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/waiting.spec.js
129
144
  - lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/window.spec.js
145
+ - lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/advance_factory_bot_spec.js
130
146
  - 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/using_factory_bot.js
132
- - lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_fixtures.js
147
+ - lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_factory_bot_spec.js
148
+ - lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_fixtures_spec.js
133
149
  - lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_scenarios_spec.js
134
150
  - lib/generators/cypress_on_rails/templates/spec/cypress/support/commands.js
135
151
  - lib/generators/cypress_on_rails/templates/spec/cypress/support/index.js
136
152
  - lib/generators/cypress_on_rails/templates/spec/cypress/support/on-rails.js
153
+ - lib/generators/cypress_on_rails/update_generator.rb
137
154
  - spec/cypress_on_rails/command_executor/cypress_helper.rb
138
155
  - spec/cypress_on_rails/command_executor/test_command.rb
139
156
  - spec/cypress_on_rails/command_executor/test_command_with_options.rb
@@ -282,9 +299,14 @@ files:
282
299
  - spec/integrations/rails_5_2/tmp/.keep
283
300
  - spec/integrations/rails_5_2/vendor/.keep
284
301
  - spec/spec_helper.rb
285
- homepage: http://github.com/grantspeelman/cypress-on-rails
302
+ homepage: http://github.com/shakacode/cypress-on-rails
286
303
  licenses: []
287
- metadata: {}
304
+ metadata:
305
+ bug_tracker_uri: https://github.com/shakacode/cypress-on-rails/issues
306
+ changelog_uri: https://github.com/shakacode/cypress-on-rails/blob/master/CHANGELOG.md
307
+ documentation_uri: https://github.com/shakacode/cypress-on-rails/blob/master/README.md
308
+ homepage_uri: http://github.com/shakacode/cypress-on-rails
309
+ source_code_uri: http://github.com/shakacode/cypress-on-rails
288
310
  post_install_message: The CypressDev constant is being deprecated and will be completely
289
311
  removed and replaced with CypressOnRails.
290
312
  rdoc_options: []
@@ -302,7 +324,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
302
324
  version: '0'
303
325
  requirements: []
304
326
  rubyforge_project:
305
- rubygems_version: 2.7.6
327
+ rubygems_version: 2.6.14.4
306
328
  signing_key:
307
329
  specification_version: 4
308
330
  summary: Integrates cypress with rails or rack applications