Cle*_*ton 11 ruby-on-rails vcr
我正在使用录像机记录我正在整合的其他系统的响应.
但是,这个响应获得了一个巨大的JSON,VCR正在以二进制格式保存它:
body:
encoding: ASCII-8BIT
string: !binary |-
eyJsaXN0IjpbXSwiZmFjZXRzIjpbeyJuYW1lIjoiU2FsZXNDaGFubmVsTmFt
ZSIsInR5cGUiOi...
Run Code Online (Sandbox Code Playgroud)
有没有办法我只能将响应体保存为JSON?
我想这样做来编辑返回的JSON,以便为我的测试制作其他场景,
谢谢
pol*_*tti 23
从Cleyton提供的谷歌论坛链接(如果我有代表,我会发表评论),以下更改spec_helper.rb为我工作:
VCR.configure do |c|
c.before_record do |i|
i.response.body.force_encoding('UTF-8')
end
end
Run Code Online (Sandbox Code Playgroud)
decode_compressed_response在您的配置中使用。
VCR.configure do |c|
c.cassette_library_dir = 'cassettes'
c.hook_into :webmock
c.default_cassette_options = { :decode_compressed_response => true }
end
Run Code Online (Sandbox Code Playgroud)