diff --git a/CHANGELOG.md b/CHANGELOG.md index 7542e91..9d86293 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ +## 1.4.0 * Accept an options argument for scenarios +### Tasks +* renamed to CypressOnRails + ## 1.3.0 * send any arguments to simple rails factory, not only hashes ### Tasks diff --git a/README.md b/README.md index 1a4af67..be73f46 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# CypressDev +# CypressOnRails [![Build Status](https://travis-ci.org/grantspeelman/cypress-on-rails.svg?branch=master)](https://travis-ci.org/grantspeelman/cypress-on-rails) @@ -33,17 +33,17 @@ end The generate the boilerplate code using: ``` -bin/rails g cypress_dev:install +bin/rails g cypress_on_rails:install # if you have/want a different cypress folder (default is spec/cypress) -bin/rails g cypress_dev:install --cypress_folder=test/cypress +bin/rails g cypress_on_rails:install --cypress_folder=test/cypress # if you want to install cypress with npm -bin/rails g cypress_dev:install --install_cypress_with=npm +bin/rails g cypress_on_rails:install --install_cypress_with=npm ``` The generator adds the following files/directory to your application: -* `config/initializers/cypress_dev` used to configure CypressDev +* `config/initializers/cypress_on_rails` used to configure CypressDev * `spec/cypress/integrations/` contains your cypress tests * `spec/cypress/support/on-rails.js` contains CypressDev support code * `spec/cypress/app_commands/scenarios/` contains your CypressDev scenario definitions @@ -76,9 +76,9 @@ You can run your [factory_bot](https://github.com/thoughtbot/factory_bot) direct ```ruby # spec/cypress/app_commands/factory_bot.rb -require 'cypress_dev/smart_factory_wrapper' +require 'cypress_on_rails/smart_factory_wrapper' -CypressDev::SmartFactoryWrapper.configure( +CypressOnRails::SmartFactoryWrapper.configure( always_reload: !Rails.configuration.cache_classes, factory: FactoryBot, files: Dir['./spec/factories/**/*.rb'] @@ -141,7 +141,7 @@ You define a scenario in the `spec/cypress/app_commands/scenarios` directory: Profile.create name: "Cypress Hill" # or if you have factory_bot enabled in your cypress_helper -CypressDev::SmartFactoryWrapper.create(:profile, name: "Cypress Hill") +CypressOnRails::SmartFactoryWrapper.create(:profile, name: "Cypress Hill") ``` Then reference the scenario in your test: @@ -183,17 +183,17 @@ describe('My First Test', function() { ## Usage with other rack applications -Add CypressDev to your config.ru +Add CypressOnRails to your config.ru ```ruby # an example config.ru require File.expand_path('my_app', File.dirname(__FILE__)) -require 'cypress_dev/middleware' -CypressDev.configure do |c| +require 'cypress_on_rails/middleware' +CypressOnRails.configure do |c| c.cypress_folder = File.expand_path("#{__dir__}/test/cypress") end -use CypressDev::Middleware +use CypressOnRails::Middleware run MyApp ``` @@ -202,7 +202,7 @@ add the following file to cypress ```js // test/cypress/support/on-rails.js -// CypressDev: dont remove these command +// CypressOnRails: dont remove these command Cypress.Commands.add('appCommands', function (body) { cy.request({ method: 'POST', @@ -224,7 +224,7 @@ Cypress.Commands.add('appScenario', function (name) { Cypress.Commands.add('appFactories', function (options) { cy.app('factory_bot', options) }); -// CypressDev: end +// CypressOnRails: end // The next is optional beforeEach(() => { diff --git a/Rakefile b/Rakefile index 324d713..0187ea3 100644 --- a/Rakefile +++ b/Rakefile @@ -3,7 +3,7 @@ require 'bundler/gem_tasks' require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) do |t| - t.pattern = 'spec/cypress/*_spec.rb' + t.pattern = 'spec/cypress_on_rails/*_spec.rb' end task default: %w[spec build] diff --git a/cypress-on-rails.gemspec b/cypress-on-rails.gemspec index 1516767..7c1e59d 100644 --- a/cypress-on-rails.gemspec +++ b/cypress-on-rails.gemspec @@ -1,15 +1,16 @@ # -*- encoding: utf-8 -*- $LOAD_PATH.push File.expand_path("../lib", __FILE__) -require "cypress_dev/version" +require "cypress_on_rails/version" Gem::Specification.new do |s| s.name = "cypress-on-rails" - s.version = CypressDev::VERSION + s.version = CypressOnRails::VERSION s.author = ["miceportal team", 'Grant Petersen-Speelman'] s.email = ["info@miceportal.de", 'grantspeelman@gmail.com'] s.homepage = "http://github.com/grantspeelman/cypress-on-rails" s.summary = "Integrates cypress with rails or rack applications" s.description = "Integrates cypress with rails or rack applications" + s.post_install_message = 'The CypressDev constant is being deprecated and will be completely removed and replaced with CypressOnRails.' s.rubyforge_project = s.name s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {spec}/*`.split("\n") diff --git a/lib/cypress-on-rails.rb b/lib/cypress-on-rails.rb index cdc453f..2473b1e 100644 --- a/lib/cypress-on-rails.rb +++ b/lib/cypress-on-rails.rb @@ -1,3 +1,7 @@ -require 'cypress_dev' +require 'cypress_on_rails/version' +require 'cypress_on_rails/configuration' +require_relative './cypress_on_rails/railtie' if defined?(Rails) +# maintain backward compatibility +CypressDev = CypressOnRails Cypress = CypressDev diff --git a/lib/cypress/smart_factory_wrapper.rb b/lib/cypress/smart_factory_wrapper.rb index d1b27ef..32c2529 100644 --- a/lib/cypress/smart_factory_wrapper.rb +++ b/lib/cypress/smart_factory_wrapper.rb @@ -1,3 +1,3 @@ require 'cypress-on-rails' -require 'cypress_dev/smart_factory_wrapper' +require 'cypress_on_rails/smart_factory_wrapper' # for backward compatibility \ No newline at end of file diff --git a/lib/cypress_dev.rb b/lib/cypress_dev.rb index 717b6b8..75f13d1 100644 --- a/lib/cypress_dev.rb +++ b/lib/cypress_dev.rb @@ -1,4 +1 @@ -require 'cypress_dev/version' -require 'cypress_dev/configuration' -require_relative './cypress_dev/railtie' if defined?(Rails) - +require 'cypress-on-rails' diff --git a/lib/cypress_dev/middleware.rb b/lib/cypress_dev/middleware.rb index c53bc4a..06d6f3f 100644 --- a/lib/cypress_dev/middleware.rb +++ b/lib/cypress_dev/middleware.rb @@ -1,65 +1,2 @@ -require 'json' -require 'rack' -require 'cypress_dev/configuration' -require 'cypress_dev/command_executor' - -module CypressDev - # Middleware to handle cypress commands and eval - class Middleware - def initialize(app, command_executor = CommandExecutor, file = ::File) - @app = app - @command_executor = command_executor - @file = file - end - - def call(env) - request = Rack::Request.new(env) - if request.path.start_with?('/__cypress__/command') - configuration.tagged_logged { handle_command(request) } - else - @app.call(env) - end - end - - private - - def configuration - CypressDev.configuration - end - - def logger - configuration.logger - end - - Command = Struct.new(:name, :options, :cypress_folder) do - # @return [Array] - def self.from_body(body, configuration) - if body.is_a?(Array) - command_params = body - else - command_params = [body] - end - command_params.map do |params| - new(params.fetch('name'), params['options'], configuration.cypress_folder) - end - end - - def file_path - "#{cypress_folder}/app_commands/#{name}.rb" - end - end - - def handle_command(req) - body = JSON.parse(req.body.read) - logger.info "handle_command: #{body}" - commands = Command.from_body(body, configuration) - missing_command = commands.find {|command| !@file.exists?(command.file_path) } - if missing_command.nil? - commands.each { |command| @command_executor.load(command.file_path, command.options) } - [201, {}, ['success']] - else - [404, {}, ["could not find command file: #{missing_command.file_path}"]] - end - end - end -end +warn "cypress_dev is being deprecated, please require \"cypress_on_rails/middleware\" instead" +require 'cypress_on_rails/middleware' diff --git a/lib/cypress_dev/smart_factory_wrapper.rb b/lib/cypress_dev/smart_factory_wrapper.rb index 0c5bb20..5105077 100644 --- a/lib/cypress_dev/smart_factory_wrapper.rb +++ b/lib/cypress_dev/smart_factory_wrapper.rb @@ -1,91 +1,2 @@ -require 'cypress_dev/configuration' -require 'cypress_dev/simple_rails_factory' - -module CypressDev - class SmartFactoryWrapper - module FactoryCleaner - def self.clean(f = FactoryBot) - f.factories.clear if f.respond_to?(:factories) - f.traits.clear if f.respond_to?(:traits) - f.callbacks.clear if f.respond_to?(:callbacks) - f.sequences.clear if f.respond_to?(:sequences) - end - end - - def self.instance - @instance ||= new(files: [], factory: SimpleRailsFactory) - end - - def self.configure(files:, factory:, always_reload: true) - @instance = new(files: files, factory: factory, always_reload: always_reload) - end - - def self.create(*args) - instance.create(*args) - end - - def self.create_list(*args) - instance.create_list(*args) - end - - # @return [Array] - attr_accessor :factory - attr_accessor :always_reload - - def initialize(files:, factory:, always_reload: false, - factory_cleaner: FactoryCleaner, kernel: Kernel, file_system: File, - dir_system: Dir) - self.files = files - self.factory = factory - self.always_reload = always_reload - @kernel = kernel - @file_system = file_system - @factory_cleaner = factory_cleaner - @latest_mtime = nil - @dir_system = dir_system - end - - def create(*args) - load_files - factory.create(*args) - end - - def create_list(*args) - load_files - factory.create_list(*args) - end - - private - - # @param [String,Array] arg - def files=(array) - array = [array] if array.is_a?(String) - @dir_array = array - end - - # @return [Array] - def files - Dir[*@dir_array] - end - - def logger - CypressDev.configuration.logger - end - - def load_files - current_latest_mtime = files.map{|file| @file_system.mtime(file) }.max - return unless should_reload?(current_latest_mtime) - logger.info 'Loading Factories' - @latest_mtime = current_latest_mtime - @factory_cleaner.clean(factory) - files.each do |file| - logger.debug "-- Loading: #{file}" - @kernel.load(file) - end - end - - def should_reload?(current_latest_mtime) - @always_reload || @latest_mtime.nil? || @latest_mtime < current_latest_mtime - end - end -end \ No newline at end of file +warn "cypress_dev is being deprecated, please require \"cypress_on_rails/smart_factory_wrapper\" instead" +require 'cypress_on_rails/smart_factory_wrapper' diff --git a/lib/cypress_dev/version.rb b/lib/cypress_dev/version.rb deleted file mode 100644 index 3e0544e..0000000 --- a/lib/cypress_dev/version.rb +++ /dev/null @@ -1,3 +0,0 @@ -module CypressDev - VERSION = '1.3.0' -end diff --git a/lib/cypress_dev/command_executor.rb b/lib/cypress_on_rails/command_executor.rb similarity index 88% rename from lib/cypress_dev/command_executor.rb rename to lib/cypress_on_rails/command_executor.rb index d5232c2..13a0d6d 100644 --- a/lib/cypress_dev/command_executor.rb +++ b/lib/cypress_on_rails/command_executor.rb @@ -1,6 +1,6 @@ -require 'cypress_dev/configuration' +require 'cypress_on_rails/configuration' -module CypressDev +module CypressOnRails # loads and evals the command files class CommandExecutor def self.load(file,command_options = nil) @@ -27,7 +27,7 @@ def self.logger end def self.configuration - CypressDev.configuration + CypressOnRails.configuration end end end diff --git a/lib/cypress_dev/configuration.rb b/lib/cypress_on_rails/configuration.rb similarity index 96% rename from lib/cypress_dev/configuration.rb rename to lib/cypress_on_rails/configuration.rb index 74b5d05..a08571c 100644 --- a/lib/cypress_dev/configuration.rb +++ b/lib/cypress_on_rails/configuration.rb @@ -1,6 +1,6 @@ require 'logger' -module CypressDev +module CypressOnRails class Configuration attr_accessor :cypress_folder attr_accessor :use_middleware diff --git a/lib/cypress_on_rails/middleware.rb b/lib/cypress_on_rails/middleware.rb new file mode 100644 index 0000000..a6d4162 --- /dev/null +++ b/lib/cypress_on_rails/middleware.rb @@ -0,0 +1,65 @@ +require 'json' +require 'rack' +require 'cypress_on_rails/configuration' +require 'cypress_on_rails/command_executor' + +module CypressOnRails + # Middleware to handle cypress commands and eval + class Middleware + def initialize(app, command_executor = CommandExecutor, file = ::File) + @app = app + @command_executor = command_executor + @file = file + end + + def call(env) + request = Rack::Request.new(env) + if request.path.start_with?('/__cypress__/command') + configuration.tagged_logged { handle_command(request) } + else + @app.call(env) + end + end + + private + + def configuration + CypressOnRails.configuration + end + + def logger + configuration.logger + end + + Command = Struct.new(:name, :options, :cypress_folder) do + # @return [Array] + def self.from_body(body, configuration) + if body.is_a?(Array) + command_params = body + else + command_params = [body] + end + command_params.map do |params| + new(params.fetch('name'), params['options'], configuration.cypress_folder) + end + end + + def file_path + "#{cypress_folder}/app_commands/#{name}.rb" + end + end + + def handle_command(req) + body = JSON.parse(req.body.read) + logger.info "handle_command: #{body}" + commands = Command.from_body(body, configuration) + missing_command = commands.find {|command| !@file.exists?(command.file_path) } + if missing_command.nil? + commands.each { |command| @command_executor.load(command.file_path, command.options) } + [201, {}, ['success']] + else + [404, {}, ["could not find command file: #{missing_command.file_path}"]] + end + end + end +end diff --git a/lib/cypress_dev/railtie.rb b/lib/cypress_on_rails/railtie.rb similarity index 53% rename from lib/cypress_dev/railtie.rb rename to lib/cypress_on_rails/railtie.rb index 8eda650..530ee29 100644 --- a/lib/cypress_dev/railtie.rb +++ b/lib/cypress_on_rails/railtie.rb @@ -1,11 +1,11 @@ require 'rails/railtie' -require 'cypress_dev/configuration' -require 'cypress_dev/middleware' +require 'cypress_on_rails/configuration' +require 'cypress_on_rails/middleware' -module CypressDev +module CypressOnRails class Railtie < Rails::Railtie initializer :setup_cypress_middleware do |app| - if CypressDev.configuration.use_middleware? + if CypressOnRails.configuration.use_middleware? app.middleware.use Middleware end end diff --git a/lib/cypress_dev/simple_rails_factory.rb b/lib/cypress_on_rails/simple_rails_factory.rb similarity index 93% rename from lib/cypress_dev/simple_rails_factory.rb rename to lib/cypress_on_rails/simple_rails_factory.rb index 35043e0..63d71d0 100644 --- a/lib/cypress_dev/simple_rails_factory.rb +++ b/lib/cypress_on_rails/simple_rails_factory.rb @@ -1,6 +1,6 @@ require 'active_support/core_ext/string' -module CypressDev +module CypressOnRails module SimpleRailsFactory def self.create(type, *params) params = [{}] if params.empty? diff --git a/lib/cypress_on_rails/smart_factory_wrapper.rb b/lib/cypress_on_rails/smart_factory_wrapper.rb new file mode 100644 index 0000000..5effbf8 --- /dev/null +++ b/lib/cypress_on_rails/smart_factory_wrapper.rb @@ -0,0 +1,91 @@ +require 'cypress_on_rails/configuration' +require 'cypress_on_rails/simple_rails_factory' + +module CypressOnRails + class SmartFactoryWrapper + module FactoryCleaner + def self.clean(f = FactoryBot) + f.factories.clear if f.respond_to?(:factories) + f.traits.clear if f.respond_to?(:traits) + f.callbacks.clear if f.respond_to?(:callbacks) + f.sequences.clear if f.respond_to?(:sequences) + end + end + + def self.instance + @instance ||= new(files: [], factory: SimpleRailsFactory) + end + + def self.configure(files:, factory:, always_reload: true) + @instance = new(files: files, factory: factory, always_reload: always_reload) + end + + def self.create(*args) + instance.create(*args) + end + + def self.create_list(*args) + instance.create_list(*args) + end + + # @return [Array] + attr_accessor :factory + attr_accessor :always_reload + + def initialize(files:, factory:, always_reload: false, + factory_cleaner: FactoryCleaner, kernel: Kernel, file_system: File, + dir_system: Dir) + self.files = files + self.factory = factory + self.always_reload = always_reload + @kernel = kernel + @file_system = file_system + @factory_cleaner = factory_cleaner + @latest_mtime = nil + @dir_system = dir_system + end + + def create(*args) + load_files + factory.create(*args) + end + + def create_list(*args) + load_files + factory.create_list(*args) + end + + private + + # @param [String,Array] arg + def files=(array) + array = [array] if array.is_a?(String) + @dir_array = array + end + + # @return [Array] + def files + Dir[*@dir_array] + end + + def logger + CypressOnRails.configuration.logger + end + + def load_files + current_latest_mtime = files.map{|file| @file_system.mtime(file) }.max + return unless should_reload?(current_latest_mtime) + logger.info 'Loading Factories' + @latest_mtime = current_latest_mtime + @factory_cleaner.clean(factory) + files.each do |file| + logger.debug "-- Loading: #{file}" + @kernel.load(file) + end + end + + def should_reload?(current_latest_mtime) + @always_reload || @latest_mtime.nil? || @latest_mtime < current_latest_mtime + end + end +end \ No newline at end of file diff --git a/lib/cypress_on_rails/version.rb b/lib/cypress_on_rails/version.rb new file mode 100644 index 0000000..5131456 --- /dev/null +++ b/lib/cypress_on_rails/version.rb @@ -0,0 +1,3 @@ +module CypressOnRails + VERSION = '1.4.0' +end diff --git a/lib/generators/cypress_dev/install_generator.rb b/lib/generators/cypress_on_rails/install_generator.rb similarity index 95% rename from lib/generators/cypress_dev/install_generator.rb rename to lib/generators/cypress_on_rails/install_generator.rb index c88a142..2f80aa2 100644 --- a/lib/generators/cypress_dev/install_generator.rb +++ b/lib/generators/cypress_on_rails/install_generator.rb @@ -1,4 +1,4 @@ -module CypressDev +module CypressOnRails class InstallGenerator < Rails::Generators::Base class_option :cypress_folder, type: :string, default: 'spec/cypress' class_option :install_cypress_with, type: :string, default: 'yarn' @@ -31,7 +31,7 @@ def install_cypress end def add_initial_files - template "config/initializers/cypress_dev.rb.erb", "config/initializers/cypress_dev.rb" + template "config/initializers/cypress_on_rails.rb.erb", "config/initializers/cypress_on_rails.rb" copy_file "spec/cypress/cypress_helper.rb", "#{options.cypress_folder}/cypress_helper.rb" copy_file "spec/cypress/support/on-rails.js", "#{options.cypress_folder}/support/on-rails.js" directory 'spec/cypress/app_commands', "#{options.cypress_folder}/app_commands" diff --git a/lib/generators/cypress_dev/templates/config/initializers/cypress_dev.rb.erb b/lib/generators/cypress_on_rails/templates/config/initializers/cypress_on_rails.rb.erb similarity index 67% rename from lib/generators/cypress_dev/templates/config/initializers/cypress_dev.rb.erb rename to lib/generators/cypress_on_rails/templates/config/initializers/cypress_on_rails.rb.erb index d8b6c6e..251143a 100644 --- a/lib/generators/cypress_dev/templates/config/initializers/cypress_dev.rb.erb +++ b/lib/generators/cypress_on_rails/templates/config/initializers/cypress_on_rails.rb.erb @@ -1,9 +1,9 @@ -if defined?(CypressDev) - CypressDev.configure do |c| +if defined?(CypressOnRails) + CypressOnRails.configure do |c| c.cypress_folder = File.expand_path("#{__dir__}/../../<%= options.cypress_folder %>") - # WARNING!! CypressDev can execute arbitrary ruby code + # WARNING!! CypressOnRails can execute arbitrary ruby code # please use with extra caution if enabling on hosted servers or starting your local server on 0.0.0.0 c.use_middleware = Rails.env.test? c.logger = Rails.logger end -end \ No newline at end of file +end diff --git a/lib/generators/cypress_dev/templates/spec/cypress.json b/lib/generators/cypress_on_rails/templates/spec/cypress.json similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress.json rename to lib/generators/cypress_on_rails/templates/spec/cypress.json diff --git a/lib/generators/cypress_dev/templates/spec/cypress/app_commands/activerecord_fixtures.rb b/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/activerecord_fixtures.rb similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/app_commands/activerecord_fixtures.rb rename to lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/activerecord_fixtures.rb diff --git a/lib/generators/cypress_dev/templates/spec/cypress/app_commands/clean.rb b/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/clean.rb similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/app_commands/clean.rb rename to lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/clean.rb diff --git a/lib/generators/cypress_dev/templates/spec/cypress/app_commands/eval.rb b/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/eval.rb similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/app_commands/eval.rb rename to lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/eval.rb diff --git a/lib/generators/cypress_dev/templates/spec/cypress/app_commands/factory_bot.rb b/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/factory_bot.rb similarity index 81% rename from lib/generators/cypress_dev/templates/spec/cypress/app_commands/factory_bot.rb rename to lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/factory_bot.rb index 04525ec..1caab9a 100644 --- a/lib/generators/cypress_dev/templates/spec/cypress/app_commands/factory_bot.rb +++ b/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/factory_bot.rb @@ -2,7 +2,7 @@ factory_method = factory_options.shift begin logger.debug "running #{factory_method}, #{factory_options}" - CypressDev::SmartFactoryWrapper.public_send(factory_method, *factory_options) + CypressOnRails::SmartFactoryWrapper.public_send(factory_method, *factory_options) rescue => e logger.error "#{e.class}: #{e.message}" logger.error e.backtrace.join("\n") diff --git a/lib/generators/cypress_dev/templates/spec/cypress/app_commands/log_fail.rb b/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/log_fail.rb similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/app_commands/log_fail.rb rename to lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/log_fail.rb diff --git a/lib/generators/cypress_dev/templates/spec/cypress/app_commands/scenarios/basic.rb b/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/scenarios/basic.rb similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/app_commands/scenarios/basic.rb rename to lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/scenarios/basic.rb diff --git a/lib/generators/cypress_dev/templates/spec/cypress/cypress_helper.rb b/lib/generators/cypress_on_rails/templates/spec/cypress/cypress_helper.rb similarity index 79% rename from lib/generators/cypress_dev/templates/spec/cypress/cypress_helper.rb rename to lib/generators/cypress_on_rails/templates/spec/cypress/cypress_helper.rb index b3a8cd7..0e49aa2 100644 --- a/lib/generators/cypress_dev/templates/spec/cypress/cypress_helper.rb +++ b/lib/generators/cypress_on_rails/templates/spec/cypress/cypress_helper.rb @@ -17,13 +17,13 @@ end end -require 'cypress_dev/smart_factory_wrapper' +require 'cypress_on_rails/smart_factory_wrapper' -factory = CypressDev::SimpleRailsFactory +factory = CypressOnRails::SimpleRailsFactory factory = FactoryBot if defined?(FactoryBot) factory = FactoryGirl if defined?(FactoryGirl) -CypressDev::SmartFactoryWrapper.configure( +CypressOnRails::SmartFactoryWrapper.configure( always_reload: !Rails.configuration.cache_classes, factory: factory, files: %w(spec/factories.rb ./spec/factories/**/*.rb) diff --git a/lib/generators/cypress_dev/templates/spec/cypress/fixtures/example.json b/lib/generators/cypress_on_rails/templates/spec/cypress/fixtures/example.json similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/fixtures/example.json rename to lib/generators/cypress_on_rails/templates/spec/cypress/fixtures/example.json diff --git a/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/actions.spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/actions.spec.js similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/integration/examples/actions.spec.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/actions.spec.js diff --git a/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/aliasing.spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/aliasing.spec.js similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/integration/examples/aliasing.spec.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/aliasing.spec.js diff --git a/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/assertions.spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/assertions.spec.js similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/integration/examples/assertions.spec.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/assertions.spec.js diff --git a/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/connectors.spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/connectors.spec.js similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/integration/examples/connectors.spec.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/connectors.spec.js diff --git a/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/cookies.spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/cookies.spec.js similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/integration/examples/cookies.spec.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/cookies.spec.js diff --git a/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/cypress_api.spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/cypress_api.spec.js similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/integration/examples/cypress_api.spec.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/cypress_api.spec.js diff --git a/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/files.spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/files.spec.js similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/integration/examples/files.spec.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/files.spec.js diff --git a/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/local_storage.spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/local_storage.spec.js similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/integration/examples/local_storage.spec.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/local_storage.spec.js diff --git a/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/location.spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/location.spec.js similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/integration/examples/location.spec.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/location.spec.js diff --git a/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/misc.spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/misc.spec.js similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/integration/examples/misc.spec.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/misc.spec.js diff --git a/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/navigation.spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/navigation.spec.js similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/integration/examples/navigation.spec.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/navigation.spec.js diff --git a/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/network_requests.spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/network_requests.spec.js similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/integration/examples/network_requests.spec.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/network_requests.spec.js diff --git a/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/querying.spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/querying.spec.js similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/integration/examples/querying.spec.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/querying.spec.js diff --git a/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/spies_stubs_clocks.spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/spies_stubs_clocks.spec.js similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/integration/examples/spies_stubs_clocks.spec.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/spies_stubs_clocks.spec.js diff --git a/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/traversal.spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/traversal.spec.js similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/integration/examples/traversal.spec.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/traversal.spec.js diff --git a/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/utilities.spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/utilities.spec.js similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/integration/examples/utilities.spec.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/utilities.spec.js diff --git a/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/viewport.spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/viewport.spec.js similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/integration/examples/viewport.spec.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/viewport.spec.js diff --git a/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/waiting.spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/waiting.spec.js similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/integration/examples/waiting.spec.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/waiting.spec.js diff --git a/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/window.spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/window.spec.js similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/integration/examples/window.spec.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/window.spec.js diff --git a/lib/generators/cypress_dev/templates/spec/cypress/integration/rails_examples/other_spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/other_spec.js similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/integration/rails_examples/other_spec.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/other_spec.js diff --git a/lib/generators/cypress_dev/templates/spec/cypress/integration/rails_examples/using_factory_bot.js b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_factory_bot.js similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/integration/rails_examples/using_factory_bot.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_factory_bot.js diff --git a/lib/generators/cypress_dev/templates/spec/cypress/integration/rails_examples/using_fixtures.js b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_fixtures.js similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/integration/rails_examples/using_fixtures.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_fixtures.js diff --git a/lib/generators/cypress_dev/templates/spec/cypress/integration/rails_examples/using_scenarios_spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_scenarios_spec.js similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/integration/rails_examples/using_scenarios_spec.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_scenarios_spec.js diff --git a/lib/generators/cypress_dev/templates/spec/cypress/support/commands.js b/lib/generators/cypress_on_rails/templates/spec/cypress/support/commands.js similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/support/commands.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/support/commands.js diff --git a/lib/generators/cypress_dev/templates/spec/cypress/support/index.js b/lib/generators/cypress_on_rails/templates/spec/cypress/support/index.js similarity index 100% rename from lib/generators/cypress_dev/templates/spec/cypress/support/index.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/support/index.js diff --git a/lib/generators/cypress_dev/templates/spec/cypress/support/on-rails.js b/lib/generators/cypress_on_rails/templates/spec/cypress/support/on-rails.js similarity index 95% rename from lib/generators/cypress_dev/templates/spec/cypress/support/on-rails.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/support/on-rails.js index 6efca6b..2ff6ecb 100644 --- a/lib/generators/cypress_dev/templates/spec/cypress/support/on-rails.js +++ b/lib/generators/cypress_on_rails/templates/spec/cypress/support/on-rails.js @@ -1,4 +1,4 @@ -// CypressDev: dont remove these command +// CypressOnRails: dont remove these command Cypress.Commands.add('appCommands', function (body) { cy.log("APP: " + JSON.stringify(body)) cy.request({ @@ -29,7 +29,7 @@ Cypress.Commands.add('appFactories', function (options) { Cypress.Commands.add('appFixtures', function (options) { cy.app('activerecord_fixtures', options) }); -// CypressDev: end +// CypressOnRails: end // The next is optional // beforeEach(() => { diff --git a/spec/cypress_dev/configuration_spec.rb b/spec/cypress_dev/configuration_spec.rb deleted file mode 100644 index d9c884b..0000000 --- a/spec/cypress_dev/configuration_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'cypress_dev/configuration' - -RSpec.describe CypressDev::Configuration do - it 'has defaults' do - CypressDev.configure { |config| config.reset } - - expect(CypressDev.configuration.cypress_folder).to eq('spec/cypress') - expect(CypressDev.configuration.use_middleware?).to eq(true) - expect(CypressDev.configuration.logger).to_not be_nil - end - - it 'can be configured' do - my_logger = Logger.new(STDOUT) - CypressDev.configure do |config| - config.cypress_folder = 'my/path' - config.use_middleware = false - config.logger = my_logger - end - expect(CypressDev.configuration.cypress_folder).to eq('my/path') - expect(CypressDev.configuration.use_middleware?).to eq(false) - expect(CypressDev.configuration.logger).to eq(my_logger) - end -end diff --git a/spec/cypress_dev/command_executor/cypress_helper.rb b/spec/cypress_on_rails/command_executor/cypress_helper.rb similarity index 100% rename from spec/cypress_dev/command_executor/cypress_helper.rb rename to spec/cypress_on_rails/command_executor/cypress_helper.rb diff --git a/spec/cypress_dev/command_executor/test_command.rb b/spec/cypress_on_rails/command_executor/test_command.rb similarity index 100% rename from spec/cypress_dev/command_executor/test_command.rb rename to spec/cypress_on_rails/command_executor/test_command.rb diff --git a/spec/cypress_dev/command_executor/test_command_with_options.rb b/spec/cypress_on_rails/command_executor/test_command_with_options.rb similarity index 100% rename from spec/cypress_dev/command_executor/test_command_with_options.rb rename to spec/cypress_on_rails/command_executor/test_command_with_options.rb diff --git a/spec/cypress_dev/command_executor_spec.rb b/spec/cypress_on_rails/command_executor_spec.rb similarity index 83% rename from spec/cypress_dev/command_executor_spec.rb rename to spec/cypress_on_rails/command_executor_spec.rb index 2f1dba9..cd47d35 100644 --- a/spec/cypress_dev/command_executor_spec.rb +++ b/spec/cypress_on_rails/command_executor_spec.rb @@ -1,6 +1,6 @@ -require 'cypress_dev/command_executor' +require 'cypress_on_rails/command_executor' -RSpec.describe CypressDev::CommandExecutor do +RSpec.describe CypressOnRails::CommandExecutor do describe '.load' do let(:folder) { "#{__dir__}/command_executor" } subject { described_class } @@ -10,7 +10,7 @@ def executor_load(*values) end before do - CypressDev.configuration.cypress_folder = folder + CypressOnRails.configuration.cypress_folder = folder DummyTest.values.clear if defined?(DummyTest) end diff --git a/spec/cypress_on_rails/configuration_spec.rb b/spec/cypress_on_rails/configuration_spec.rb new file mode 100644 index 0000000..ba65157 --- /dev/null +++ b/spec/cypress_on_rails/configuration_spec.rb @@ -0,0 +1,23 @@ +require 'cypress_on_rails/configuration' + +RSpec.describe CypressOnRails::Configuration do + it 'has defaults' do + CypressOnRails.configure { |config| config.reset } + + expect(CypressOnRails.configuration.cypress_folder).to eq('spec/cypress') + expect(CypressOnRails.configuration.use_middleware?).to eq(true) + expect(CypressOnRails.configuration.logger).to_not be_nil + end + + it 'can be configured' do + my_logger = Logger.new(STDOUT) + CypressOnRails.configure do |config| + config.cypress_folder = 'my/path' + config.use_middleware = false + config.logger = my_logger + end + expect(CypressOnRails.configuration.cypress_folder).to eq('my/path') + expect(CypressOnRails.configuration.use_middleware?).to eq(false) + expect(CypressOnRails.configuration.logger).to eq(my_logger) + end +end diff --git a/spec/cypress_dev/middleware_spec.rb b/spec/cypress_on_rails/middleware_spec.rb similarity index 95% rename from spec/cypress_dev/middleware_spec.rb rename to spec/cypress_on_rails/middleware_spec.rb index 03e0ba7..e93b166 100644 --- a/spec/cypress_dev/middleware_spec.rb +++ b/spec/cypress_on_rails/middleware_spec.rb @@ -1,8 +1,8 @@ -require 'cypress_dev/middleware' +require 'cypress_on_rails/middleware' -RSpec.describe CypressDev::Middleware do +RSpec.describe CypressOnRails::Middleware do let(:app) { ->(env) { [200, {}, ["app did #{env['PATH_INFO']}"]] } } - let(:command_executor) { class_double(CypressDev::CommandExecutor) } + let(:command_executor) { class_double(CypressOnRails::CommandExecutor) } let(:file) { class_double(File) } subject { described_class.new(app, command_executor, file) } diff --git a/spec/cypress_dev/railtie_spec.rb b/spec/cypress_on_rails/railtie_spec.rb similarity index 71% rename from spec/cypress_dev/railtie_spec.rb rename to spec/cypress_on_rails/railtie_spec.rb index ef3edf5..88f61b3 100644 --- a/spec/cypress_dev/railtie_spec.rb +++ b/spec/cypress_on_rails/railtie_spec.rb @@ -1,11 +1,11 @@ -require 'cypress_dev/railtie' +require 'cypress_on_rails/railtie' module Rails def self.env end end -RSpec.describe CypressDev::Railtie do +RSpec.describe CypressOnRails::Railtie do let(:rails_env) { double } let(:middleware) { double('Middleware', use: true) } let(:rails_app) { double('RailsApp', middleware: middleware) } @@ -15,7 +15,7 @@ def self.env end it 'runs the middleware in test mode' do - CypressDev::Railtie.initializers.each do |initializer| + CypressOnRails::Railtie.initializers.each do |initializer| initializer.run(rails_app) end end diff --git a/spec/cypress_dev/simple_rails_factory_spec.rb b/spec/cypress_on_rails/simple_rails_factory_spec.rb similarity index 81% rename from spec/cypress_dev/simple_rails_factory_spec.rb rename to spec/cypress_on_rails/simple_rails_factory_spec.rb index be88e77..c93f0be 100644 --- a/spec/cypress_dev/simple_rails_factory_spec.rb +++ b/spec/cypress_on_rails/simple_rails_factory_spec.rb @@ -1,7 +1,7 @@ -require 'cypress_dev/simple_rails_factory' +require 'cypress_on_rails/simple_rails_factory' -RSpec.describe CypressDev::SimpleRailsFactory do - subject { CypressDev::SimpleRailsFactory } +RSpec.describe CypressOnRails::SimpleRailsFactory do + subject { CypressOnRails::SimpleRailsFactory } class AppRecord def self.create!(*) diff --git a/spec/cypress_dev/smart_factory_wrapper_spec.rb b/spec/cypress_on_rails/smart_factory_wrapper_spec.rb similarity index 94% rename from spec/cypress_dev/smart_factory_wrapper_spec.rb rename to spec/cypress_on_rails/smart_factory_wrapper_spec.rb index 1980d52..fdb4e71 100644 --- a/spec/cypress_dev/smart_factory_wrapper_spec.rb +++ b/spec/cypress_on_rails/smart_factory_wrapper_spec.rb @@ -1,6 +1,6 @@ -require 'cypress_dev/smart_factory_wrapper' +require 'cypress_on_rails/smart_factory_wrapper' -RSpec.describe CypressDev::SmartFactoryWrapper do +RSpec.describe CypressOnRails::SmartFactoryWrapper do FileSystemDummy = Struct.new(:file_hash) do def mtime(filename) file_hash.fetch(filename) @@ -11,7 +11,7 @@ def mtime(filename) let(:mtime_hash) { {'file1.rb' => time_now, 'file2.rb' => time_now } } let(:files) { %w(file1.rb file2.rb) } let(:factory_double) { double('FactoryBot', create: true, create_list: true) } - let(:factory_cleaner) { class_double(CypressDev::SmartFactoryWrapper::FactoryCleaner, clean: true) } + let(:factory_cleaner) { class_double(CypressOnRails::SmartFactoryWrapper::FactoryCleaner, clean: true) } let(:kernel_double) { class_double(Kernel, load: true) } let(:file_double) { FileSystemDummy.new(mtime_hash) } let(:dir_double) { class_double(Dir) } diff --git a/spec/integrations/rails_3_2/.gitignore b/spec/integrations/rails_3_2/.gitignore index 980d7fe..55daf9b 100644 --- a/spec/integrations/rails_3_2/.gitignore +++ b/spec/integrations/rails_3_2/.gitignore @@ -3,7 +3,7 @@ node_modules cypress.json package-lock.json cypress/ -config/initializers/cypress_dev.rb +config/initializers/cypress_on_rails.rb vendor/bundle tmp/pids tmp/cache diff --git a/spec/integrations/rails_3_2/test.sh b/spec/integrations/rails_3_2/test.sh index ce78016..d8c0815 100755 --- a/spec/integrations/rails_3_2/test.sh +++ b/spec/integrations/rails_3_2/test.sh @@ -14,7 +14,7 @@ bundle --version bundle install --quiet --gemfile="$DIR/Gemfile" --retry 2 --path vendor/bundle echo '-- cypress install' -bundle exec ./bin/rails g cypress_dev:install --cypress_folder=cypress --install_cypress_with=npm --no-install-cypress-examples +bundle exec ./bin/rails g cypress_on_rails:install --cypress_folder=cypress --install_cypress_with=npm --no-install-cypress-examples echo '-- start rails server' # make sure the server is not running diff --git a/spec/integrations/rails_4_2/.gitignore b/spec/integrations/rails_4_2/.gitignore index f2b2ff0..aa209f1 100644 --- a/spec/integrations/rails_4_2/.gitignore +++ b/spec/integrations/rails_4_2/.gitignore @@ -4,7 +4,7 @@ spec/cypress.json spec/package.json spec/yarn.lock spec/cypress -config/initializers/cypress_dev.rb +config/initializers/cypress_on_rails.rb vendor/bundle tmp/pids tmp/cache \ No newline at end of file diff --git a/spec/integrations/rails_4_2/test.sh b/spec/integrations/rails_4_2/test.sh index 619ed2a..445cead 100755 --- a/spec/integrations/rails_4_2/test.sh +++ b/spec/integrations/rails_4_2/test.sh @@ -14,7 +14,7 @@ bundle --version bundle install --quiet --gemfile="$DIR/Gemfile" --retry 2 --path vendor/bundle echo '-- cypress install' -bundle exec ./bin/rails g cypress_dev:install --no-install-cypress-examples +bundle exec ./bin/rails g cypress_on_rails:install --no-install-cypress-examples echo '-- start rails server' # make sure the server is not running diff --git a/spec/integrations/rails_5_2/.gitignore b/spec/integrations/rails_5_2/.gitignore index e2b42b5..f2209aa 100644 --- a/spec/integrations/rails_5_2/.gitignore +++ b/spec/integrations/rails_5_2/.gitignore @@ -4,7 +4,7 @@ test/cypress.json test/package.json test/yarn.lock test/cypress/ -config/initializers/cypress_dev.rb +config/initializers/cypress_on_rails.rb vendor/bundle tmp/pids db/*.sqlite3 diff --git a/spec/integrations/rails_5_2/test.sh b/spec/integrations/rails_5_2/test.sh index 8942920..7dbe712 100755 --- a/spec/integrations/rails_5_2/test.sh +++ b/spec/integrations/rails_5_2/test.sh @@ -17,7 +17,7 @@ echo '-- migration' bin/rails db:migrate echo '-- cypress install' -bundle exec ./bin/rails g cypress_dev:install --cypress_folder=test/cypress --no-install-cypress-examples +bundle exec ./bin/rails g cypress_on_rails:install --cypress_folder=test/cypress --no-install-cypress-examples echo '-- start rails server' # make sure the server is not running diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 42e1182..4bd0e1a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -95,8 +95,8 @@ Kernel.srand config.seed config.before(:each) do - require 'cypress_dev/configuration' - CypressDev.configure do |config| + require 'cypress_on_rails/configuration' + CypressOnRails.configure do |config| config.reset config.logger = Logger.new('spec/test.log') end