Sha256: e207af09c88cf2f2e0efb6087ee05dac58dcbc1e89cb86276c027fecdf3b7d15

Contents?: true

Size: 978 Bytes

Versions: 15

Compression:

Stored size: 978 Bytes

Contents

shared_examples_for 'a #freeze method' do
  let(:sample_exception) do
    begin
      object.dup.freeze.instance_variable_set(:@foo, :bar)
    rescue => exception
      exception
    end
  end

  let(:expected_exception_class) do
    # Ruby 1.8 blows up with TypeError Ruby 1.9 with RuntimeError
    sample_exception.class
  end

  let(:expected_exception_message) do
    # Ruby 1.8 blows up with a different message than Ruby 1.9
    sample_exception.message
  end

  it_should_behave_like 'an idempotent method'

  it 'returns object' do
    is_expected.to be(object)
  end

  it 'prevents future modifications' do
    subject
    expectation = raise_error(expected_exception_class,expected_exception_message)
    expect { object.instance_variable_set(:@foo, :bar) }.to(expectation)
  end

  describe '#frozen?' do
    subject { super().frozen? }
    it { is_expected.to be(true) }
  end

  it 'allows to access attribute' do
    expect(subject.name).to eql('John')
  end
end

Version data entries

15 entries across 13 versions & 5 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/virtus-2.0.0/spec/shared/freeze_method_behavior.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/virtus-2.0.0/spec/shared/freeze_method_behavior.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/virtus-2.0.0/spec/shared/freeze_method_behavior.rb
virtus2-2.1.0 spec/shared/freeze_method_behavior.rb
virtus2-2.0.2 spec/shared/freeze_method_behavior.rb
virtus2-2.0.1 spec/shared/freeze_method_behavior.rb
virtus-2.0.0 spec/shared/freeze_method_behavior.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/virtus-1.0.5/spec/shared/freeze_method_behavior.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/virtus-1.0.5/spec/shared/freeze_method_behavior.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/virtus-1.0.5/spec/shared/freeze_method_behavior.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/virtus-1.0.5/spec/shared/freeze_method_behavior.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/virtus-1.0.5/spec/shared/freeze_method_behavior.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/virtus-1.0.5/spec/shared/freeze_method_behavior.rb
virtus-1.0.5 spec/shared/freeze_method_behavior.rb
virtus-1.0.4 spec/shared/freeze_method_behavior.rb