<commit_before>module ControllerHelper
  # Instantiates object with the default Factory build for +var+, and expects any
  # calls to its parent class' +find+ method to return the Factory build.
  #
  # Example:
  #
  #   mock_find(:member) # => @object will be the result of Factory(:member), and Member.find will always return @object
  #   mock_find(:member, :name => 'NewName') # => Same as above, but sets an expectation on @object.name, and returns 'NewName'
  def mock_find(var, expects = {})
    @object ||= Factory(var)
    @object.class.should_receive(:find).with(anything()).exactly(:once).and_return(@object)
    
    expects.each_pair do |msg, val|
      @object.should_receive(msg).and_return(val)
    end
  end

  # Instantiates object with the default Factory build for +var+, and expects any
  # calls to its parent class' +new+ method to return the Factory build.
  #
  # Example:
  #
  #   mock_create(:member) # => @object will be the result of Factory(:member), and Member.new will always return @object
  #   mock_create(:member, :save => false) # => Same as above, but sets an expectation on @object.save, and returns false
  def mock_create(var, expects = {})
    @object ||= Factory(var)
    @object.class.should_receive(:new).with(anything()).exactly(:once).and_return(@object)
    
    expects.each_pair do |msg, val|
      @object.should_receive(msg).and_return(val)
    end
  end
end<commit_msg>I discovered Object.instance_variable_set, which lets us do some cool things in ControllerHelper.<commit_after>module ControllerHelper
  # Instantiates +@parent+ with the default Factory build for +var+, and expects any
  # calls to its parent class' +find+ method to return the Factory build.
  #
  # Example:
  #
  #   mock_parent(:member) # => @parent will be the result of Factory(:member), and Member.find will always return @parent
  #   mock_parent(:member, :name => 'NewName') # => Same as above, but sets an expectation on @parent.name, and returns 'NewName'
  def mock_parent(var, expects = {})
    @parent ||= Factory(var)
    @parent.class.should_receive(:find).and_return(@parent)
    
    expects.each_pair do |msg, val|
      @parent.should_receive(msg).and_return(val)
    end
    
    self.instance_variable_set("@#{var.to_s}", @parent) unless self.instance_variables.include? "@#{var.to_s}"
  end
  
  # Instantiates +@object+ with the default Factory build for +var+, and expects any
  # calls to its parent class' +find+ method to return the Factory build.
  #
  # Example:
  #
  #   mock_find(:member) # => @object will be the result of Factory(:member), and Member.find will always return @object
  #   mock_find(:member, :name => 'New<PASSWORD>') # => Same as above, but sets an expectation on @object.name, and returns 'NewName'
  def mock_find(var, expects = {})
    @object ||= Factory(var)
    @object.class.should_receive(:find).and_return(@object)
    
    expects.each_pair do |msg, val|
      @object.should_receive(msg).and_return(val)
    end
    
    self.instance_variable_set("@#{var.to_s}", @object) unless self.instance_variables.include? "@#{var.to_s}"
  end

  # Instantiates +@object+ with the default Factory build for +var+, and expects any
  # calls to its parent class' +new+ method to return the Factory build.
  #
  # Example:
  #
  #   mock_create(:member) # => @object will be the result of Factory(:member), and Member.new will always return @object
  #   mock_create(:member, :save => false) # => Same as above, but sets an expectation on @object.save, and returns false
  def mock_create(var, expects = {})
    @object ||= Factory(var)
    @object.class.should_receive(:new).with(anything()).exactly(:once).and_return(@object)
    
    expects.each_pair do |msg, val|
      @object.should_receive(msg).and_return(val)
    end
    
    self.instance_variable_set("@#{var.to_s}", @object) unless self.instance_variables.include? "@#{var.to_s}"
  end
end
{'fraction_non_alphanumeric': 0.12732365673542145, 'fraction_numerical': 0.0, 'mean_word_length': 3.9974554707379135, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 19, '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': '5375286', 'n_tokens_mistral': 1212, 'n_tokens_neox': 1202, 'n_words': 366}