rspactor 0.2.0 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/interactor.rb DELETED
@@ -1,63 +0,0 @@
1
- require 'timeout'
2
-
3
- class Interactor
4
-
5
- def initialize
6
- ticker
7
- end
8
-
9
- def wait_for_enter_key(msg, seconds_to_wait)
10
- begin
11
- Timeout::timeout(seconds_to_wait) do
12
- ticker(:start => true, :msg => msg)
13
- $stdin.gets
14
- return true
15
- end
16
- rescue Timeout::Error
17
- false
18
- ensure
19
- ticker(:stop => true)
20
- end
21
- end
22
-
23
- def start_termination_handler
24
- @main_thread = Thread.current
25
- Thread.new do
26
- loop do
27
- sleep 0.5
28
- if $stdin.gets
29
- if wait_for_enter_key("** Running all specs.. Hit <enter> again to exit RSpactor", 3)
30
- @main_thread.exit
31
- exit
32
- end
33
- Runner.run_all_specs
34
- end
35
- end
36
- end
37
- end
38
-
39
-
40
- private
41
-
42
- def ticker(opts = {})
43
- if opts[:stop]
44
- $stdout.puts "\n"
45
- @pointer_running = false
46
- elsif opts[:start]
47
- @pointer_running = true
48
- write(opts[:msg]) if opts[:msg]
49
- else
50
- Thread.new do
51
- loop do
52
- write('.') if @pointer_running == true
53
- sleep 1.0
54
- end
55
- end
56
- end
57
- end
58
-
59
- def write(msg)
60
- $stdout.print(msg)
61
- $stdout.flush
62
- end
63
- end
data/lib/listener.rb DELETED
@@ -1,55 +0,0 @@
1
- # Some code borrowed from http://rails.aizatto.com/2007/11/28/taming-the-autotest-beast-with-fsevents/
2
-
3
- class Listener
4
-
5
- def initialize(&block)
6
- require 'osx/foundation'
7
- begin
8
- @spec_run_time = Time.now
9
- callback = lambda do |stream, ctx, num_events, paths, marks, event_ids|
10
- changed_files = extract_changed_files_from_paths(split_paths(paths, num_events))
11
- @spec_run_time = Time.now
12
- yield changed_files
13
- end
14
-
15
- OSX.require_framework '/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework'
16
- stream = OSX::FSEventStreamCreate(OSX::KCFAllocatorDefault, callback, nil, [Dir.pwd], OSX::KFSEventStreamEventIdSinceNow, 0.5, 0)
17
- unless stream
18
- puts "Failed to create stream"
19
- exit
20
- end
21
-
22
- OSX::FSEventStreamScheduleWithRunLoop(stream, OSX::CFRunLoopGetCurrent(), OSX::KCFRunLoopDefaultMode)
23
- unless OSX::FSEventStreamStart(stream)
24
- puts "Failed to start stream"
25
- exit
26
- end
27
-
28
- OSX::CFRunLoopRun()
29
- rescue Interrupt
30
- OSX::FSEventStreamStop(stream)
31
- OSX::FSEventStreamInvalidate(stream)
32
- OSX::FSEventStreamRelease(stream)
33
- end
34
- end
35
-
36
- def split_paths(paths, num_events)
37
- paths.regard_as('*')
38
- rpaths = []
39
- num_events.times { |i| rpaths << paths[i] }
40
- rpaths
41
- end
42
-
43
- def extract_changed_files_from_paths(paths)
44
- changed_files = []
45
- paths.each do |path|
46
- Dir.glob(path + "*").each do |file|
47
- next if Inspector.file_is_invalid?(file)
48
- file_time = File.stat(file).mtime
49
- changed_files << file if file_time > @spec_run_time
50
- end
51
- end
52
- changed_files
53
- end
54
-
55
- end
data/lib/resulting.rb DELETED
@@ -1,47 +0,0 @@
1
- class RSpactorFormatter
2
- attr_accessor :example_group, :options, :where
3
- def initialize(options, where)
4
- @options = options
5
- @where = where
6
- end
7
-
8
- def dump_summary(duration, example_count, failure_count, pending_count)
9
- img = (failure_count == 0) ? "rails_ok.png" : "rails_fail.png"
10
- growl "Test Results", "#{example_count} examples, #{failure_count} failures", File.dirname(__FILE__) + "/../asset/#{img}", 0
11
- end
12
-
13
- def start(example_count)
14
- end
15
-
16
- def add_example_group(example_group)
17
- end
18
-
19
- def example_started(example)
20
- end
21
-
22
- def example_passed(example)
23
- end
24
-
25
- def example_failed(example, counter, failure)
26
- end
27
-
28
- def example_pending(example_group_description, example, message)
29
- end
30
-
31
- def start_dump
32
- end
33
-
34
- def dump_failure(counter, failure)
35
- end
36
-
37
- def dump_pending
38
- end
39
-
40
- def close
41
- end
42
-
43
- def growl(title, msg, img, pri = 0)
44
- system("growlnotify -w -n rspactor --image #{img} -p #{pri} -m #{msg.inspect} #{title} &")
45
- end
46
- end
47
-
data/lib/runner.rb DELETED
@@ -1,81 +0,0 @@
1
- class Runner
2
-
3
- def self.load
4
- @inspector = Inspector.new
5
- @interactor = Interactor.new
6
-
7
- puts "** RSpactor is now watching at '#{Dir.pwd}'"
8
-
9
- if initial_spec_run_abort
10
- @interactor.start_termination_handler
11
- else
12
- @interactor.start_termination_handler
13
- run_all_specs
14
- end
15
-
16
- Listener.new do |files|
17
- files_to_spec = []
18
- files.each do |file|
19
- spec_file = @inspector.find_spec_file(file)
20
- if spec_file
21
- puts spec_file
22
- files_to_spec << spec_file
23
- end
24
- end
25
- run_spec_command(files_to_spec) unless files_to_spec.empty?
26
- end
27
- end
28
-
29
- def self.run_all_specs
30
- run_spec_command([@inspector.inner_spec_directory(Dir.pwd)])
31
- end
32
-
33
- def self.run_specs_for_files(files, verbose = false)
34
- files_to_spec = []
35
- files.each do |file|
36
- spec_file = @inspector.find_spec_file(file)
37
- if spec_file
38
- puts spec_file if verbose
39
- files_to_spec << spec_file
40
- end
41
- end
42
- run_spec_command(files_to_spec) unless files_to_spec.empty?
43
- end
44
-
45
- def self.run_spec_command(locations)
46
- base_spec_root = extract_spec_root(locations.first)
47
- spec_runner_bin = script_runner(locations.first)
48
- locations = locations.join(" ")
49
- cmd = "RAILS_ENV=test; "
50
- cmd << "#{spec_runner_bin} "
51
- cmd << "#{locations} #{spec_opts(base_spec_root)} "
52
- cmd << "-r #{File.dirname(__FILE__)}/../lib/resulting.rb -f RSpactorFormatter:STDOUT"
53
- #puts cmd
54
- system(cmd)
55
- end
56
-
57
- def self.extract_spec_root(file)
58
- file[0..file.index("spec") + 4]
59
- end
60
-
61
- def self.spec_opts(base_spec_root)
62
- if File.exist?("#{base_spec_root}spec.opts")
63
- return "-O #{base_spec_root}spec.opts"
64
- else
65
- return "-c -f progress"
66
- end
67
- end
68
-
69
- def self.initial_spec_run_abort
70
- @interactor.wait_for_enter_key("** Hit <enter> to skip initial spec run", 3)
71
- end
72
-
73
- def self.script_runner(file)
74
- root = file[0..file.index("spec") - 1]
75
- if File.exist?(root + "script/spec")
76
- return root + "script/spec"
77
- else
78
- "spec"
79
- end
80
- end
81
- end