Sha256: ed62b0a3316ce42d5afded38aa392645876d2ff3333a217f34dd23facd76cceb

Contents?: true

Size: 1.09 KB

Versions: 8

Compression:

Stored size: 1.09 KB

Contents

require 'spec_helper'

class Danica::Wrapper::Dummy
  include Danica::DSL
  include Danica::Wrapper

  attr_reader :wrapped_value

  def initialize(value)
    @wrapped_value = wrap_value(value)
  end
end

shared_examples 'a value wrapper' do |examples|
  examples.each do |val, expected|
    context "when value is a #{val.class}" do
      let(:value) { val }

      it do
        expect(subject.wrapped_value.content).to be_a(expected)
      end
    end
  end
end

describe Danica::Wrapper do
  let(:clazz) { described_class::Dummy }
  subject { clazz.new(value) }

  describe 'wrap_value' do
    it_behaves_like 'a value wrapper', {
      x: Danica::Wrapper::Variable,
      'x' => Danica::Wrapper::Variable,
      10 => Danica::Wrapper::Number,
      -10 => Danica::Wrapper::Negative,
      { name: :x } => Danica::Wrapper::Variable
    }

    context 'when value is a Hash' do
      context 'but it is a constant' do
        let(:value) { { value: 10, latex: :x, gnu: :X } }

        it do
          expect(subject.wrapped_value.content).to be_a(Danica::Wrapper::Constant)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
danica-2.6.4 spec/lib/danica/wrapper_spec.rb
danica-2.6.3 spec/lib/danica/wrapper_spec.rb
danica-2.6.2 spec/lib/danica/wrapper_spec.rb
danica-2.6.1 spec/lib/danica/wrapper_spec.rb
danica-2.6.0 spec/lib/danica/wrapper_spec.rb
danica-2.5.1 spec/lib/danica/wrapper_spec.rb
danica-2.5.0 spec/lib/danica/wrapper_spec.rb
danica-2.4.4 spec/lib/danica/wrapper_spec.rb