heychrisek / world-cup

A simple Ruby wrapper for the "World Cup...in JSON" API.
0 stars 0 forks source link

Encoding conversion error on VCR.eject_cassette #1

Open heychrisek opened 10 years ago

heychrisek commented 10 years ago

I'm running into trouble configuring VCR. Running rspec returns the following error message:

1) WorldCup::Match GET matches records the fixture
     Failure/Error: after { VCR.eject_cassette }
     Encoding::UndefinedConversionError:
       "\xC4" from ASCII-8BIT to UTF-8
       Note: Using VCR's `:preserve_exact_body_bytes` option may help prevent this error in the future.
     # ./spec/world-cup/match_spec.rb:20:in `block (3 levels) in <top (required)>'

Adding c.default_cassette_options = { preserve_exact_body_bytes: true } to spec_helper.rb gets around that error, but the base64_string in the cassette (matches.json) is not human-readable. It's also one single line of json, not properly formatted as a hash.

My VCR configuration currently looks like this (all current code is in the configure-vcr branch at the moment):

VCR.configure do |c|
  c.cassette_library_dir = "spec/cassettes"
  c.hook_into :webmock
  c.default_cassette_options = { record: :new_episodes, serialize_with: :json }
  # c.default_cassette_options = { preserve_exact_body_bytes: true }
end

@JohnKellyFerguson, I noticed some commits in your gratitude gem related to utf-8 encoding. Any insight? Is there a better way to be using :preserve_exact_body_bytes, perhaps by passing a block rather than just a true option?

johnkferguson commented 10 years ago

Hey, try the following in your Gemfile

source :rubygems

gem 'httparty'
gem 'json'
gem 'multi_json'

group :test do
  gem 'rspec'
  gem 'webmock'
  gem 'vcr'
  gem 'turn'
  gem 'rake'
end

That should fix it.

httparty, json, & multi_json should eventually go in your gemspec as a dependency. You actually don't even need to have json as it should be a dependency of multi_json.

All the utf-8 encoding in my gem were suggested by rubocop, so I put them in. They don't matter in any ruby >= 2.0.0.

:heart: :smile: :+1:

heychrisek commented 10 years ago

Thanks for the feedback! Still couldn't get it working (same error), but I'll look into it some more.

johnkferguson commented 10 years ago

Hmm, that fixed it for me. I can't replicate the problem, so I'm not really sure what's causing the error.

You can try opening an issue with VCR.

Also, try bundle update as maybe this issue is resolved in later versions of some of your gems.

heychrisek commented 10 years ago

Interesting. That in itself is helpful--I'll try bundle update. And maybe it's the version of ruby I'm using or some other version issue?

On Monday, June 30, 2014, John notifications@github.com wrote:

Hmm, that fixed it for me. I can't replicate the problem, so I'm not really sure what's causing the error.

You can try opening an issue with VCR https://github.com/vcr/vcr.

Also, try bundle update as maybe this issue is resolved in later versions of some of your gems.

— Reply to this email directly or view it on GitHub https://github.com/chriskohlbrenner/world-cup/issues/1#issuecomment-47537637 .

Chris Kohlbrenner c.kohlbrenner@gmail.com 845-596-0066 (cell)

johnkferguson commented 10 years ago

Yea, it could be related to that. I know on my machine I use ruby 2.1.2.