<commit_before>describe ThreadKit::ThreadLocal::Accessors do

  let(:klass) do
    Class.new(Object) do
      extend ThreadKit::ThreadLocal::Accessors
      tl_attr_accessor :tl_aa
      tl_attr_reader :tl_ar
      tl_attr_writer :tl_aw
      tl_cattr_accessor :tl_ca
      tl_cattr_reader :tl_cr
      tl_cattr_writer :tl_cw
    end
  end

  let(:klass_instance) { klass.new }

  context "#tl_attr_accessor" do
    it "responds to both reader and writer methods" do
      expect(klass_instance).to respond_to(:tl_aa)
      expect(klass_instance).to respond_to(:tl_aa=)
    end
  end

  context "#tl_attr_reader" do
    it "responds to the reader method" do
      expect(klass_instance).to respond_to(:tl_ar)
    end

    it "does not respond to the writer method" do
      expect(klass_instance).to_not respond_to(:tl_ar=)
    end
  end

  context "#tl_attr_writer" do
    it "responds to the writer method" do
      expect(klass_instance).to respond_to(:tl_aw=)
    end

    it "does not respond to the reader method" do
      expect(klass_instance).to_not respond_to(:tl_aw)
    end
  end

  context "#tl_cattr_accessor" do
    it "responds to reader and writer methods at the class level" do
      expect(klass).to respond_to(:tl_ca)
      expect(klass).to respond_to(:tl_ca=)
    end

    it "responds to reader and writer methods at the instance level" do
      expect(klass_instance).to respond_to(:tl_ca)
      expect(klass_instance).to respond_to(:tl_ca=)
    end
  end

  context "#tl_cattr_reader" do
    it "responds to the reader method at the class level" do
      expect(klass).to respond_to(:tl_cr)
    end

    it "does not respond to the writer method at the class level" do
      expect(klass).to_not respond_to(:tl_cr=)
    end

    it "responds to the reader method at the instance level" do
      expect(klass_instance).to respond_to(:tl_cr)
    end

    it "does not respond to the writer method at the instance level" do
      expect(klass_instance).to_not respond_to(:tl_cr=)
    end
  end

  context "#tl_cattr_writer" do
    it "responds to the writer method at the class level" do
      expect(klass).to respond_to(:tl_cw=)
    end

    it "does not respond to the reader method at the class level" do
      expect(klass).to_not respond_to(:tl_cw)
    end

    it "responds to the writer method at the instance level" do
      expect(klass_instance).to respond_to(:tl_cw=)
    end

    it "does not respond to the reader method at the instance level" do
      expect(klass_instance).to_not respond_to(:tl_cw)
    end
  end
