<commit_before>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

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

  describe 'wrap_value' do
    context 'when value is a number' do
      let(:value) { 10 }

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

    context 'when value is a symbol' do
      let(:value) { :x }

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

    context 'when value is a string' do
      let(:value) { 'x' }

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

    context 'when value is a hash' do
      let(:value) { { name: :x } }

      it do
        expect(subject.wrapped_value).to be_a(Danica::Wrapper::Variable)
      end
    end
  end
end<commit_msg>Use shared examples<commit_after>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).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,
      { name: :x } => Danica::Wrapper::Variable
    }
  end
end
{'fraction_non_alphanumeric': 0.11052353252247488, 'fraction_numerical': 0.0021152829190904283, 'mean_word_length': 3.025531914893617, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4988370', 'n_tokens_mistral': 641, 'n_tokens_neox': 618, 'n_words': 158}