test_console 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,3 +1,9 @@
1
1
  = TestConsole
2
2
 
3
- This project rocks and uses MIT-LICENSE.
3
+ Interactive console for running TestUnit tests against a Rails application.
4
+
5
+ Please note : This console was written specifically to aid with testing a specific application and so has only been tested in a small number of environments. Please report any issues via the [Github issues](https://github.com/adamphillips/test_console/issues) page.
6
+
7
+ For more information see
8
+
9
+ https://github.com/adamphillips/test_console
@@ -1,6 +1,10 @@
1
- # This sets ActionView to use our custom test when checking whether to cache view templates
1
+ # In order to be able to run our tests with cache_classes enabled, we need to be able to control when our views are reloaded.
2
+ # Otherwise view changes won't take effect in our console
3
+ # This sets ActionView to use our custom test when checking whether to cache view templates meaning that we can use this function to expire the view cache as necessary.
2
4
  module ActionView
3
5
  class Resolver
6
+
7
+ # Wether to cache view templates
4
8
  def caching?
5
9
  @caching = TestConsole.views_changed?
6
10
  end
@@ -3,11 +3,20 @@ module TestConsole
3
3
  yield Config
4
4
  end
5
5
 
6
+ # Returns an array of commands for the specfied function.
7
+ # Valid commands are:
8
+ #
9
+ # :run
10
+ # :rerun
11
+ # :quit
12
+ # :help
13
+ #
6
14
  def self.commands(type)
7
15
  command = "#{type}_commands".to_sym # Deliberately not to_s-ing to avoid :
8
16
  TestConsole::Config.send(command) if TestConsole::Config.respond_to?(command)
9
17
  end
10
18
 
19
+ # Configuration options for the test console.
11
20
  module Config
12
21
 
13
22
  # Folders to watch
@@ -23,6 +32,9 @@ module TestConsole
23
32
  mattr_accessor :stop_folders
24
33
  @@stop_folders = ['test/fixtures', 'config/environments']
25
34
 
35
+ # These folders are dropped from class paths when determining a class from a filename
36
+ mattr_accessor :drop_folders
37
+ @@drop_folders = ['test', 'unit', 'functional', 'helpers', 'integration']
26
38
 
27
39
  # CLI Commands
28
40
  #
@@ -62,11 +74,11 @@ module TestConsole
62
74
  @@backtrace_local_color = @@error_color
63
75
  @@backtrace_gem_color = :magenta
64
76
 
65
- # Fail
77
+ # Failed test runs
66
78
  mattr_accessor :fail_color
67
79
  @@fail_color = :magenta
68
80
 
69
- # Success
81
+ # Successful test runs
70
82
  mattr_accessor :success_color
71
83
  @@success_color = :green
72
84
 
@@ -9,6 +9,14 @@ module TestConsole
9
9
  # =================
10
10
  # Functions to format and display output
11
11
 
12
+ # Writes content out to the terminal
13
+ # Use Hirb to format tables.
14
+ # Can specify a color using one of the defined color constants
15
+ #
16
+ # Examples
17
+ #
18
+ # out 'some_text', :blue # Prints out the text in blue
19
+ #
12
20
  def out(text, text_color=nil, *opts)
13
21
  extend Hirb::Console
14
22
  text = text.to_a if text.kind_of? ActiveRecord::Base
@@ -24,6 +32,8 @@ module TestConsole
24
32
  end
25
33
  end
26
34
 
35
+ # Puts out an error.
36
+ # The error is written to STDERR and colored in the error color.
27
37
  def error(message, backtrace=nil)
28
38
  STDERR.puts color(message, error_color)
29
39
  backtrace.each {|line| line_color = (line[0..1] == '/') ? backtrace_local_color : backtrace_gem_color; STDERR.puts color(line, line_color)} unless backtrace.nil? || backtrace.empty?
@@ -37,6 +47,7 @@ module TestConsole
37
47
  end
38
48
  end
39
49
 
50
+ # Outputs a summary of the results
40
51
  def print_result_summary(result, time_taken=0)
41
52
  if result.failure_count == 0 && result.error_count == 0
42
53
  final_color = success_color
@@ -3,8 +3,16 @@ module TestConsole
3
3
  include TestConsole::Colors
4
4
  include TestConsole::Config
5
5
 
6
- # Checks that the specified path is valid
7
- # If so it creates a test suite from the path and runs it
6
+ # Checks that the specified path is valid.
7
+ # If so it creates a test suite from the path and runs it.
8
+ # If a filter is passed as a string or regex, individual test names are filtered by the expression.
9
+ #
10
+ # Examples:
11
+ #
12
+ # run './unit' # Run every test in the unit folder
13
+ # run './unit/a_model_test.rb' # Run the specific test file
14
+ # run './unit', 'update' # Run every test in the unit folder that has update in the test name
15
+ # run './unit/a_model_test.rb' /update/i # Run every test in specified file whose name contains a case-insensitve version of 'update'
8
16
  def run path, filter=nil
9
17
  begin
10
18
  unless path && !path.empty?
@@ -36,6 +44,14 @@ module TestConsole
36
44
  end
37
45
 
38
46
  # Reruns previous failures or errors
47
+ # Can either just run errors or failures
48
+ #
49
+ # Examples:
50
+ #
51
+ # rerun # Rerun everything
52
+ # rerun :errors # Rerun errors
53
+ # rerun :failures # Rerun failures
54
+ #
39
55
  def rerun type=nil
40
56
  return false unless @last_run_path
41
57
 
@@ -66,6 +82,7 @@ module TestConsole
66
82
  end
67
83
 
68
84
  # Runs a defined suite of tests
85
+ # Outputs the results
69
86
  def run_suite(suite)
70
87
  @abort = false
71
88
  @running = true
@@ -107,6 +124,8 @@ module TestConsole
107
124
  @last_run_time = Time.now
108
125
  end
109
126
 
127
+ # If there is a test suite running, the run is aborted
128
+ # Otherwise the console is killed
110
129
  def abort
111
130
  (@running) ? @abort = true : die
112
131
  end
@@ -4,9 +4,17 @@ module TestConsole
4
4
  base.extend(ClassMethods)
5
5
  end
6
6
 
7
+ # Returns an array of class components from a filename
8
+ #
9
+ # Common folder names are dropped from the array to avoid confusion.
10
+ #
11
+ # Examples:
12
+ #
13
+ # class_from_filename module/controller # ['Module', 'Controller']
14
+ # class_from_filename unit/module/controller # ['Module', 'Controller']
15
+ # class_from_filename parent/module/controller # ['Parent', 'Module', 'Controller']
16
+ #
7
17
  module ClassMethods
8
- ## Returns an array of class components from a filename
9
- ## eg for module/controller => ['Module', 'Controller']
10
18
  def class_from_filename(filename)
11
19
  segs = filename.split('/')
12
20
  segs.delete ''
@@ -14,13 +22,20 @@ module TestConsole
14
22
  segs.last.gsub!('.rb', '')
15
23
 
16
24
  # drop the test folder
17
- segs = segs[1..-1] while segs[0] == 'test'
18
- segs = segs[1..-1] while ['unit', 'functional', 'helpers', 'integration'].include?(segs[0])
25
+ segs = segs[1..-1] while TestConsole.drop_folders.include?(segs[0])
19
26
  ret = segs.map {|seg| seg.camelize}
20
27
 
21
28
  return ret
22
29
  end
23
30
 
31
+ # Returns boolean as to wether the specified constant is defined.
32
+ #
33
+ # Examples:
34
+ #
35
+ # const_defined? 'String' # true
36
+ # const_defined? 'WierdClass' # false
37
+ # const_defined? ['ActiveRecord', 'Base'] # true (assuming Active Record is installed)
38
+ #
24
39
  def const_defined?(klass)
25
40
  klass = [klass] unless klass.kind_of? Array
26
41
  klass.inject(Object) do |context, scope|
@@ -32,6 +47,13 @@ module TestConsole
32
47
  end
33
48
  end
34
49
 
50
+ # Returns the specified class.
51
+ #
52
+ # Examples:
53
+ #
54
+ # const_get 'String' # String
55
+ # const_get ['ActiveRecord', 'Base'] # ActiveRecord::Base
56
+ #
35
57
  def const_get(klass)
36
58
  klass = [klass] unless klass.kind_of? Array
37
59
  klass.inject(Object) do |context, scope|
@@ -39,6 +61,13 @@ module TestConsole
39
61
  end
40
62
  end
41
63
 
64
+ # Removes the specified class.
65
+ #
66
+ # Examples:
67
+ #
68
+ # const_get 'String' # String
69
+ # const_get ['ActiveRecord', 'Base'] # ActiveRecord::Base
70
+ #
42
71
  def const_remove(klass)
43
72
  klass = [klass] unless klass.kind_of? Array
44
73
  if klass.length > 1
@@ -1,3 +1,3 @@
1
1
  module TestConsole
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -1738,3 +1738,40 @@ Connecting to database specified by database.yml
1738
1738
   (0.0ms) rollback transaction
1739
1739
   (0.0ms) begin transaction
1740
1740
   (0.0ms) rollback transaction
1741
+ Connecting to database specified by database.yml
1742
+  (0.0ms) begin transaction
1743
+  (0.0ms) rollback transaction
1744
+  (0.0ms) begin transaction
1745
+  (0.0ms) rollback transaction
1746
+  (0.0ms) begin transaction
1747
+  (0.0ms) rollback transaction
1748
+  (0.0ms) begin transaction
1749
+  (0.0ms) rollback transaction
1750
+  (0.0ms) begin transaction
1751
+  (0.0ms) rollback transaction
1752
+  (0.0ms) begin transaction
1753
+  (0.0ms) rollback transaction
1754
+  (0.0ms) begin transaction
1755
+  (0.0ms) rollback transaction
1756
+  (0.0ms) begin transaction
1757
+  (0.0ms) rollback transaction
1758
+  (0.0ms) begin transaction
1759
+  (0.0ms) rollback transaction
1760
+  (0.0ms) begin transaction
1761
+  (0.0ms) rollback transaction
1762
+  (0.0ms) begin transaction
1763
+  (0.0ms) rollback transaction
1764
+  (0.0ms) begin transaction
1765
+  (0.0ms) rollback transaction
1766
+  (0.0ms) begin transaction
1767
+  (0.0ms) rollback transaction
1768
+  (0.0ms) begin transaction
1769
+  (0.0ms) rollback transaction
1770
+  (0.0ms) begin transaction
1771
+  (0.0ms) rollback transaction
1772
+  (0.0ms) begin transaction
1773
+  (0.0ms) rollback transaction
1774
+  (0.0ms) begin transaction
1775
+  (0.0ms) rollback transaction
1776
+  (0.0ms) begin transaction
1777
+  (0.0ms) rollback transaction
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test_console
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adam Phillips