end<commit_msg>cleaned up accessor tests<commit_after># These tests enforce a contract. That is to say, they do not ensure that the accessors
#   actually work. Instead, they test that the accessor methods define the appropriate
#   getters and setters, and that those getter and setter methods result in the correct
#   methods being called on ThreadKit::ThreadLocal::Store with the correct arguments.
#   ThreadKit::ThreadLocal::Store is tested separately.
describe ThreadKit::ThreadLocal::Accessors do

  let(:klass) do
    Class.new(Object) do
      extend ThreadKit::ThreadLocal::Accessors
      tl_attr_accessor :tl_aa
      tl_attr_reader :tl_ar
      tl_attr_writer :tl_aw
      tl_cattr_accessor :tl_ca
      tl_cattr_reader :tl_cr
      tl_cattr_writer :tl_cw
    end
  end

  let(:klass_instance) { klass.new }

  # assert that method_name is defined on klass_instance such that calls to it result in the appropriate
  #   key being retrieved from ThreadKit::ThreadLocal::Store relative_to the appropriate object
  def assert_instance_method_reader_defined(method_name, default: nil, relative_to: klass_instance)
    expect(klass_instance).to respond_to(method_name)
    expect(ThreadKit::ThreadLocal::Store).to receive(:get).with(relative_to, method_name, default: default).and_return(:bar)
    expect(klass_instance.send(method_name)).to eql(:bar)
  end

  # assert that method_name is defined on klass_instance such that calls to it result in the appropriate
  #   key being set in ThreadKit::ThreadLocal::Store relative_to the appropriate object
  def assert_instance_method_writer_defined(method_name, relative_to: klass_instance)
    method_name = (method_name.to_s + '=').squeeze('=').to_sym
    store_key = method_name.to_s.sub(/\=$/, '').to_sym
    expect(klass_instance).to respond_to(method_name)
    expect(ThreadKit::ThreadLocal::Store).to receive(:set).with(relative_to, store_key, :foo).and_return(:foo)
    expect(klass_instance.send(method_name, :foo)).to eql(:foo)
  end

  # assert that method_name is defined on klass such that calls to it result in the appropriate
  #   key being retrieved from ThreadKit::ThreadLocal::Store relative to klass
  def assert_singleton_method_reader_defined(method_name, default: nil)
    expect(klass).to respond_to(method_name)
    expect(ThreadKit::ThreadLocal::Store).to receive(:get).with(klass, method_name, default: default).and_return(:bar)
    expect(klass.send(method_name)).to eql(:bar)
  end

  # assert that method_name is defined on klass such that calls to it result in the appropriate
  #   key being set in ThreadKit::ThreadLocal::Store relative to klass
  def assert_singleton_method_writer_defined(method_name)
    method_name = (method_name.to_s + '=').squeeze('=').to_sym
    store_key = method_name.to_s.sub(/\=$/, '').to_sym
    expect(klass).to respond_to(method_name)
    expect(ThreadKit::ThreadLocal::Store).to receive(:set).with(klass, store_key, :foo).and_return(:foo)
    expect(klass.send(method_name, :foo)).to eql(:foo)
  end

  # assert that klass_instance does not have the specified method defined
  def assert_instance_method_not_defined(method_name)
    expect(klass_instance).to_not respond_to(method_name)
  end

  # assert that klass does not have the specified method defined
  def assert_singleton_method_not_defined(method_name)
    expect(klass).to_not respond_to(method_name)
  end

  describe "#tl_attr_accessor" do
    it("defines an instance reader") { assert_instance_method_reader_defined(:tl_aa) }
    it("defines an instance writer") { assert_instance_method_writer_defined(:tl_aa=) }
    it("does not define a class reader") { assert_singleton_method_not_defined(:tl_aa) }
    it("does not define a class writer") { assert_singleton_method_not_defined(:tl_aa=) }
  end

  describe "#tl_attr_reader" do
    it("defines an instance reader") { assert_instance_method_reader_defined(:tl_ar) }
    it("does not define an instance writer") { assert_instance_method_not_defined(:tl_ar=) }
    it("does not define a class reader") { assert_singleton_method_not_defined(:tl_ar) }
    it("does not define a class writer") { assert_singleton_method_not_defined(:tl_ar=) }
  end

  describe "#tl_attr_writer" do
    it("defines an instance writer") { assert_instance_method_writer_defined(:tl_aw=) }
    it("does not define an instance reader") { assert_instance_method_not_defined(:tl_aw) }
    it("does not define a class reader") { assert_singleton_method_not_defined(:tl_aw) }
    it("does not define a class writer") { assert_singleton_method_not_defined(:tl_aw=) }
  end

  describe "#tl_cattr_accessor" do
    it("defines an instance reader") { assert_instance_method_reader_defined(:tl_ca, relative_to: klass) }
    it("defines an instance writer") { assert_instance_method_writer_defined(:tl_ca=, relative_to: klass) }
    it("defines a class reader") { assert_singleton_method_reader_defined(:tl_ca) }
    it("defines a class writer") { assert_singleton_method_writer_defined(:tl_ca=) }
  end

  describe "#tl_cattr_reader" do
    it("defines an instance reader") { assert_instance_method_reader_defined(:tl_cr, relative_to: klass) }
    it("does not define an instance writer") { assert_instance_method_not_defined(:tl_cr=) }
    it("defines a class reader") { assert_singleton_method_reader_defined(:tl_cr) }
    it("does not define a class writer") { assert_singleton_method_not_defined(:tl_cr=) }
  end

  describe "#tl_cattr_writer" do
    it("does not define an instance reader") { assert_instance_method_not_defined(:tl_cw) }
    it("defines an instance writer") { assert_instance_method_writer_defined(:tl_cw=, relative_to: klass) }
    it("does not define a class reader") { assert_singleton_method_not_defined(:tl_cw) }
    it("defines a class writer") { assert_singleton_method_writer_defined(:tl_cw=) }
  end
end
{'fraction_non_alphanumeric': 0.08951132300357569, 'fraction_numerical': 0.0, 'mean_word_length': 4.568015925680159, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1879506', 'n_tokens_mistral': 2650, 'n_tokens_neox': 2652, 'n_words': 718}