<commit_before>require 'spec_helper'

describe SchemaMigrationMonitor::Monitor do

  before(:each) do
    MigrationPathService.expects(:execute).returns(MigrationPathService::DEFAULT_MIGRATION_PATH)
  end

  it "should check the pending migrations" do
    get_migrator_with_pending_migrations([])
    SchemaMigrationMonitor::Monitor.new.execute
  end

  describe "when there are no pending migrations" do
    it "should do nothing" do
      output_stream = get_output_stream_mock
      output_stream.should_receive(:write).exactly(0).times
      get_migrator_with_pending_migrations([])
      SchemaMigrationMonitor::Monitor.new(output_stream).execute
    end
  end

  describe "when there are pending migrations" do
    let(:migrations) { ['20120101000000_fake_migration', '20120101000001_fake_migration_2'] }

    before(:each) do
      get_migrator_with_pending_migrations(migrations)
    end
    
    it "should print a message to stdout" do
      output_stream = get_output_stream_mock
      output_stream.expects(:write).with("The following migration[s] need to be run #{migrations.join(', ')}")
      SchemaMigrationMonitor::Monitor.new(output_stream).execute
    end
  end

  def get_migrator_with_pending_migrations(pending_migrations)
    mock_migrator = mock('migrator') 
    mock_migrator.expects(:pending_migrations).returns(pending_migrations)
    ActiveRecord::Migrator.expects(:new).returns(mock_migrator)
  end

  def get_output_stream_mock
    stdout_mock = mock('output_stream')
    stdout_mock.stubs(:write)
    stdout_mock
  end

end<commit_msg>cleanup<commit_after>require 'spec_helper'

describe SchemaMigrationMonitor::Monitor do

  before(:each) do
    MigrationPathService.expects(:execute).returns(MigrationPathService::DEFAULT_MIGRATION_PATH)
  end

  it "should check the pending migrations" do
    get_migrator_with_pending_migrations([])
    SchemaMigrationMonitor::Monitor.new.execute
  end

  describe "when there are no pending migrations" do
    before(:each) do
      get_migrator_with_pending_migrations([])
    end

    it "should do nothing" do
      output_stream = get_output_stream_mock
      output_stream.should_receive(:write).exactly(0).times
      SchemaMigrationMonitor::Monitor.new(output_stream).execute
    end
  end

  describe "when there are pending migrations" do
    let(:migrations) { ['20120101000000_fake_migration', '20120101000001_fake_migration_2'] }

    before(:each) do
      get_migrator_with_pending_migrations(migrations)
    end
    
    it "should print a message to stdout" do
      output_stream = get_output_stream_mock
      output_stream.expects(:write).with("The following migration[s] need to be run #{migrations.join(', ')}")
      SchemaMigrationMonitor::Monitor.new(output_stream).execute
    end
  end

  def get_migrator_with_pending_migrations(pending_migrations)
    mock_migrator = mock('migrator') 
    mock_migrator.expects(:pending_migrations).returns(pending_migrations)
    ActiveRecord::Migrator.expects(:new).returns(mock_migrator)
    mock_migrator
  end

  def get_output_stream_mock
    stdout_mock = mock('output_stream')
    stdout_mock.stubs(:write)
    stdout_mock
  end

end
{'fraction_non_alphanumeric': 0.08412098298676748, 'fraction_numerical': 0.01890359168241966, 'mean_word_length': 4.793795620437956, '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': '5176406', 'n_tokens_mistral': 1010, 'n_tokens_neox': 995, 'n_words': 181}