From 9773dc8f3f8a7771b902fe8f171cc9eef54574c2 Mon Sep 17 00:00:00 2001 From: Grant Petersen-Speelman Date: Mon, 3 Jan 2022 11:59:58 +1100 Subject: [PATCH 01/44] switch to github actions to run tests (#96) --- .github/workflows/ruby.yml | 57 +++++++++++++++++++++++++++++ .gitignore | 3 +- .travis.yml | 39 -------------------- CHANGELOG.md | 6 +++ README.md | 3 +- spec/integrations/rails_3_2/test.sh | 6 +-- spec/integrations/rails_4_2/test.sh | 6 +-- spec/integrations/rails_5_2/test.sh | 6 +-- 8 files changed, 76 insertions(+), 50 deletions(-) create mode 100644 .github/workflows/ruby.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml new file mode 100644 index 0000000..a20043f --- /dev/null +++ b/.github/workflows/ruby.yml @@ -0,0 +1,57 @@ +name: Ruby + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + rails_3_2: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.3 + bundler-cache: true + - name: Run tests + run: bundle exec rake + - run: gem uninstall -v '>= 2' -ax bundler || true + - run: gem install bundler -v '< 2' + - name: Run interaction tests + run: ./spec/integrations/rails_3_2/test.sh + + rails_4_2: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.5 + bundler-cache: true + - name: Run tests + run: bundle exec rake + - run: gem uninstall -v '>= 2' -ax bundler || true + - run: gem install bundler -v '< 2' + - name: Run interaction tests + run: ./spec/integrations/rails_4_2/test.sh + + rails_5_2: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.6 + bundler-cache: true + - name: Run tests + run: bundle exec rake + - name: Run interaction tests + run: ./spec/integrations/rails_5_2/test.sh diff --git a/.gitignore b/.gitignore index 31a50fc..ec9e4e3 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ spec/examples.txt .idea spec/test.log pkg/*.gem -vendor/bundle \ No newline at end of file +vendor/bundle +.vscode \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index c2994f9..0000000 --- a/.travis.yml +++ /dev/null @@ -1,39 +0,0 @@ -language: ruby -rvm: - - 2.3 - - 2.4 - - 2.5 - - 2.6 -# - 2.7 - -#addons: -# artifacts: -# s3_region: "ap-southeast-2" -# paths: -# - $(ls spec/integrations/*/*/cypress/{screenshots,videos}/* | tr "\n" ":") -# - $(ls spec/integrations/rails_3_2/cypress/{screenshots,videos}/* | tr "\n" ":") - -cache: - directories: - - spec/integrations/rails_5_2/spec/node_modules - - spec/integrations/rails_5_2/vendor/bundle - - spec/integrations/rails_4_2/test/node_modules - - spec/integrations/rails_4_2/vendor/bundle - - spec/integrations/rails_3_2/node_modules - - spec/integrations/rails_3_2/vendor/bundle - -before_install: - - sudo apt-get -qq update - - sudo apt-get install -y build-essential patch ruby-dev zlib1g-dev liblzma-dev libxml2-dev - - sudo apt-get install -y xvfb libgtk2.0-0 libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 - - travis_retry nvm install 14.13.1 - - node -v - - nvm alias default 14.13.1 - -script: - - bundle exec rake - - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true - - gem install bundler -v '< 2' - - ./spec/integrations/rails_5_2/test.sh - - ./spec/integrations/rails_4_2/test.sh - - ./spec/integrations/rails_3_2/test.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index b7830f5..2f1d217 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## Unreleased +[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.10.1...main + +### Tasks +* switch from travis to github actions [PR 96] + ## [1.11.0] [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.10.1...v1.11.0 diff --git a/README.md b/README.md index 2a06fe5..277ab09 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # CypressOnRails -[![Build Status](https://travis-ci.com/shakacode/cypress-on-rails.svg?branch=master)](https://travis-ci.org/shakacode/cypress-on-rails) [![Gem Version](https://badge.fury.io/rb/cypress-on-rails.svg)](https://badge.fury.io/rb/cypress-on-rails) +![Build Status](https://github.com/shakacode/cypress-on-rails/actions/workflows/ruby.yml/badge.svg) +[![Gem Version](https://badge.fury.io/rb/cypress-on-rails.svg)](https://badge.fury.io/rb/cypress-on-rails) ---- diff --git a/spec/integrations/rails_3_2/test.sh b/spec/integrations/rails_3_2/test.sh index 9a4c30d..3895847 100755 --- a/spec/integrations/rails_3_2/test.sh +++ b/spec/integrations/rails_3_2/test.sh @@ -4,9 +4,9 @@ set -eo pipefail echo '--- testing rails 3.2' echo '-- setting environment' -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -RAILS_ENV=test -BUNDLE_GEMFILE="$DIR/Gemfile" +export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +export RAILS_ENV=test +export BUNDLE_GEMFILE="$DIR/Gemfile" cd $DIR echo '-- bundle install' diff --git a/spec/integrations/rails_4_2/test.sh b/spec/integrations/rails_4_2/test.sh index 542d1dd..ebe1a23 100755 --- a/spec/integrations/rails_4_2/test.sh +++ b/spec/integrations/rails_4_2/test.sh @@ -4,9 +4,9 @@ set -eo pipefail echo '--- testing rails 4.2' echo '-- setting environment' -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -RAILS_ENV=test -BUNDLE_GEMFILE="$DIR/Gemfile" +export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +export RAILS_ENV=test +export BUNDLE_GEMFILE="$DIR/Gemfile" cd $DIR echo '-- bundle install' diff --git a/spec/integrations/rails_5_2/test.sh b/spec/integrations/rails_5_2/test.sh index f148291..f76a12e 100755 --- a/spec/integrations/rails_5_2/test.sh +++ b/spec/integrations/rails_5_2/test.sh @@ -4,9 +4,9 @@ set -eo pipefail echo '--- testing rails 5.2' echo '-- setting environment' -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -RAILS_ENV=test -BUNDLE_GEMFILE="$DIR/Gemfile" +export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +export RAILS_ENV=test +export BUNDLE_GEMFILE="$DIR/Gemfile" cd $DIR echo '-- bundle install' From b6a00a7f3248584e19041409504d75aa2ac22cea Mon Sep 17 00:00:00 2001 From: Cameron Crockett Date: Sun, 2 Jan 2022 19:10:53 -0600 Subject: [PATCH 02/44] alternative tail command using tac added as comment (#89) Co-authored-by: Grant Petersen-Speelman --- CHANGELOG.md | 3 +++ .../templates/spec/cypress/app_commands/log_fail.rb | 2 ++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f1d217..a08b28a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ ## Unreleased [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.10.1...main +### Changed +* alternative command added for get tail of logs [PR 89](https://github.com/shakacode/cypress-on-rails/pull/89) by [ccrockett] + ### Tasks * switch from travis to github actions [PR 96] diff --git a/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/log_fail.rb b/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/log_fail.rb index 31ec058..a81563c 100644 --- a/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/log_fail.rb +++ b/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/log_fail.rb @@ -3,6 +3,8 @@ # grab last lines until "APPCLEANED" (Make sure in clean.rb to log the text "APPCLEANED") system "tail -n 10000 -r log/#{Rails.env}.log | sed \"/APPCLEANED/ q\" | sed 'x;1!H;$!d;x' > 'log/#{filename}.log'" +# Alternative command if the above does not work +# system "tail -n 10000 log/#{Rails.env}.log | tac | sed \"/APPCLEANED/ q\" | sed 'x;1!H;$!d;x' > 'log/#{filename}.log'" # create a json debug file for server debugging json_result = {} From d870d4e4570fcb9dc508340b099847328196c751 Mon Sep 17 00:00:00 2001 From: Grant Petersen-Speelman Date: Tue, 4 Jan 2022 09:34:46 +1100 Subject: [PATCH 03/44] Factory reload on clean to allow usage of sequences (#95) instead of reloading between every request --- CHANGELOG.md | 1 + lib/cypress_on_rails/middleware.rb | 2 +- lib/cypress_on_rails/smart_factory_wrapper.rb | 30 ++++++++++++------- .../spec/cypress/app_commands/clean.rb | 2 ++ .../templates/spec/cypress/cypress_helper.rb | 2 +- spec/cypress_on_rails/middleware_spec.rb | 24 +++++++-------- .../smart_factory_wrapper_spec.rb | 7 +++++ spec/integrations/rails_5_2/test.sh | 3 +- 8 files changed, 45 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a08b28a..5a17b74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.10.1...main ### Changed +* only reload factories on clean instead of every factory create request [PR 95](https://github.com/shakacode/cypress-on-rails/pull/95) * alternative command added for get tail of logs [PR 89](https://github.com/shakacode/cypress-on-rails/pull/89) by [ccrockett] ### Tasks diff --git a/lib/cypress_on_rails/middleware.rb b/lib/cypress_on_rails/middleware.rb index 5aad679..911583c 100644 --- a/lib/cypress_on_rails/middleware.rb +++ b/lib/cypress_on_rails/middleware.rb @@ -53,7 +53,7 @@ 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) } + missing_command = commands.find {|command| !@file.exist?(command.file_path) } if missing_command.nil? begin diff --git a/lib/cypress_on_rails/smart_factory_wrapper.rb b/lib/cypress_on_rails/smart_factory_wrapper.rb index 064e4b6..cbaab29 100644 --- a/lib/cypress_on_rails/smart_factory_wrapper.rb +++ b/lib/cypress_on_rails/smart_factory_wrapper.rb @@ -27,6 +27,10 @@ def self.build_list(*args) instance.build_list(*args) end + def self.reload + instance.reload + end + # @return [Array] attr_accessor :factory attr_accessor :always_reload @@ -44,7 +48,7 @@ def initialize(files:, factory:, always_reload: false, end def create(*options) - load_files + auto_reload factory_name = options.shift if options.last.is_a?(Hash) args = options.pop @@ -55,12 +59,12 @@ def create(*options) end def create_list(*args) - load_files + auto_reload factory.create_list(*args) end def build(*options) - load_files + auto_reload factory_name = options.shift if options.last.is_a?(Hash) args = options.pop @@ -71,10 +75,19 @@ def build(*options) end def build_list(*args) - load_files + auto_reload factory.build_list(*args) end + def reload + logger.info 'Loading Factories' + factory.reload + files.each do |file| + logger.debug "-- Loading: #{file}" + @kernel.load(file) + end + end + private # @param [String,Array] arg @@ -92,16 +105,11 @@ def logger CypressOnRails.configuration.logger end - def load_files + def auto_reload 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.reload - files.each do |file| - logger.debug "-- Loading: #{file}" - @kernel.load(file) - end + reload end def should_reload?(current_latest_mtime) diff --git a/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/clean.rb b/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/clean.rb index 5dccb09..a6c56b0 100644 --- a/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/clean.rb +++ b/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/clean.rb @@ -7,4 +7,6 @@ Post.delete_all if defined?(Post) end +CypressOnRails::SmartFactoryWrapper.reload + Rails.logger.info "APPCLEANED" # used by log_fail.rb diff --git a/lib/generators/cypress_on_rails/templates/spec/cypress/cypress_helper.rb b/lib/generators/cypress_on_rails/templates/spec/cypress/cypress_helper.rb index ba41721..3709c4a 100644 --- a/lib/generators/cypress_on_rails/templates/spec/cypress/cypress_helper.rb +++ b/lib/generators/cypress_on_rails/templates/spec/cypress/cypress_helper.rb @@ -29,7 +29,7 @@ factory = FactoryGirl if defined?(FactoryGirl) CypressOnRails::SmartFactoryWrapper.configure( - always_reload: !Rails.configuration.cache_classes, + always_reload: false, factory: factory, files: [ Rails.root.join('spec', 'factories.rb'), diff --git a/spec/cypress_on_rails/middleware_spec.rb b/spec/cypress_on_rails/middleware_spec.rb index a2eb262..ccba771 100644 --- a/spec/cypress_on_rails/middleware_spec.rb +++ b/spec/cypress_on_rails/middleware_spec.rb @@ -17,14 +17,14 @@ def rack_input(json_value) context '/__cypress__/command' do before do allow(command_executor).to receive(:perform).and_return({ id: 1, title: 'some result' }) - allow(file).to receive(:exists?) + allow(file).to receive(:exist?) env['PATH_INFO'] = '/__cypress__/command' end - it 'command file exists' do + it 'command file exist' do allow(command_executor).to receive(:perform).and_return({ id: 1, title: 'some result' }) env['rack.input'] = rack_input(name: 'seed') - allow(file).to receive(:exists?).with('spec/cypress/app_commands/seed.rb').and_return(true) + allow(file).to receive(:exist?).with('spec/cypress/app_commands/seed.rb').and_return(true) aggregate_failures do expect(response).to eq([201, @@ -34,9 +34,9 @@ def rack_input(json_value) end end - it 'command file exists with options' do + it 'command file exist with options' do env['rack.input'] = rack_input(name: 'seed', options: ['my_options']) - allow(file).to receive(:exists?).with('spec/cypress/app_commands/seed.rb').and_return(true) + allow(file).to receive(:exist?).with('spec/cypress/app_commands/seed.rb').and_return(true) aggregate_failures do expect(response).to eq([201, @@ -46,11 +46,11 @@ def rack_input(json_value) end end - it 'command file does not exists' do + it 'command file does not exist' do object = BasicObject.new allow(command_executor).to receive(:perform).and_return(object) env['rack.input'] = rack_input(name: 'seed') - allow(file).to receive(:exists?).with('spec/cypress/app_commands/seed.rb').and_return(true) + allow(file).to receive(:exist?).with('spec/cypress/app_commands/seed.rb').and_return(true) aggregate_failures do expect(response).to eq([201, @@ -62,7 +62,7 @@ def rack_input(json_value) it 'command result does not respond to to_json' do env['rack.input'] = rack_input(name: 'seed') - allow(file).to receive(:exists?).with('spec/cypress/app_commands/seed.rb').and_return(true) + allow(file).to receive(:exist?).with('spec/cypress/app_commands/seed.rb').and_return(true) aggregate_failures do expect(response).to eq([201, @@ -75,8 +75,8 @@ def rack_input(json_value) it 'running multiple commands' do env['rack.input'] = rack_input([{name: 'load_user'}, {name: 'load_sample', options: {'all' => 'true'}}]) - allow(file).to receive(:exists?).with('spec/cypress/app_commands/load_user.rb').and_return(true) - allow(file).to receive(:exists?).with('spec/cypress/app_commands/load_sample.rb').and_return(true) + allow(file).to receive(:exist?).with('spec/cypress/app_commands/load_user.rb').and_return(true) + allow(file).to receive(:exist?).with('spec/cypress/app_commands/load_sample.rb').and_return(true) aggregate_failures do expect(response).to eq([201, @@ -89,8 +89,8 @@ def rack_input(json_value) it 'running multiple commands but one missing' do env['rack.input'] = rack_input([{name: 'load_user'}, {name: 'load_sample'}]) - allow(file).to receive(:exists?).with('spec/cypress/app_commands/load_user.rb').and_return(true) - allow(file).to receive(:exists?).with('spec/cypress/app_commands/load_sample.rb').and_return(false) + allow(file).to receive(:exist?).with('spec/cypress/app_commands/load_user.rb').and_return(true) + allow(file).to receive(:exist?).with('spec/cypress/app_commands/load_sample.rb').and_return(false) aggregate_failures do expect(response).to eq([404, {}, ['could not find command file: spec/cypress/app_commands/load_sample.rb']]) diff --git a/spec/cypress_on_rails/smart_factory_wrapper_spec.rb b/spec/cypress_on_rails/smart_factory_wrapper_spec.rb index a71e77a..0f52072 100644 --- a/spec/cypress_on_rails/smart_factory_wrapper_spec.rb +++ b/spec/cypress_on_rails/smart_factory_wrapper_spec.rb @@ -140,6 +140,13 @@ def mtime(filename) expect(kernel_double).to have_received(:load).with('file2.rb').twice end + it 'can manually reload' do + subject.reload + expect(factory_double).to have_received(:reload) + expect(kernel_double).to have_received(:load).with('file1.rb') + expect(kernel_double).to have_received(:load).with('file2.rb') + end + context 'files is a string' do let(:files) { 'file*.rb' } diff --git a/spec/integrations/rails_5_2/test.sh b/spec/integrations/rails_5_2/test.sh index f76a12e..930e94b 100755 --- a/spec/integrations/rails_5_2/test.sh +++ b/spec/integrations/rails_5_2/test.sh @@ -11,7 +11,8 @@ cd $DIR echo '-- bundle install' bundle --version -bundle install --quiet --gemfile="$DIR/Gemfile" --retry 2 --path vendor/bundle +bundle config set --local path 'vendor/bundle' +bundle install --quiet --gemfile="$DIR/Gemfile" --retry 2 echo '-- migration' bundle exec ./bin/rails db:drop || true From 69357dffc244db4762bfad5c6962365358abecc5 Mon Sep 17 00:00:00 2001 From: Grant Petersen-Speelman Date: Tue, 4 Jan 2022 09:37:36 +1100 Subject: [PATCH 04/44] v1.12.0 --- CHANGELOG.md | 4 ++-- lib/cypress_on_rails/version.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a17b74..3556606 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ -## Unreleased -[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.10.1...main +## [1.12.0] +[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.11.0...v1.12.0 ### Changed * only reload factories on clean instead of every factory create request [PR 95](https://github.com/shakacode/cypress-on-rails/pull/95) diff --git a/lib/cypress_on_rails/version.rb b/lib/cypress_on_rails/version.rb index 96704e2..df652aa 100644 --- a/lib/cypress_on_rails/version.rb +++ b/lib/cypress_on_rails/version.rb @@ -1,3 +1,3 @@ module CypressOnRails - VERSION = '1.11.0'.freeze + VERSION = '1.12.0'.freeze end From 6e0b9b36bea3a31282848a1ac668820a9738a56f Mon Sep 17 00:00:00 2001 From: Grant Petersen-Speelman Date: Fri, 7 Jan 2022 12:34:50 +1100 Subject: [PATCH 05/44] Documenting how to setup Factory Associations (#100) --- CHANGELOG.md | 5 ++ README.md | 12 +--- docs/factory_bot_associations.md | 109 +++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+), 11 deletions(-) create mode 100644 docs/factory_bot_associations.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 3556606..1ed4bde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## Unreleased + +### Tasks +* Documenting how to setup Factory Associations [PR 100](https://github.com/shakacode/cypress-on-rails/pull/100) + ## [1.12.0] [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.11.0...v1.12.0 diff --git a/README.md b/README.md index 277ab09..fc10616 100644 --- a/README.md +++ b/README.md @@ -132,17 +132,6 @@ node_modules/.bin/cypress run You can run your [factory_bot](https://github.com/thoughtbot/factory_bot) directly as well -```ruby -# spec/cypress/app_commands/factory_bot.rb -require 'cypress_on_rails/smart_factory_wrapper' - -CypressOnRails::SmartFactoryWrapper.configure( - always_reload: !Rails.configuration.cache_classes, - factory: FactoryBot, - files: Dir['./spec/factories/**/*.rb'] -) -``` - ```js // spec/cypress/integrations/simple_spec.js describe('My First Test', function() { @@ -166,6 +155,7 @@ describe('My First Test', function() { }) }) ``` +You can check the [association Docs](https://github.com/shakacode/cypress-on-rails/blob/master/docs/factory_bot_associations.md) on more ways to setup association with the correct data. In some cases, using static Cypress fixtures may not provide sufficient flexibility when mocking HTTP response bodies - it's possible to use `FactoryBot.build` to generate Ruby hashes that can then be used as mock JSON responses: ```ruby diff --git a/docs/factory_bot_associations.md b/docs/factory_bot_associations.md new file mode 100644 index 0000000..e0d6e81 --- /dev/null +++ b/docs/factory_bot_associations.md @@ -0,0 +1,109 @@ +# Setting up associations with the correct data + +You cannot access associations directly from Cypress like you can do with ruby tests. +So setting up associations has to be done differently from within Cypress. + +There are a few ways you can setup associations with the correct data using Cypress and FactoryBot. +1. Setting the foreign keys +2. Using transient attributes +3. Using Nested Attributes +4. Combination of the above depending on your situation + +Assuming you have the following models + +```rb +class Post < ApplicationRecord + belongs_to :author + accepts_nested_attributes_for :author +end + +class Author < ApplicationRecord + has_many :posts + accepts_nested_attributes_for :posts +end +``` + +You can do the following: + +## 1. Setting the foreign keys + +factories.rb +```rb +FactoryBot.define do + factory :author do + name { 'Taylor' } + end + + factory :post do + title { 'Cypress on Rails is Awesome' } + author_id { create(:author).id } + end +end +``` + +then in Cypress +```js +// example with overriding the defaults +cy.appFactories([['create', 'author', { name: 'James' }]]).then((records) => { + cy.appFactories([['create', 'post', { title: 'Cypress is cool', author_id: records[0].id }]] +}); + +// example without overriding anything +cy.appFactories([['create', 'author']]).then((records) => { + cy.appFactories([['create', 'post', { author_id: records[0].id }]] +}); +``` + +## 2. Using transient attributes + +```rb +FactoryBot.define do + factory :author do + name { 'Taylor' } + end + + factory :post do + transient do + author_name { 'Taylor' } + end + title { 'Cypress on Rails is Awesome' } + author { create(:author, name: author_name ) } + end +end +``` + +then in Cypress +```js +// example with overriding the defaults +cy.appFactories([['create', 'post', { title: 'Cypress is cool', author_name: 'James' }]] + +// example without overriding +cy.appFactories([['create', 'post']] +``` + +## 3. Using Nested Attributes + +```rb +FactoryBot.define do + factory :author do + name { 'Taylor' } + end + + factory :post do + title { 'Cypress on Rails is Awesome' } + author_attributes { { name: 'Taylor' } } + end +end +``` + +then in Cypress +```js +// example with overriding the defaults +cy.appFactories([['create', 'post', { title: 'Cypress is cool', author_attributes: { name: 'James' } }]] + +// example without overriding +cy.appFactories([['create', 'post']] + +// example of creating author with multiple posts +cy.appFactories([['create', 'author', { name: 'James', posts_attributes: [{ name: 'Cypress is cool' }, {name: 'Rails is awesome' }] ]] +``` From 4dfd46d15d4c6c1ceab076e578f569d17c4f50ad Mon Sep 17 00:00:00 2001 From: Grant Petersen-Speelman Date: Wed, 12 Jan 2022 17:53:35 +1100 Subject: [PATCH 06/44] prevent auto_reload from reloading factories that has just been reloaded (#98) --- CHANGELOG.md | 3 +++ lib/cypress_on_rails/smart_factory_wrapper.rb | 11 +++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ed4bde..84be99c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ ### Tasks * Documenting how to setup Factory Associations [PR 100](https://github.com/shakacode/cypress-on-rails/pull/100) +### Fixed +* keep track of factory manual reloads to prevent auto_reload from reloading again [PR 98](https://github.com/shakacode/cypress-on-rails/pull/98) + ## [1.12.0] [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.11.0...v1.12.0 diff --git a/lib/cypress_on_rails/smart_factory_wrapper.rb b/lib/cypress_on_rails/smart_factory_wrapper.rb index cbaab29..b8fb882 100644 --- a/lib/cypress_on_rails/smart_factory_wrapper.rb +++ b/lib/cypress_on_rails/smart_factory_wrapper.rb @@ -80,6 +80,7 @@ def build_list(*args) end def reload + @latest_mtime = current_latest_mtime logger.info 'Loading Factories' factory.reload files.each do |file| @@ -105,14 +106,16 @@ def logger CypressOnRails.configuration.logger end + def current_latest_mtime + files.map{|file| @file_system.mtime(file) }.max + end + def auto_reload - current_latest_mtime = files.map{|file| @file_system.mtime(file) }.max - return unless should_reload?(current_latest_mtime) - @latest_mtime = current_latest_mtime + return unless should_reload? reload end - def should_reload?(current_latest_mtime) + def should_reload? @always_reload || @latest_mtime.nil? || @latest_mtime < current_latest_mtime end end From a35dcd1ed68662f44bfdeffbb34cea5444226a3a Mon Sep 17 00:00:00 2001 From: Grant Petersen-Speelman Date: Wed, 12 Jan 2022 09:47:08 +0200 Subject: [PATCH 07/44] v1.12.1 --- CHANGELOG.md | 3 ++- lib/cypress_on_rails/version.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84be99c..15f1224 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ -## Unreleased +## [1.12.1] +[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.12.0...v1.12.1 ### Tasks * Documenting how to setup Factory Associations [PR 100](https://github.com/shakacode/cypress-on-rails/pull/100) diff --git a/lib/cypress_on_rails/version.rb b/lib/cypress_on_rails/version.rb index df652aa..21ce006 100644 --- a/lib/cypress_on_rails/version.rb +++ b/lib/cypress_on_rails/version.rb @@ -1,3 +1,3 @@ module CypressOnRails - VERSION = '1.12.0'.freeze + VERSION = '1.12.1'.freeze end From 17cd55423f0b429e211a1c428c5d6a12e3729243 Mon Sep 17 00:00:00 2001 From: Grant Petersen-Speelman Date: Tue, 8 Mar 2022 16:08:27 +1100 Subject: [PATCH 08/44] cypress js plugin and vcr integration (#103) --- .github/workflows/ruby.yml | 6 +- .gitignore | 5 +- CHANGELOG.md | 5 + README.md | 62 ++++++++++ cypress-on-rails.gemspec | 1 + lib/cypress_on_rails/middleware.rb | 15 +-- lib/cypress_on_rails/middleware_config.rb | 17 +++ lib/cypress_on_rails/railtie.rb | 4 +- lib/cypress_on_rails/vcr_middleware.rb | 60 ++++++++++ .../cypress_on_rails/install_generator.rb | 43 ++++--- .../spec/cypress/app_commands/clean.rb | 4 + ...ypress_helper.rb => cypress_helper.rb.erb} | 5 + .../rails_examples/using_vcr_spec.js | 17 +++ .../support/{index.js => index.js.erb} | 1 + .../spec/cypress/support/on-rails.js | 2 +- plugin/.gitignore | 1 + plugin/cypress/plugins/index.js | 4 + plugin/package.json | 31 +++++ plugin/support/index.js | 37 ++++++ spec/cypress_on_rails/middleware_spec.rb | 4 +- spec/cypress_on_rails/vcr_middleware_spec.rb | 109 ++++++++++++++++++ spec/integrations/rails_5_2/tmp/.keep | 0 spec/integrations/rails_5_2/vendor/.keep | 0 {spec/integrations => specs_e2e}/cypress.json | 0 .../rails_3_2/.gitignore | 0 .../rails_3_2/.ruby_version | 0 .../rails_3_2/Gemfile | 2 +- .../rails_3_2/README.rdoc | 0 .../rails_3_2/Rakefile | 0 .../app/assets/stylesheets/application.css | 0 .../app/controllers/application_controller.rb | 0 .../app/controllers/welcome_controller.rb | 0 .../app/helpers/application_helper.rb | 0 .../rails_3_2/app/models/post.rb | 0 .../app/views/layouts/application.html.erb | 0 .../app/views/welcome/index.html.erb | 0 .../rails_3_2/bin/rails | 0 .../rails_3_2/config.ru | 0 .../rails_3_2/config/application.rb | 0 .../rails_3_2/config/boot.rb | 0 .../rails_3_2/config/environment.rb | 0 .../config/environments/development.rb | 0 .../config/environments/production.rb | 0 .../rails_3_2/config/environments/test.rb | 0 .../initializers/backtrace_silencers.rb | 0 .../config/initializers/inflections.rb | 0 .../config/initializers/mime_types.rb | 0 .../config/initializers/secret_token.rb | 0 .../config/initializers/session_store.rb | 0 .../config/initializers/wrap_parameters.rb | 0 .../rails_3_2/config/locales/en.yml | 0 .../rails_3_2/config/routes.rb | 0 .../tmp => specs_e2e/rails_3_2/log}/.keep | 0 .../rails_3_2/public/404.html | 0 .../rails_3_2/public/422.html | 0 .../rails_3_2/public/500.html | 0 .../rails_3_2/public/favicon.ico | 0 .../rails_3_2/public/robots.txt | 0 .../rails_3_2/test.sh | 1 + .../log => specs_e2e/rails_3_2/tmp}/.keep | 0 .../rails_3_2/vendor/.gitkeep | 0 .../rails_4_2/.gitignore | 3 +- .../rails_4_2/Gemfile | 4 +- .../rails_4_2/README.rdoc | 0 .../rails_4_2/Rakefile | 0 .../app/assets/javascripts/using_vcr.js | 0 .../app/assets/stylesheets/using_vcr.css | 0 .../app/controllers/application_controller.rb | 0 .../app/controllers/using_vcr_controller.rb | 10 ++ .../app/controllers/welcome_controller.rb | 0 .../rails_4_2/app/models/post.rb | 0 .../app/views/layouts/application.html.erb | 0 .../app/views/using_vcr/index.html.erb | 6 + .../app/views/using_vcr/record_cats.html.erb | 7 ++ .../app/views/welcome/index.html.erb | 0 .../rails_4_2/bin/bundle | 0 .../rails_4_2/bin/rails | 0 .../rails_4_2/bin/rake | 0 .../rails_4_2/bin/setup | 0 .../rails_4_2/config.ru | 0 .../rails_4_2/config/application.rb | 0 .../rails_4_2/config/boot.rb | 0 .../rails_4_2/config/environment.rb | 0 .../config/environments/development.rb | 0 .../config/environments/production.rb | 0 .../rails_4_2/config/environments/test.rb | 0 .../initializers/backtrace_silencers.rb | 0 .../config/initializers/cookies_serializer.rb | 0 .../initializers/filter_parameter_logging.rb | 0 .../config/initializers/inflections.rb | 0 .../config/initializers/mime_types.rb | 0 .../config/initializers/session_store.rb | 0 .../to_time_preserves_timezone.rb | 0 .../config/initializers/wrap_parameters.rb | 0 .../rails_4_2/config/locales/en.yml | 0 .../rails_4_2/config/routes.rb | 5 + .../rails_4_2/config/secrets.yml | 0 specs_e2e/rails_4_2/package.json | 9 ++ .../rails_4_2/public/404.html | 0 .../rails_4_2/public/422.html | 0 .../rails_4_2/public/500.html | 0 .../rails_4_2/public/favicon.ico | 0 .../rails_4_2/public/robots.txt | 0 .../rails_4_2/spec/.keep | 0 .../rails_4_2/test.sh | 13 ++- .../rails_4_2/vendor/.keep | 0 .../rails_5_2/.gitignore | 0 .../rails_5_2/Gemfile | 2 +- .../rails_5_2/README.md | 0 .../rails_5_2/Rakefile | 0 .../rails_5_2/app/assets/javascripts/posts.js | 2 + .../app/assets/stylesheets/posts.css | 4 + .../app/assets/stylesheets/scaffold.css | 0 .../app/controllers/application_controller.rb | 0 .../app/controllers/posts_controller.rb | 0 .../rails_5_2/app/helpers/posts_helper.rb | 0 .../rails_5_2/app/jobs/application_job.rb | 0 .../app/models/application_record.rb | 0 .../rails_5_2/app/models/post.rb | 0 .../app/views/layouts/application.html.erb | 0 .../rails_5_2/app/views/posts/_form.html.erb | 0 .../rails_5_2/app/views/posts/edit.html.erb | 0 .../rails_5_2/app/views/posts/index.html.erb | 0 .../rails_5_2/app/views/posts/new.html.erb | 0 .../rails_5_2/app/views/posts/show.html.erb | 0 .../app/views/welcome/index.html.erb | 0 .../rails_5_2/bin/bundle | 0 .../rails_5_2/bin/rails | 0 .../rails_5_2/bin/rake | 0 .../rails_5_2/bin/setup | 0 .../rails_5_2/bin/update | 0 .../rails_5_2/config.ru | 0 .../rails_5_2/config/application.rb | 0 .../rails_5_2/config/boot.rb | 0 .../rails_5_2/config/credentials.yml.enc | 0 .../rails_5_2/config/database.yml | 0 .../rails_5_2/config/environment.rb | 0 .../config/environments/development.rb | 0 .../config/environments/production.rb | 0 .../rails_5_2/config/environments/test.rb | 0 .../application_controller_renderer.rb | 0 .../initializers/backtrace_silencers.rb | 0 .../initializers/content_security_policy.rb | 0 .../config/initializers/cookies_serializer.rb | 0 .../initializers/filter_parameter_logging.rb | 0 .../config/initializers/inflections.rb | 0 .../config/initializers/mime_types.rb | 0 .../config/initializers/wrap_parameters.rb | 0 .../rails_5_2/config/locales/en.yml | 0 .../rails_5_2/config/master.key | 0 .../rails_5_2/config/routes.rb | 0 .../db/migrate/20180621085832_create_posts.rb | 0 .../rails_5_2/public/404.html | 0 .../rails_5_2/public/422.html | 0 .../rails_5_2/public/500.html | 0 .../public/apple-touch-icon-precomposed.png | 0 .../rails_5_2/public/apple-touch-icon.png | 0 .../rails_5_2/public/favicon.ico | 0 .../rails_5_2/public/robots.txt | 0 .../rails_5_2/test.sh | 3 +- .../test/controllers/posts_controller_test.rb | 0 .../rails_5_2/test/cypress_fixtures/posts.yml | 0 .../rails_5_2/test/fixtures/posts.yml | 0 .../rails_5_2/test/models/post_test.rb | 0 .../log => specs_e2e/rails_5_2/vendor}/.keep | 0 165 files changed, 454 insertions(+), 50 deletions(-) create mode 100644 lib/cypress_on_rails/middleware_config.rb create mode 100644 lib/cypress_on_rails/vcr_middleware.rb rename lib/generators/cypress_on_rails/templates/spec/cypress/{cypress_helper.rb => cypress_helper.rb.erb} (76%) create mode 100644 lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_vcr_spec.js rename lib/generators/cypress_on_rails/templates/spec/cypress/support/{index.js => index.js.erb} (89%) create mode 100644 plugin/.gitignore create mode 100644 plugin/cypress/plugins/index.js create mode 100644 plugin/package.json create mode 100644 plugin/support/index.js create mode 100644 spec/cypress_on_rails/vcr_middleware_spec.rb delete mode 100644 spec/integrations/rails_5_2/tmp/.keep delete mode 100644 spec/integrations/rails_5_2/vendor/.keep rename {spec/integrations => specs_e2e}/cypress.json (100%) rename {spec/integrations => specs_e2e}/rails_3_2/.gitignore (100%) rename spec/integrations/rails_3_2/log/.keep => specs_e2e/rails_3_2/.ruby_version (100%) rename {spec/integrations => specs_e2e}/rails_3_2/Gemfile (66%) rename {spec/integrations => specs_e2e}/rails_3_2/README.rdoc (100%) rename {spec/integrations => specs_e2e}/rails_3_2/Rakefile (100%) rename {spec/integrations => specs_e2e}/rails_3_2/app/assets/stylesheets/application.css (100%) rename {spec/integrations => specs_e2e}/rails_3_2/app/controllers/application_controller.rb (100%) rename {spec/integrations => specs_e2e}/rails_3_2/app/controllers/welcome_controller.rb (100%) rename {spec/integrations => specs_e2e}/rails_3_2/app/helpers/application_helper.rb (100%) rename {spec/integrations => specs_e2e}/rails_3_2/app/models/post.rb (100%) rename {spec/integrations => specs_e2e}/rails_3_2/app/views/layouts/application.html.erb (100%) rename {spec/integrations => specs_e2e}/rails_3_2/app/views/welcome/index.html.erb (100%) rename {spec/integrations => specs_e2e}/rails_3_2/bin/rails (100%) rename {spec/integrations => specs_e2e}/rails_3_2/config.ru (100%) rename {spec/integrations => specs_e2e}/rails_3_2/config/application.rb (100%) rename {spec/integrations => specs_e2e}/rails_3_2/config/boot.rb (100%) rename {spec/integrations => specs_e2e}/rails_3_2/config/environment.rb (100%) rename {spec/integrations => specs_e2e}/rails_3_2/config/environments/development.rb (100%) rename {spec/integrations => specs_e2e}/rails_3_2/config/environments/production.rb (100%) rename {spec/integrations => specs_e2e}/rails_3_2/config/environments/test.rb (100%) rename {spec/integrations => specs_e2e}/rails_3_2/config/initializers/backtrace_silencers.rb (100%) rename {spec/integrations => specs_e2e}/rails_3_2/config/initializers/inflections.rb (100%) rename {spec/integrations => specs_e2e}/rails_3_2/config/initializers/mime_types.rb (100%) rename {spec/integrations => specs_e2e}/rails_3_2/config/initializers/secret_token.rb (100%) rename {spec/integrations => specs_e2e}/rails_3_2/config/initializers/session_store.rb (100%) rename {spec/integrations => specs_e2e}/rails_3_2/config/initializers/wrap_parameters.rb (100%) rename {spec/integrations => specs_e2e}/rails_3_2/config/locales/en.yml (100%) rename {spec/integrations => specs_e2e}/rails_3_2/config/routes.rb (100%) rename {spec/integrations/rails_3_2/tmp => specs_e2e/rails_3_2/log}/.keep (100%) rename {spec/integrations => specs_e2e}/rails_3_2/public/404.html (100%) rename {spec/integrations => specs_e2e}/rails_3_2/public/422.html (100%) rename {spec/integrations => specs_e2e}/rails_3_2/public/500.html (100%) rename {spec/integrations => specs_e2e}/rails_3_2/public/favicon.ico (100%) rename {spec/integrations => specs_e2e}/rails_3_2/public/robots.txt (100%) rename {spec/integrations => specs_e2e}/rails_3_2/test.sh (94%) rename {spec/integrations/rails_4_2/log => specs_e2e/rails_3_2/tmp}/.keep (100%) rename {spec/integrations => specs_e2e}/rails_3_2/vendor/.gitkeep (100%) rename {spec/integrations => specs_e2e}/rails_4_2/.gitignore (90%) rename {spec/integrations => specs_e2e}/rails_4_2/Gemfile (72%) rename {spec/integrations => specs_e2e}/rails_4_2/README.rdoc (100%) rename {spec/integrations => specs_e2e}/rails_4_2/Rakefile (100%) rename spec/integrations/rails_5_2/app/assets/javascripts/posts.js => specs_e2e/rails_4_2/app/assets/javascripts/using_vcr.js (100%) rename spec/integrations/rails_5_2/app/assets/stylesheets/posts.css => specs_e2e/rails_4_2/app/assets/stylesheets/using_vcr.css (100%) rename {spec/integrations => specs_e2e}/rails_4_2/app/controllers/application_controller.rb (100%) create mode 100644 specs_e2e/rails_4_2/app/controllers/using_vcr_controller.rb rename {spec/integrations => specs_e2e}/rails_4_2/app/controllers/welcome_controller.rb (100%) rename {spec/integrations => specs_e2e}/rails_4_2/app/models/post.rb (100%) rename {spec/integrations => specs_e2e}/rails_4_2/app/views/layouts/application.html.erb (100%) create mode 100644 specs_e2e/rails_4_2/app/views/using_vcr/index.html.erb create mode 100644 specs_e2e/rails_4_2/app/views/using_vcr/record_cats.html.erb rename {spec/integrations => specs_e2e}/rails_4_2/app/views/welcome/index.html.erb (100%) rename {spec/integrations => specs_e2e}/rails_4_2/bin/bundle (100%) rename {spec/integrations => specs_e2e}/rails_4_2/bin/rails (100%) rename {spec/integrations => specs_e2e}/rails_4_2/bin/rake (100%) rename {spec/integrations => specs_e2e}/rails_4_2/bin/setup (100%) rename {spec/integrations => specs_e2e}/rails_4_2/config.ru (100%) rename {spec/integrations => specs_e2e}/rails_4_2/config/application.rb (100%) rename {spec/integrations => specs_e2e}/rails_4_2/config/boot.rb (100%) rename {spec/integrations => specs_e2e}/rails_4_2/config/environment.rb (100%) rename {spec/integrations => specs_e2e}/rails_4_2/config/environments/development.rb (100%) rename {spec/integrations => specs_e2e}/rails_4_2/config/environments/production.rb (100%) rename {spec/integrations => specs_e2e}/rails_4_2/config/environments/test.rb (100%) rename {spec/integrations => specs_e2e}/rails_4_2/config/initializers/backtrace_silencers.rb (100%) rename {spec/integrations => specs_e2e}/rails_4_2/config/initializers/cookies_serializer.rb (100%) rename {spec/integrations => specs_e2e}/rails_4_2/config/initializers/filter_parameter_logging.rb (100%) rename {spec/integrations => specs_e2e}/rails_4_2/config/initializers/inflections.rb (100%) rename {spec/integrations => specs_e2e}/rails_4_2/config/initializers/mime_types.rb (100%) rename {spec/integrations => specs_e2e}/rails_4_2/config/initializers/session_store.rb (100%) rename {spec/integrations => specs_e2e}/rails_4_2/config/initializers/to_time_preserves_timezone.rb (100%) rename {spec/integrations => specs_e2e}/rails_4_2/config/initializers/wrap_parameters.rb (100%) rename {spec/integrations => specs_e2e}/rails_4_2/config/locales/en.yml (100%) rename {spec/integrations => specs_e2e}/rails_4_2/config/routes.rb (95%) rename {spec/integrations => specs_e2e}/rails_4_2/config/secrets.yml (100%) create mode 100644 specs_e2e/rails_4_2/package.json rename {spec/integrations => specs_e2e}/rails_4_2/public/404.html (100%) rename {spec/integrations => specs_e2e}/rails_4_2/public/422.html (100%) rename {spec/integrations => specs_e2e}/rails_4_2/public/500.html (100%) rename {spec/integrations => specs_e2e}/rails_4_2/public/favicon.ico (100%) rename {spec/integrations => specs_e2e}/rails_4_2/public/robots.txt (100%) rename {spec/integrations => specs_e2e}/rails_4_2/spec/.keep (100%) rename {spec/integrations => specs_e2e}/rails_4_2/test.sh (75%) rename {spec/integrations => specs_e2e}/rails_4_2/vendor/.keep (100%) rename {spec/integrations => specs_e2e}/rails_5_2/.gitignore (100%) rename {spec/integrations => specs_e2e}/rails_5_2/Gemfile (90%) rename {spec/integrations => specs_e2e}/rails_5_2/README.md (100%) rename {spec/integrations => specs_e2e}/rails_5_2/Rakefile (100%) create mode 100644 specs_e2e/rails_5_2/app/assets/javascripts/posts.js create mode 100644 specs_e2e/rails_5_2/app/assets/stylesheets/posts.css rename {spec/integrations => specs_e2e}/rails_5_2/app/assets/stylesheets/scaffold.css (100%) rename {spec/integrations => specs_e2e}/rails_5_2/app/controllers/application_controller.rb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/app/controllers/posts_controller.rb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/app/helpers/posts_helper.rb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/app/jobs/application_job.rb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/app/models/application_record.rb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/app/models/post.rb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/app/views/layouts/application.html.erb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/app/views/posts/_form.html.erb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/app/views/posts/edit.html.erb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/app/views/posts/index.html.erb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/app/views/posts/new.html.erb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/app/views/posts/show.html.erb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/app/views/welcome/index.html.erb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/bin/bundle (100%) rename {spec/integrations => specs_e2e}/rails_5_2/bin/rails (100%) rename {spec/integrations => specs_e2e}/rails_5_2/bin/rake (100%) rename {spec/integrations => specs_e2e}/rails_5_2/bin/setup (100%) rename {spec/integrations => specs_e2e}/rails_5_2/bin/update (100%) rename {spec/integrations => specs_e2e}/rails_5_2/config.ru (100%) rename {spec/integrations => specs_e2e}/rails_5_2/config/application.rb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/config/boot.rb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/config/credentials.yml.enc (100%) rename {spec/integrations => specs_e2e}/rails_5_2/config/database.yml (100%) rename {spec/integrations => specs_e2e}/rails_5_2/config/environment.rb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/config/environments/development.rb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/config/environments/production.rb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/config/environments/test.rb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/config/initializers/application_controller_renderer.rb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/config/initializers/backtrace_silencers.rb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/config/initializers/content_security_policy.rb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/config/initializers/cookies_serializer.rb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/config/initializers/filter_parameter_logging.rb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/config/initializers/inflections.rb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/config/initializers/mime_types.rb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/config/initializers/wrap_parameters.rb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/config/locales/en.yml (100%) rename {spec/integrations => specs_e2e}/rails_5_2/config/master.key (100%) rename {spec/integrations => specs_e2e}/rails_5_2/config/routes.rb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/db/migrate/20180621085832_create_posts.rb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/public/404.html (100%) rename {spec/integrations => specs_e2e}/rails_5_2/public/422.html (100%) rename {spec/integrations => specs_e2e}/rails_5_2/public/500.html (100%) rename {spec/integrations => specs_e2e}/rails_5_2/public/apple-touch-icon-precomposed.png (100%) rename {spec/integrations => specs_e2e}/rails_5_2/public/apple-touch-icon.png (100%) rename {spec/integrations => specs_e2e}/rails_5_2/public/favicon.ico (100%) rename {spec/integrations => specs_e2e}/rails_5_2/public/robots.txt (100%) rename {spec/integrations => specs_e2e}/rails_5_2/test.sh (89%) rename {spec/integrations => specs_e2e}/rails_5_2/test/controllers/posts_controller_test.rb (100%) rename {spec/integrations => specs_e2e}/rails_5_2/test/cypress_fixtures/posts.yml (100%) rename {spec/integrations => specs_e2e}/rails_5_2/test/fixtures/posts.yml (100%) rename {spec/integrations => specs_e2e}/rails_5_2/test/models/post_test.rb (100%) rename {spec/integrations/rails_5_2/log => specs_e2e/rails_5_2/vendor}/.keep (100%) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index a20043f..d0be0ca 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -22,7 +22,7 @@ jobs: - run: gem uninstall -v '>= 2' -ax bundler || true - run: gem install bundler -v '< 2' - name: Run interaction tests - run: ./spec/integrations/rails_3_2/test.sh + run: ./specs_e2e/rails_3_2/test.sh rails_4_2: runs-on: ubuntu-latest @@ -39,7 +39,7 @@ jobs: - run: gem uninstall -v '>= 2' -ax bundler || true - run: gem install bundler -v '< 2' - name: Run interaction tests - run: ./spec/integrations/rails_4_2/test.sh + run: ./specs_e2e/rails_4_2/test.sh rails_5_2: runs-on: ubuntu-latest @@ -54,4 +54,4 @@ jobs: - name: Run tests run: bundle exec rake - name: Run interaction tests - run: ./spec/integrations/rails_5_2/test.sh + run: ./specs_e2e/rails_5_2/test.sh diff --git a/.gitignore b/.gitignore index ec9e4e3..39ca350 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,7 @@ spec/examples.txt spec/test.log pkg/*.gem vendor/bundle -.vscode \ No newline at end of file +.vscode +node_modules +package-lock.json +yarn.lock \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 15f1224..cf39676 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## [] + +### Changed +* Add support for matching npm package and VCR + ## [1.12.1] [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.12.0...v1.12.1 diff --git a/README.md b/README.md index fc10616..e269c80 100644 --- a/README.md +++ b/README.md @@ -271,6 +271,68 @@ describe('My First Test', function() { }) ``` +## Expermintal Features (matching npm package) + +Please test and give feedback + +add the npm package: + +``` +yarn add cypress-on-rails --dev +``` + +### for VCR + +#### setup + +Add you VCR configuration to your `cypress_helper.rb` + +```ruby +require 'vcr' +VCR.configure do |config| + config.hook_into :webmock +end +``` + +Add to you `cypress/support/index.js` + +```js +import 'cypress-on-rails/support/index' +``` + +Add to you `clean.rb` + +```ruby +VCR.eject_cassette # make sure we no cassettes inserted before the next test starts +``` + +#### usage + +You have `vcr_insert_cassette` and `vcr_eject_cassette` available. https://www.rubydoc.info/github/vcr/vcr/VCR:insert_cassette + + +```js +describe('My First Test', function() { + beforeEach(() => { cy.app('load_seed') }) + + it('visit root', function() { + cy.app('clean') // have a look at cypress/app_commands/clean.rb + + cy.vcr_insert_cassette('cats', { record: "new_episodes" }) + cy.visit('/using_vcr/index') + + cy.get('a').contains('Cats').click() + cy.contains('Wikipedia has a recording of a cat meowing, because why not?') + + cy.vcr_eject_cassette(); + + cy.vcr_insert_cassette('cats') + cy.visit('/using_vcr/record_cats') + cy.contains('Wikipedia has a recording of a cat meowing, because why not?') + }) +}) +``` + ## Usage with other rack applications Add CypressOnRails to your config.ru diff --git a/cypress-on-rails.gemspec b/cypress-on-rails.gemspec index 33a4b2f..04a1bfc 100644 --- a/cypress-on-rails.gemspec +++ b/cypress-on-rails.gemspec @@ -20,6 +20,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'rspec' s.add_development_dependency 'railties', '>= 3.2' s.add_development_dependency 'factory_bot' + s.add_development_dependency 'vcr' s.metadata = { "bug_tracker_uri" => "https://github.com/shakacode/cypress-on-rails/issues", "changelog_uri" => "https://github.com/shakacode/cypress-on-rails/blob/master/CHANGELOG.md", diff --git a/lib/cypress_on_rails/middleware.rb b/lib/cypress_on_rails/middleware.rb index 911583c..96ff611 100644 --- a/lib/cypress_on_rails/middleware.rb +++ b/lib/cypress_on_rails/middleware.rb @@ -1,11 +1,13 @@ require 'json' require 'rack' -require 'cypress_on_rails/configuration' +require 'cypress_on_rails/middleware_config' require 'cypress_on_rails/command_executor' module CypressOnRails # Middleware to handle cypress commands and eval class Middleware + include MiddlewareConfig + def initialize(app, command_executor = CommandExecutor, file = ::File) @app = app @command_executor = command_executor @@ -23,14 +25,6 @@ def call(env) 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) @@ -71,7 +65,8 @@ def handle_command(req) [500, {'Content-Type' => 'application/json'}, [output]] end else - [404, {}, ["could not find command file: #{missing_command.file_path}"]] + output = {"message" => "could not find command file: #{missing_command.file_path}"}.to_json + [404, {'Content-Type' => 'application/json'}, [output]] end end end diff --git a/lib/cypress_on_rails/middleware_config.rb b/lib/cypress_on_rails/middleware_config.rb new file mode 100644 index 0000000..65945de --- /dev/null +++ b/lib/cypress_on_rails/middleware_config.rb @@ -0,0 +1,17 @@ +require 'json' +require 'rack' +require 'cypress_on_rails/configuration' + +module CypressOnRails + module MiddlewareConfig + protected + + def configuration + CypressOnRails.configuration + end + + def logger + configuration.logger + end + end +end diff --git a/lib/cypress_on_rails/railtie.rb b/lib/cypress_on_rails/railtie.rb index 4565377..1d5ca44 100644 --- a/lib/cypress_on_rails/railtie.rb +++ b/lib/cypress_on_rails/railtie.rb @@ -1,12 +1,14 @@ require 'rails/railtie' require 'cypress_on_rails/configuration' -require 'cypress_on_rails/middleware' module CypressOnRails class Railtie < Rails::Railtie initializer :setup_cypress_middleware, after: :load_config_initializers do |app| if CypressOnRails.configuration.use_middleware? + require 'cypress_on_rails/middleware' app.middleware.use Middleware + require 'cypress_on_rails/vcr_middleware' + app.middleware.use VCRMiddleware end end end diff --git a/lib/cypress_on_rails/vcr_middleware.rb b/lib/cypress_on_rails/vcr_middleware.rb new file mode 100644 index 0000000..71dd3f7 --- /dev/null +++ b/lib/cypress_on_rails/vcr_middleware.rb @@ -0,0 +1,60 @@ +require 'json' +require 'rack' +require 'cypress_on_rails/middleware_config' + +module CypressOnRails + # Middleware to handle vcr + class VCRMiddleware + include MiddlewareConfig + + def initialize(app, vcr = nil) + @app = app + @vcr = vcr + end + + def call(env) + request = Rack::Request.new(env) + if request.path.start_with?('/__cypress__/vcr/insert') + configuration.tagged_logged { handle_insert(request) } + elsif request.path.start_with?('/__cypress__/vcr/eject') + configuration.tagged_logged { handle_eject } + else + @app.call(env) + end + end + + private + + def handle_insert(req) + body = JSON.parse(req.body.read) + logger.info "vcr insert cassette: #{body}" + cassette_name = body[0] + options = (body[1] || {}).symbolize_keys + options[:record] = options[:record].to_sym if options[:record] + options[:match_requests_on] = options[:match_requests_on].map(&:to_sym) if options[:match_requests_on] + options[:serialize_with] = options[:serialize_with].to_sym if options[:serialize_with] + options[:persist_with] = options[:persist_with].to_sym if options[:persist_with] + vcr.insert_cassette(cassette_name, options) + [201, {'Content-Type' => 'application/json'}, [{'message': 'OK'}.to_json]] + rescue LoadError, ArgumentError => e + [501, {'Content-Type' => 'application/json'}, [{'message': e.message}.to_json]] + end + + def handle_eject + logger.info "vcr eject cassette" + vcr.eject_cassette + [201, {'Content-Type' => 'application/json'}, [{'message': 'OK'}.to_json]] + rescue LoadError, ArgumentError => e + [501, {'Content-Type' => 'application/json'}, [{'message': e.message}.to_json]] + end + + def vcr + return @vcr if @vcr + require 'vcr' + VCR.configure do |config| + config.cassette_library_dir = "#{configuration.cypress_folder}/fixtures/vcr_cassettes" + end + @vcr = VCR + end + end +end diff --git a/lib/generators/cypress_on_rails/install_generator.rb b/lib/generators/cypress_on_rails/install_generator.rb index f5b6b08..4d930a9 100644 --- a/lib/generators/cypress_on_rails/install_generator.rb +++ b/lib/generators/cypress_on_rails/install_generator.rb @@ -4,38 +4,37 @@ class InstallGenerator < Rails::Generators::Base class_option :install_cypress, type: :boolean, default: true class_option :install_cypress_with, type: :string, default: 'yarn' class_option :install_cypress_examples, type: :boolean, default: false + class_option :experimental, type: :boolean, default: false source_root File.expand_path('../templates', __FILE__) def install_cypress - if !Dir.exists?(options.cypress_folder) || Dir["#{options.cypress_folder}/*"].empty? - directories = options.cypress_folder.split('/') - directories.pop - install_dir = "#{Dir.pwd}/#{directories.join('/')}" - command = nil - if options.install_cypress - if options.install_cypress_with == 'yarn' - command = "yarn --cwd=#{install_dir} add cypress --dev" - elsif options.install_cypress_with == 'npm' - command = "cd #{install_dir}; npm install cypress --save-dev" - end - if command - say command - fail 'failed to install cypress' unless system(command) - end + directories = options.cypress_folder.split('/') + directories.pop + install_dir = "#{Dir.pwd}/#{directories.join('/')}" + command = nil + if options.install_cypress + if options.install_cypress_with == 'yarn' + command = "yarn --cwd=#{install_dir} add cypress --dev" + elsif options.install_cypress_with == 'npm' + command = "cd #{install_dir}; npm install cypress --save-dev" end - if options.install_cypress_examples - directory 'spec/cypress/integration/examples', "#{options.cypress_folder}/integration/examples" - directory 'spec/cypress/fixtures', "#{options.cypress_folder}/fixtures" + if command + say command + fail 'failed to install cypress' unless system(command) end - copy_file "spec/cypress/support/index.js", "#{options.cypress_folder}/support/index.js" - copy_file "spec/cypress/support/commands.js", "#{options.cypress_folder}/support/commands.js" - copy_file "spec/cypress.json", "#{options.cypress_folder}/../cypress.json" end + if options.install_cypress_examples + directory 'spec/cypress/integration/examples', "#{options.cypress_folder}/integration/examples" + directory 'spec/cypress/fixtures', "#{options.cypress_folder}/fixtures" + end + template "spec/cypress/support/index.js.erb", "#{options.cypress_folder}/support/index.js" + copy_file "spec/cypress/support/commands.js", "#{options.cypress_folder}/support/commands.js" + copy_file "spec/cypress.json", "#{options.cypress_folder}/../cypress.json" end def add_initial_files 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" + template "spec/cypress/cypress_helper.rb.erb", "#{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" directory 'spec/cypress/integration/rails_examples', "#{options.cypress_folder}/integration/rails_examples" diff --git a/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/clean.rb b/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/clean.rb index a6c56b0..85bcf9c 100644 --- a/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/clean.rb +++ b/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/clean.rb @@ -9,4 +9,8 @@ CypressOnRails::SmartFactoryWrapper.reload +if defined?(VCR) + VCR.eject_cassette # make sure we any cassettes inserted before the next test starts +end + Rails.logger.info "APPCLEANED" # used by log_fail.rb diff --git a/lib/generators/cypress_on_rails/templates/spec/cypress/cypress_helper.rb b/lib/generators/cypress_on_rails/templates/spec/cypress/cypress_helper.rb.erb similarity index 76% rename from lib/generators/cypress_on_rails/templates/spec/cypress/cypress_helper.rb rename to lib/generators/cypress_on_rails/templates/spec/cypress/cypress_helper.rb.erb index 3709c4a..3ecabef 100644 --- a/lib/generators/cypress_on_rails/templates/spec/cypress/cypress_helper.rb +++ b/lib/generators/cypress_on_rails/templates/spec/cypress/cypress_helper.rb.erb @@ -36,3 +36,8 @@ Rails.root.join('spec', 'factories', '**', '*.rb') ] ) + +<% unless options.experimental %># <% end %>require 'vcr' +<% unless options.experimental %># <% end %>VCR.configure do |config| +<% unless options.experimental %># <% end %> config.hook_into :webmock +<% unless options.experimental %># <% end %>end diff --git a/lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_vcr_spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_vcr_spec.js new file mode 100644 index 0000000..7751d20 --- /dev/null +++ b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_vcr_spec.js @@ -0,0 +1,17 @@ +describe('Rails Other examples', function() { + it('Inserting a cassette', function() { + cy.app('clean') // have a look at cypress/app_commands/clean.rb + + cy.vcr_insert_cassette('cats', { record: "new_episodes" }) + cy.visit('/using_vcr/index') + + cy.get('a').contains('Cats').click() + cy.contains('Wikipedia has a recording of a cat meowing, because why not?') + + cy.vcr_eject_cassette(); + + cy.vcr_insert_cassette('cats') + cy.visit('/using_vcr/record_cats') + cy.contains('Wikipedia has a recording of a cat meowing, because why not?') + }) +}) diff --git a/lib/generators/cypress_on_rails/templates/spec/cypress/support/index.js b/lib/generators/cypress_on_rails/templates/spec/cypress/support/index.js.erb similarity index 89% rename from lib/generators/cypress_on_rails/templates/spec/cypress/support/index.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/support/index.js.erb index edba3c8..a465224 100644 --- a/lib/generators/cypress_on_rails/templates/spec/cypress/support/index.js +++ b/lib/generators/cypress_on_rails/templates/spec/cypress/support/index.js.erb @@ -14,6 +14,7 @@ // *********************************************************** // Import commands.js using ES2015 syntax: +<% unless options.experimental %>// <% end %>import 'cypress-on-rails/support/index' import './commands' import './on-rails' diff --git a/lib/generators/cypress_on_rails/templates/spec/cypress/support/on-rails.js b/lib/generators/cypress_on_rails/templates/spec/cypress/support/on-rails.js index f5b8f42..18cc1ee 100644 --- a/lib/generators/cypress_on_rails/templates/spec/cypress/support/on-rails.js +++ b/lib/generators/cypress_on_rails/templates/spec/cypress/support/on-rails.js @@ -11,7 +11,7 @@ Cypress.Commands.add('appCommands', function (body) { }).then((response) => { log.end(); if (response.status !== 201) { - expect(response.body.message).to.be.empty + expect(response.body.message).to.equal('') expect(response.status).to.be.equal(201) } return response.body diff --git a/plugin/.gitignore b/plugin/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/plugin/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/plugin/cypress/plugins/index.js b/plugin/cypress/plugins/index.js new file mode 100644 index 0000000..be95c7b --- /dev/null +++ b/plugin/cypress/plugins/index.js @@ -0,0 +1,4 @@ +// export a function +module.exports = (on, config) => { + // configure plugins here +} diff --git a/plugin/package.json b/plugin/package.json new file mode 100644 index 0000000..374bb87 --- /dev/null +++ b/plugin/package.json @@ -0,0 +1,31 @@ +{ + "name": "cypress-on-rails", + "version": "0.1.0", + "description": "Integrates cypress with rails or rack applications", + "main": "cypress/index.js", + "directories": { + "src": "cypress" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "build": "tsc" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/shakacode/cypress-on-rails.git" + }, + "keywords": [ + "cypress", + "ruby", + "rails" + ], + "author": "Grant Petersen-Speelman", + "license": "MIT", + "bugs": { + "url": "https://github.com/shakacode/cypress-on-rails/issues" + }, + "homepage": "https://github.com/shakacode/cypress-on-rails#readme", + "dependencies": { + "cypress": "*" + } +} diff --git a/plugin/support/index.js b/plugin/support/index.js new file mode 100644 index 0000000..ead33dd --- /dev/null +++ b/plugin/support/index.js @@ -0,0 +1,37 @@ +Cypress.Commands.add("vcr_insert_cassette", (cassette_name, options) => { + if (!options) options = {}; + + Object.keys(options).forEach(key => options[key] === undefined ? delete options[key] : {}); + const log = Cypress.log({ name: "VCR Insert", message: cassette_name, autoEnd: false }) + return cy.request({ + method: 'POST', + url: "/__cypress__/vcr/insert", + body: JSON.stringify([cassette_name,options]), + log: false, + failOnStatusCode: false + }).then((response) => { + log.end(); + if (response.status !== 201) { + expect(response.body.message).to.equal('') + expect(response.status).to.be.equal(201) + } + return response.body + }); +}); + +Cypress.Commands.add("vcr_eject_cassette", () => { + const log = Cypress.log({ name: "VCR Eject", autoEnd: false }) + return cy.request({ + method: 'POST', + url: "/__cypress__/vcr/eject", + log: false, + failOnStatusCode: false + }).then((response) => { + log.end(); + if (response.status !== 201) { + expect(response.body.message).to.equal('') + expect(response.status).to.be.equal(201) + } + return response.body + }); +}); diff --git a/spec/cypress_on_rails/middleware_spec.rb b/spec/cypress_on_rails/middleware_spec.rb index ccba771..639157b 100644 --- a/spec/cypress_on_rails/middleware_spec.rb +++ b/spec/cypress_on_rails/middleware_spec.rb @@ -93,7 +93,9 @@ def rack_input(json_value) allow(file).to receive(:exist?).with('spec/cypress/app_commands/load_sample.rb').and_return(false) aggregate_failures do - expect(response).to eq([404, {}, ['could not find command file: spec/cypress/app_commands/load_sample.rb']]) + expect(response).to eq([404, + {"Content-Type"=>"application/json"}, + ["{\"message\":\"could not find command file: spec/cypress/app_commands/load_sample.rb\"}"]]) expect(command_executor).to_not have_received(:perform) end end diff --git a/spec/cypress_on_rails/vcr_middleware_spec.rb b/spec/cypress_on_rails/vcr_middleware_spec.rb new file mode 100644 index 0000000..5c7f5c9 --- /dev/null +++ b/spec/cypress_on_rails/vcr_middleware_spec.rb @@ -0,0 +1,109 @@ +require 'cypress_on_rails/vcr_middleware' +require 'vcr' +require 'active_support/core_ext/hash' unless Hash.new.respond_to?(:symbolize_keys) + +module CypressOnRails + RSpec.describe VCRMiddleware do + let(:app) { ->(env) { [200, {}, ["app did #{env['PATH_INFO']}"]] } } + let(:vcr) { class_double(VCR, insert_cassette: true, eject_cassette: true) } + subject { described_class.new(app, vcr) } + + let(:env) { {} } + + let(:response) { subject.call(env) } + + def rack_input(json_value) + StringIO.new(JSON.generate(json_value)) + end + + describe '/__cypress__/vcr/insert' do + before do + env['PATH_INFO'] = '/__cypress__/vcr/insert' + end + + it do + env['rack.input'] = rack_input(['cas1']) + + aggregate_failures do + expect(response).to eq([201, + {"Content-Type"=>"application/json"}, + ["{\"message\":\"OK\"}"]]) + expect(vcr).to have_received(:insert_cassette).with('cas1', {}) + end + end + + it 'works with record' do + env['rack.input'] = rack_input(['cas1', { "record" => "new_episodes" }]) + + aggregate_failures do + expect(response).to eq([201, + {"Content-Type"=>"application/json"}, + ["{\"message\":\"OK\"}"]]) + expect(vcr).to have_received(:insert_cassette).with('cas1', record: :new_episodes) + end + end + + it 'works with match_requests_on' do + env['rack.input'] = rack_input(['cas1', { "match_requests_on" => ["method", "uri"] }]) + + aggregate_failures do + expect(response).to eq([201, + {"Content-Type"=>"application/json"}, + ["{\"message\":\"OK\"}"]]) + expect(vcr).to have_received(:insert_cassette).with('cas1', match_requests_on: [:method, :uri]) + end + end + + it 'works with serialize_with' do + env['rack.input'] = rack_input(['cas1', { "serialize_with" => "yaml" }]) + + aggregate_failures do + expect(response).to eq([201, + {"Content-Type"=>"application/json"}, + ["{\"message\":\"OK\"}"]]) + expect(vcr).to have_received(:insert_cassette).with('cas1', serialize_with: :yaml) + end + end + + it 'works with persist_with' do + env['rack.input'] = rack_input(['cas1', { "persist_with" => "file_system" }]) + + aggregate_failures do + expect(response).to eq([201, + {"Content-Type"=>"application/json"}, + ["{\"message\":\"OK\"}"]]) + expect(vcr).to have_received(:insert_cassette).with('cas1', persist_with: :file_system) + end + end + end + + describe '/__cypress__/vcr/eject' do + before do + env['PATH_INFO'] = '/__cypress__/vcr/eject' + end + + it do + aggregate_failures do + expect(response).to eq([201, + {"Content-Type"=>"application/json"}, + ["{\"message\":\"OK\"}"]]) + expect(vcr).to have_received(:eject_cassette) + end + end + end + + describe '"Other paths"' do + it 'runs app' do + aggregate_failures do + %w(/ /__cypress__/login command /cypress_command /).each do |path| + env['PATH_INFO'] = path + + response = subject.call(env) + + expect(response).to eq([200, {}, ["app did #{path}"]]) + end + end + end + end + end +end diff --git a/spec/integrations/rails_5_2/tmp/.keep b/spec/integrations/rails_5_2/tmp/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/spec/integrations/rails_5_2/vendor/.keep b/spec/integrations/rails_5_2/vendor/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/spec/integrations/cypress.json b/specs_e2e/cypress.json similarity index 100% rename from spec/integrations/cypress.json rename to specs_e2e/cypress.json diff --git a/spec/integrations/rails_3_2/.gitignore b/specs_e2e/rails_3_2/.gitignore similarity index 100% rename from spec/integrations/rails_3_2/.gitignore rename to specs_e2e/rails_3_2/.gitignore diff --git a/spec/integrations/rails_3_2/log/.keep b/specs_e2e/rails_3_2/.ruby_version similarity index 100% rename from spec/integrations/rails_3_2/log/.keep rename to specs_e2e/rails_3_2/.ruby_version diff --git a/spec/integrations/rails_3_2/Gemfile b/specs_e2e/rails_3_2/Gemfile similarity index 66% rename from spec/integrations/rails_3_2/Gemfile rename to specs_e2e/rails_3_2/Gemfile index 13306ca..c6c3c92 100644 --- a/spec/integrations/rails_3_2/Gemfile +++ b/specs_e2e/rails_3_2/Gemfile @@ -3,5 +3,5 @@ source 'https://rubygems.org' gem 'rails', '~> 3.2.22' group :development, :test do - gem 'cypress-on-rails', path: '../../../' + gem 'cypress-on-rails', path: '../../' end \ No newline at end of file diff --git a/spec/integrations/rails_3_2/README.rdoc b/specs_e2e/rails_3_2/README.rdoc similarity index 100% rename from spec/integrations/rails_3_2/README.rdoc rename to specs_e2e/rails_3_2/README.rdoc diff --git a/spec/integrations/rails_3_2/Rakefile b/specs_e2e/rails_3_2/Rakefile similarity index 100% rename from spec/integrations/rails_3_2/Rakefile rename to specs_e2e/rails_3_2/Rakefile diff --git a/spec/integrations/rails_3_2/app/assets/stylesheets/application.css b/specs_e2e/rails_3_2/app/assets/stylesheets/application.css similarity index 100% rename from spec/integrations/rails_3_2/app/assets/stylesheets/application.css rename to specs_e2e/rails_3_2/app/assets/stylesheets/application.css diff --git a/spec/integrations/rails_3_2/app/controllers/application_controller.rb b/specs_e2e/rails_3_2/app/controllers/application_controller.rb similarity index 100% rename from spec/integrations/rails_3_2/app/controllers/application_controller.rb rename to specs_e2e/rails_3_2/app/controllers/application_controller.rb diff --git a/spec/integrations/rails_3_2/app/controllers/welcome_controller.rb b/specs_e2e/rails_3_2/app/controllers/welcome_controller.rb similarity index 100% rename from spec/integrations/rails_3_2/app/controllers/welcome_controller.rb rename to specs_e2e/rails_3_2/app/controllers/welcome_controller.rb diff --git a/spec/integrations/rails_3_2/app/helpers/application_helper.rb b/specs_e2e/rails_3_2/app/helpers/application_helper.rb similarity index 100% rename from spec/integrations/rails_3_2/app/helpers/application_helper.rb rename to specs_e2e/rails_3_2/app/helpers/application_helper.rb diff --git a/spec/integrations/rails_3_2/app/models/post.rb b/specs_e2e/rails_3_2/app/models/post.rb similarity index 100% rename from spec/integrations/rails_3_2/app/models/post.rb rename to specs_e2e/rails_3_2/app/models/post.rb diff --git a/spec/integrations/rails_3_2/app/views/layouts/application.html.erb b/specs_e2e/rails_3_2/app/views/layouts/application.html.erb similarity index 100% rename from spec/integrations/rails_3_2/app/views/layouts/application.html.erb rename to specs_e2e/rails_3_2/app/views/layouts/application.html.erb diff --git a/spec/integrations/rails_3_2/app/views/welcome/index.html.erb b/specs_e2e/rails_3_2/app/views/welcome/index.html.erb similarity index 100% rename from spec/integrations/rails_3_2/app/views/welcome/index.html.erb rename to specs_e2e/rails_3_2/app/views/welcome/index.html.erb diff --git a/spec/integrations/rails_3_2/bin/rails b/specs_e2e/rails_3_2/bin/rails similarity index 100% rename from spec/integrations/rails_3_2/bin/rails rename to specs_e2e/rails_3_2/bin/rails diff --git a/spec/integrations/rails_3_2/config.ru b/specs_e2e/rails_3_2/config.ru similarity index 100% rename from spec/integrations/rails_3_2/config.ru rename to specs_e2e/rails_3_2/config.ru diff --git a/spec/integrations/rails_3_2/config/application.rb b/specs_e2e/rails_3_2/config/application.rb similarity index 100% rename from spec/integrations/rails_3_2/config/application.rb rename to specs_e2e/rails_3_2/config/application.rb diff --git a/spec/integrations/rails_3_2/config/boot.rb b/specs_e2e/rails_3_2/config/boot.rb similarity index 100% rename from spec/integrations/rails_3_2/config/boot.rb rename to specs_e2e/rails_3_2/config/boot.rb diff --git a/spec/integrations/rails_3_2/config/environment.rb b/specs_e2e/rails_3_2/config/environment.rb similarity index 100% rename from spec/integrations/rails_3_2/config/environment.rb rename to specs_e2e/rails_3_2/config/environment.rb diff --git a/spec/integrations/rails_3_2/config/environments/development.rb b/specs_e2e/rails_3_2/config/environments/development.rb similarity index 100% rename from spec/integrations/rails_3_2/config/environments/development.rb rename to specs_e2e/rails_3_2/config/environments/development.rb diff --git a/spec/integrations/rails_3_2/config/environments/production.rb b/specs_e2e/rails_3_2/config/environments/production.rb similarity index 100% rename from spec/integrations/rails_3_2/config/environments/production.rb rename to specs_e2e/rails_3_2/config/environments/production.rb diff --git a/spec/integrations/rails_3_2/config/environments/test.rb b/specs_e2e/rails_3_2/config/environments/test.rb similarity index 100% rename from spec/integrations/rails_3_2/config/environments/test.rb rename to specs_e2e/rails_3_2/config/environments/test.rb diff --git a/spec/integrations/rails_3_2/config/initializers/backtrace_silencers.rb b/specs_e2e/rails_3_2/config/initializers/backtrace_silencers.rb similarity index 100% rename from spec/integrations/rails_3_2/config/initializers/backtrace_silencers.rb rename to specs_e2e/rails_3_2/config/initializers/backtrace_silencers.rb diff --git a/spec/integrations/rails_3_2/config/initializers/inflections.rb b/specs_e2e/rails_3_2/config/initializers/inflections.rb similarity index 100% rename from spec/integrations/rails_3_2/config/initializers/inflections.rb rename to specs_e2e/rails_3_2/config/initializers/inflections.rb diff --git a/spec/integrations/rails_3_2/config/initializers/mime_types.rb b/specs_e2e/rails_3_2/config/initializers/mime_types.rb similarity index 100% rename from spec/integrations/rails_3_2/config/initializers/mime_types.rb rename to specs_e2e/rails_3_2/config/initializers/mime_types.rb diff --git a/spec/integrations/rails_3_2/config/initializers/secret_token.rb b/specs_e2e/rails_3_2/config/initializers/secret_token.rb similarity index 100% rename from spec/integrations/rails_3_2/config/initializers/secret_token.rb rename to specs_e2e/rails_3_2/config/initializers/secret_token.rb diff --git a/spec/integrations/rails_3_2/config/initializers/session_store.rb b/specs_e2e/rails_3_2/config/initializers/session_store.rb similarity index 100% rename from spec/integrations/rails_3_2/config/initializers/session_store.rb rename to specs_e2e/rails_3_2/config/initializers/session_store.rb diff --git a/spec/integrations/rails_3_2/config/initializers/wrap_parameters.rb b/specs_e2e/rails_3_2/config/initializers/wrap_parameters.rb similarity index 100% rename from spec/integrations/rails_3_2/config/initializers/wrap_parameters.rb rename to specs_e2e/rails_3_2/config/initializers/wrap_parameters.rb diff --git a/spec/integrations/rails_3_2/config/locales/en.yml b/specs_e2e/rails_3_2/config/locales/en.yml similarity index 100% rename from spec/integrations/rails_3_2/config/locales/en.yml rename to specs_e2e/rails_3_2/config/locales/en.yml diff --git a/spec/integrations/rails_3_2/config/routes.rb b/specs_e2e/rails_3_2/config/routes.rb similarity index 100% rename from spec/integrations/rails_3_2/config/routes.rb rename to specs_e2e/rails_3_2/config/routes.rb diff --git a/spec/integrations/rails_3_2/tmp/.keep b/specs_e2e/rails_3_2/log/.keep similarity index 100% rename from spec/integrations/rails_3_2/tmp/.keep rename to specs_e2e/rails_3_2/log/.keep diff --git a/spec/integrations/rails_3_2/public/404.html b/specs_e2e/rails_3_2/public/404.html similarity index 100% rename from spec/integrations/rails_3_2/public/404.html rename to specs_e2e/rails_3_2/public/404.html diff --git a/spec/integrations/rails_3_2/public/422.html b/specs_e2e/rails_3_2/public/422.html similarity index 100% rename from spec/integrations/rails_3_2/public/422.html rename to specs_e2e/rails_3_2/public/422.html diff --git a/spec/integrations/rails_3_2/public/500.html b/specs_e2e/rails_3_2/public/500.html similarity index 100% rename from spec/integrations/rails_3_2/public/500.html rename to specs_e2e/rails_3_2/public/500.html diff --git a/spec/integrations/rails_3_2/public/favicon.ico b/specs_e2e/rails_3_2/public/favicon.ico similarity index 100% rename from spec/integrations/rails_3_2/public/favicon.ico rename to specs_e2e/rails_3_2/public/favicon.ico diff --git a/spec/integrations/rails_3_2/public/robots.txt b/specs_e2e/rails_3_2/public/robots.txt similarity index 100% rename from spec/integrations/rails_3_2/public/robots.txt rename to specs_e2e/rails_3_2/public/robots.txt diff --git a/spec/integrations/rails_3_2/test.sh b/specs_e2e/rails_3_2/test.sh similarity index 94% rename from spec/integrations/rails_3_2/test.sh rename to specs_e2e/rails_3_2/test.sh index 3895847..5021af0 100755 --- a/spec/integrations/rails_3_2/test.sh +++ b/specs_e2e/rails_3_2/test.sh @@ -16,6 +16,7 @@ bundle install --quiet --gemfile="$DIR/Gemfile" --retry 2 --path vendor/bundle echo '-- cypress install' bundle exec ./bin/rails g cypress_on_rails:install --install_cypress_with=npm rm -vf cypress/integration/rails_examples/advance_factory_bot_spec.js +rm -vf cypress/integration/rails_examples/using_vcr_spec.js echo '-- start rails server' # make sure the server is not running diff --git a/spec/integrations/rails_4_2/log/.keep b/specs_e2e/rails_3_2/tmp/.keep similarity index 100% rename from spec/integrations/rails_4_2/log/.keep rename to specs_e2e/rails_3_2/tmp/.keep diff --git a/spec/integrations/rails_3_2/vendor/.gitkeep b/specs_e2e/rails_3_2/vendor/.gitkeep similarity index 100% rename from spec/integrations/rails_3_2/vendor/.gitkeep rename to specs_e2e/rails_3_2/vendor/.gitkeep diff --git a/spec/integrations/rails_4_2/.gitignore b/specs_e2e/rails_4_2/.gitignore similarity index 90% rename from spec/integrations/rails_4_2/.gitignore rename to specs_e2e/rails_4_2/.gitignore index aa209f1..36c1bc2 100644 --- a/spec/integrations/rails_4_2/.gitignore +++ b/specs_e2e/rails_4_2/.gitignore @@ -7,4 +7,5 @@ spec/cypress config/initializers/cypress_on_rails.rb vendor/bundle tmp/pids -tmp/cache \ No newline at end of file +tmp/cache +log/*.* \ No newline at end of file diff --git a/spec/integrations/rails_4_2/Gemfile b/specs_e2e/rails_4_2/Gemfile similarity index 72% rename from spec/integrations/rails_4_2/Gemfile rename to specs_e2e/rails_4_2/Gemfile index d5c14cf..835f8b5 100644 --- a/spec/integrations/rails_4_2/Gemfile +++ b/specs_e2e/rails_4_2/Gemfile @@ -5,5 +5,7 @@ gem 'rails', '~> 4.2.10' gem 'sprockets', '~> 3.7.2' group :development, :test do - gem 'cypress-on-rails', path: '../../../' + gem 'vcr' + gem 'webmock' + gem 'cypress-on-rails', path: '../../' end diff --git a/spec/integrations/rails_4_2/README.rdoc b/specs_e2e/rails_4_2/README.rdoc similarity index 100% rename from spec/integrations/rails_4_2/README.rdoc rename to specs_e2e/rails_4_2/README.rdoc diff --git a/spec/integrations/rails_4_2/Rakefile b/specs_e2e/rails_4_2/Rakefile similarity index 100% rename from spec/integrations/rails_4_2/Rakefile rename to specs_e2e/rails_4_2/Rakefile diff --git a/spec/integrations/rails_5_2/app/assets/javascripts/posts.js b/specs_e2e/rails_4_2/app/assets/javascripts/using_vcr.js similarity index 100% rename from spec/integrations/rails_5_2/app/assets/javascripts/posts.js rename to specs_e2e/rails_4_2/app/assets/javascripts/using_vcr.js diff --git a/spec/integrations/rails_5_2/app/assets/stylesheets/posts.css b/specs_e2e/rails_4_2/app/assets/stylesheets/using_vcr.css similarity index 100% rename from spec/integrations/rails_5_2/app/assets/stylesheets/posts.css rename to specs_e2e/rails_4_2/app/assets/stylesheets/using_vcr.css diff --git a/spec/integrations/rails_4_2/app/controllers/application_controller.rb b/specs_e2e/rails_4_2/app/controllers/application_controller.rb similarity index 100% rename from spec/integrations/rails_4_2/app/controllers/application_controller.rb rename to specs_e2e/rails_4_2/app/controllers/application_controller.rb diff --git a/specs_e2e/rails_4_2/app/controllers/using_vcr_controller.rb b/specs_e2e/rails_4_2/app/controllers/using_vcr_controller.rb new file mode 100644 index 0000000..c12d0c5 --- /dev/null +++ b/specs_e2e/rails_4_2/app/controllers/using_vcr_controller.rb @@ -0,0 +1,10 @@ +class UsingVcrController < ApplicationController + def index + end + + def record_cats + uri = URI('https://cat-fact.herokuapp.com/facts') + res = Net::HTTP.get_response(uri) + @cat_facts = JSON.parse(res.body) + end +end diff --git a/spec/integrations/rails_4_2/app/controllers/welcome_controller.rb b/specs_e2e/rails_4_2/app/controllers/welcome_controller.rb similarity index 100% rename from spec/integrations/rails_4_2/app/controllers/welcome_controller.rb rename to specs_e2e/rails_4_2/app/controllers/welcome_controller.rb diff --git a/spec/integrations/rails_4_2/app/models/post.rb b/specs_e2e/rails_4_2/app/models/post.rb similarity index 100% rename from spec/integrations/rails_4_2/app/models/post.rb rename to specs_e2e/rails_4_2/app/models/post.rb diff --git a/spec/integrations/rails_4_2/app/views/layouts/application.html.erb b/specs_e2e/rails_4_2/app/views/layouts/application.html.erb similarity index 100% rename from spec/integrations/rails_4_2/app/views/layouts/application.html.erb rename to specs_e2e/rails_4_2/app/views/layouts/application.html.erb diff --git a/specs_e2e/rails_4_2/app/views/using_vcr/index.html.erb b/specs_e2e/rails_4_2/app/views/using_vcr/index.html.erb new file mode 100644 index 0000000..956c65f --- /dev/null +++ b/specs_e2e/rails_4_2/app/views/using_vcr/index.html.erb @@ -0,0 +1,6 @@ +

Using VCR

+
+  <%= JSON.pretty_generate VCR.configuration.as_json['default_cassette_options'] %>
+
+ +<%= link_to 'Record Cats', { action: :record_cats } %> \ No newline at end of file diff --git a/specs_e2e/rails_4_2/app/views/using_vcr/record_cats.html.erb b/specs_e2e/rails_4_2/app/views/using_vcr/record_cats.html.erb new file mode 100644 index 0000000..b1f9f4a --- /dev/null +++ b/specs_e2e/rails_4_2/app/views/using_vcr/record_cats.html.erb @@ -0,0 +1,7 @@ +

Record from Cats API

+ +
    + <% @cat_facts.each do |fact| %> +
  • <%= fact['text'] %>
  • + <% end %> +
      diff --git a/spec/integrations/rails_4_2/app/views/welcome/index.html.erb b/specs_e2e/rails_4_2/app/views/welcome/index.html.erb similarity index 100% rename from spec/integrations/rails_4_2/app/views/welcome/index.html.erb rename to specs_e2e/rails_4_2/app/views/welcome/index.html.erb diff --git a/spec/integrations/rails_4_2/bin/bundle b/specs_e2e/rails_4_2/bin/bundle similarity index 100% rename from spec/integrations/rails_4_2/bin/bundle rename to specs_e2e/rails_4_2/bin/bundle diff --git a/spec/integrations/rails_4_2/bin/rails b/specs_e2e/rails_4_2/bin/rails similarity index 100% rename from spec/integrations/rails_4_2/bin/rails rename to specs_e2e/rails_4_2/bin/rails diff --git a/spec/integrations/rails_4_2/bin/rake b/specs_e2e/rails_4_2/bin/rake similarity index 100% rename from spec/integrations/rails_4_2/bin/rake rename to specs_e2e/rails_4_2/bin/rake diff --git a/spec/integrations/rails_4_2/bin/setup b/specs_e2e/rails_4_2/bin/setup similarity index 100% rename from spec/integrations/rails_4_2/bin/setup rename to specs_e2e/rails_4_2/bin/setup diff --git a/spec/integrations/rails_4_2/config.ru b/specs_e2e/rails_4_2/config.ru similarity index 100% rename from spec/integrations/rails_4_2/config.ru rename to specs_e2e/rails_4_2/config.ru diff --git a/spec/integrations/rails_4_2/config/application.rb b/specs_e2e/rails_4_2/config/application.rb similarity index 100% rename from spec/integrations/rails_4_2/config/application.rb rename to specs_e2e/rails_4_2/config/application.rb diff --git a/spec/integrations/rails_4_2/config/boot.rb b/specs_e2e/rails_4_2/config/boot.rb similarity index 100% rename from spec/integrations/rails_4_2/config/boot.rb rename to specs_e2e/rails_4_2/config/boot.rb diff --git a/spec/integrations/rails_4_2/config/environment.rb b/specs_e2e/rails_4_2/config/environment.rb similarity index 100% rename from spec/integrations/rails_4_2/config/environment.rb rename to specs_e2e/rails_4_2/config/environment.rb diff --git a/spec/integrations/rails_4_2/config/environments/development.rb b/specs_e2e/rails_4_2/config/environments/development.rb similarity index 100% rename from spec/integrations/rails_4_2/config/environments/development.rb rename to specs_e2e/rails_4_2/config/environments/development.rb diff --git a/spec/integrations/rails_4_2/config/environments/production.rb b/specs_e2e/rails_4_2/config/environments/production.rb similarity index 100% rename from spec/integrations/rails_4_2/config/environments/production.rb rename to specs_e2e/rails_4_2/config/environments/production.rb diff --git a/spec/integrations/rails_4_2/config/environments/test.rb b/specs_e2e/rails_4_2/config/environments/test.rb similarity index 100% rename from spec/integrations/rails_4_2/config/environments/test.rb rename to specs_e2e/rails_4_2/config/environments/test.rb diff --git a/spec/integrations/rails_4_2/config/initializers/backtrace_silencers.rb b/specs_e2e/rails_4_2/config/initializers/backtrace_silencers.rb similarity index 100% rename from spec/integrations/rails_4_2/config/initializers/backtrace_silencers.rb rename to specs_e2e/rails_4_2/config/initializers/backtrace_silencers.rb diff --git a/spec/integrations/rails_4_2/config/initializers/cookies_serializer.rb b/specs_e2e/rails_4_2/config/initializers/cookies_serializer.rb similarity index 100% rename from spec/integrations/rails_4_2/config/initializers/cookies_serializer.rb rename to specs_e2e/rails_4_2/config/initializers/cookies_serializer.rb diff --git a/spec/integrations/rails_4_2/config/initializers/filter_parameter_logging.rb b/specs_e2e/rails_4_2/config/initializers/filter_parameter_logging.rb similarity index 100% rename from spec/integrations/rails_4_2/config/initializers/filter_parameter_logging.rb rename to specs_e2e/rails_4_2/config/initializers/filter_parameter_logging.rb diff --git a/spec/integrations/rails_4_2/config/initializers/inflections.rb b/specs_e2e/rails_4_2/config/initializers/inflections.rb similarity index 100% rename from spec/integrations/rails_4_2/config/initializers/inflections.rb rename to specs_e2e/rails_4_2/config/initializers/inflections.rb diff --git a/spec/integrations/rails_4_2/config/initializers/mime_types.rb b/specs_e2e/rails_4_2/config/initializers/mime_types.rb similarity index 100% rename from spec/integrations/rails_4_2/config/initializers/mime_types.rb rename to specs_e2e/rails_4_2/config/initializers/mime_types.rb diff --git a/spec/integrations/rails_4_2/config/initializers/session_store.rb b/specs_e2e/rails_4_2/config/initializers/session_store.rb similarity index 100% rename from spec/integrations/rails_4_2/config/initializers/session_store.rb rename to specs_e2e/rails_4_2/config/initializers/session_store.rb diff --git a/spec/integrations/rails_4_2/config/initializers/to_time_preserves_timezone.rb b/specs_e2e/rails_4_2/config/initializers/to_time_preserves_timezone.rb similarity index 100% rename from spec/integrations/rails_4_2/config/initializers/to_time_preserves_timezone.rb rename to specs_e2e/rails_4_2/config/initializers/to_time_preserves_timezone.rb diff --git a/spec/integrations/rails_4_2/config/initializers/wrap_parameters.rb b/specs_e2e/rails_4_2/config/initializers/wrap_parameters.rb similarity index 100% rename from spec/integrations/rails_4_2/config/initializers/wrap_parameters.rb rename to specs_e2e/rails_4_2/config/initializers/wrap_parameters.rb diff --git a/spec/integrations/rails_4_2/config/locales/en.yml b/specs_e2e/rails_4_2/config/locales/en.yml similarity index 100% rename from spec/integrations/rails_4_2/config/locales/en.yml rename to specs_e2e/rails_4_2/config/locales/en.yml diff --git a/spec/integrations/rails_4_2/config/routes.rb b/specs_e2e/rails_4_2/config/routes.rb similarity index 95% rename from spec/integrations/rails_4_2/config/routes.rb rename to specs_e2e/rails_4_2/config/routes.rb index b697a6e..b6bf0c5 100644 --- a/spec/integrations/rails_4_2/config/routes.rb +++ b/specs_e2e/rails_4_2/config/routes.rb @@ -1,10 +1,15 @@ Rails.application.routes.draw do + get 'using_vcr/index' + # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". # You can have the root of your site routed with "root" root 'welcome#index' + get 'using_vcr/:action', to: 'using_vcr#:action' + + # Example of regular route: # get 'products/:id' => 'catalog#view' diff --git a/spec/integrations/rails_4_2/config/secrets.yml b/specs_e2e/rails_4_2/config/secrets.yml similarity index 100% rename from spec/integrations/rails_4_2/config/secrets.yml rename to specs_e2e/rails_4_2/config/secrets.yml diff --git a/specs_e2e/rails_4_2/package.json b/specs_e2e/rails_4_2/package.json new file mode 100644 index 0000000..490ce8e --- /dev/null +++ b/specs_e2e/rails_4_2/package.json @@ -0,0 +1,9 @@ +{ + "name": "rails_4_2", + "version": "1.0.0", + "main": "index.js", + "license": "MIT", + "devDependencies": { + "cypress-on-rails": "file:../../plugin" + } +} diff --git a/spec/integrations/rails_4_2/public/404.html b/specs_e2e/rails_4_2/public/404.html similarity index 100% rename from spec/integrations/rails_4_2/public/404.html rename to specs_e2e/rails_4_2/public/404.html diff --git a/spec/integrations/rails_4_2/public/422.html b/specs_e2e/rails_4_2/public/422.html similarity index 100% rename from spec/integrations/rails_4_2/public/422.html rename to specs_e2e/rails_4_2/public/422.html diff --git a/spec/integrations/rails_4_2/public/500.html b/specs_e2e/rails_4_2/public/500.html similarity index 100% rename from spec/integrations/rails_4_2/public/500.html rename to specs_e2e/rails_4_2/public/500.html diff --git a/spec/integrations/rails_4_2/public/favicon.ico b/specs_e2e/rails_4_2/public/favicon.ico similarity index 100% rename from spec/integrations/rails_4_2/public/favicon.ico rename to specs_e2e/rails_4_2/public/favicon.ico diff --git a/spec/integrations/rails_4_2/public/robots.txt b/specs_e2e/rails_4_2/public/robots.txt similarity index 100% rename from spec/integrations/rails_4_2/public/robots.txt rename to specs_e2e/rails_4_2/public/robots.txt diff --git a/spec/integrations/rails_4_2/spec/.keep b/specs_e2e/rails_4_2/spec/.keep similarity index 100% rename from spec/integrations/rails_4_2/spec/.keep rename to specs_e2e/rails_4_2/spec/.keep diff --git a/spec/integrations/rails_4_2/test.sh b/specs_e2e/rails_4_2/test.sh similarity index 75% rename from spec/integrations/rails_4_2/test.sh rename to specs_e2e/rails_4_2/test.sh index ebe1a23..d4a0697 100755 --- a/spec/integrations/rails_4_2/test.sh +++ b/specs_e2e/rails_4_2/test.sh @@ -10,11 +10,13 @@ export BUNDLE_GEMFILE="$DIR/Gemfile" cd $DIR echo '-- bundle install' +gem install bundler -v "~> 1.0" --conservative bundle --version bundle install --quiet --gemfile="$DIR/Gemfile" --retry 2 --path vendor/bundle echo '-- cypress install' -bundle exec ./bin/rails g cypress_on_rails:install --cypress_folder=spec/cypress +yarn install +bundle exec ./bin/rails g cypress_on_rails:install --cypress_folder=spec/cypress --experimental --skip rm -vf spec/cypress/integration/rails_examples/advance_factory_bot_spec.js echo '-- start rails server' @@ -22,17 +24,16 @@ echo '-- start rails server' (kill -9 `cat tmp/pids/server.pid` || true ) bundle exec ./bin/rails server -p 5017 -e test & -sleep 2 # give rails a chance to start up correctly +sleep 5 # give rails a chance to start up correctly echo '-- cypress run' cp -fv ../cypress.json spec/ -cd spec if [ -z $CYPRESS_RECORD_KEY ] then - yarn run cypress run + yarn run cypress run -P ./spec else - yarn run cypress run --record + yarn run cypress run -P ./spec --record fi echo '-- stop rails server' -kill -9 `cat ../tmp/pids/server.pid` +kill -9 `cat tmp/pids/server.pid` diff --git a/spec/integrations/rails_4_2/vendor/.keep b/specs_e2e/rails_4_2/vendor/.keep similarity index 100% rename from spec/integrations/rails_4_2/vendor/.keep rename to specs_e2e/rails_4_2/vendor/.keep diff --git a/spec/integrations/rails_5_2/.gitignore b/specs_e2e/rails_5_2/.gitignore similarity index 100% rename from spec/integrations/rails_5_2/.gitignore rename to specs_e2e/rails_5_2/.gitignore diff --git a/spec/integrations/rails_5_2/Gemfile b/specs_e2e/rails_5_2/Gemfile similarity index 90% rename from spec/integrations/rails_5_2/Gemfile rename to specs_e2e/rails_5_2/Gemfile index 795d95f..8b9b5c3 100644 --- a/spec/integrations/rails_5_2/Gemfile +++ b/specs_e2e/rails_5_2/Gemfile @@ -11,5 +11,5 @@ gem 'bootsnap', '>= 1.1.0', require: false group :development, :test do gem 'database_cleaner' - gem 'cypress-on-rails', path: '../../../' + gem 'cypress-on-rails', path: '../../' end diff --git a/spec/integrations/rails_5_2/README.md b/specs_e2e/rails_5_2/README.md similarity index 100% rename from spec/integrations/rails_5_2/README.md rename to specs_e2e/rails_5_2/README.md diff --git a/spec/integrations/rails_5_2/Rakefile b/specs_e2e/rails_5_2/Rakefile similarity index 100% rename from spec/integrations/rails_5_2/Rakefile rename to specs_e2e/rails_5_2/Rakefile diff --git a/specs_e2e/rails_5_2/app/assets/javascripts/posts.js b/specs_e2e/rails_5_2/app/assets/javascripts/posts.js new file mode 100644 index 0000000..dee720f --- /dev/null +++ b/specs_e2e/rails_5_2/app/assets/javascripts/posts.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/specs_e2e/rails_5_2/app/assets/stylesheets/posts.css b/specs_e2e/rails_5_2/app/assets/stylesheets/posts.css new file mode 100644 index 0000000..afad32d --- /dev/null +++ b/specs_e2e/rails_5_2/app/assets/stylesheets/posts.css @@ -0,0 +1,4 @@ +/* + Place all the styles related to the matching controller here. + They will automatically be included in application.css. +*/ diff --git a/spec/integrations/rails_5_2/app/assets/stylesheets/scaffold.css b/specs_e2e/rails_5_2/app/assets/stylesheets/scaffold.css similarity index 100% rename from spec/integrations/rails_5_2/app/assets/stylesheets/scaffold.css rename to specs_e2e/rails_5_2/app/assets/stylesheets/scaffold.css diff --git a/spec/integrations/rails_5_2/app/controllers/application_controller.rb b/specs_e2e/rails_5_2/app/controllers/application_controller.rb similarity index 100% rename from spec/integrations/rails_5_2/app/controllers/application_controller.rb rename to specs_e2e/rails_5_2/app/controllers/application_controller.rb diff --git a/spec/integrations/rails_5_2/app/controllers/posts_controller.rb b/specs_e2e/rails_5_2/app/controllers/posts_controller.rb similarity index 100% rename from spec/integrations/rails_5_2/app/controllers/posts_controller.rb rename to specs_e2e/rails_5_2/app/controllers/posts_controller.rb diff --git a/spec/integrations/rails_5_2/app/helpers/posts_helper.rb b/specs_e2e/rails_5_2/app/helpers/posts_helper.rb similarity index 100% rename from spec/integrations/rails_5_2/app/helpers/posts_helper.rb rename to specs_e2e/rails_5_2/app/helpers/posts_helper.rb diff --git a/spec/integrations/rails_5_2/app/jobs/application_job.rb b/specs_e2e/rails_5_2/app/jobs/application_job.rb similarity index 100% rename from spec/integrations/rails_5_2/app/jobs/application_job.rb rename to specs_e2e/rails_5_2/app/jobs/application_job.rb diff --git a/spec/integrations/rails_5_2/app/models/application_record.rb b/specs_e2e/rails_5_2/app/models/application_record.rb similarity index 100% rename from spec/integrations/rails_5_2/app/models/application_record.rb rename to specs_e2e/rails_5_2/app/models/application_record.rb diff --git a/spec/integrations/rails_5_2/app/models/post.rb b/specs_e2e/rails_5_2/app/models/post.rb similarity index 100% rename from spec/integrations/rails_5_2/app/models/post.rb rename to specs_e2e/rails_5_2/app/models/post.rb diff --git a/spec/integrations/rails_5_2/app/views/layouts/application.html.erb b/specs_e2e/rails_5_2/app/views/layouts/application.html.erb similarity index 100% rename from spec/integrations/rails_5_2/app/views/layouts/application.html.erb rename to specs_e2e/rails_5_2/app/views/layouts/application.html.erb diff --git a/spec/integrations/rails_5_2/app/views/posts/_form.html.erb b/specs_e2e/rails_5_2/app/views/posts/_form.html.erb similarity index 100% rename from spec/integrations/rails_5_2/app/views/posts/_form.html.erb rename to specs_e2e/rails_5_2/app/views/posts/_form.html.erb diff --git a/spec/integrations/rails_5_2/app/views/posts/edit.html.erb b/specs_e2e/rails_5_2/app/views/posts/edit.html.erb similarity index 100% rename from spec/integrations/rails_5_2/app/views/posts/edit.html.erb rename to specs_e2e/rails_5_2/app/views/posts/edit.html.erb diff --git a/spec/integrations/rails_5_2/app/views/posts/index.html.erb b/specs_e2e/rails_5_2/app/views/posts/index.html.erb similarity index 100% rename from spec/integrations/rails_5_2/app/views/posts/index.html.erb rename to specs_e2e/rails_5_2/app/views/posts/index.html.erb diff --git a/spec/integrations/rails_5_2/app/views/posts/new.html.erb b/specs_e2e/rails_5_2/app/views/posts/new.html.erb similarity index 100% rename from spec/integrations/rails_5_2/app/views/posts/new.html.erb rename to specs_e2e/rails_5_2/app/views/posts/new.html.erb diff --git a/spec/integrations/rails_5_2/app/views/posts/show.html.erb b/specs_e2e/rails_5_2/app/views/posts/show.html.erb similarity index 100% rename from spec/integrations/rails_5_2/app/views/posts/show.html.erb rename to specs_e2e/rails_5_2/app/views/posts/show.html.erb diff --git a/spec/integrations/rails_5_2/app/views/welcome/index.html.erb b/specs_e2e/rails_5_2/app/views/welcome/index.html.erb similarity index 100% rename from spec/integrations/rails_5_2/app/views/welcome/index.html.erb rename to specs_e2e/rails_5_2/app/views/welcome/index.html.erb diff --git a/spec/integrations/rails_5_2/bin/bundle b/specs_e2e/rails_5_2/bin/bundle similarity index 100% rename from spec/integrations/rails_5_2/bin/bundle rename to specs_e2e/rails_5_2/bin/bundle diff --git a/spec/integrations/rails_5_2/bin/rails b/specs_e2e/rails_5_2/bin/rails similarity index 100% rename from spec/integrations/rails_5_2/bin/rails rename to specs_e2e/rails_5_2/bin/rails diff --git a/spec/integrations/rails_5_2/bin/rake b/specs_e2e/rails_5_2/bin/rake similarity index 100% rename from spec/integrations/rails_5_2/bin/rake rename to specs_e2e/rails_5_2/bin/rake diff --git a/spec/integrations/rails_5_2/bin/setup b/specs_e2e/rails_5_2/bin/setup similarity index 100% rename from spec/integrations/rails_5_2/bin/setup rename to specs_e2e/rails_5_2/bin/setup diff --git a/spec/integrations/rails_5_2/bin/update b/specs_e2e/rails_5_2/bin/update similarity index 100% rename from spec/integrations/rails_5_2/bin/update rename to specs_e2e/rails_5_2/bin/update diff --git a/spec/integrations/rails_5_2/config.ru b/specs_e2e/rails_5_2/config.ru similarity index 100% rename from spec/integrations/rails_5_2/config.ru rename to specs_e2e/rails_5_2/config.ru diff --git a/spec/integrations/rails_5_2/config/application.rb b/specs_e2e/rails_5_2/config/application.rb similarity index 100% rename from spec/integrations/rails_5_2/config/application.rb rename to specs_e2e/rails_5_2/config/application.rb diff --git a/spec/integrations/rails_5_2/config/boot.rb b/specs_e2e/rails_5_2/config/boot.rb similarity index 100% rename from spec/integrations/rails_5_2/config/boot.rb rename to specs_e2e/rails_5_2/config/boot.rb diff --git a/spec/integrations/rails_5_2/config/credentials.yml.enc b/specs_e2e/rails_5_2/config/credentials.yml.enc similarity index 100% rename from spec/integrations/rails_5_2/config/credentials.yml.enc rename to specs_e2e/rails_5_2/config/credentials.yml.enc diff --git a/spec/integrations/rails_5_2/config/database.yml b/specs_e2e/rails_5_2/config/database.yml similarity index 100% rename from spec/integrations/rails_5_2/config/database.yml rename to specs_e2e/rails_5_2/config/database.yml diff --git a/spec/integrations/rails_5_2/config/environment.rb b/specs_e2e/rails_5_2/config/environment.rb similarity index 100% rename from spec/integrations/rails_5_2/config/environment.rb rename to specs_e2e/rails_5_2/config/environment.rb diff --git a/spec/integrations/rails_5_2/config/environments/development.rb b/specs_e2e/rails_5_2/config/environments/development.rb similarity index 100% rename from spec/integrations/rails_5_2/config/environments/development.rb rename to specs_e2e/rails_5_2/config/environments/development.rb diff --git a/spec/integrations/rails_5_2/config/environments/production.rb b/specs_e2e/rails_5_2/config/environments/production.rb similarity index 100% rename from spec/integrations/rails_5_2/config/environments/production.rb rename to specs_e2e/rails_5_2/config/environments/production.rb diff --git a/spec/integrations/rails_5_2/config/environments/test.rb b/specs_e2e/rails_5_2/config/environments/test.rb similarity index 100% rename from spec/integrations/rails_5_2/config/environments/test.rb rename to specs_e2e/rails_5_2/config/environments/test.rb diff --git a/spec/integrations/rails_5_2/config/initializers/application_controller_renderer.rb b/specs_e2e/rails_5_2/config/initializers/application_controller_renderer.rb similarity index 100% rename from spec/integrations/rails_5_2/config/initializers/application_controller_renderer.rb rename to specs_e2e/rails_5_2/config/initializers/application_controller_renderer.rb diff --git a/spec/integrations/rails_5_2/config/initializers/backtrace_silencers.rb b/specs_e2e/rails_5_2/config/initializers/backtrace_silencers.rb similarity index 100% rename from spec/integrations/rails_5_2/config/initializers/backtrace_silencers.rb rename to specs_e2e/rails_5_2/config/initializers/backtrace_silencers.rb diff --git a/spec/integrations/rails_5_2/config/initializers/content_security_policy.rb b/specs_e2e/rails_5_2/config/initializers/content_security_policy.rb similarity index 100% rename from spec/integrations/rails_5_2/config/initializers/content_security_policy.rb rename to specs_e2e/rails_5_2/config/initializers/content_security_policy.rb diff --git a/spec/integrations/rails_5_2/config/initializers/cookies_serializer.rb b/specs_e2e/rails_5_2/config/initializers/cookies_serializer.rb similarity index 100% rename from spec/integrations/rails_5_2/config/initializers/cookies_serializer.rb rename to specs_e2e/rails_5_2/config/initializers/cookies_serializer.rb diff --git a/spec/integrations/rails_5_2/config/initializers/filter_parameter_logging.rb b/specs_e2e/rails_5_2/config/initializers/filter_parameter_logging.rb similarity index 100% rename from spec/integrations/rails_5_2/config/initializers/filter_parameter_logging.rb rename to specs_e2e/rails_5_2/config/initializers/filter_parameter_logging.rb diff --git a/spec/integrations/rails_5_2/config/initializers/inflections.rb b/specs_e2e/rails_5_2/config/initializers/inflections.rb similarity index 100% rename from spec/integrations/rails_5_2/config/initializers/inflections.rb rename to specs_e2e/rails_5_2/config/initializers/inflections.rb diff --git a/spec/integrations/rails_5_2/config/initializers/mime_types.rb b/specs_e2e/rails_5_2/config/initializers/mime_types.rb similarity index 100% rename from spec/integrations/rails_5_2/config/initializers/mime_types.rb rename to specs_e2e/rails_5_2/config/initializers/mime_types.rb diff --git a/spec/integrations/rails_5_2/config/initializers/wrap_parameters.rb b/specs_e2e/rails_5_2/config/initializers/wrap_parameters.rb similarity index 100% rename from spec/integrations/rails_5_2/config/initializers/wrap_parameters.rb rename to specs_e2e/rails_5_2/config/initializers/wrap_parameters.rb diff --git a/spec/integrations/rails_5_2/config/locales/en.yml b/specs_e2e/rails_5_2/config/locales/en.yml similarity index 100% rename from spec/integrations/rails_5_2/config/locales/en.yml rename to specs_e2e/rails_5_2/config/locales/en.yml diff --git a/spec/integrations/rails_5_2/config/master.key b/specs_e2e/rails_5_2/config/master.key similarity index 100% rename from spec/integrations/rails_5_2/config/master.key rename to specs_e2e/rails_5_2/config/master.key diff --git a/spec/integrations/rails_5_2/config/routes.rb b/specs_e2e/rails_5_2/config/routes.rb similarity index 100% rename from spec/integrations/rails_5_2/config/routes.rb rename to specs_e2e/rails_5_2/config/routes.rb diff --git a/spec/integrations/rails_5_2/db/migrate/20180621085832_create_posts.rb b/specs_e2e/rails_5_2/db/migrate/20180621085832_create_posts.rb similarity index 100% rename from spec/integrations/rails_5_2/db/migrate/20180621085832_create_posts.rb rename to specs_e2e/rails_5_2/db/migrate/20180621085832_create_posts.rb diff --git a/spec/integrations/rails_5_2/public/404.html b/specs_e2e/rails_5_2/public/404.html similarity index 100% rename from spec/integrations/rails_5_2/public/404.html rename to specs_e2e/rails_5_2/public/404.html diff --git a/spec/integrations/rails_5_2/public/422.html b/specs_e2e/rails_5_2/public/422.html similarity index 100% rename from spec/integrations/rails_5_2/public/422.html rename to specs_e2e/rails_5_2/public/422.html diff --git a/spec/integrations/rails_5_2/public/500.html b/specs_e2e/rails_5_2/public/500.html similarity index 100% rename from spec/integrations/rails_5_2/public/500.html rename to specs_e2e/rails_5_2/public/500.html diff --git a/spec/integrations/rails_5_2/public/apple-touch-icon-precomposed.png b/specs_e2e/rails_5_2/public/apple-touch-icon-precomposed.png similarity index 100% rename from spec/integrations/rails_5_2/public/apple-touch-icon-precomposed.png rename to specs_e2e/rails_5_2/public/apple-touch-icon-precomposed.png diff --git a/spec/integrations/rails_5_2/public/apple-touch-icon.png b/specs_e2e/rails_5_2/public/apple-touch-icon.png similarity index 100% rename from spec/integrations/rails_5_2/public/apple-touch-icon.png rename to specs_e2e/rails_5_2/public/apple-touch-icon.png diff --git a/spec/integrations/rails_5_2/public/favicon.ico b/specs_e2e/rails_5_2/public/favicon.ico similarity index 100% rename from spec/integrations/rails_5_2/public/favicon.ico rename to specs_e2e/rails_5_2/public/favicon.ico diff --git a/spec/integrations/rails_5_2/public/robots.txt b/specs_e2e/rails_5_2/public/robots.txt similarity index 100% rename from spec/integrations/rails_5_2/public/robots.txt rename to specs_e2e/rails_5_2/public/robots.txt diff --git a/spec/integrations/rails_5_2/test.sh b/specs_e2e/rails_5_2/test.sh similarity index 89% rename from spec/integrations/rails_5_2/test.sh rename to specs_e2e/rails_5_2/test.sh index 930e94b..8810718 100755 --- a/spec/integrations/rails_5_2/test.sh +++ b/specs_e2e/rails_5_2/test.sh @@ -19,7 +19,8 @@ bundle exec ./bin/rails db:drop || true bundle exec ./bin/rails db:create db:migrate echo '-- cypress install' -bundle exec ./bin/rails g cypress_on_rails: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 --skip +rm -vf test/cypress/integration/rails_examples/using_vcr_spec.js echo '-- start rails server' # make sure the server is not running diff --git a/spec/integrations/rails_5_2/test/controllers/posts_controller_test.rb b/specs_e2e/rails_5_2/test/controllers/posts_controller_test.rb similarity index 100% rename from spec/integrations/rails_5_2/test/controllers/posts_controller_test.rb rename to specs_e2e/rails_5_2/test/controllers/posts_controller_test.rb diff --git a/spec/integrations/rails_5_2/test/cypress_fixtures/posts.yml b/specs_e2e/rails_5_2/test/cypress_fixtures/posts.yml similarity index 100% rename from spec/integrations/rails_5_2/test/cypress_fixtures/posts.yml rename to specs_e2e/rails_5_2/test/cypress_fixtures/posts.yml diff --git a/spec/integrations/rails_5_2/test/fixtures/posts.yml b/specs_e2e/rails_5_2/test/fixtures/posts.yml similarity index 100% rename from spec/integrations/rails_5_2/test/fixtures/posts.yml rename to specs_e2e/rails_5_2/test/fixtures/posts.yml diff --git a/spec/integrations/rails_5_2/test/models/post_test.rb b/specs_e2e/rails_5_2/test/models/post_test.rb similarity index 100% rename from spec/integrations/rails_5_2/test/models/post_test.rb rename to specs_e2e/rails_5_2/test/models/post_test.rb diff --git a/spec/integrations/rails_5_2/log/.keep b/specs_e2e/rails_5_2/vendor/.keep similarity index 100% rename from spec/integrations/rails_5_2/log/.keep rename to specs_e2e/rails_5_2/vendor/.keep From b0311e704e9cab1f7ebe6cd88cfdd677dab19e15 Mon Sep 17 00:00:00 2001 From: Grant Petersen-Speelman Date: Thu, 10 Mar 2022 14:37:25 +1100 Subject: [PATCH 09/44] Turn VCR on and off between inserts and ejects (#104) --- README.md | 6 +++++- lib/cypress_on_rails/vcr_middleware.rb | 13 +++++++++++++ .../templates/spec/cypress/app_commands/clean.rb | 4 +++- .../integration/rails_examples/using_vcr_spec.js | 13 ++++++++++--- spec/cypress_on_rails/vcr_middleware_spec.rb | 12 +++++++++++- 5 files changed, 42 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e269c80..f5de8a6 100644 --- a/README.md +++ b/README.md @@ -283,9 +283,11 @@ yarn add cypress-on-rails --dev ### for VCR +This only works when you start the rails server with a single worker and single thread + #### setup -Add you VCR configuration to your `cypress_helper.rb` +Add your VCR configuration to your `cypress_helper.rb` ```ruby require 'vcr' @@ -304,6 +306,8 @@ Add to you `clean.rb` ```ruby VCR.eject_cassette # make sure we no cassettes inserted before the next test starts +VCR.turn_off! +WebMock.disable! if defined?(WebMock) ``` #### usage diff --git a/lib/cypress_on_rails/vcr_middleware.rb b/lib/cypress_on_rails/vcr_middleware.rb index 71dd3f7..6fe9a43 100644 --- a/lib/cypress_on_rails/vcr_middleware.rb +++ b/lib/cypress_on_rails/vcr_middleware.rb @@ -10,6 +10,7 @@ class VCRMiddleware def initialize(app, vcr = nil) @app = app @vcr = vcr + @first_call = false end def call(env) @@ -19,6 +20,7 @@ def call(env) elsif request.path.start_with?('/__cypress__/vcr/eject') configuration.tagged_logged { handle_eject } else + do_first_call unless @first_call @app.call(env) end end @@ -26,6 +28,8 @@ def call(env) private def handle_insert(req) + WebMock.enable! if defined?(WebMock) + vcr.turn_on! body = JSON.parse(req.body.read) logger.info "vcr insert cassette: #{body}" cassette_name = body[0] @@ -43,6 +47,7 @@ def handle_insert(req) def handle_eject logger.info "vcr eject cassette" vcr.eject_cassette + do_first_call [201, {'Content-Type' => 'application/json'}, [{'message': 'OK'}.to_json]] rescue LoadError, ArgumentError => e [501, {'Content-Type' => 'application/json'}, [{'message': e.message}.to_json]] @@ -56,5 +61,13 @@ def vcr end @vcr = VCR end + + def do_first_call + @first_call = true + vcr.turn_off! + WebMock.disable! if defined?(WebMock) + rescue LoadError + # nop + end end end diff --git a/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/clean.rb b/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/clean.rb index 85bcf9c..10c3a82 100644 --- a/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/clean.rb +++ b/lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/clean.rb @@ -10,7 +10,9 @@ CypressOnRails::SmartFactoryWrapper.reload if defined?(VCR) - VCR.eject_cassette # make sure we any cassettes inserted before the next test starts + VCR.eject_cassette # make sure we no cassette inserted before the next test starts + VCR.turn_off! + WebMock.disable! if defined?(WebMock) end Rails.logger.info "APPCLEANED" # used by log_fail.rb diff --git a/lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_vcr_spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_vcr_spec.js index 7751d20..0cb9a47 100644 --- a/lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_vcr_spec.js +++ b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_vcr_spec.js @@ -6,12 +6,19 @@ describe('Rails Other examples', function() { cy.visit('/using_vcr/index') cy.get('a').contains('Cats').click() - cy.contains('Wikipedia has a recording of a cat meowing, because why not?') + cy.contains('Record from Cats API'); cy.vcr_eject_cassette(); + }) + + it('Using previous a cassette', function() { + cy.app('clean') // have a look at cypress/app_commands/clean.rb cy.vcr_insert_cassette('cats') - cy.visit('/using_vcr/record_cats') - cy.contains('Wikipedia has a recording of a cat meowing, because why not?') + cy.visit('/using_vcr/index') + cy.get('a').contains('Cats').click() + cy.contains('Record from Cats API'); + + cy.vcr_eject_cassette(); }) }) diff --git a/spec/cypress_on_rails/vcr_middleware_spec.rb b/spec/cypress_on_rails/vcr_middleware_spec.rb index 5c7f5c9..34906aa 100644 --- a/spec/cypress_on_rails/vcr_middleware_spec.rb +++ b/spec/cypress_on_rails/vcr_middleware_spec.rb @@ -5,7 +5,7 @@ module CypressOnRails RSpec.describe VCRMiddleware do let(:app) { ->(env) { [200, {}, ["app did #{env['PATH_INFO']}"]] } } - let(:vcr) { class_double(VCR, insert_cassette: true, eject_cassette: true) } + let(:vcr) { class_double(VCR, turn_on!: true, turn_off!: true, insert_cassette: true, eject_cassette: true) } subject { described_class.new(app, vcr) } let(:env) { {} } @@ -28,6 +28,7 @@ def rack_input(json_value) expect(response).to eq([201, {"Content-Type"=>"application/json"}, ["{\"message\":\"OK\"}"]]) + expect(vcr).to have_received(:turn_on!) expect(vcr).to have_received(:insert_cassette).with('cas1', {}) end end @@ -87,12 +88,20 @@ def rack_input(json_value) expect(response).to eq([201, {"Content-Type"=>"application/json"}, ["{\"message\":\"OK\"}"]]) + expect(vcr).to have_received(:turn_off!) expect(vcr).to have_received(:eject_cassette) end end end describe '"Other paths"' do + it 'calls vcr turn off the first time' do + env['PATH_INFO'] = '/test' + + expect(response).to eq([200, {}, ["app did /test"]]) + expect(vcr).to have_received(:turn_off!) + end + it 'runs app' do aggregate_failures do %w(/ /__cypress__/login command /cypress_command /).each do |path| @@ -101,6 +110,7 @@ def rack_input(json_value) response = subject.call(env) expect(response).to eq([200, {}, ["app did #{path}"]]) + expect(vcr).to have_received(:turn_off!) end end end From 3a5e5a2f13bb2961b15d59a8010ff0f44501e4ad Mon Sep 17 00:00:00 2001 From: Grant Petersen-Speelman Date: Fri, 11 Mar 2022 16:13:58 +1100 Subject: [PATCH 10/44] allow to enable VCR middleware independently (#105) --- README.md | 6 ++++++ lib/cypress_on_rails/configuration.rb | 3 +++ lib/cypress_on_rails/railtie.rb | 2 ++ .../templates/config/initializers/cypress_on_rails.rb.erb | 1 + 4 files changed, 12 insertions(+) diff --git a/README.md b/README.md index f5de8a6..1e9f29a 100644 --- a/README.md +++ b/README.md @@ -310,6 +310,12 @@ VCR.turn_off! WebMock.disable! if defined?(WebMock) ``` +Add to you `config/cypress_on_rails.rb` + +```ruby + c.use_vcr_middleware = !Rails.env.production? && ENV['CYPRESS'].present? +``` + #### usage You have `vcr_insert_cassette` and `vcr_eject_cassette` available. https://www.rubydoc.info/github/vcr/vcr/VCR:insert_cassette diff --git a/lib/cypress_on_rails/configuration.rb b/lib/cypress_on_rails/configuration.rb index a08571c..28a0ca1 100644 --- a/lib/cypress_on_rails/configuration.rb +++ b/lib/cypress_on_rails/configuration.rb @@ -4,6 +4,7 @@ module CypressOnRails class Configuration attr_accessor :cypress_folder attr_accessor :use_middleware + attr_accessor :use_vcr_middleware attr_accessor :logger def initialize @@ -11,10 +12,12 @@ def initialize end alias :use_middleware? :use_middleware + alias :use_vcr_middleware? :use_vcr_middleware def reset self.cypress_folder = 'spec/cypress' self.use_middleware = true + self.use_vcr_middleware = true self.logger = Logger.new(STDOUT) end diff --git a/lib/cypress_on_rails/railtie.rb b/lib/cypress_on_rails/railtie.rb index 1d5ca44..de6a582 100644 --- a/lib/cypress_on_rails/railtie.rb +++ b/lib/cypress_on_rails/railtie.rb @@ -7,6 +7,8 @@ class Railtie < Rails::Railtie if CypressOnRails.configuration.use_middleware? require 'cypress_on_rails/middleware' app.middleware.use Middleware + end + if CypressOnRails.configuration.use_vcr_middleware? require 'cypress_on_rails/vcr_middleware' app.middleware.use VCRMiddleware end diff --git a/lib/generators/cypress_on_rails/templates/config/initializers/cypress_on_rails.rb.erb b/lib/generators/cypress_on_rails/templates/config/initializers/cypress_on_rails.rb.erb index be6ad63..31ccbc5 100644 --- a/lib/generators/cypress_on_rails/templates/config/initializers/cypress_on_rails.rb.erb +++ b/lib/generators/cypress_on_rails/templates/config/initializers/cypress_on_rails.rb.erb @@ -4,6 +4,7 @@ if defined?(CypressOnRails) # 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.production? + <% unless options.experimental %># <% end %> c.use_vcr_middleware = !Rails.env.production? c.logger = Rails.logger end From 6ec8394736f90465cf67e40bc91f5d9340e9921f Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Mon, 30 May 2022 18:05:07 -1000 Subject: [PATCH 11/44] Update README.md --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 1e9f29a..b4147f5 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ This project is sponsored by the software consulting firm [ShakaCode](https://ww Interested in joining a small team that loves open source? Check our [careers page](https://www.shakacode.com/career/). +Need help with cypress-on-rails? Contact [ShakaCode](mailto:justin@shakacode.com). + ---- # Totally new to Cypress? @@ -401,3 +403,15 @@ beforeEach(() => { 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create a new Pull Request + +# Supporters + +The following companies support this open source project, and ShakaCode uses their products! Justin writes React on Rails on [RubyMine](https://www.jetbrains.com/ruby/). We use [Scout](https://scoutapp.com/) to monitor the live performance of [HiChee.com](https://HiChee.com), [Rails AutoScale](https://railsautoscale.com) to scale the dynos of HiChee, and [HoneyBadger](https://www.honeybadger.io/) to monitor application errors. We love [BrowserStack](https://www.browserstack.com) to solve problems with oddball browsers. + +[![RubyMine](https://user-images.githubusercontent.com/1118459/114100597-3b0e3000-9860-11eb-9b12-73beb1a184b2.png)](https://www.jetbrains.com/ruby/) +[![Scout](https://user-images.githubusercontent.com/1118459/171088197-81555b69-9ed0-4235-9acf-fcb37ecfb949.png)](https://scoutapp.com/) +[![Rails AutoScale](https://user-images.githubusercontent.com/1118459/103197530-48dc0e80-488a-11eb-8b1b-a16664b30274.png)](https://railsautoscale.com/) +[![BrowserStack](https://cloud.githubusercontent.com/assets/1118459/23203304/1261e468-f886-11e6-819e-93b1a3f17da4.png)](https://www.browserstack.com) +[![HoneyBadger](https://user-images.githubusercontent.com/1118459/114100696-63962a00-9860-11eb-8ac1-75ca02856d8e.png)](https://www.honeybadger.io/) + +ShakaCode's favorite project tracking tool is [Shortcut](https://shortcut.com/). If you want to **try Shortcut and get 2 months free beyond the 14-day trial period**, click [here to use ShakaCode's referral code](http://r.clbh.se/mvfoNeH). We're participating in their awesome triple-sided referral program, which you can read about [here](https://shortcut.com/referral/). By using our [referral code](http://r.clbh.se/mvfoNeH) you'll be supporting ShakaCode and, thus, React on Rails! From 2f09a94f86c186108a9d5489dce076644bb637ed Mon Sep 17 00:00:00 2001 From: Grant Petersen-Speelman Date: Mon, 6 Jun 2022 11:28:12 +1000 Subject: [PATCH 12/44] Change to generators to generate for cypress 10 (#108) closes #107 --- CHANGELOG.md | 1 + README.md | 10 +- lib/cypress-on-rails.rb | 4 +- lib/cypress_on_rails/middleware.rb | 1 + .../cypress_on_rails/install_generator.rb | 9 +- .../templates/spec/cypress.config.js | 9 + .../templates/spec/cypress.json | 4 - .../rails_examples/advance_factory_bot.cy.js} | 0 .../rails_examples/other.cy.js} | 0 .../rails_examples/using_factory_bot.cy.js} | 0 .../rails_examples/using_fixtures.cy.js} | 0 .../rails_examples/using_scenarios.cy.js} | 0 .../rails_examples/using_vcr.cy.js} | 0 .../spec/cypress/fixtures/example.json | 5 - .../integration/examples/actions.spec.js | 272 ------------------ .../integration/examples/aliasing.spec.js | 42 --- .../integration/examples/assertions.spec.js | 63 ---- .../integration/examples/connectors.spec.js | 55 ---- .../integration/examples/cookies.spec.js | 78 ----- .../integration/examples/cypress_api.spec.js | 211 -------------- .../integration/examples/files.spec.js | 86 ------ .../examples/local_storage.spec.js | 52 ---- .../integration/examples/location.spec.js | 32 --- .../cypress/integration/examples/misc.spec.js | 68 ----- .../integration/examples/navigation.spec.js | 54 ---- .../examples/network_requests.spec.js | 108 ------- .../integration/examples/querying.spec.js | 65 ----- .../examples/spies_stubs_clocks.spec.js | 62 ---- .../integration/examples/traversal.spec.js | 121 -------- .../integration/examples/utilities.spec.js | 89 ------ .../integration/examples/viewport.spec.js | 59 ---- .../integration/examples/waiting.spec.js | 34 --- .../integration/examples/window.spec.js | 22 -- specs_e2e/cypress.config.js | 10 + specs_e2e/cypress.json | 5 - specs_e2e/rails_3_2/.gitignore | 2 +- specs_e2e/rails_3_2/.ruby_version | 1 + specs_e2e/rails_3_2/test.sh | 16 +- specs_e2e/rails_4_2/.gitignore | 2 +- specs_e2e/rails_4_2/app/models/post.rb | 4 +- specs_e2e/rails_4_2/package.json | 1 + specs_e2e/rails_4_2/test.sh | 14 +- specs_e2e/rails_5_2/.gitignore | 2 +- specs_e2e/rails_5_2/test.sh | 16 +- 44 files changed, 61 insertions(+), 1628 deletions(-) create mode 100644 lib/generators/cypress_on_rails/templates/spec/cypress.config.js delete mode 100644 lib/generators/cypress_on_rails/templates/spec/cypress.json rename lib/generators/cypress_on_rails/templates/spec/cypress/{integration/rails_examples/advance_factory_bot_spec.js => e2e/rails_examples/advance_factory_bot.cy.js} (100%) rename lib/generators/cypress_on_rails/templates/spec/cypress/{integration/rails_examples/other_spec.js => e2e/rails_examples/other.cy.js} (100%) rename lib/generators/cypress_on_rails/templates/spec/cypress/{integration/rails_examples/using_factory_bot_spec.js => e2e/rails_examples/using_factory_bot.cy.js} (100%) rename lib/generators/cypress_on_rails/templates/spec/cypress/{integration/rails_examples/using_fixtures_spec.js => e2e/rails_examples/using_fixtures.cy.js} (100%) rename lib/generators/cypress_on_rails/templates/spec/cypress/{integration/rails_examples/using_scenarios_spec.js => e2e/rails_examples/using_scenarios.cy.js} (100%) rename lib/generators/cypress_on_rails/templates/spec/cypress/{integration/rails_examples/using_vcr_spec.js => e2e/rails_examples/using_vcr.cy.js} (100%) delete mode 100644 lib/generators/cypress_on_rails/templates/spec/cypress/fixtures/example.json delete mode 100644 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/actions.spec.js delete mode 100644 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/aliasing.spec.js delete mode 100644 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/assertions.spec.js delete mode 100644 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/connectors.spec.js delete mode 100644 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/cookies.spec.js delete mode 100644 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/cypress_api.spec.js delete mode 100644 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/files.spec.js delete mode 100644 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/local_storage.spec.js delete mode 100644 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/location.spec.js delete mode 100644 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/misc.spec.js delete mode 100644 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/navigation.spec.js delete mode 100644 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/network_requests.spec.js delete mode 100644 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/querying.spec.js delete mode 100644 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/spies_stubs_clocks.spec.js delete mode 100644 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/traversal.spec.js delete mode 100644 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/utilities.spec.js delete mode 100644 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/viewport.spec.js delete mode 100644 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/waiting.spec.js delete mode 100644 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/window.spec.js create mode 100644 specs_e2e/cypress.config.js delete mode 100644 specs_e2e/cypress.json diff --git a/CHANGELOG.md b/CHANGELOG.md index cf39676..cecf1e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Changed * Add support for matching npm package and VCR +* generate for cypress 10 [PR 108](https://github.com/shakacode/cypress-on-rails/pull/108) ## [1.12.1] [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.12.0...v1.12.1 diff --git a/README.md b/README.md index b4147f5..3cc4f3e 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ bin/rails g cypress_on_rails:update The generator modifies/adds the following files/directory in your application: * `config/environments/test.rb` * `config/initializers/cypress_on_rails` used to configure CypressDev -* `spec/cypress/integrations/` contains your cypress tests +* `spec/cypress/e2e/` contains your cypress tests * `spec/cypress/support/on-rails.js` contains CypressDev support code * `spec/cypress/app_commands/scenarios/` contains your CypressDev scenario definitions * `spec/cypress/cypress_helper.rb` contains helper code for CypressDev app commands @@ -135,7 +135,7 @@ node_modules/.bin/cypress run You can run your [factory_bot](https://github.com/thoughtbot/factory_bot) directly as well ```js -// spec/cypress/integrations/simple_spec.js +// spec/cypress/e2e/simple.cy.js describe('My First Test', function() { it('visit root', function() { // This calls to the backend to prepare the application state @@ -209,7 +209,7 @@ ActiveRecord::FixtureSet.create_fixtures(fixtures_dir, fixture_files) ``` ```js -// spec/cypress/integrations/simple_spec.js +// spec/cypress/e2e/simple.cy.js describe('My First Test', function() { it('visit root', function() { // This calls to the backend to prepare the application state @@ -238,7 +238,7 @@ CypressOnRails::SmartFactoryWrapper.create(:profile, name: "Cypress Hill") Then reference the scenario in your test: ```js -// spec/cypress/integrations/scenario_example_spec.js +// spec/cypress/e2e/scenario_example.cy.js describe('My First Test', function() { it('visit root', function() { // This calls to the backend to prepare the application state @@ -261,7 +261,7 @@ load "#{Rails.root}/db/seeds.rb" Then reference the command in your test with `cy.app('load_seed')`: ```js -// spec/cypress/integrations/simple_spec.js +// spec/cypress/e2e/simple.cy.js describe('My First Test', function() { beforeEach(() => { cy.app('load_seed') }) diff --git a/lib/cypress-on-rails.rb b/lib/cypress-on-rails.rb index 2473b1e..ec49210 100644 --- a/lib/cypress-on-rails.rb +++ b/lib/cypress-on-rails.rb @@ -3,5 +3,5 @@ require_relative './cypress_on_rails/railtie' if defined?(Rails) # maintain backward compatibility -CypressDev = CypressOnRails -Cypress = CypressDev +CypressDev = CypressOnRails unless defined?(CypressDev) +Cypress = CypressDev unless defined?(Cypress) diff --git a/lib/cypress_on_rails/middleware.rb b/lib/cypress_on_rails/middleware.rb index 96ff611..043ab70 100644 --- a/lib/cypress_on_rails/middleware.rb +++ b/lib/cypress_on_rails/middleware.rb @@ -59,6 +59,7 @@ def handle_command(req) output = {"message" => "Cannot convert to json"}.to_json end + logger.debug "output: #{output}" [201, {'Content-Type' => 'application/json'}, [output]] rescue => e output = {"message" => e.message, "class" => e.class.to_s}.to_json diff --git a/lib/generators/cypress_on_rails/install_generator.rb b/lib/generators/cypress_on_rails/install_generator.rb index 4d930a9..43c9138 100644 --- a/lib/generators/cypress_on_rails/install_generator.rb +++ b/lib/generators/cypress_on_rails/install_generator.rb @@ -3,7 +3,6 @@ class InstallGenerator < Rails::Generators::Base class_option :cypress_folder, type: :string, default: 'cypress' class_option :install_cypress, type: :boolean, default: true class_option :install_cypress_with, type: :string, default: 'yarn' - class_option :install_cypress_examples, type: :boolean, default: false class_option :experimental, type: :boolean, default: false source_root File.expand_path('../templates', __FILE__) @@ -23,13 +22,9 @@ def install_cypress fail 'failed to install cypress' unless system(command) end end - if options.install_cypress_examples - directory 'spec/cypress/integration/examples', "#{options.cypress_folder}/integration/examples" - directory 'spec/cypress/fixtures', "#{options.cypress_folder}/fixtures" - end template "spec/cypress/support/index.js.erb", "#{options.cypress_folder}/support/index.js" copy_file "spec/cypress/support/commands.js", "#{options.cypress_folder}/support/commands.js" - copy_file "spec/cypress.json", "#{options.cypress_folder}/../cypress.json" + copy_file "spec/cypress.config.js", "#{options.cypress_folder}/../cypress.config.js" end def add_initial_files @@ -37,7 +32,7 @@ def add_initial_files template "spec/cypress/cypress_helper.rb.erb", "#{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" - directory 'spec/cypress/integration/rails_examples', "#{options.cypress_folder}/integration/rails_examples" + directory 'spec/cypress/e2e/rails_examples', "#{options.cypress_folder}/e2e/rails_examples" end def update_files diff --git a/lib/generators/cypress_on_rails/templates/spec/cypress.config.js b/lib/generators/cypress_on_rails/templates/spec/cypress.config.js new file mode 100644 index 0000000..e1066e5 --- /dev/null +++ b/lib/generators/cypress_on_rails/templates/spec/cypress.config.js @@ -0,0 +1,9 @@ +const { defineConfig } = require('cypress') + +module.exports = defineConfig({ + e2e: { + baseUrl: "http://localhost:5017", + defaultCommandTimeout: 10000, + supportFile: "cypress/support/index.js", + } +}) diff --git a/lib/generators/cypress_on_rails/templates/spec/cypress.json b/lib/generators/cypress_on_rails/templates/spec/cypress.json deleted file mode 100644 index 06d1bf5..0000000 --- a/lib/generators/cypress_on_rails/templates/spec/cypress.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "baseUrl": "http://localhost:5017", - "defaultCommandTimeout": 10000 -} diff --git a/lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/advance_factory_bot_spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/advance_factory_bot.cy.js similarity index 100% rename from lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/advance_factory_bot_spec.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/advance_factory_bot.cy.js diff --git a/lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/other_spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/other.cy.js similarity index 100% rename from lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/other_spec.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/other.cy.js diff --git a/lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_factory_bot_spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/using_factory_bot.cy.js similarity index 100% rename from lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_factory_bot_spec.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/using_factory_bot.cy.js diff --git a/lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_fixtures_spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/using_fixtures.cy.js similarity index 100% rename from lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_fixtures_spec.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/using_fixtures.cy.js diff --git a/lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_scenarios_spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/using_scenarios.cy.js similarity index 100% rename from lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_scenarios_spec.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/using_scenarios.cy.js diff --git a/lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_vcr_spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/using_vcr.cy.js similarity index 100% rename from lib/generators/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_vcr_spec.js rename to lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/using_vcr.cy.js diff --git a/lib/generators/cypress_on_rails/templates/spec/cypress/fixtures/example.json b/lib/generators/cypress_on_rails/templates/spec/cypress/fixtures/example.json deleted file mode 100644 index da18d93..0000000 --- a/lib/generators/cypress_on_rails/templates/spec/cypress/fixtures/example.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Using fixtures to represent data", - "email": "hello@cypress.io", - "body": "Fixtures are a great way to mock data for responses to routes" -} \ No newline at end of file diff --git a/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/actions.spec.js b/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/actions.spec.js deleted file mode 100644 index 0375aba..0000000 --- a/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/actions.spec.js +++ /dev/null @@ -1,272 +0,0 @@ -/// - -context('Actions', () => { - beforeEach(() => { - cy.visit('https://example.cypress.io/commands/actions') - }) - - // https://on.cypress.io/interacting-with-elements - - it('.type() - type into a DOM element', () => { - // https://on.cypress.io/type - cy.get('.action-email') - .type('fake@email.com').should('have.value', 'fake@email.com') - - // .type() with special character sequences - .type('{leftarrow}{rightarrow}{uparrow}{downarrow}') - .type('{del}{selectall}{backspace}') - - // .type() with key modifiers - .type('{alt}{option}') //these are equivalent - .type('{ctrl}{control}') //these are equivalent - .type('{meta}{command}{cmd}') //these are equivalent - .type('{shift}') - - // Delay each keypress by 0.1 sec - .type('slow.typing@email.com', { delay: 100 }) - .should('have.value', 'slow.typing@email.com') - - cy.get('.action-disabled') - // Ignore error checking prior to type - // like whether the input is visible or disabled - .type('disabled error checking', { force: true }) - .should('have.value', 'disabled error checking') - }) - - it('.focus() - focus on a DOM element', () => { - // https://on.cypress.io/focus - cy.get('.action-focus').focus() - .should('have.class', 'focus') - .prev().should('have.attr', 'style', 'color: orange;') - }) - - it('.blur() - blur off a DOM element', () => { - // https://on.cypress.io/blur - cy.get('.action-blur').type('About to blur').blur() - .should('have.class', 'error') - .prev().should('have.attr', 'style', 'color: red;') - }) - - it('.clear() - clears an input or textarea element', () => { - // https://on.cypress.io/clear - cy.get('.action-clear').type('Clear this text') - .should('have.value', 'Clear this text') - .clear() - .should('have.value', '') - }) - - it('.submit() - submit a form', () => { - // https://on.cypress.io/submit - cy.get('.action-form') - .find('[type="text"]').type('HALFOFF') - cy.get('.action-form').submit() - .next().should('contain', 'Your form has been submitted!') - }) - - it('.click() - click on a DOM element', () => { - // https://on.cypress.io/click - cy.get('.action-btn').click() - - // You can click on 9 specific positions of an element: - // ----------------------------------- - // | topLeft top topRight | - // | | - // | | - // | | - // | left center right | - // | | - // | | - // | | - // | bottomLeft bottom bottomRight | - // ----------------------------------- - - // clicking in the center of the element is the default - cy.get('#action-canvas').click() - - cy.get('#action-canvas').click('topLeft') - cy.get('#action-canvas').click('top') - cy.get('#action-canvas').click('topRight') - cy.get('#action-canvas').click('left') - cy.get('#action-canvas').click('right') - cy.get('#action-canvas').click('bottomLeft') - cy.get('#action-canvas').click('bottom') - cy.get('#action-canvas').click('bottomRight') - - // .click() accepts an x and y coordinate - // that controls where the click occurs :) - - cy.get('#action-canvas') - .click(80, 75) // click 80px on x coord and 75px on y coord - .click(170, 75) - .click(80, 165) - .click(100, 185) - .click(125, 190) - .click(150, 185) - .click(170, 165) - - // click multiple elements by passing multiple: true - cy.get('.action-labels>.label').click({ multiple: true }) - - // Ignore error checking prior to clicking - cy.get('.action-opacity>.btn').click({ force: true }) - }) - - it('.dblclick() - double click on a DOM element', () => { - // https://on.cypress.io/dblclick - - // Our app has a listener on 'dblclick' event in our 'scripts.js' - // that hides the div and shows an input on double click - cy.get('.action-div').dblclick().should('not.be.visible') - cy.get('.action-input-hidden').should('be.visible') - }) - - it('.check() - check a checkbox or radio element', () => { - // https://on.cypress.io/check - - // By default, .check() will check all - // matching checkbox or radio elements in succession, one after another - cy.get('.action-checkboxes [type="checkbox"]').not('[disabled]') - .check().should('be.checked') - - cy.get('.action-radios [type="radio"]').not('[disabled]') - .check().should('be.checked') - - // .check() accepts a value argument - cy.get('.action-radios [type="radio"]') - .check('radio1').should('be.checked') - - // .check() accepts an array of values - cy.get('.action-multiple-checkboxes [type="checkbox"]') - .check(['checkbox1', 'checkbox2']).should('be.checked') - - // Ignore error checking prior to checking - cy.get('.action-checkboxes [disabled]') - .check({ force: true }).should('be.checked') - - cy.get('.action-radios [type="radio"]') - .check('radio3', { force: true }).should('be.checked') - }) - - it('.uncheck() - uncheck a checkbox element', () => { - // https://on.cypress.io/uncheck - - // By default, .uncheck() will uncheck all matching - // checkbox elements in succession, one after another - cy.get('.action-check [type="checkbox"]') - .not('[disabled]') - .uncheck().should('not.be.checked') - - // .uncheck() accepts a value argument - cy.get('.action-check [type="checkbox"]') - .check('checkbox1') - .uncheck('checkbox1').should('not.be.checked') - - // .uncheck() accepts an array of values - cy.get('.action-check [type="checkbox"]') - .check(['checkbox1', 'checkbox3']) - .uncheck(['checkbox1', 'checkbox3']).should('not.be.checked') - - // Ignore error checking prior to unchecking - cy.get('.action-check [disabled]') - .uncheck({ force: true }).should('not.be.checked') - }) - - it('.select() - select an option in a