From ce87c33040994f4a9e9842a960cf11488dd67db3 Mon Sep 17 00:00:00 2001 From: Grant Petersen-Speelman Date: Fri, 11 Mar 2022 15:59:23 +1100 Subject: [PATCH 1/2] allow to enable VCR middleware independently --- README.md | 6 ++++++ lib/cypress_on_rails/configuration.rb | 2 ++ lib/cypress_on_rails/railtie.rb | 2 ++ .../templates/config/initializers/cypress_on_rails.rb.erb | 3 ++- 4 files changed, 12 insertions(+), 1 deletion(-) 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..69cd238 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,6 +12,7 @@ def initialize end alias :use_middleware? :use_middleware + alias :use_vcr_middleware? :use_vcr_middleware def reset self.cypress_folder = 'spec/cypress' 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..88231fa 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 @@ -3,7 +3,8 @@ if defined?(CypressOnRails) c.cypress_folder = File.expand_path("#{__dir__}/../../<%= options.cypress_folder %>") # 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? + c.use_middleware = !Rails.env.production? && ENV['CYPRESS'].present? + <% unless options.experimental %># <% end %> c.use_vcr_middleware = !Rails.env.production? && ENV['CYPRESS'].present? c.logger = Rails.logger end From 6dde8dc83b738c2df07d55082e86403dd05de831 Mon Sep 17 00:00:00 2001 From: Grant Petersen-Speelman Date: Fri, 11 Mar 2022 16:08:53 +1100 Subject: [PATCH 2/2] updates --- lib/cypress_on_rails/configuration.rb | 1 + .../templates/config/initializers/cypress_on_rails.rb.erb | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/cypress_on_rails/configuration.rb b/lib/cypress_on_rails/configuration.rb index 69cd238..28a0ca1 100644 --- a/lib/cypress_on_rails/configuration.rb +++ b/lib/cypress_on_rails/configuration.rb @@ -17,6 +17,7 @@ def initialize 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/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 88231fa..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 @@ -3,8 +3,8 @@ if defined?(CypressOnRails) c.cypress_folder = File.expand_path("#{__dir__}/../../<%= options.cypress_folder %>") # 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? && ENV['CYPRESS'].present? - <% unless options.experimental %># <% end %> c.use_vcr_middleware = !Rails.env.production? && ENV['CYPRESS'].present? + c.use_middleware = !Rails.env.production? + <% unless options.experimental %># <% end %> c.use_vcr_middleware = !Rails.env.production? c.logger = Rails.logger end