automated-commands 0.0.4 → 0.1.0
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/README.md +6 -4
- data/lib/automated_commands.rb +1 -5
- data/lib/automated_commands/rails/console_methods.rb +41 -7
- data/lib/automated_commands/version.rb +1 -1
- metadata +2 -3
- data/tasks/watch.rake +0 -30
data/README.md
CHANGED
@@ -20,16 +20,18 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
You basically need to follow two steps to get it up and running:
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
``` bash
|
24
|
+
$ RAILS_ENV=test bundle exec rails c
|
25
|
+
```
|
26
|
+
``` ruby
|
27
|
+
irb(main):001:0> start_test_listener
|
28
|
+
```
|
26
29
|
|
27
30
|
That's it! Now when you are changing any files located under `test` your tests will be automatically be run.
|
28
31
|
|
29
32
|
## TODO
|
30
33
|
|
31
34
|
- tests
|
32
|
-
- display test results in :watch task output
|
33
35
|
|
34
36
|
## Contributing
|
35
37
|
|
data/lib/automated_commands.rb
CHANGED
@@ -3,8 +3,4 @@ require "automated_commands/test_result"
|
|
3
3
|
|
4
4
|
require "automated_commands/rails/console_methods"
|
5
5
|
|
6
|
-
require "automated_commands/railtie" if defined?(Rails)
|
7
|
-
|
8
|
-
if defined?(Rake)
|
9
|
-
Dir[File.join(File.dirname(__FILE__), "../tasks/*.rake")].each { |ext| load ext }
|
10
|
-
end
|
6
|
+
require "automated_commands/railtie" if defined?(Rails)
|
@@ -1,26 +1,42 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'drb'
|
3
|
+
require 'listen'
|
4
|
+
require 'pathname'
|
3
5
|
|
4
6
|
module AutomatedCommands
|
5
7
|
module Rails
|
6
8
|
module ConsoleMethods
|
7
9
|
def start_test_listener
|
10
|
+
%x[mkfifo ./test_pipe]
|
11
|
+
|
12
|
+
change_listener = setup_change_listener
|
13
|
+
change_listener.start false
|
14
|
+
|
8
15
|
original_trap = Signal.trap("SIGINT", proc { raise "exit" })
|
16
|
+
handle_file_changes # blocks until user stops using STRG+C
|
17
|
+
Signal.trap("SIGINT", &original_trap)
|
18
|
+
|
19
|
+
change_listener.stop
|
20
|
+
%x[rm ./test_pipe]
|
21
|
+
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def handle_file_changes
|
28
|
+
distributed_test_result = TestResult.new(0, 0, 0, 0, 0)
|
29
|
+
last_test_result = nil
|
9
30
|
|
10
31
|
mapping = {
|
11
32
|
"models" => "unit",
|
12
33
|
"controllers" => "functional"
|
13
34
|
}
|
14
35
|
|
15
|
-
distributed_test_result = TestResult.new(0, 0, 0, 0, 0)
|
16
|
-
last_test_result = nil
|
17
|
-
|
18
36
|
DRb.start_service 'druby://:9191', distributed_test_result
|
19
|
-
|
20
37
|
loop do
|
21
38
|
begin
|
22
39
|
input = open(::Rails.root.join("test_pipe"), "r+")
|
23
|
-
|
24
40
|
path = input.gets # e.g. test/unit/some_test.rb
|
25
41
|
|
26
42
|
reload!
|
@@ -43,11 +59,29 @@ module AutomatedCommands
|
|
43
59
|
end
|
44
60
|
end
|
45
61
|
|
46
|
-
Signal.trap("SIGINT", &original_trap)
|
47
62
|
DRb.stop_service
|
48
|
-
|
49
63
|
nil
|
50
64
|
end
|
65
|
+
|
66
|
+
def setup_change_listener
|
67
|
+
return ::Listen::MultiListener.new('test', 'app', filter: /.*\.rb$/, latency: 0.2) do |modified, added, removed|
|
68
|
+
output = open("test_pipe", "w+")
|
69
|
+
|
70
|
+
(modified || []).each do |modified_file|
|
71
|
+
path = Pathname.new(modified_file)
|
72
|
+
|
73
|
+
output.puts path.relative_path_from(Pathname.pwd)
|
74
|
+
output.flush
|
75
|
+
end
|
76
|
+
|
77
|
+
(added || []).each do |added_file|
|
78
|
+
path = Pathname.new(added_file)
|
79
|
+
|
80
|
+
output.puts path.relative_path_from(Pathname.pwd)
|
81
|
+
output.flush
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
51
85
|
end
|
52
86
|
end
|
53
87
|
end
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: automated-commands
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0
|
5
|
+
version: 0.1.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Raphael Randschau
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -77,7 +77,6 @@ files:
|
|
77
77
|
- lib/automated_commands/railtie.rb
|
78
78
|
- lib/automated_commands/test_result.rb
|
79
79
|
- lib/automated_commands/version.rb
|
80
|
-
- tasks/watch.rake
|
81
80
|
homepage: ''
|
82
81
|
licenses: []
|
83
82
|
post_install_message:
|
data/tasks/watch.rake
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
namespace :automated_commands do
|
2
|
-
desc "watch TestUnit files for changes"
|
3
|
-
task :watch do
|
4
|
-
require 'listen'
|
5
|
-
require 'pathname'
|
6
|
-
|
7
|
-
%x[mkfifo ./test_pipe]
|
8
|
-
at_exit { %x[rm ./test_pipe] }
|
9
|
-
|
10
|
-
p "listening for changes in your tests"
|
11
|
-
|
12
|
-
Listen.to('test', 'app', filter: /.*\.rb$/, latency: 0.2) do |modified, added, removed|
|
13
|
-
output = open("test_pipe", "w+")
|
14
|
-
|
15
|
-
(modified || []).each do |modified_file|
|
16
|
-
path = Pathname.new(modified_file)
|
17
|
-
|
18
|
-
output.puts path.relative_path_from(Pathname.pwd)
|
19
|
-
output.flush
|
20
|
-
end
|
21
|
-
|
22
|
-
(added || []).each do |added_file|
|
23
|
-
path = Pathname.new(added_file)
|
24
|
-
|
25
|
-
output.puts path.relative_path_from(Pathname.pwd)
|
26
|
-
output.flush
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|