Skip to content

Commit b5e5202

Browse files
committed
Update init method
1 parent bd1dc92 commit b5e5202

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

lib/cypress_on_rails/vcr/insert_eject_middleware.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ class InsertEjectMiddleware
77
include MiddlewareHelpers
88

99
def initialize(app, vcr = nil)
10-
super(app, vcr)
10+
@app = app
11+
@vcr = vcr
1112
@first_call = false
1213
end
1314

@@ -33,6 +34,8 @@ def handle_insert(req)
3334
cassette_name, options = extract_cassette_info(body)
3435
vcr.insert_cassette(cassette_name, options)
3536
[201, { 'Content-Type' => 'application/json' }, [{ 'message': 'OK' }.to_json]]
37+
rescue JSON::ParserError => e
38+
[400, { 'Content-Type' => 'application/json' }, [{ 'message': e.message }.to_json]]
3639
rescue LoadError, ArgumentError => e
3740
[500, { 'Content-Type' => 'application/json' }, [{ 'message': e.message }.to_json]]
3841
end

lib/cypress_on_rails/vcr/middleware_helpers.rb

-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ module Vcr
66
module MiddlewareHelpers
77
include MiddlewareConfig
88

9-
def initialize(app, vcr = nil)
10-
@app = app
11-
@vcr = vcr
12-
end
13-
149
def vcr
1510
@vcr ||= configure_vcr
1611
end

lib/cypress_on_rails/vcr/use_cassette_middleware.rb

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ module Vcr
66
class UseCassetteMiddleware
77
include MiddlewareHelpers
88

9+
def initialize(app, vcr = nil)
10+
@app = app
11+
@vcr = vcr
12+
end
13+
914
def call(env)
1015
return @app.call(env) if should_not_use_vcr?
1116

spec/cypress_on_rails/vcr/insert_eject_middleware_spec.rb

+10
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ def rack_input(json_value)
101101
])
102102
end
103103
end
104+
105+
it 'returns a 400 error when JSON parsing fails' do
106+
env['rack.input'] = StringIO.new('invalid json')
107+
108+
expect(response).to eq([
109+
400,
110+
{ 'Content-Type' => 'application/json' },
111+
['{"message":"unexpected token at \'invalid json\'"}']
112+
])
113+
end
104114
end
105115

106116
describe '/__e2e__/vcr/eject' do

0 commit comments

Comments
 (0)