<commit_before>require 'spec_helper'

describe Missingly::Matchers do
  let(:search_class) do
    Class.new do
      include Missingly::Matchers
      
      handle_missingly [:find_by_name], class_method: true do |name|
        return {foo: 'bar'}
      end
      
      handle_missingly /^find_all_by_(\w+)$/, class_method: true do |matches, *args, &block|
        return matches
      end
    end
  end
  
  let(:delegation_test) do
    Class.new do
      include Missingly::Matchers
      
      handle_missingly [:find_by_foo], to: :proxy, class_method: true
      
      def self.proxy
        OpenStruct.new({find_by_foo: "foo"})
      end
    end
  end
  
  
  it "should not break normal method_missing" do
    search_class.new.respond_to?("foo_bar_widget").should be_false
  end
  
  it "should allow you to define class methods" do
    search_class.respond_to?("find_by_name").should be_true
    search_class.respond_to?("find_all_by_name").should be_true
    search_class.find_all_by_name.should be_a MatchData
    search_class.find_by_name.should be_a Hash
  end
  
  it "should support delegation matchers" do
    delegation_test.respond_to?("find_by_foo").should be_true
    delegation_test.find_by_foo.should be_true
  end
  
  it "should not make class methods avliable to instances" do
    search_class.new.respond_to?("find_by_name").should be_false
    lambda { search_class.new.find_by_name("foo") }.should raise_exception
  end
end<commit_msg>test that class methods get inherited<commit_after>require 'spec_helper'

describe Missingly::Matchers do
  let(:search_class) do
    Class.new do
      include Missingly::Matchers
      
      handle_missingly [:find_by_name], class_method: true do |name|
        return {foo: 'bar'}
      end
      
      handle_missingly /^find_all_by_(\w+)$/, class_method: true do |matches, *args, &block|
        return matches
      end
    end
  end
  
  let(:delegation_test) do
    Class.new(search_class) do
      handle_missingly [:find_by_foo], to: :proxy, class_method: true
      
      def self.proxy
        OpenStruct.new({find_by_foo: "foo"})
      end
    end
  end
  
  
  it "should not break normal method_missing" do
    search_class.new.respond_to?("foo_bar_widget").should be_false
  end
  
  it "should allow you to define class methods" do
    search_class.respond_to?("find_by_name").should be_true
    search_class.respond_to?("find_all_by_name").should be_true
    search_class.find_all_by_name.should be_a MatchData
    search_class.find_by_name.should be_a Hash
  end
  
  it "should support delegation matchers" do
    delegation_test.respond_to?("find_by_foo").should be_true
    delegation_test.find_by_foo.should be_true
  end
  
  it "should not make class methods avliable to instances" do
    search_class.new.respond_to?("find_by_name").should be_false
    lambda { search_class.new.find_by_name("foo") }.should raise_exception
  end
  
  it "should work through inheritence" do
    delegation_test.respond_to?("find_all_by_name").should be_true
    delegation_test.find_all_by_name.should be_a MatchData
  end
end
{'fraction_non_alphanumeric': 0.08344072164948453, 'fraction_numerical': 0.0, 'mean_word_length': 3.4105113636363638, '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': '5971840', 'n_tokens_mistral': 1036, 'n_tokens_neox': 1037, 'n_words': 238}