Skip to content

Commit

Permalink
Update middlewares
Browse files Browse the repository at this point in the history
  • Loading branch information
MUTOgen committed Sep 27, 2024
1 parent 916ad59 commit 218e3a4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 29 deletions.
9 changes: 5 additions & 4 deletions lib/cypress_on_rails/vcr/insert_eject_middleware.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
require_relative 'base_middleware'
require_relative 'middleware_helpers'

module CypressOnRails
module Vcr
# Middleware to handle vcr with insert/eject endpoints
class InsertEjectMiddleware < BaseMiddleware
class InsertEjectMiddleware
include MiddlewareHelpers

def initialize(app, vcr = nil)
@app = app
@vcr = vcr
super(app, vcr)
@first_call = false
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
require 'json'
require 'rack'
require 'cypress_on_rails/middleware_config'

module CypressOnRails
module Vcr
# Base abstract Middleware
class BaseMiddleware
# Provides helper methods for VCR middlewares
module MiddlewareHelpers
include MiddlewareConfig

def initialize(**_args)
raise_not_implemented
end

def call(_env)
raise_not_implemented
def initialize(app, vcr = nil)
@app = app
@vcr = vcr
end

def vcr
@vcr ||= configure_vcr
end

def cassette_library_dir
"#{configuration.install_folder}/fixtures/vcr_cassettes"
end

private

def configure_vcr
Expand All @@ -29,15 +28,6 @@ def configure_vcr
end
VCR
end

def cassette_library_dir
"#{configuration.install_folder}/fixtures/vcr_cassettes"
end

def raise_not_implemented
raise NotImplementedError,
'BaseMiddleware can not be initialized directly, use InsertEjectMiddleware or UseCassetteMiddleware'
end
end
end
end
9 changes: 3 additions & 6 deletions lib/cypress_on_rails/vcr/use_cassette_middleware.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
require_relative 'base_middleware'
require_relative 'middleware_helpers'

module CypressOnRails
module Vcr
# Middleware to handle vcr with use_cassette
class UseCassetteMiddleware < BaseMiddleware
def initialize(app, vcr = nil)
@app = app
@vcr = vcr
end
class UseCassetteMiddleware
include MiddlewareHelpers

def call(env)
return @app.call(env) if should_not_use_vcr?
Expand Down

0 comments on commit 218e3a4

Please sign in to comment.