duck_test 0.1.4 → 0.1.5

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.
@@ -0,0 +1,20 @@
1
+ module DuckTest
2
+
3
+ # ...
4
+ class Autorun
5
+
6
+ ##################################################################################
7
+ def self.config
8
+ ::Test::Unit::Runner.class_eval do
9
+ alias_method :original_run, :run
10
+ def run(args = [])
11
+ if DuckTest::FrameWork::Base.ok_to_run
12
+ original_run(args)
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -4,6 +4,7 @@ require "duck_test/version"
4
4
  module DuckTest
5
5
 
6
6
  autoload :AutoloadConfig, 'duck_test/autoload_config'
7
+ autoload :Autorun, 'duck_test/autorun'
7
8
  autoload :Config, 'duck_test/config'
8
9
  autoload :ConfigHelper, 'duck_test/config_helper'
9
10
  autoload :Console, 'duck_test/console'
@@ -128,6 +128,18 @@ module DuckTest
128
128
 
129
129
  end
130
130
 
131
+ ##################################################################################
132
+ # Global flag used to prevent Test::Unit::Runner from running automatically after exiting the console
133
+ # @return [Boolean]
134
+ def self.ok_to_run
135
+ @@ok_to_run = false unless defined?(@@ok_to_run)
136
+ return @@ok_to_run
137
+ end
138
+
139
+ def self.ok_to_run=(value)
140
+ @@ok_to_run = value
141
+ end
142
+
131
143
  ##################################################################################
132
144
  # Processes a list of file specifications and prepares them to be run
133
145
  def queue_event(event)
@@ -303,8 +315,13 @@ module DuckTest
303
315
 
304
316
  self.pre_run.call self unless self.pre_run.blank?
305
317
 
318
+ self.class.ok_to_run = true
319
+
306
320
  run_tests
307
321
 
322
+ # prevents tests from autorunning when the console exits.
323
+ self.class.ok_to_run = false
324
+
308
325
  self.post_run.call self unless self.post_run.blank?
309
326
 
310
327
  end
@@ -314,8 +331,11 @@ module DuckTest
314
331
  Process.wait pid
315
332
 
316
333
  end
317
-
318
- ActiveRecord::Base.connection_pool.verify_active_connections! if defined?(ActiveRecord::Base)
334
+
335
+ if defined?(ActiveRecord::Base)
336
+ ::ActiveRecord::Base.clear_active_connections!
337
+ ::ActiveRecord::Base.establish_connection
338
+ end
319
339
 
320
340
  end
321
341
 
@@ -20,7 +20,7 @@ module DuckTest
20
20
 
21
21
  ::RSpec::Core::Runner.run([])
22
22
 
23
- puts ::IRB.CurrentContext.io.prompt
23
+ print ::IRB.CurrentContext.io.prompt
24
24
 
25
25
  end
26
26
 
@@ -23,7 +23,7 @@ module DuckTest
23
23
 
24
24
  end
25
25
 
26
- puts ::IRB.CurrentContext.io.prompt
26
+ print ::IRB.CurrentContext.io.prompt
27
27
 
28
28
  end
29
29
 
@@ -9,7 +9,7 @@ module DuckTest
9
9
  end
10
10
 
11
11
  # Custom Logger
12
- class Logger < ActiveSupport::BufferedLogger
12
+ class Logger < ::Logger #ActiveSupport::BufferedLogger
13
13
 
14
14
  SYSTEM = 6
15
15
 
@@ -1,7 +1,5 @@
1
- # TODO figure out a good strategy for setting autoload_paths or getting the test/specs into the load path to run tests in the console.
2
1
  require 'active_support'
3
2
  require 'irb' unless defined?(IRB)
4
- #require 'rspec'
5
3
 
6
4
  module DuckTest
7
5
  extend ActiveSupport::Autoload
@@ -19,8 +17,19 @@ module DuckTest
19
17
  DuckTest::Config.reload!
20
18
  end
21
19
 
22
- #initializer 'duck_test' do
23
- #end
20
+ initializer 'duck_test' do
21
+
22
+ # $0 holds the name of the ruby file initially loaded by the ruby interpreter.
23
+ # this is basicially preventing the run method from being aliased and overridden if the gem
24
+ # is loaded as the result of running a rake task such as rake test:units
25
+ # if started using a command like: rails c test, then, the following if statement should evaluate to true
26
+ # and re-configure Test::Unit::Runner to alias the run method and check a class variable on DuckTest::FrameWork::Base.ok_to_run
27
+ # if true, the tests should run, otherwise, the tests should not run. this should prevent tests from running when
28
+ # the console exits.
29
+ if $0 =~ /rails$/
30
+ Autorun.config
31
+ end
32
+ end
24
33
 
25
34
  IRB::ExtendCommandBundle.send :include, DuckTest::Console
26
35
 
@@ -1,3 +1,3 @@
1
1
  module DuckTest
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duck_test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-22 00:00:00.000000000 Z
12
+ date: 2012-03-01 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: DuckTest is a gem that facilitates automated running of TestUnit and
15
15
  RSpec tests directly in the IRB console. Tests run within a second of being changed.
@@ -32,6 +32,7 @@ files:
32
32
  - lib/duck_test/option_parser.rb
33
33
  - lib/duck_test/usage.rb
34
34
  - lib/duck_test/commands.rb
35
+ - lib/duck_test/autorun.rb
35
36
  - lib/duck_test/platforms/dependencies.rb
36
37
  - lib/duck_test/platforms/watch_event.rb
37
38
  - lib/duck_test/platforms/listener.rb