Sha256: 83ffd03546561e88bde427554cfbe86e689ff15bdaba27d356ff84bd884cf232
Contents?: true
Size: 1.71 KB
Versions: 4
Compression:
Stored size: 1.71 KB
Contents
# frozen_string_literal: true describe Sinclair::MethodDefinition do describe 'yard' do describe '#build' do describe 'using string method with no options' do subject(:method_definition) do described_class.from(name, code) end let(:klass) { Class.new } let(:instance) { klass.new } let(:code) { '@x = @x.to_i ** 2 + 1' } let(:name) { :sequence } it 'adds a dynamic method' do expect { method_definition.build(klass) }.to add_method(name).to(instance) expect { instance.sequence } .to change { instance.instance_variable_get(:@x) }.from(nil).to 1 expect(instance.sequence).to eq(2) expect(instance.sequence).to eq(5) end it 'changes instance variable' do method_definition.build(klass) expect { instance.sequence } .to change { instance.instance_variable_get(:@x) } .from(nil).to 1 end end describe 'using block with cache option' do subject(:method_definition) do described_class.from(name, cached: true) do @x = @x.to_i**2 + 1 end end let(:klass) { Class.new } let(:instance) { klass.new } let(:name) { :sequence } it 'adds a dynamic method' do expect { method_definition.build(klass) }.to add_method(name).to(instance) expect { instance.sequence } .to change { instance.instance_variable_get(:@x) }.from(nil).to 1 expect { instance.sequence }.not_to change(instance, :sequence) expect(instance.instance_variable_get(:@sequence)).to eq(1) end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems