Sha256: 8522f599af532cf54ceb4810f8b024c93c32dd0e36e9bb4d59c7bac238787ac9

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

require 'spec_helper'

RSpec.describe Uncruft::Deprecatable do
  let(:my_name) { "Jess" }

  subject { klass.new }

  describe '.deprecate_attribute' do
    let(:klass) do
      Class.new do
        include Uncruft::Deprecatable

        attr_accessor :first_name

        deprecate_attribute(:first_name,
                            message: "Please stop using this attribute!")
      end
    end

    it 'applies deprecation warning when setting deprecated attribute' do
      expect(ActiveSupport::Deprecation).to receive(:warn).once
        .with("Please stop using this attribute!")

      expect(subject.first_name = my_name).to eq my_name
    end

    it 'applies deprecation warning when getting deprecated attribute' do
      subject.instance_variable_set(:@first_name, my_name)

      expect(ActiveSupport::Deprecation).to receive(:warn)
        .with("Please stop using this attribute!")

      expect(subject.first_name).to eq my_name
    end
  end

  describe '.deprecate_method' do
    let(:klass) do
      Class.new do
        include Uncruft::Deprecatable

        def legacy_method
          "Hello Old World!"
        end

        deprecate_method(:legacy_method,
                         message: "Please stop using this method!")
      end
    end

    it 'applies deprecation warning when calling the deprecated method' do
      expect(ActiveSupport::Deprecation).to receive(:warn)
        .with("Please stop using this method!")

      expect(subject.legacy_method).to eq "Hello Old World!"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
uncruft-0.3.0 spec/uncruft/deprecatable_spec.rb