<commit_before>require 'support/ruby_interpreter'
require 'vcr/cassette/serializers'
require 'multi_json'
begin
  require 'psych' # ensure psych is loaded for these tests if its available
rescue LoadError
end

module VCR
  class Cassette
    describe Serializers do
      shared_examples_for "encoding error handling" do |name, error_class|
        context "the #{name} serializer" do
          it 'appends info about the :preserve_exact_body_bytes option to the error' do
            expect {
              result = serializer.serialize("a" => string)
              serializer.deserialize(result)
            }.to raise_error(error_class, /preserve_exact_body_bytes/)
          end
        end
      end

      shared_examples_for "a serializer" do |name, file_extension, lazily_loaded|
        let(:serializer) { subject[name] }

        context "the #{name} serializer" do
          it 'lazily loads the serializer' do
            serializers = subject.instance_variable_get(:@serializers)
            serializers.should_not have_key(name)
            subject[name].should_not be_nil
            serializers.should have_key(name)
          end if lazily_loaded

          it "returns '#{file_extension}' as the file extension" do
            serializer.file_extension.should eq(file_extension)
          end

          it "can serialize and deserialize a hash" do
            hash = { "a" => 7, "nested" => { "hash" => [1, 2, 3] }}
            serialized = serializer.serialize(hash)
            serialized.should_not eq(hash)
            serialized.should be_a(String)
            deserialized = serializer.deserialize(serialized)
            deserialized.should eq(hash)
          end<commit_msg>1.9 mode on rbx doesn't have the same serialization errors.<commit_after>require 'support/ruby_interpreter'
require 'vcr/cassette/serializers'
require 'multi_json'
begin
  require 'psych' # ensure psych is loaded for these tests if its available
rescue LoadError
end

module VCR
  class Cassette
    describe Serializers do
      shared_examples_for "encoding error handling" do |name, error_class|
        context "the #{name} serializer" do
          it 'appends info about the :preserve_exact_body_bytes option to the error' do
            expect {
              result = serializer.serialize("a" => string)
              serializer.deserialize(result)
            }.to raise_error(error_class, /preserve_exact_body_bytes/)
          end unless (RUBY_INTERPRETER == :rubinius && RUBY_VERSION =~ /^1.9/)
        end
      end

      shared_examples_for "a serializer" do |name, file_extension, lazily_loaded|
        let(:serializer) { subject[name] }

        context "the #{name} serializer" do
          it 'lazily loads the serializer' do
            serializers = subject.instance_variable_get(:@serializers)
            serializers.should_not have_key(name)
            subject[name].should_not be_nil
            serializers.should have_key(name)
          end if lazily_loaded

          it "returns '#{file_extension}' as the file extension" do
            serializer.file_extension.should eq(file_extension)
          end

          it "can serialize and deserialize a hash" do
            hash = { "a" => 7, "nested" => { "hash" => [1, 2, 3] }}
            serialized = serializer.serialize(hash)
            serialized.should_not eq(hash)
            serialized.should be_a(String)
            deserialized = serializer.deserialize(serialized)
            deserialized.should eq(hash)
          end
{'fraction_non_alphanumeric': 0.08084258468545402, 'fraction_numerical': 0.0034158838599487617, 'mean_word_length': 2.4826560951437067, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5815509', 'n_tokens_mistral': 992, 'n_tokens_neox': 968, 'n_words': 277}