Sha256: da238ac66732563bdd2a2177eefdd115c501a9439f1c03050f1178c8e950a072

Contents?: true

Size: 1.11 KB

Versions: 11

Compression:

Stored size: 1.11 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Axiom::Types::Encodable, '.extended' do
  subject { object.extend(described_class) }

  let(:object) { Class.new(Axiom::Types::Type) }

  it 'delegates to the ancestor' do
    # RSpec will reset stubbed methods after the example. A normal expectation
    # causes a SystemStackError to be thrown, so we stub it first so that
    # RSpec tracks the original method (if any), then we add our own stub that
    # actually works, and finally when the example finishes RSpec will reset
    # the Module#extended method back to it's original state.
    allow_any_instance_of(Module).to receive(:extended).with(object)

    delegated_ancestor = false
    Module.send(:undef_method, :extended)
    Module.send(:define_method, :extended) { |_| delegated_ancestor = true }
    expect { subject }.to change { delegated_ancestor }.from(false).to(true)
  end

  it 'adds encoding method' do
    expect { subject }.to change { object.respond_to?(:encoding) }
      .from(false).to(true)
  end

  it 'sets the encoding default to UTF-8' do
    expect(subject.encoding).to be(Encoding::UTF_8)
  end
end

Version data entries

11 entries across 9 versions & 4 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/encodable/class_methods/extended_spec.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/encodable/class_methods/extended_spec.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/encodable/class_methods/extended_spec.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/encodable/class_methods/extended_spec.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/encodable/class_methods/extended_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/encodable/class_methods/extended_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/encodable/class_methods/extended_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/encodable/class_methods/extended_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/encodable/class_methods/extended_spec.rb
axiom-types-0.1.1 spec/unit/axiom/types/encodable/class_methods/extended_spec.rb
axiom-types-0.1.0 spec/unit/axiom/types/encodable/class_methods/extended_spec.rb