Sha256: 92fdd00f5e362ec600689b000c11d03648d385aec6bf6e252ef868f8cf847233

Contents?: true

Size: 1.11 KB

Versions: 11

Compression:

Stored size: 1.11 KB

Contents

require "spec_helper"
require "lutaml/model/toml_adapter/toml_rb_adapter"
require "lutaml/model/toml_adapter/tomlib_adapter"
require_relative "../../fixtures/sample_model"

RSpec.shared_examples "a TOML adapter" do |adapter_class|
  let(:attributes) { { name: "John Doe", age: 30 } }
  let(:model) { SampleModel.new(attributes) }

  let(:expected_toml) do
    if adapter_class == Lutaml::Model::TomlAdapter::TomlRbAdapter
      TomlRB.dump(attributes)
    elsif adapter_class == Lutaml::Model::TomlAdapter::TomlibAdapter
      Tomlib.dump(attributes)
    end
  end

  it "serializes to TOML" do
    toml = adapter_class.new(attributes).to_toml

    expect(toml).to eq(expected_toml)
  end

  it "deserializes from TOML" do
    doc = adapter_class.parse(expected_toml)
    new_model = SampleModel.new(doc.to_h)

    expect(new_model.name).to eq("John Doe")
    expect(new_model.age).to eq(30)
  end
end

RSpec.describe Lutaml::Model::TomlAdapter::TomlRbAdapter do
  it_behaves_like "a TOML adapter", described_class
end

RSpec.describe Lutaml::Model::TomlAdapter::TomlibAdapter do
  it_behaves_like "a TOML adapter", described_class
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
lutaml-model-0.5.3 spec/lutaml/model/toml_adapter_spec.rb
lutaml-model-0.5.2 spec/lutaml/model/toml_adapter_spec.rb
lutaml-model-0.5.1 spec/lutaml/model/toml_adapter_spec.rb
lutaml-model-0.5.0 spec/lutaml/model/toml_adapter_spec.rb
lutaml-model-0.4.0 spec/lutaml/model/toml_adapter_spec.rb
lutaml-model-0.3.30 spec/lutaml/model/toml_adapter_spec.rb
lutaml-model-0.3.29 spec/lutaml/model/toml_adapter_spec.rb
lutaml-model-0.3.28 spec/lutaml/model/toml_adapter_spec.rb
lutaml-model-0.3.27 spec/lutaml/model/toml_adapter_spec.rb
lutaml-model-0.3.26 spec/lutaml/model/toml_adapter_spec.rb
lutaml-model-0.3.25 spec/lutaml/model/toml_adapter_spec.rb