Sha256: e0d99e297a57f02be16b2314a59afa4a7eef9a7d1ca32bcf1ef9cefee17175fa

Contents?: true

Size: 1.92 KB

Versions: 3

Compression:

Stored size: 1.92 KB

Contents

require File.expand_path('../test_helper', __FILE__)

describe "Kicker, when a change occurs" do
  before do
    Kicker.any_instance.stubs(:last_command_succeeded?).returns(true)
    Kicker.any_instance.stubs(:log)
    @kicker = Kicker.new({})
  end
  
  it "should store the current time as when the last change occurred" do
    now = Time.now
    Time.stubs(:now).returns(now)
    
    @kicker.send(:finished_processing!)
    @kicker.last_event_processed_at.should.be now
  end
  
  it "should return an array of files that have changed since the last event" do
    file1 = touch('1')
    file2 = touch('2')
    file3 = touch('3')
    file4 = touch('4')
    @kicker.send(:finished_processing!)
    
    events = [event(file1, file2), event(file3, file4)]
    
    @kicker.send(:changed_files, events).should == []
    @kicker.send(:finished_processing!)
    
    sleep(1)
    touch('2')
    
    @kicker.send(:changed_files, events).should == [file2]
    @kicker.send(:finished_processing!)
    
    sleep(1)
    touch('1')
    touch('3')
    
    @kicker.send(:changed_files, events).should == [file1, file3]
  end
  
  it "should call the full_chain with all changed files" do
    files = %w{ /file/1 /file/2 }
    events = [event('/file/1'), event('/file/2')]
    
    @kicker.expects(:changed_files).with(events).returns(files)
    @kicker.full_chain.expects(:call).with(@kicker, files)
    @kicker.expects(:finished_processing!)
    
    @kicker.send(:process, events)
  end
  
  it "should not call the full_chain if there were no changed files" do
    @kicker.stubs(:changed_files).returns([])
    @kicker.full_chain.expects(:call).never
    @kicker.expects(:finished_processing!).never
    
    @kicker.send(:process, [event()])
  end
  
  private
  
  def touch(file)
    file = "/tmp/kicker_test_tmp_#{file}"
    `touch #{file}`
    file
  end
  
  def event(*files)
    event = stub('FSEvent')
    event.stubs(:files).returns(files)
    event
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
alloy-kicker-1.9.1 test/filesystem_change_test.rb
alloy-kicker-1.9.2 test/filesystem_change_test.rb
alloy-kicker-1.9.3 test/filesystem_change_test.rb