-
-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rename CypressDev to CypressOnRails #19
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = ["[email protected]", '[email protected]'] | ||
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") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
require 'cypress-on-rails' | ||
require 'cypress_dev/smart_factory_wrapper' | ||
require 'cypress_on_rails/smart_factory_wrapper' | ||
# for backward compatibility |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
require 'cypress_dev/version' | ||
require 'cypress_dev/configuration' | ||
require_relative './cypress_dev/railtie' if defined?(Rails) | ||
|
||
require 'cypress-on-rails' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Cypress::Middleware::Command>] | ||
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String>] | ||
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 | ||
warn "cypress_dev is being deprecated, please require \"cypress_on_rails/smart_factory_wrapper\" instead" | ||
require 'cypress_on_rails/smart_factory_wrapper' |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
lib/cypress_dev/configuration.rb → lib/cypress_on_rails/configuration.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should the file itself be called
cypress-on-rails
?