spec/eigenclass_spec.rb in eigenclass-2.0.3 vs spec/eigenclass_spec.rb in eigenclass-2.0.4

- old
+ new

@@ -1,60 +1,27 @@ -require_relative '../lib/eigenclass' +require File.expand_path('../../lib/eigenclass', __FILE__) RSpec.describe Eigenclass do subject { Object.new.extend(described_class) } - it { should delegate_method(:ealias_method) - .to(:eigenclass) - .as(:alias_method) } + it { should delegate_method(:ealias_method).to(:eigenclass).as(:alias_method) } + it { should delegate_method(:eattr_accessor).to(:eigenclass).as(:attr_accessor) } + it { should delegate_method(:eattr_reader).to(:eigenclass).as(:attr_reader) } + it { should delegate_method(:eattr_writer).to(:eigenclass).as(:attr_writer) } + it { should delegate_method(:edefine_method).to(:eigenclass).as(:define_method) } + it { should delegate_method(:extended_modules).to(:eigenclass).as(:included_modules) } + it { should delegate_method(:eigenclass_eval).to(:eigenclass).as(:instance_eval) } + it { should delegate_method(:eigenclass_exec).to(:eigenclass).as(:instance_exec) } - it { should delegate_method(:eattr_accessor) - .to(:eigenclass) - .as(:attr_accessor) } - - it { should delegate_method(:eattr_reader) - .to(:eigenclass) - .as(:attr_reader) } - - it { should delegate_method(:eattr_writer) - .to(:eigenclass) - .as(:attr_writer) } - - it { should delegate_method(:edefine_method) - .to(:eigenclass) - .as(:define_method) } - - it { should delegate_method(:extended_modules) - .to(:eigenclass) - .as(:included_modules) } - describe '#eigenclass' do it 'should return the eigenclass instance' do expected = class << subject; self end expect(subject.eigenclass).to eq(expected) end - end - describe '#eigenclass_eval' do - it 'should evaluate in the eigenclass scope' do - expectation = be_respond_to(:test) - - expect(subject).not_to expectation - subject.eigenclass_eval { attr_reader :test } - expect(subject).to expectation - - expect(subject.class.new).not_to expectation - end - end - - describe '#eigenclass_exec' do - it 'should evaluate in the eigenclass scope' do - expectation = be_respond_to(:test) - - expect(subject).not_to expectation - subject.eigenclass_exec(:test) { |name| attr_reader name } - expect(subject).to expectation - - expect(subject.class.new).not_to expectation + it 'should return the same object as singleton_class if that method exists' do + if subject.respond_to?(:singleton_class) + expect(subject.eigenclass).to eq(subject.singleton_class) + end end end end