<commit_before>require 'spec_helper'

describe HasConfiguration::Configuration do

  let(:klass) { Class }

  describe ".new" do

    before { mock_file('spec/fixtures/class.yml') }

    context "when no filename provided" do

      let(:file) { "/RAILS_ROOT/config/class.yml" }

      it "loads default file" do
        expect_any_instance_of(Configuration).to receive(:raw_file).with(file)
        HasConfiguration::Configuration.new(klass)
      end

    end

    context "when filename provided" do

      let(:file) { "foo/bar.yml" }

      it "loads provided file" do
        expect_any_instance_of(Configuration).to receive(:raw_file).with(file)
        HasConfiguration::Configuration.new(klass, :file => file)
      end

    end

  end

  context "when initialized" do

    context "environment" do

      before { mock_file('spec/fixtures/class.yml') }

      context "without env option" do

        subject { HasConfiguration::Configuration.new(klass) }
        its(:to_h) { should eq('env' => 'development') }

      end

      context "with env option" do

        let(:environment) { 'production' }
        subject { HasConfiguration::Configuration.new(klass, :env => environment) }
        its(:to_h) { should eq('env' => environment) }

      end

    end

    context "yaml defaults" do

      before { mock_file('spec/fixtures/with_defaults.yml') }

      subject { HasConfiguration::Configuration.new(klass) }
      its(:to_h) { should eq('default' => 'default', 'development' => 'development') }

    end

    context "with erb" do

      before { mock_file('spec/fixtures/with_erb.yml') }

      subject { HasConfiguration::Configuration.new(klass) }
      its(:to_h) { should eq('erb' => Rails.env) }

    end

  end

  describe "#to_h" do

    before { mock_file('spec/fixtures/with_nested_attributes.yml') }

    context "#to_h" do
      subject { HasConfiguration::Configuration.new(klass).to_h }
      it { should be_a(HashWithIndifferentAccess) }
    end

    context "#to_h(:stringify)" do
      subject { HasConfiguration::Configuration.new(klass).to_h(:stringify) }
      it { should eq('development' => 'development', 'nested' => { 'foo' => 'bar', 'baz' => true }) }
    end

    context "#to_h(:symbolized)" do
      subject { HasConfiguration::Configuration.new(klass).to_h(:symbolized) }
      it { should eq(:development => 'development', :nested => { :foo => 'bar', :baz => true }) }
    end

  end

  describe "struct methods" do

    before { mock_file('spec/fixtures/with_nested_attributes.yml') }

    let(:configuration) { HasConfiguration::Configuration.new(klass) }

    it "is structified" do
      expect(configuration.development).to eql('development')
      expect(configuration.nested.foo ).to eql('bar')
    end

  end<commit_msg>Adds more spec for fetching data from configuration hash<commit_after>require 'spec_helper'

describe HasConfiguration::Configuration do

  let(:klass) { Class }

  describe ".new" do

    before { mock_file('spec/fixtures/class.yml') }

    context "when no filename provided" do

      let(:file) { "/RAILS_ROOT/config/class.yml" }

      it "loads default file" do
        expect_any_instance_of(Configuration).to receive(:raw_file).with(file)
        HasConfiguration::Configuration.new(klass)
      end

    end

    context "when filename provided" do

      let(:file) { "foo/bar.yml" }

      it "loads provided file" do
        expect_any_instance_of(Configuration).to receive(:raw_file).with(file)
        HasConfiguration::Configuration.new(klass, :file => file)
      end

    end

  end

  context "when initialized" do

    context "environment" do

      before { mock_file('spec/fixtures/class.yml') }

      context "without env option" do

        subject { HasConfiguration::Configuration.new(klass) }
        its(:to_h) { should eq('env' => 'development') }

      end

      context "with env option" do

        let(:environment) { 'production' }
        subject { HasConfiguration::Configuration.new(klass, :env => environment) }
        its(:to_h) { should eq('env' => environment) }

      end

    end

    context "yaml defaults" do

      before { mock_file('spec/fixtures/with_defaults.yml') }

      subject { HasConfiguration::Configuration.new(klass) }
      its(:to_h) { should eq('default' => 'default', 'development' => 'development') }

    end

    context "with erb" do

      before { mock_file('spec/fixtures/with_erb.yml') }

      subject { HasConfiguration::Configuration.new(klass) }
      its(:to_h) { should eq('erb' => Rails.env) }

    end

  end

  describe "#to_h" do

    before { mock_file('spec/fixtures/with_nested_attributes.yml') }

    context "#to_h" do
      subject { HasConfiguration::Configuration.new(klass).to_h }
      it { should be_a(HashWithIndifferentAccess) }
    end

    context "#to_h(:stringify)" do
      subject { HasConfiguration::Configuration.new(klass).to_h(:stringify) }
      it { should eq('development' => 'development', 'nested' => { 'foo' => 'bar', 'baz' => true }) }
    end

    context "#to_h(:symbolized)" do
      subject { HasConfiguration::Configuration.new(klass).to_h(:symbolized) }
      it { should eq(:development => 'development', :nested => { :foo => 'bar', :baz => true }) }
    end

  end

  describe "struct methods" do

    before { mock_file('spec/fixtures/with_nested_attributes.yml') }

    let(:configuration) { HasConfiguration::Configuration.new(klass) }

    it "is structified" do
      expect(configuration.to_h[:development]   ).to eql('development')
      expect(configuration[:development]        ).to eql('development')
      expect(configuration.development          ).to eql('development')

      expect(configuration.to_h[:nested]['foo'] ).to eql('bar')
      expect(configuration[:nested]['foo']      ).to eql('bar')
      expect(configuration.nested.foo           ).to eql('bar')
    end

  end
{'fraction_non_alphanumeric': 0.13432835820895522, 'fraction_numerical': 0.0, 'mean_word_length': 3.1469760900140646, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, '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': '3738813', 'n_tokens_mistral': 1821, 'n_tokens_neox': 1715, 'n_words': 382}