cypress-on-rails 0.2.2 → 1.0.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +6 -1
- data/.rspec +1 -0
- data/.travis.yml +29 -0
- data/CHANGELOG.md +6 -0
- data/README.md +155 -54
- data/Rakefile +8 -0
- data/cypress-on-rails.gemspec +10 -9
- data/lib/cypress-on-rails.rb +3 -1
- data/lib/cypress/smart_factory_wrapper.rb +3 -0
- data/lib/cypress_dev.rb +4 -0
- data/lib/cypress_dev/command_executor.rb +33 -0
- data/lib/cypress_dev/configuration.rb +37 -0
- data/lib/cypress_dev/middleware.rb +65 -0
- data/lib/{cypress → cypress_dev}/railtie.rb +5 -7
- data/lib/cypress_dev/simple_rails_factory.rb +17 -0
- data/lib/cypress_dev/smart_factory_wrapper.rb +79 -0
- data/lib/cypress_dev/version.rb +3 -0
- data/lib/generators/cypress_dev/install_generator.rb +59 -0
- data/lib/generators/cypress_dev/templates/config/initializers/cypress_dev.rb.erb +9 -0
- data/lib/generators/cypress_dev/templates/spec/cypress.json +4 -0
- data/lib/generators/cypress_dev/templates/spec/cypress/app_commands/clean.rb +7 -0
- data/lib/generators/cypress_dev/templates/spec/cypress/app_commands/eval.rb +1 -0
- data/lib/generators/cypress_dev/templates/spec/cypress/app_commands/factory_bot.rb +12 -0
- data/lib/generators/cypress_dev/templates/spec/cypress/app_commands/scenarios/basic.rb +2 -0
- data/lib/generators/cypress_dev/templates/spec/cypress/cypress_helper.rb +30 -0
- data/lib/generators/cypress_dev/templates/spec/cypress/integration/on_rails_spec.js +33 -0
- data/lib/generators/cypress_dev/templates/spec/cypress/support/commands.js +25 -0
- data/lib/generators/cypress_dev/templates/spec/cypress/support/index.js +21 -0
- data/lib/generators/cypress_dev/templates/spec/cypress/support/on-rails.js +33 -0
- data/spec/cypress_dev/command_executor/cypress_helper.rb +6 -0
- data/spec/cypress_dev/command_executor/test_command.rb +1 -0
- data/spec/cypress_dev/command_executor/test_command_with_options.rb +1 -0
- data/spec/cypress_dev/command_executor_spec.rb +33 -0
- data/spec/cypress_dev/configuration_spec.rb +23 -0
- data/spec/cypress_dev/middleware_spec.rb +104 -0
- data/spec/cypress_dev/railtie_spec.rb +22 -0
- data/spec/cypress_dev/smart_factory_wrapper_spec.rb +83 -0
- data/spec/integrations/rails_3_2/.gitignore +9 -0
- data/spec/integrations/rails_3_2/Gemfile +7 -0
- data/spec/integrations/rails_3_2/README.rdoc +261 -0
- data/spec/integrations/rails_3_2/Rakefile +7 -0
- data/spec/integrations/rails_3_2/app/assets/stylesheets/application.css +13 -0
- data/spec/integrations/rails_3_2/app/controllers/application_controller.rb +3 -0
- data/spec/integrations/rails_3_2/app/controllers/welcome_controller.rb +4 -0
- data/spec/integrations/rails_3_2/app/helpers/application_helper.rb +2 -0
- data/spec/integrations/rails_3_2/app/models/post.rb +13 -0
- data/spec/integrations/rails_3_2/app/views/layouts/application.html.erb +13 -0
- data/spec/integrations/rails_3_2/app/views/welcome/index.html.erb +5 -0
- data/spec/integrations/rails_3_2/bin/rails +6 -0
- data/spec/integrations/rails_3_2/config.ru +4 -0
- data/spec/integrations/rails_3_2/config/application.rb +69 -0
- data/spec/integrations/rails_3_2/config/boot.rb +6 -0
- data/spec/integrations/rails_3_2/config/environment.rb +5 -0
- data/spec/integrations/rails_3_2/config/environments/development.rb +31 -0
- data/spec/integrations/rails_3_2/config/environments/production.rb +64 -0
- data/spec/integrations/rails_3_2/config/environments/test.rb +35 -0
- data/spec/integrations/rails_3_2/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/integrations/rails_3_2/config/initializers/inflections.rb +15 -0
- data/spec/integrations/rails_3_2/config/initializers/mime_types.rb +5 -0
- data/spec/integrations/rails_3_2/config/initializers/secret_token.rb +7 -0
- data/spec/integrations/rails_3_2/config/initializers/session_store.rb +8 -0
- data/spec/integrations/rails_3_2/config/initializers/wrap_parameters.rb +10 -0
- data/spec/integrations/rails_3_2/config/locales/en.yml +5 -0
- data/spec/integrations/rails_3_2/config/routes.rb +60 -0
- data/spec/integrations/rails_3_2/public/404.html +26 -0
- data/spec/integrations/rails_3_2/public/422.html +26 -0
- data/spec/integrations/rails_3_2/public/500.html +25 -0
- data/spec/integrations/rails_3_2/public/favicon.ico +0 -0
- data/spec/integrations/rails_3_2/public/robots.txt +5 -0
- data/spec/integrations/rails_3_2/test.sh +30 -0
- data/spec/integrations/rails_3_2/tmp/.keep +0 -0
- data/spec/integrations/rails_3_2/vendor/.gitkeep +0 -0
- data/spec/integrations/rails_4_2/.gitignore +10 -0
- data/spec/integrations/rails_4_2/Gemfile +8 -0
- data/spec/integrations/rails_4_2/README.rdoc +28 -0
- data/spec/integrations/rails_4_2/Rakefile +6 -0
- data/spec/integrations/rails_4_2/app/controllers/application_controller.rb +5 -0
- data/spec/integrations/rails_4_2/app/controllers/welcome_controller.rb +4 -0
- data/spec/integrations/rails_4_2/app/models/post.rb +13 -0
- data/spec/integrations/rails_4_2/app/views/layouts/application.html.erb +12 -0
- data/spec/integrations/rails_4_2/app/views/welcome/index.html.erb +5 -0
- data/spec/integrations/rails_4_2/bin/bundle +3 -0
- data/spec/integrations/rails_4_2/bin/rails +4 -0
- data/spec/integrations/rails_4_2/bin/rake +4 -0
- data/spec/integrations/rails_4_2/bin/setup +29 -0
- data/spec/integrations/rails_4_2/config.ru +4 -0
- data/spec/integrations/rails_4_2/config/application.rb +33 -0
- data/spec/integrations/rails_4_2/config/boot.rb +3 -0
- data/spec/integrations/rails_4_2/config/environment.rb +5 -0
- data/spec/integrations/rails_4_2/config/environments/development.rb +25 -0
- data/spec/integrations/rails_4_2/config/environments/production.rb +64 -0
- data/spec/integrations/rails_4_2/config/environments/test.rb +42 -0
- data/spec/integrations/rails_4_2/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/integrations/rails_4_2/config/initializers/cookies_serializer.rb +3 -0
- data/spec/integrations/rails_4_2/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/integrations/rails_4_2/config/initializers/inflections.rb +16 -0
- data/spec/integrations/rails_4_2/config/initializers/mime_types.rb +4 -0
- data/spec/integrations/rails_4_2/config/initializers/session_store.rb +3 -0
- data/spec/integrations/rails_4_2/config/initializers/to_time_preserves_timezone.rb +10 -0
- data/spec/integrations/rails_4_2/config/initializers/wrap_parameters.rb +9 -0
- data/spec/integrations/rails_4_2/config/locales/en.yml +23 -0
- data/spec/integrations/rails_4_2/config/routes.rb +56 -0
- data/spec/integrations/rails_4_2/config/secrets.yml +22 -0
- data/spec/integrations/rails_4_2/public/404.html +67 -0
- data/spec/integrations/rails_4_2/public/422.html +67 -0
- data/spec/integrations/rails_4_2/public/500.html +66 -0
- data/spec/integrations/rails_4_2/public/favicon.ico +0 -0
- data/spec/integrations/rails_4_2/public/robots.txt +5 -0
- data/spec/integrations/rails_4_2/test.sh +31 -0
- data/spec/integrations/rails_4_2/vendor/.keep +0 -0
- data/spec/integrations/rails_5_2/.gitignore +10 -0
- data/spec/integrations/rails_5_2/Gemfile +12 -0
- data/spec/integrations/rails_5_2/README.md +24 -0
- data/spec/integrations/rails_5_2/Rakefile +6 -0
- data/spec/integrations/rails_5_2/app/controllers/application_controller.rb +2 -0
- data/spec/integrations/rails_5_2/app/controllers/welcome_controller.rb +4 -0
- data/spec/integrations/rails_5_2/app/jobs/application_job.rb +2 -0
- data/spec/integrations/rails_5_2/app/models/post.rb +13 -0
- data/spec/integrations/rails_5_2/app/views/layouts/application.html.erb +12 -0
- data/spec/integrations/rails_5_2/app/views/welcome/index.html.erb +5 -0
- data/spec/integrations/rails_5_2/bin/bundle +3 -0
- data/spec/integrations/rails_5_2/bin/rails +4 -0
- data/spec/integrations/rails_5_2/bin/rake +4 -0
- data/spec/integrations/rails_5_2/bin/setup +25 -0
- data/spec/integrations/rails_5_2/bin/update +25 -0
- data/spec/integrations/rails_5_2/config.ru +5 -0
- data/spec/integrations/rails_5_2/config/application.rb +37 -0
- data/spec/integrations/rails_5_2/config/boot.rb +4 -0
- data/spec/integrations/rails_5_2/config/credentials.yml.enc +1 -0
- data/spec/integrations/rails_5_2/config/environment.rb +5 -0
- data/spec/integrations/rails_5_2/config/environments/development.rb +40 -0
- data/spec/integrations/rails_5_2/config/environments/production.rb +68 -0
- data/spec/integrations/rails_5_2/config/environments/test.rb +36 -0
- data/spec/integrations/rails_5_2/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/integrations/rails_5_2/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/integrations/rails_5_2/config/initializers/content_security_policy.rb +25 -0
- data/spec/integrations/rails_5_2/config/initializers/cookies_serializer.rb +5 -0
- data/spec/integrations/rails_5_2/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/integrations/rails_5_2/config/initializers/inflections.rb +16 -0
- data/spec/integrations/rails_5_2/config/initializers/mime_types.rb +4 -0
- data/spec/integrations/rails_5_2/config/initializers/wrap_parameters.rb +9 -0
- data/spec/integrations/rails_5_2/config/locales/en.yml +33 -0
- data/spec/integrations/rails_5_2/config/master.key +1 -0
- data/spec/integrations/rails_5_2/config/routes.rb +4 -0
- data/spec/integrations/rails_5_2/public/404.html +67 -0
- data/spec/integrations/rails_5_2/public/422.html +67 -0
- data/spec/integrations/rails_5_2/public/500.html +66 -0
- data/spec/integrations/rails_5_2/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/integrations/rails_5_2/public/apple-touch-icon.png +0 -0
- data/spec/integrations/rails_5_2/public/favicon.ico +0 -0
- data/spec/integrations/rails_5_2/public/robots.txt +1 -0
- data/spec/integrations/rails_5_2/test.sh +31 -0
- data/spec/integrations/rails_5_2/tmp/.keep +0 -0
- data/spec/integrations/rails_5_2/vendor/.keep +0 -0
- data/spec/spec_helper.rb +104 -0
- metadata +177 -25
- data/Gemfile.lock +0 -32
- data/bin/cypress +0 -3
- data/lib/cypress.rb +0 -27
- data/lib/cypress/configuration.rb +0 -41
- data/lib/cypress/middleware.rb +0 -69
- data/lib/cypress/runner.rb +0 -42
- data/lib/cypress/scenario_bank.rb +0 -21
- data/lib/cypress/scenario_context.rb +0 -23
- data/lib/cypress/version.rb +0 -3
- data/lib/generators/install_generator.rb +0 -77
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'rack'
|
3
|
+
require 'cypress_dev/configuration'
|
4
|
+
require 'cypress_dev/command_executor'
|
5
|
+
|
6
|
+
module CypressDev
|
7
|
+
# Middleware to handle cypress commands and eval
|
8
|
+
class Middleware
|
9
|
+
def initialize(app, command_executor = CommandExecutor, file = ::File)
|
10
|
+
@app = app
|
11
|
+
@command_executor = command_executor
|
12
|
+
@file = file
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
request = Rack::Request.new(env)
|
17
|
+
if request.path.start_with?('/__cypress__/command')
|
18
|
+
configuration.tagged_logged { handle_command(request) }
|
19
|
+
else
|
20
|
+
@app.call(env)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def configuration
|
27
|
+
CypressDev.configuration
|
28
|
+
end
|
29
|
+
|
30
|
+
def logger
|
31
|
+
configuration.logger
|
32
|
+
end
|
33
|
+
|
34
|
+
Command = Struct.new(:name, :options, :cypress_folder) do
|
35
|
+
# @return [Array<Cypress::Middleware::Command>]
|
36
|
+
def self.from_body(body, configuration)
|
37
|
+
if body.is_a?(Array)
|
38
|
+
command_params = body
|
39
|
+
else
|
40
|
+
command_params = [body]
|
41
|
+
end
|
42
|
+
command_params.map do |params|
|
43
|
+
new(params.fetch('name'), params['options'], configuration.cypress_folder)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def file_path
|
48
|
+
"#{cypress_folder}/app_commands/#{name}.rb"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def handle_command(req)
|
53
|
+
body = JSON.parse(req.body.read)
|
54
|
+
logger.info "handle_command: #{body}"
|
55
|
+
commands = Command.from_body(body, configuration)
|
56
|
+
missing_command = commands.find {|command| !@file.exists?(command.file_path) }
|
57
|
+
if missing_command.nil?
|
58
|
+
commands.each { |command| @command_executor.load(command.file_path, command.options) }
|
59
|
+
[201, {}, ['success']]
|
60
|
+
else
|
61
|
+
[404, {}, ["could not find command file: #{missing_command.file_path}"]]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -1,15 +1,13 @@
|
|
1
1
|
require 'rails/railtie'
|
2
|
-
|
2
|
+
require 'cypress_dev/configuration'
|
3
|
+
require 'cypress_dev/middleware'
|
4
|
+
|
5
|
+
module CypressDev
|
3
6
|
class Railtie < Rails::Railtie
|
4
7
|
initializer :setup_cypress_middleware do |app|
|
5
|
-
if
|
6
|
-
Cypress.configuration.load_support
|
8
|
+
if CypressDev.configuration.use_middleware?
|
7
9
|
app.middleware.use Middleware
|
8
10
|
end
|
9
11
|
end
|
10
|
-
|
11
|
-
generators do
|
12
|
-
require_relative '../generators/install_generator'
|
13
|
-
end
|
14
12
|
end
|
15
13
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module CypressDev
|
2
|
+
module SimpleRailsFactory
|
3
|
+
def self.create(type, params = {})
|
4
|
+
type.camelize.constantize.create(params)
|
5
|
+
rescue NameError => e
|
6
|
+
Rails.logger.warn e.message
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.create_list(type, amount, params = {})
|
10
|
+
amount.to_i.times do
|
11
|
+
create(type,params)
|
12
|
+
end
|
13
|
+
rescue NameError => e
|
14
|
+
Rails.logger.warn e.message
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'cypress_dev/configuration'
|
2
|
+
require 'cypress_dev/simple_rails_factory'
|
3
|
+
|
4
|
+
module CypressDev
|
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
|
+
def self.instance
|
16
|
+
@instance ||= new(files: [], factory: SimpleRailsFactory)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.configure(files:, factory:, always_reload: true)
|
20
|
+
@instance = new(files: files, factory: factory, always_reload: always_reload)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.create(*args)
|
24
|
+
instance.create(*args)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.create_list(*args)
|
28
|
+
instance.create_list(*args)
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [Array]
|
32
|
+
attr_accessor :files
|
33
|
+
attr_accessor :factory
|
34
|
+
attr_accessor :always_reload
|
35
|
+
|
36
|
+
def initialize(files:, factory:, always_reload: false,
|
37
|
+
factory_cleaner: FactoryCleaner, kernel: Kernel, file_system: File)
|
38
|
+
self.files = files
|
39
|
+
self.factory = factory
|
40
|
+
self.always_reload = always_reload
|
41
|
+
@kernel = kernel
|
42
|
+
@file_system = file_system
|
43
|
+
@factory_cleaner = factory_cleaner
|
44
|
+
@latest_mtime = nil
|
45
|
+
end
|
46
|
+
|
47
|
+
def create(*args)
|
48
|
+
load_files
|
49
|
+
factory.create(*args)
|
50
|
+
end
|
51
|
+
|
52
|
+
def create_list(*args)
|
53
|
+
load_files
|
54
|
+
factory.create_list(*args)
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def logger
|
60
|
+
CypressDev.configuration.logger
|
61
|
+
end
|
62
|
+
|
63
|
+
def load_files
|
64
|
+
current_latest_mtime = files.map{|file| @file_system.mtime(file) }.max
|
65
|
+
return unless should_reload?(current_latest_mtime)
|
66
|
+
logger.info 'Loading Factories'
|
67
|
+
@latest_mtime = current_latest_mtime
|
68
|
+
@factory_cleaner.clean(factory)
|
69
|
+
files.each do |file|
|
70
|
+
logger.debug "-- Loading: #{file}"
|
71
|
+
@kernel.load(file)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def should_reload?(current_latest_mtime)
|
76
|
+
@always_reload || @latest_mtime.nil? || @latest_mtime < current_latest_mtime
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module CypressDev
|
2
|
+
class InstallGenerator < Rails::Generators::Base
|
3
|
+
class_option :cypress_folder, type: :string, default: 'spec/cypress'
|
4
|
+
class_option :install_cypress_with, type: :string, default: 'yarn'
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
def install_cypress
|
8
|
+
if !Dir.exists?(options.cypress_folder) || Dir["#{options.cypress_folder}/*"].empty?
|
9
|
+
directories = options.cypress_folder.split('/')
|
10
|
+
directories.pop
|
11
|
+
install_dir = "#{Dir.pwd}/#{directories.join('/')}"
|
12
|
+
command = nil
|
13
|
+
if options.install_cypress_with == 'yarn'
|
14
|
+
command = "yarn --cwd=#{install_dir} add cypress --dev --silent"
|
15
|
+
elsif options.install_cypress_with == 'npm'
|
16
|
+
command = "cd #{install_dir}; npm add cypress --save-dev --silent"
|
17
|
+
end
|
18
|
+
if command
|
19
|
+
say command
|
20
|
+
fail 'failed to install cypress' unless system(command)
|
21
|
+
end
|
22
|
+
copy_file "spec/cypress/support/index.js", "#{options.cypress_folder}/support/index.js"
|
23
|
+
copy_file "spec/cypress/support/commands.js", "#{options.cypress_folder}/support/commands.js"
|
24
|
+
copy_file "spec/cypress.json", "#{options.cypress_folder}/../cypress.json"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_initial_files
|
29
|
+
template "config/initializers/cypress_dev.rb.erb", "config/initializers/cypress_dev.rb"
|
30
|
+
copy_file "spec/cypress/cypress_helper.rb", "#{options.cypress_folder}/cypress_helper.rb"
|
31
|
+
copy_file "spec/cypress/integration/on_rails_spec.js", "#{options.cypress_folder}/integration/on_rails_spec.js"
|
32
|
+
copy_file "spec/cypress/support/on-rails.js", "#{options.cypress_folder}/support/on-rails.js"
|
33
|
+
copy_file "spec/cypress/app_commands/scenarios/basic.rb", "#{options.cypress_folder}/app_commands/scenarios/basic.rb"
|
34
|
+
copy_file "spec/cypress/app_commands/clean.rb", "#{options.cypress_folder}/app_commands/clean.rb"
|
35
|
+
copy_file "spec/cypress/app_commands/eval.rb", "#{options.cypress_folder}/app_commands/eval.rb"
|
36
|
+
copy_file "spec/cypress/app_commands/factory_bot.rb", "#{options.cypress_folder}/app_commands/factory_bot.rb"
|
37
|
+
end
|
38
|
+
|
39
|
+
def update_files
|
40
|
+
append_to_file "#{options.cypress_folder}/support/index.js",
|
41
|
+
'import \'./on-rails\'',
|
42
|
+
after: 'import \'./commands\''
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def update_test_rb
|
47
|
+
if File.exist?('config/environments/test.rb')
|
48
|
+
gsub_file 'config/environments/test.rb',
|
49
|
+
'config.cache_classes = true',
|
50
|
+
'config.cache_classes = ENV[\'CI\'].present?'
|
51
|
+
end
|
52
|
+
if File.exist?('spec/dummy/config/environments/test.rb')
|
53
|
+
gsub_file 'spec/dummy/config/environments/test.rb',
|
54
|
+
'config.cache_classes = true',
|
55
|
+
'config.cache_classes = ENV[\'CI\'].present?'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
if defined?(CypressDev)
|
2
|
+
CypressDev.configure do |c|
|
3
|
+
c.cypress_folder = File.expand_path("#{__dir__}/../../<%= options.cypress_folder %>")
|
4
|
+
# WARNING!! CypressDev can execute arbitrary ruby code
|
5
|
+
# please use with extra caution if enabling on hosted servers or starting your local server on 0.0.0.0
|
6
|
+
c.use_middleware = Rails.env.test?
|
7
|
+
c.logger = Rails.logger
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Kernel.eval(command_options) unless command_options.nil?
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Array.wrap(command_options).each do |factory_options|
|
2
|
+
factory_method = factory_options.shift
|
3
|
+
begin
|
4
|
+
logger.debug "running #{factory_method}, #{factory_options}"
|
5
|
+
CypressDev::SmartFactoryWrapper.public_send(factory_method, *factory_options)
|
6
|
+
rescue => e
|
7
|
+
logger.error "#{e.class}: #{e.message}"
|
8
|
+
logger.error e.backtrace.join("\n")
|
9
|
+
logger.error "#{e.record.inspect}" if e.is_a?(ActiveRecord::RecordInvalid)
|
10
|
+
raise e
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# This is loaded once before the first command is executed
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'database_cleaner'
|
5
|
+
rescue LoadError => e
|
6
|
+
puts e.message
|
7
|
+
end
|
8
|
+
|
9
|
+
begin
|
10
|
+
require 'factory_bot_rails'
|
11
|
+
rescue LoadError => e
|
12
|
+
puts e.message
|
13
|
+
begin
|
14
|
+
require 'factory_girl_rails'
|
15
|
+
rescue LoadError => e
|
16
|
+
puts e.message
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'cypress_dev/smart_factory_wrapper'
|
21
|
+
|
22
|
+
factory = CypressDev::SimpleRailsFactory
|
23
|
+
factory = FactoryBot if defined?(FactoryBot)
|
24
|
+
factory = FactoryGirl if defined?(FactoryGirl)
|
25
|
+
|
26
|
+
CypressDev::SmartFactoryWrapper.configure(
|
27
|
+
always_reload: !Rails.configuration.cache_classes,
|
28
|
+
factory: factory,
|
29
|
+
files: Dir['./spec/factories/**/*.rb']
|
30
|
+
)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
describe('My First On Rails Tests', function() {
|
2
|
+
it('setup basic scenario', function() {
|
3
|
+
cy.appScenario('basic')
|
4
|
+
cy.visit('/')
|
5
|
+
})
|
6
|
+
|
7
|
+
it('using factory bot', function() {
|
8
|
+
cy.appFactories([
|
9
|
+
['create_list', 'post', 10],
|
10
|
+
['create', 'post', {title: 'Hello World'} ]
|
11
|
+
])
|
12
|
+
cy.visit('/')
|
13
|
+
})
|
14
|
+
|
15
|
+
it('cypress eval', function() {
|
16
|
+
cy.appEval("Time.now")
|
17
|
+
})
|
18
|
+
|
19
|
+
it('runs multiple commands', function() {
|
20
|
+
cy.appCommands([{ name: 'clean' },
|
21
|
+
{ name: 'eval', options: "Time.now" }])
|
22
|
+
cy.visit('/')
|
23
|
+
})
|
24
|
+
|
25
|
+
// uncomment these if you want to see what happens
|
26
|
+
// it('example of missing scenario failure', function() {
|
27
|
+
// cy.appScenario('missing')
|
28
|
+
// })
|
29
|
+
//
|
30
|
+
// it('example of missing app failure', function() {
|
31
|
+
// cy.app('run_me')
|
32
|
+
// })
|
33
|
+
})
|
@@ -0,0 +1,25 @@
|
|
1
|
+
// ***********************************************
|
2
|
+
// This example commands.js shows you how to
|
3
|
+
// create various custom commands and overwrite
|
4
|
+
// existing commands.
|
5
|
+
//
|
6
|
+
// For more comprehensive examples of custom
|
7
|
+
// commands please read more here:
|
8
|
+
// https://on.cypress.io/custom-commands
|
9
|
+
// ***********************************************
|
10
|
+
//
|
11
|
+
//
|
12
|
+
// -- This is a parent command --
|
13
|
+
// Cypress.Commands.add("login", (email, password) => { ... })
|
14
|
+
//
|
15
|
+
//
|
16
|
+
// -- This is a child command --
|
17
|
+
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
|
18
|
+
//
|
19
|
+
//
|
20
|
+
// -- This is a dual command --
|
21
|
+
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
|
22
|
+
//
|
23
|
+
//
|
24
|
+
// -- This is will overwrite an existing command --
|
25
|
+
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
|
@@ -0,0 +1,21 @@
|
|
1
|
+
// ***********************************************************
|
2
|
+
// This example support/index.js is processed and
|
3
|
+
// loaded automatically before your test files.
|
4
|
+
//
|
5
|
+
// This is a great place to put global configuration and
|
6
|
+
// behavior that modifies Cypress.
|
7
|
+
//
|
8
|
+
// You can change the location of this file or turn off
|
9
|
+
// automatically serving support files with the
|
10
|
+
// 'supportFile' configuration option.
|
11
|
+
//
|
12
|
+
// You can read more here:
|
13
|
+
// https://on.cypress.io/configuration
|
14
|
+
// ***********************************************************
|
15
|
+
|
16
|
+
// Import commands.js using ES2015 syntax:
|
17
|
+
import './commands'
|
18
|
+
import './on-rails'
|
19
|
+
|
20
|
+
// Alternatively you can use CommonJS syntax:
|
21
|
+
// require('./commands')
|
@@ -0,0 +1,33 @@
|
|
1
|
+
// CypressDev: dont remove these command
|
2
|
+
Cypress.Commands.add('appCommands', function (body) {
|
3
|
+
cy.log("APP: " + JSON.stringify(body))
|
4
|
+
cy.request({
|
5
|
+
method: 'POST',
|
6
|
+
url: "/__cypress__/command",
|
7
|
+
body: JSON.stringify(body),
|
8
|
+
log: true,
|
9
|
+
failOnStatusCode: true
|
10
|
+
})
|
11
|
+
});
|
12
|
+
|
13
|
+
Cypress.Commands.add('app', function (name, command_options) {
|
14
|
+
cy.appCommands({name: name, options: command_options})
|
15
|
+
});
|
16
|
+
|
17
|
+
Cypress.Commands.add('appScenario', function (name) {
|
18
|
+
cy.app('scenarios/' + name)
|
19
|
+
});
|
20
|
+
|
21
|
+
Cypress.Commands.add('appEval', function (code) {
|
22
|
+
cy.app('eval', code)
|
23
|
+
});
|
24
|
+
|
25
|
+
Cypress.Commands.add('appFactories', function (options) {
|
26
|
+
cy.app('factory_bot', options)
|
27
|
+
});
|
28
|
+
// CypressDev: end
|
29
|
+
|
30
|
+
// The next is optional
|
31
|
+
beforeEach(() => {
|
32
|
+
cy.app('clean') // have a look at cypress/app_commands/clean.rb
|
33
|
+
});
|