automated-commands 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,22 @@
1
1
  # encoding: utf-8
2
+ require 'drb'
3
+
2
4
  module AutomatedCommands
3
5
  module Rails
4
6
  module ConsoleMethods
5
7
  def start_test_listener
6
8
  original_trap = Signal.trap("SIGINT", proc { raise "exit" })
7
9
 
10
+ mapping = {
11
+ "models" => "unit",
12
+ "controllers" => "functional"
13
+ }
14
+
15
+ distributed_test_result = TestResult.new(0, 0, 0, 0, 0)
16
+ last_test_result = nil
17
+
18
+ DRb.start_service 'druby://:9191', distributed_test_result
19
+
8
20
  loop do
9
21
  begin
10
22
  input = open(::Rails.root.join("test_pipe"), "r+")
@@ -12,18 +24,54 @@ module AutomatedCommands
12
24
  path = input.gets # e.g. test/unit/some_test.rb
13
25
 
14
26
  reload!
15
- if path =~ /test\/(.*)\/.*\.rb/
16
- # p "test '#{$1}'"
17
- test $1
27
+ if path =~ /test\/(.*)\/(.*)_test\.rb/
28
+ test "#{$1}/#{$2}"
29
+
30
+ if last_test_result.present? && last_test_result.failures > 0 && distributed_test_result.failures < 1
31
+ test $1
32
+ end
33
+ last_test_result = distributed_test_result.dup
34
+
35
+ elsif path =~ /app\/(.*)\/(.*)\.rb/
36
+ tests = "#{mapping[$1]}/#{$2}"
37
+
38
+ test tests
18
39
  end
19
40
  rescue => e
41
+ p e
20
42
  break
21
43
  end
22
44
  end
23
45
 
24
46
  Signal.trap("SIGINT", &original_trap)
47
+ DRb.stop_service
48
+
25
49
  nil
26
50
  end
27
51
  end
28
52
  end
53
+ end
54
+
55
+ # monkey patch commands to publish test results via drb
56
+ module Rails
57
+ module Commands
58
+ class Tester
59
+ private
60
+ def trigger_runner
61
+ if defined?(Test::Unit::TestCase) && ActiveSupport::TestCase.ancestors.include?(Test::Unit::TestCase)
62
+ runner = MiniTest::Unit.runner
63
+ runner.run
64
+
65
+ counter = DRbObject.new nil, 'druby://:9191'
66
+ counter.errors = runner.errors
67
+ counter.failures = runner.failures
68
+ counter.skips = runner.skips
69
+ counter.test_count = runner.test_count
70
+ counter.assertion_count = runner.assertion_count
71
+ else
72
+ # MiniTest::Spec setups in Rails 4.0+ has autorun defined
73
+ end
74
+ end
75
+ end
76
+ end
29
77
  end
@@ -2,7 +2,7 @@
2
2
  module AutomatedCommands
3
3
  class Railtie < ::Rails::Railtie
4
4
  initializer "automated_commands.environment" do |app|
5
- if ::Rails.env.test?
5
+ if ::Rails.env.test? && defined?(::IRB)
6
6
  ::IRB::ExtendCommandBundle.send :include, ::AutomatedCommands::Rails::ConsoleMethods
7
7
  end
8
8
  end
@@ -0,0 +1,4 @@
1
+ module AutomatedCommands
2
+ class TestResult < Struct.new(:errors, :failures, :skips, :test_count, :assertion_count)
3
+ end
4
+ end
@@ -1,3 +1,3 @@
1
1
  module AutomatedCommands
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require "automated_commands/version"
2
+ require "automated_commands/test_result"
2
3
 
3
4
  require "automated_commands/rails/console_methods"
4
5
 
data/tasks/watch.rake CHANGED
@@ -9,7 +9,7 @@ namespace :automated_commands do
9
9
 
10
10
  p "listening for changes in your tests"
11
11
 
12
- Listen.to('test', filter: /.*_test\.rb$/, latency: 0.2) do |modified, added, removed|
12
+ Listen.to('test', 'app', filter: /.*\.rb$/, latency: 0.2) do |modified, added, removed|
13
13
  output = open("test_pipe", "w+")
14
14
 
15
15
  (modified || []).each do |modified_file|
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.2
5
+ version: 0.0.4
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 00:00:00.000000000 Z
12
+ date: 2013-02-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  version_requirements: !ruby/object:Gem::Requirement
@@ -75,6 +75,7 @@ files:
75
75
  - lib/automated_commands.rb
76
76
  - lib/automated_commands/rails/console_methods.rb
77
77
  - lib/automated_commands/railtie.rb
78
+ - lib/automated_commands/test_result.rb
78
79
  - lib/automated_commands/version.rb
79
80
  - tasks/watch.rake
80
81
  homepage: ''