rspactor 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,8 +1,12 @@
1
+ === Dependencies
2
+
3
+ RubyCocoa is needed (you can help to switch to ruby-fsevent, see branches)
4
+
5
+ Installing ruby-cocoa with rvm: http://gist.github.com/294465
6
+
1
7
  === Install
2
8
 
3
- git clone git://github.com/guillaumegentil/rspactor.git
4
- cd rspactor
5
- rake install
9
+ gem install rspactor
6
10
 
7
11
  === Usage
8
12
 
@@ -15,4 +19,4 @@
15
19
  * <code> --drb </code>
16
20
  * <code> --view </code>
17
21
  * <code> --clear </code>
18
- * <code> --run_in </code>
22
+ * <code> --run_in </code>
data/Rakefile CHANGED
@@ -10,7 +10,6 @@ begin
10
10
  gem.email = "thibaud@thibaud.me"
11
11
  gem.homepage = "http://github.com/thibaudgg/rspactor"
12
12
  gem.authors = ["Mislav Marohnić", "Andreas Wolff", "Pelle Braendgaard", "Thibaud Guillaume-Gentil"]
13
- gem.add_dependency "ruby-fsevent", ">= 0.2.1"
14
13
  gem.add_development_dependency "rspec", ">= 1.2.9"
15
14
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
15
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.2
1
+ 0.6.3
@@ -1,38 +1,76 @@
1
- require 'fsevent'
1
+ require 'osx/foundation'
2
+ OSX.require_framework '/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework'
2
3
 
3
4
  module RSpactor
4
- # based on http://github.com/sandro/beholder/commit/2ac026f8fc199b75944b8a2c1a3f80ee277dd81b
5
- class Listener < FSEvent
6
- attr_reader :last_event, :callback, :valid_extensions, :modified_directories
5
+ # based on http://rails.aizatto.com/2007/11/28/taming-the-autotest-beast-with-fsevents/
6
+ class Listener
7
+ attr_reader :last_check, :callback, :valid_extensions
7
8
 
8
9
  def initialize(valid_extensions = nil)
9
10
  @valid_extensions = valid_extensions
10
- update_last_event
11
- super()
11
+ timestamp_checked
12
+
13
+ @callback = lambda do |stream, ctx, num_events, paths, marks, event_ids|
14
+ changed_files = extract_changed_files_from_paths(split_paths(paths, num_events))
15
+ timestamp_checked
16
+ yield changed_files unless changed_files.empty?
17
+ end
12
18
  end
13
19
 
14
- def on_change(directories)
15
- @modified_directories = directories
16
- callback.call(modified_files)
17
- update_last_event
20
+ def run(directories)
21
+ dirs = Array(directories)
22
+ stream = OSX::FSEventStreamCreate(OSX::KCFAllocatorDefault, callback, nil, dirs, OSX::KFSEventStreamEventIdSinceNow, 0.5, 0)
23
+ unless stream
24
+ $stderr.puts "Failed to create stream"
25
+ exit(1)
26
+ end
27
+
28
+ OSX::FSEventStreamScheduleWithRunLoop(stream, OSX::CFRunLoopGetCurrent(), OSX::KCFRunLoopDefaultMode)
29
+ unless OSX::FSEventStreamStart(stream)
30
+ $stderr.puts "Failed to start stream"
31
+ exit(1)
32
+ end
33
+
34
+ begin
35
+ OSX::CFRunLoopRun()
36
+ rescue Interrupt
37
+ OSX::FSEventStreamStop(stream)
38
+ OSX::FSEventStreamInvalidate(stream)
39
+ OSX::FSEventStreamRelease(stream)
40
+ end
18
41
  end
19
42
 
20
- def watch_directories(directories, &block)
21
- super(directories)
22
- @callback = block
43
+ def timestamp_checked
44
+ @last_check = Time.now
23
45
  end
24
46
 
25
-
26
- def potentially_modified_files
27
- Dir.glob(modified_directories.map {|dir| File.join(dir, "**", "*")})
47
+ def split_paths(paths, num_events)
48
+ paths.regard_as('*')
49
+ rpaths = []
50
+ num_events.times { |i| rpaths << paths[i] }
51
+ rpaths
28
52
  end
29
53
 
