Sha256: abb01f6c421600ebc72ccb6dc5b0ca60de46c142078fff5efe0bfb42a5098355

Contents?: true

Size: 1.47 KB

Versions: 2

Compression:

Stored size: 1.47 KB

Contents

require_relative '../test_helper'


# Extends the original handler
module MockHandler
  
  include Autocuke::Handler        
  
  def file_modified
    $modified = true
    super
  end
  
  private   
     
    # don't run, just output the command
    def run_with_defer(cmd)
      operation = proc {
        puts(cmd)
        # simulate delay
        #sleep 0.25
      }
      callback = proc {|result|
        runtime.current_file = nil
      }
      EM.defer operation, callback
    end
    
end


# use the MockHandler
module Autocuke
  class Runtime
    def handler
      ::MockHandler
    end
  end
end


class HandlerTest < Test::Unit::TestCase

  def setup
    $modified = false
    @features = Dir[File.expand_path("../../dummy/features/**/*.feature", __FILE__)]
    @options = OpenStruct.new
    @options.root     = File.expand_path("../../dummy", __FILE__)
    @options.features = File.join(@options.root, "features")
    @options.verbose  = false
  end
    
  should "watch a file" do
    
    outputs = within_loop do
      File.open(@features.first, 'w+'){ |f| f.write "\n" }
    end
    
    # disregard the start-up message
    outputs.shift
    
    assert $modified
    
    name = File.basename(@features.first)
    assert_equal "features/#{name} modified - re-cuking it.", outputs.shift
    
    commands = outputs.shift.split("; ")
    assert_equal "cd #{@options.root}", commands.first
    assert_equal "bundle exec cucumber -p autocuke features/#{name}", commands.last
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
autocuke-0.1.1 test/unit/handler_test.rb
autocuke-0.1.0 test/unit/handler_test.rb