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

require 'rubygems'
require 'active_record'
require 'action_controller'

class NilIO
  def write(*args); end
  def close(*args); end
  def puts(*args); end
  def path; nil; end
  def fsync; 0; end
  def to_s; "hello"; end
  def sync; true; end
  def sync=(arg); arg; end
end

def shhh(&block)
  orig_out = $stdout
  $stdout = NilIO.new
  yield
  $stdout = orig_out
end

#
# Setup faux Rails environment

RAILS_ROOT = File.join(File.dirname(__FILE__), 'rails_root')

require File.join(RAILS_ROOT, "config", "routes.rb")

shhh do
  ActiveRecord::Base.configurations = {"test" => { "adapter" => "sqlite3", "database" => ":memory:"}}
  ActiveRecord::Base.establish_connection("test")
  load(File.join(RAILS_ROOT, "db", "schema.rb"))
end

ActiveRecord::Base.logger = Logger.new(NilIO.new)
ActionController::Base.view_paths = [File.join(RAILS_ROOT, 'app', 'views')]

#
# Model definition

class Room < ActiveRecord::Base
  validates_presence_of :location, :foo, :bar
  validates_format_of :email, :with => /^\w+@\w+\.\w+$/
  validates_uniqueness_of :email

  has_many :doors
  has_one :floor

  def self.create_with_good_data(attributes={})
    create!({:location => "a", :foo => "b", :bar => "c", :email => "a@b.c"}.merge(attributes))
  end
end

#
# Test refactorings

require 'riot/rails'

module RiotRails
  module Context
    # def asserts_passes_failures_errors(passes=0, failures=0, errors=0)
    #   should("pass #{passes} test(s)") { topic.passes }.equals(passes)
    #   should("fail #{failures} test(s)") { topic.failures }.equals(failures)
    #   should("error on #{errors} test(s)") { topic.errors }.equals(errors)
    # end
    # 
    # def setup_with_test_context(&block)
    #   setup do
    #     @test_report = Riot::SilentReporter.new
    #     @test_context = Riot::Context.new("test context", @test_report)
    #     yield(@test_context)
    #     @test_context.report
    #     @test_report
    #   end
    # end
    # 
    # def setup_and_run_context(name, *passes_failures_errors, &block)
    #   context name do
    #     setup_with_test_context(&block)
    #     asserts_passes_failures_errors(*passes_failures_errors)
    #   end
    # end

    def setup_test_context
      setup { Riot::Context.new("test context") {} }
    end

    def setup_for_assertion_test(&block)
      setup do
        topic.setup(&block).run(@situation)
        topic
      end
    end
    
    def assertion_test_passes(description, success_message=nil, &block)
      should("pass #{description}") do
        instance_eval(&block).run(@situation)
      end.equals([:pass, success_message])
    end

    def assertion_test_fails(description, failure_message, &block)
      should("fail #{description}") do
        instance_eval(&block).run(@situation)
      end.equals([:fail, failure_message])
    end

  end # Context
end # RiotRails

Riot::Context.instance_eval { include RiotRails::Context }

#
## Let's see if we can get this way working sometime in the future

# def get(action, options={})
#   @env = {}
#   @request = ActionController::TestRequest.new(@env)
#   # @request = Rack::MockRequest.new(@app)
#   # @response = @request.request("GET", path, options)
#   # request = ActionController::TestRequest.new(@env)
#   @request.query_parameters["action"] = action
#   @env["action_controller.rescue.request"] = @request
#   @env["action_controller.rescue.response"] = ActionController::TestResponse.new
#   @app.call(@env)
# end

# setup do
  # DashboardsController.instance_eval { include ActionController::TestCase::RaiseActionExceptions }
  # @controller_class = DashboardsController
  # @app = DashboardsController
# end
<commit_msg>Removing useless commented out code<commit_after>$:.unshift File.join(File.dirname(__FILE__), "..", "lib")

require 'rubygems'
require 'active_record'
require 'action_controller'

class NilIO
  def write(*args); end
  def close(*args); end
  def puts(*args); end
  def path; nil; end
  def fsync; 0; end
  def to_s; "hello"; end
  def sync; true; end
  def sync=(arg); arg; end
end

def shhh(&block)
  orig_out = $stdout
  $stdout = NilIO.new
  yield
  $stdout = orig_out
end

#
# Setup faux Rails environment

RAILS_ROOT = File.join(File.dirname(__FILE__), 'rails_root')

require File.join(RAILS_ROOT, "config", "routes.rb")

shhh do
  ActiveRecord::Base.configurations = {"test" => { "adapter" => "sqlite3", "database" => ":memory:"}}
  ActiveRecord::Base.establish_connection("test")
  load(File.join(RAILS_ROOT, "db", "schema.rb"))
end

ActiveRecord::Base.logger = Logger.new(NilIO.new)
ActionController::Base.view_paths = [File.join(RAILS_ROOT, 'app', 'views')]

#
# Model definition

class Room < ActiveRecord::Base
  validates_presence_of :location, :foo, :bar
  validates_format_of :email, :with => /^\w+@\w+\.\w+$/
  validates_uniqueness_of :email

  has_many :doors
  has_one :floor

  def self.create_with_good_data(attributes={})
    create!({:location => "a", :foo => "b", :bar => "c", :email => "a@b.c"}.merge(attributes))
  end
end

#
# Test refactorings

require 'riot/rails'

module RiotRails
  module Context
    def setup_test_context
      setup { Riot::Context.new("test context") {} }
    end

    def setup_for_assertion_test(&block)
      setup do
        topic.setup(&block).run(@situation)
        topic
      end
    end
    
    def assertion_test_passes(description, success_message=nil, &block)
      should("pass #{description}") do
        instance_eval(&block).run(@situation)
      end.equals([:pass, success_message])
    end

    def assertion_test_fails(description, failure_message, &block)
      should("fail #{description}") do
        instance_eval(&block).run(@situation)
      end.equals([:fail, failure_message])
    end

  end # Context
end # RiotRails

Riot::Context.instance_eval { include RiotRails::Context }

#
## Let's see if we can get this way working sometime in the future

# def get(action, options={})
#   @env = {}
#   @request = ActionController::TestRequest.new(@env)
#   # @request = Rack::MockRequest.new(@app)
#   # @response = @request.request("GET", path, options)
#   # request = ActionController::TestRequest.new(@env)
#   @request.query_parameters["action"] = action
#   @env["action_controller.rescue.request"] = @request
#   @env["action_controller.rescue.response"] = ActionController::TestResponse.new
#   @app.call(@env)
# end

# setup do
  # DashboardsController.instance_eval { include ActionController::TestCase::RaiseActionExceptions }
  # @controller_class = DashboardsController
  # @app = DashboardsController
# end

{'fraction_non_alphanumeric': 0.1444343617664852, 'fraction_numerical': 0.001058681185722928, 'mean_word_length': 4.146303501945526, 'pattern_counts': {'":': 2, '<': 5, '<?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': '871125', 'n_tokens_mistral': 2259, 'n_tokens_neox': 2210, 'n_words': 467}