<commit_before>$:.unshift File.join(File.dirname(__FILE__), "..", "lib")

require 'spec'

def require_project_file(file)
  require(File.join(File.dirname(__FILE__), '..', 'lib', file))  
end

require_project_file('twitter')
require_project_file('twitter/console')
require_project_file('twitter/extras')

# Add helper methods here if relevant to multiple _spec.rb files

# Spec helper that sets attribute <tt>att</tt> for given objects <tt>obj</tt> 
# and <tt>other</tt> to given <tt>value</tt>.
def equalizer(obj, other, att, value)
  setter = "#{att}="
  obj.send(setter, value)
  other.send(setter, value)
end

# Spec helper that nil-izes objects passed in
def nilize(*objects)
  objects.each {|obj| obj = nil }
end

# Returns default <tt>client</tt> context object
def client_context(file = 'config/twitter.yml')
  Twitter::Client.from_config(file)
end

# Spec helper that returns a mocked <tt>Twitter::Config</tt> object
# with stubbed attributes and <tt>attrs</tt> for overriding attribute 
# values.
def stubbed_twitter_config(config, attrs = {})
  opts = { 
    :protocol => :ssl,
    :host => 'twitter.com',
    :port => 443,
    :proxy_host => 'proxy.host',
    :proxy_port => 8080,
  }.merge(attrs)
  config.stub!(:protocol).and_return(opts[:protocol])
  config.stub!(:host).and_return(opts[:host])
  config.stub!(:port).and_return(opts[:port])
  config.stub!(:proxy_host).and_return(opts[:proxy_host])
  config.stub!(:proxy_port).and_return(opts[:proxy_port])
  config
end

def mas_twitter_config(attrs = {})
  config = mock(Twitter::Config)
  stubbed_twitter_conf(config, attrs)
end

def stubbed_twitter_status(status, attrs = {})
  opts = {
    :id => 23492343,
  }.merge(attrs)
  status.stub!(:id).and_return(opts[:id])
  status.stub!(:to_i).and_return(opts[:id])
  (opts.keys - [:id]).each do |att|
    status.stub!(att).and_return(opts[att])
  end
  status.stub!(:bless).and_return(nil)
  status
end

def mas_twitter_status(attrs = {})<commit_msg>Minor refactoring of a spec helper method.<commit_after>$:.unshift File.join(File.dirname(__FILE__), "..", "lib")

require 'spec'

def require_project_file(file)
  require(File.join(File.dirname(__FILE__), '..', 'lib', file))  
end

require_project_file('twitter')
require_project_file('twitter/console')
require_project_file('twitter/extras')

# Add helper methods here if relevant to multiple _spec.rb files

# Spec helper that sets attribute <tt>att</tt> for given objects <tt>obj</tt> 
# and <tt>other</tt> to given <tt>value</tt>.
def equalizer(obj, other, att, value)
  setter = "#{att}="
  obj.send(setter, value)
  other.send(setter, value)
end

# Spec helper that nil-izes objects passed in
def nilize(*objects)
  objects.each {|obj| obj = nil }
end

# Returns default <tt>client</tt> context object
def client_context(file = 'config/twitter.yml')
  Twitter::Client.from_config(file)
end

# Spec helper that returns a mocked <tt>Twitter::Config</tt> object
# with stubbed attributes and <tt>attrs</tt> for overriding attribute 
# values.
def stubbed_twitter_config(config, attrs = {})
  opts = { 
    :protocol => :ssl,
    :host => 'twitter.com',
    :port => 443,
    :proxy_host => 'proxy.host',
    :proxy_port => 8080,
  }.merge(attrs)
  opts.keys.each do |key|
    config.stub!(key).and_return(opts[key])
  end
  config
end

def mas_twitter_config(attrs = {})
  config = mock(Twitter::Config)
  stubbed_twitter_conf(config, attrs)
end

def stubbed_twitter_status(status, attrs = {})
  opts = {
    :id => 23492343,
  }.merge(attrs)
  status.stub!(:id).and_return(opts[:id])
  status.stub!(:to_i).and_return(opts[:id])
  (opts.keys - [:id]).each do |att|
    status.stub!(att).and_return(opts[att])
  end
  status.stub!(:bless).and_return(nil)
  status
end

def mas_twitter_status(attrs = {})
{'fraction_non_alphanumeric': 0.15998938710533298, 'fraction_numerical': 0.007959671000265322, 'mean_word_length': 4.909090909090909, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 43, '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': '3699571', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1336, 'n_words': 288}