30
- def modified_files
31
- potentially_modified_files.select do |file|
32
- next if File.directory?(file)
33
- next if ignore_file?(file)
34
- File.mtime(file) >= last_event || File.atime(file) >= last_event
54
+ def extract_changed_files_from_paths(paths)
55
+ changed_files = []
56
+ paths.each do |path|
57
+ next if ignore_path?(path)
58
+ Dir.glob(path + "*").each do |file|
59
+ next if ignore_file?(file)
60
+ changed_files << file if file_changed?(file)
61
+ end
35
62
  end
63
+ changed_files
64
+ end
65
+
66
+ def file_changed?(file)
67
+ File.stat(file).mtime > last_check
68
+ rescue Errno::ENOENT
69
+ false
70
+ end
71
+
72
+ def ignore_path?(path)
73
+ path =~ /(?:^|\/)\.(git|svn)/
36
74
  end
37
75
 
38
76
  def ignore_file?(file)
@@ -46,10 +84,5 @@ module RSpactor
46
84
  def valid_extension?(file)
47
85
  valid_extensions.nil? or valid_extensions.include?(file_extension(file))
48
86
  end
49
-
50
- def update_last_event
51
- @last_event = Time.now
52
- end
53
-
54
87
  end
55
88
  end
@@ -38,12 +38,9 @@ module RSpactor
38
38
  def start_listener
39
39
  @inspector = Inspector.new(self)
40
40
 
41
- @listener = Listener.new(Inspector::EXTENSIONS)
42
- @listener.latency = 0.2
43
- @listener.watch_directories(dir) do |files|
41
+ Listener.new(Inspector::EXTENSIONS) do |files|
44
42
  changed_files(files) unless git_head_changed?
45
- end
46
- @listener.start
43
+ end.run(dir)
47
44
  end
48
45
 
49
46
  def load_dotfile
data/rspactor.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rspactor}
8
- s.version = "0.6.2"
8
+ s.version = "0.6.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mislav Marohni\304\207", "Andreas Wolff", "Pelle Braendgaard", "Thibaud Guillaume-Gentil"]
12
- s.date = %q{2010-01-31}
12
+ s.date = %q{2010-02-04}
13
13
  s.default_executable = %q{rspactor}
14
14
  s.description = %q{RSpactor is a command line tool to automatically run your changed specs & cucumber features (much like autotest).}
15
15
  s.email = %q{thibaud@thibaud.me}
@@ -59,14 +59,11 @@ Gem::Specification.new do |s|
59
59
  s.specification_version = 3
60
60
 
61
61
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
62
- s.add_runtime_dependency(%q<ruby-fsevent>, [">= 0.2.1"])
63
62
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
64
63
  else
65
- s.add_dependency(%q<ruby-fsevent>, [">= 0.2.1"])
66
64
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
67
65
  end
68
66
  else
69
- s.add_dependency(%q<ruby-fsevent>, [">= 0.2.1"])
70
67
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
71
68
  end
72
69
  end
@@ -6,7 +6,15 @@ describe RSpactor::Listener do
6
6
  end
7
7
 
8
8
  it "should be timestamped" do
9
- @listener.last_event.should be_instance_of(Time)
9
+ @listener.last_check.should be_instance_of(Time)
10
+ end
11
+
12
+ it "should not ignore regular directories" do
13
+ @listener.ignore_path?('/project/foo/bar').should_not be
14
+ end
15
+
16
+ it "should ignore .git directories" do
17
+ @listener.ignore_path?('/project/.git/index').should be
10
18
  end
11
19
 
12
20
  it "should ignore dotfiles" do
data/spec/runner_spec.rb CHANGED
@@ -110,9 +110,7 @@ describe RSpactor::Runner do
110
110
  end
111
111
 
112
112
  it "should run Listener" do
113
- @listener.should_receive(:start)
114
- @listener.should_receive(:latency=).with(0.2)
115
- @listener.should_receive(:watch_directories).with('/my/path')
113
+ @listener.should_receive(:run).with('/my/path')
116
114
  RSpactor::Listener.should_receive(:new).with(instance_of(Array)).and_return(@listener)
117
115
  setup
118
116
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspactor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Mislav Marohni\xC4\x87"
@@ -12,19 +12,9 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2010-01-31 00:00:00 +01:00
15
+ date: 2010-02-04 00:00:00 +01:00
16
16
  default_executable: rspactor
17
17
  dependencies:
18
- - !ruby/object:Gem::Dependency
19
- name: ruby-fsevent
20
- type: :runtime
21
- version_requirement:
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: 0.2.1
27
- version:
28
18
  - !ruby/object:Gem::Dependency
29
19
  name: rspec
30
20
  type: :development