<commit_before>require 'spec_helper'

class HeadingComponent
  include Rafters::Component
end

describe Rafters::Component do
  describe ".template_name" do
    it "set the component's template name to the provided value" do
      HeadingComponent.template_name("foo_bar_baz")
      HeadingComponent._template_name == "foo_bar_baz"
    end
  end

  describe ".attribute" do
    it "adds the provided method to the component's attributes" do
      HeadingComponent.send(:define_method, :title, -> { "Lorem Ipsum" })
      HeadingComponent.attribute(:title)

      heading = HeadingComponent.new
      heading.attributes.should have_key(:title)
    end
  end

  describe ".setting" do
    it "adds the provided key to the component's settings" do
      HeadingComponent.setting(:type)

      heading = HeadingComponent.new
      heading.settings.should respond_to(:type)
    end

    context "with a :default value" do
      it "sets the setting's value to the provided value when no value is available" do
        HeadingComponent.setting(:type, default: "h1")

        heading = HeadingComponent.new
        heading.settings.type.should == "h1"
      end
    end

    context "with the :required option" do
      it "raises an error when accessing the settings if the value is nil" do
        HeadingComponent.setting(:type, required: true)

        heading = HeadingComponent.new
        -> { heading.settings }.should raise_error(Rafters::Component::SettingRequired)
      end
    end
  end

  describe "#attributes" do
    before do
      HeadingComponent.send(:define_method, :title, -> { "Lorem Ipsum" })
      HeadingComponent.attribute(:title)
    end

    subject { HeadingComponent.new }

    it "returns the registered attributes and their values" do
      subject.attributes.should == Hashie::Mash.new({ title: "Lorem Ipsum" })
    end
  end

  describe "#settings" do
    before do
      HeadingComponent.setting(:type)
    end

    subject { HeadingComponent.new({ type: "h2" }) }

    it "returns the registered settings and their values" do
      subject.settings.should == Hashie::Mash.new({ type: "h2" })
    end<commit_msg>Fix broken spec<commit_after>require 'spec_helper'

class HeadingComponent
  include Rafters::Component
end

describe Rafters::Component do
  describe ".template_name" do
    it "set the component's template name to the provided value" do
      HeadingComponent.template_name("foo_bar_baz")
      HeadingComponent._template_name == "foo_bar_baz"
    end
  end

  describe ".attribute" do
    it "adds the provided method to the component's attributes" do
      HeadingComponent.send(:define_method, :title, -> { "Lorem Ipsum" })
      HeadingComponent.attribute(:title)

      heading = HeadingComponent.new
      heading.attributes.should have_key(:title)
    end
  end

  describe ".setting" do
    it "adds the provided key to the component's settings" do
      HeadingComponent.setting(:type)

      heading = HeadingComponent.new
      heading.settings.should respond_to(:type)
    end

    context "with a :default value" do
      it "sets the setting's value to the provided value when no value is available" do
        HeadingComponent.setting(:type, default: "h1")

        heading = HeadingComponent.new
        heading.settings.type.should == "h1"
      end
    end

    context "with the :required option" do
      it "raises an error when accessing the settings if the value is nil" do
        HeadingComponent.setting(:type, required: true)

        heading = HeadingComponent.new
        -> { heading.settings }.should raise_error(Rafters::Component::SettingRequired)
      end
    end
  end

  describe "#attributes" do
    before do
      HeadingComponent.send(:define_method, :title, -> { "Lorem Ipsum" })
      HeadingComponent.attribute(:title)
    end

    subject { HeadingComponent.new }

    it "returns the registered attributes and their values" do
      subject.attributes.should == Hashie::Mash.new({ title: "Lorem Ipsum", settings: {} })
    end
  end

  describe "#settings" do
    before do
      HeadingComponent.setting(:type)
    end

    subject { HeadingComponent.new({ type: "h2" }) }

    it "returns the registered settings and their values" do
      subject.settings.should == Hashie::Mash.new({ type: "h2" })
    end
{'fraction_non_alphanumeric': 0.09027454630060493, 'fraction_numerical': 0.0018613308515588647, 'mean_word_length': 3.1296829971181555, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '2338242', 'n_tokens_mistral': 1236, 'n_tokens_neox': 1191, 'n_words': 376}