Skip to content
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 4 commits into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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']
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
```
Expand All @@ -202,7 +202,7 @@ add the following file to cypress

```js
// test/cypress/support/on-rails.js
Copy link
Contributor

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?

// CypressDev: dont remove these command
// CypressOnRails: dont remove these command
Cypress.Commands.add('appCommands', function (body) {
cy.request({
method: 'POST',
Expand All @@ -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(() => {
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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]
5 changes: 3 additions & 2 deletions cypress-on-rails.gemspec
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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

s.rubyforge_project = s.name
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {spec}/*`.split("\n")
Expand Down
6 changes: 5 additions & 1 deletion lib/cypress-on-rails.rb
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
2 changes: 1 addition & 1 deletion lib/cypress/smart_factory_wrapper.rb
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
5 changes: 1 addition & 4 deletions lib/cypress_dev.rb
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'
3 changes: 0 additions & 3 deletions lib/cypress_dev/version.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -27,7 +27,7 @@ def self.logger
end

def self.configuration
CypressDev.configuration
CypressOnRails.configuration
end
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'logger'

module CypressDev
module CypressOnRails
class Configuration
attr_accessor :cypress_folder
attr_accessor :use_middleware
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'json'
require 'rack'
require 'cypress_dev/configuration'
require 'cypress_dev/command_executor'
require 'cypress_on_rails/configuration'
require 'cypress_on_rails/command_executor'

module CypressDev
module CypressOnRails
# Middleware to handle cypress commands and eval
class Middleware
def initialize(app, command_executor = CommandExecutor, file = ::File)
Expand All @@ -24,7 +24,7 @@ def call(env)
private

def configuration
CypressDev.configuration
CypressOnRails.configuration
end

def logger
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'cypress_dev/configuration'
require 'cypress_dev/simple_rails_factory'
require 'cypress_on_rails/configuration'
require 'cypress_on_rails/simple_rails_factory'

module CypressDev
module CypressOnRails
class SmartFactoryWrapper
module FactoryCleaner
def self.clean(f = FactoryBot)
Expand Down Expand Up @@ -69,7 +69,7 @@ def files
end

def logger
CypressDev.configuration.logger
CypressOnRails.configuration.logger
end

def load_files
Expand Down
3 changes: 3 additions & 0 deletions lib/cypress_on_rails/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module CypressOnRails
VERSION = '1.4.0'
end
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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
end
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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({
Expand Down Expand Up @@ -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(() => {
Expand Down
23 changes: 0 additions & 23 deletions spec/cypress_dev/configuration_spec.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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 }
Expand All @@ -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

Expand Down
23 changes: 23 additions & 0 deletions spec/cypress_on_rails/configuration_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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) }

Expand Down
Original file line number Diff line number Diff line change
@@ -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) }
Expand All @@ -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
Expand Down
Loading