Sha256: 3f665fe8a0ec4ecee63f8250c4b1f59cd6702c0937c82787f2fad96823deb0d3

Contents?: true

Size: 1.69 KB

Versions: 99

Compression:

Stored size: 1.69 KB

Contents

require "spec_helper"

describe SafeYAML::Transform::ToSymbol do
  def with_symbol_deserialization_value(value)
    symbol_deserialization_flag = SafeYAML::OPTIONS[:deserialize_symbols]
    SafeYAML::OPTIONS[:deserialize_symbols] = value

    yield

  ensure
    SafeYAML::OPTIONS[:deserialize_symbols] = symbol_deserialization_flag
  end

  def with_symbol_deserialization(&block)
    with_symbol_deserialization_value(true, &block)
  end

  def without_symbol_deserialization(&block)
    with_symbol_deserialization_value(false, &block)
  end

  it "returns true when the value matches a valid Symbol" do
    with_symbol_deserialization { expect(subject.transform?(":foo")[0]).to be_truthy }
  end

  it "returns true when the value matches a valid String+Symbol" do
    with_symbol_deserialization { expect(subject.transform?(':"foo"')[0]).to be_truthy }
  end

  it "returns true when the value matches a valid String+Symbol with 's" do
    with_symbol_deserialization { expect(subject.transform?(":'foo'")[0]).to be_truthy }
  end

  it "returns true when the value has special characters and is wrapped in a String" do
    with_symbol_deserialization { expect(subject.transform?(':"foo.bar"')[0]).to be_truthy }
  end

  it "returns false when symbol deserialization is disabled" do
    without_symbol_deserialization { expect(subject.transform?(":foo")).to be_falsey }
  end

  it "returns false when the value does not match a valid Symbol" do
    with_symbol_deserialization { expect(subject.transform?("foo")).to be_falsey }
  end

  it "returns false when the symbol does not begin the line" do
    with_symbol_deserialization do
      expect(subject.transform?("NOT A SYMBOL\n:foo")).to be_falsey
    end
  end
end

Version data entries

99 entries across 91 versions & 13 rubygems

Version Path
cloudsmith-api-0.53.3 vendor/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/spec/transform/to_symbol_spec.rb
vagrant-unbundled-2.2.10.0 vendor/bundle/ruby/2.7.0/gems/safe_yaml-1.0.5/spec/transform/to_symbol_spec.rb
cloudsmith-api-0.53.1 vendor/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/spec/transform/to_symbol_spec.rb
cloudsmith-api-0.52.121 vendor/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/spec/transform/to_symbol_spec.rb
cloudsmith-api-0.52.92 vendor/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/spec/transform/to_symbol_spec.rb
cloudsmith-api-0.52.79 vendor/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/spec/transform/to_symbol_spec.rb
cloudsmith-api-0.52.5 vendor/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/spec/transform/to_symbol_spec.rb
cloudsmith-api-0.52.0 vendor/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/spec/transform/to_symbol_spec.rb
cloudsmith-api-0.51.93 vendor/bundle/ruby/2.3.0/gems/safe_yaml-1.0.5/spec/transform/to_symbol_spec.rb
cloudsmith-api-0.51.38 vendor/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/spec/transform/to_symbol_spec.rb
cloudsmith-api-0.51.37 vendor/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/spec/transform/to_symbol_spec.rb
cloudsmith-api-0.51.34 vendor/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/spec/transform/to_symbol_spec.rb
cloudsmith-api-0.51.22 vendor/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/spec/transform/to_symbol_spec.rb
vagrant-unbundled-2.2.9.0 vendor/bundle/ruby/2.7.0/gems/safe_yaml-1.0.5/spec/transform/to_symbol_spec.rb
vagrant-unbundled-2.2.8.0 vendor/bundle/ruby/2.7.0/gems/safe_yaml-1.0.5/spec/transform/to_symbol_spec.rb
cloudsmith-api-0.49.118 vendor/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/spec/transform/to_symbol_spec.rb
cloudsmith-api-0.49.98 vendor/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/spec/transform/to_symbol_spec.rb
cloudsmith-api-0.49.94 vendor/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/spec/transform/to_symbol_spec.rb
cloudsmith-api-0.49.21 vendor/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/spec/transform/to_symbol_spec.rb
cloudsmith-api-0.49.15 vendor/bundle/ruby/2.6.0/gems/safe_yaml-1.0.5/spec/transform/to_symbol_spec.rb