tconsole 1.2.8 → 1.3.0.pre0

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,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.join(File.dirname(__FILE__), "..", "lib", "tconsole")
4
+
5
+ TConsole::Runner.new(:rspec, ARGV).run
@@ -2,4 +2,4 @@
2
2
 
3
3
  require File.join(File.dirname(__FILE__), "..", "lib", "tconsole")
4
4
 
5
- TConsole::Runner.new(ARGV).run
5
+ TConsole::Runner.new(:minitest, ARGV).run
@@ -11,9 +11,8 @@ require "tconsole/config"
11
11
  require "tconsole/reporter"
12
12
  require "tconsole/console"
13
13
  require "tconsole/server"
14
+ require "tconsole/minitest_server"
15
+ require "tconsole/rspec_server"
14
16
  require "tconsole/test_result"
15
17
  require "tconsole/util"
16
18
  require "tconsole/runner"
17
-
18
-
19
-
@@ -1,5 +1,8 @@
1
1
  module TConsole
2
2
  class Config
3
+ # Lets us know if we're running rspec or minitest
4
+ attr_accessor :mode
5
+
3
6
  # Lets us know if we should include trace output
4
7
  attr_accessor :trace_execution
5
8
 
@@ -37,15 +40,31 @@ module TConsole
37
40
  # Only runs the command passed on the command line, and then exits
38
41
  attr_accessor :once
39
42
 
40
- def initialize(argv = [])
43
+ def initialize(mode, argv = [])
44
+ self.mode = mode
45
+
41
46
  self.trace_execution = false
42
- self.test_dir = "test"
43
- self.include_paths = ["./test", "./lib"]
47
+
48
+ if mode == :rspec
49
+ self.test_dir = "spec"
50
+ self.include_paths = ["./spec", "./lib"]
51
+ else
52
+ self.test_dir = "test"
53
+ self.include_paths = ["./test", "./lib"]
54
+ end
55
+
44
56
  self.preload_paths = []
45
57
  self.fail_fast = false
46
- self.file_sets = {
47
- "all" => ["#{test_dir}/**/*_test.rb"]
48
- }
58
+
59
+ if mode == :rspec
60
+ self.file_sets = {
61
+ "all" => ["#{test_dir}/**/*_spec.rb"]
62
+ }
63
+ else
64
+ self.file_sets = {
65
+ "all" => ["#{test_dir}/**/*_test.rb"]
66
+ }
67
+ end
49
68
 
50
69
  # load any args into this config that were passed
51
70
  load_args(argv)
@@ -156,21 +175,24 @@ module TConsole
156
175
  end
157
176
 
158
177
  # Returns an appropriate tconsole config based on the environment
159
- def self.configure(argv = [])
160
- config = Config.new(argv)
178
+ def self.configure(mode, argv = [])
179
+ config = Config.new(mode, argv)
161
180
 
162
181
  if is_rails?
163
182
  config.preload_paths = ["./config/application"]
164
- config.include_paths = ["./test"]
165
- config.file_sets = {
166
- "all" => ["#{config.test_dir}/unit/**/*_test.rb", "#{config.test_dir}/functional/**/*_test.rb",
167
- "#{config.test_dir}/integration/**/*_test.rb"],
168
- "units" => ["#{config.test_dir}/unit/**/*_test.rb"],
169
- "unit" => ["#{config.test_dir}/unit/**/*_test.rb"],
170
- "functionals" => ["#{config.test_dir}/functional/**/*_test.rb"],
171
- "functional" => ["#{config.test_dir}/functional/**/*_test.rb"],
172
- "integration" => ["#{config.test_dir}/integration/**/*_test.rb"]
173
- }
183
+
184
+ if mode == :minitest
185
+ config.include_paths = ["./test"]
186
+ config.file_sets = {
187
+ "all" => ["#{config.test_dir}/unit/**/*_test.rb", "#{config.test_dir}/functional/**/*_test.rb",
188
+ "#{config.test_dir}/integration/**/*_test.rb"],
189
+ "units" => ["#{config.test_dir}/unit/**/*_test.rb"],
190
+ "unit" => ["#{config.test_dir}/unit/**/*_test.rb"],
191
+ "functionals" => ["#{config.test_dir}/functional/**/*_test.rb"],
192
+ "functional" => ["#{config.test_dir}/functional/**/*_test.rb"],
193
+ "integration" => ["#{config.test_dir}/integration/**/*_test.rb"]
194
+ }
195
+ end
174
196
 
175
197
  config.before_load do
176
198
  ENV["RAILS_ENV"] ||= "test"
@@ -0,0 +1,120 @@
1
+ module TConsole
2
+ class MinitestServer < Server
3
+
4
+ # Loads the files that match globs and then executes tests against them. Limit tests
5
+ # with class names, method names, and test ids using match_patterns.
6
+ def run_tests(globs, match_patterns, message = "Running tests...")
7
+ time = Benchmark.realtime do
8
+ reporter.info(message)
9
+ reporter.info
10
+
11
+ paths = []
12
+ globs.each do |glob|
13
+ paths.concat(Dir.glob(glob))
14
+ end
15
+
16
+ if paths.length == 0
17
+ reporter.warn("No test files match your requested test set: #{globs.join(",")}.")
18
+ reporter.warn("Skipping execution.")
19
+ return nil
20
+ end
21
+
22
+ self.last_result = run_in_fork do
23
+
24
+ paths.each do |path|
25
+ reporter.trace("Requested path `#{path}` doesn't exist.") unless File.exist?(path)
26
+ require File.expand_path(path)
27
+ end
28
+
29
+ reporter.trace("Running before_test_run callback")
30
+ config.before_test_run!
31
+ reporter.trace("Completed before_test_run callback")
32
+
33
+ result = nil
34
+ if defined?(::MiniTest)
35
+ reporter.trace("Detected minitest.")
36
+ require File.join(File.dirname(__FILE__), "minitest_handler")
37
+
38
+ reporter.trace("Running tests.")
39
+ runner = MiniTestHandler.setup(match_patterns, config)
40
+
41
+ # Handle trapping interrupts
42
+ trap("SIGINT") do
43
+ reporter.warn
44
+ reporter.warn("Trapped interrupt. Halting tests.")
45
+
46
+ runner.interrupted = true
47
+ end
48
+
49
+ runner.run
50
+
51
+ result = runner.results
52
+
53
+ # Make sure minitest doesn't run automatically
54
+ MiniTestHandler.patch_minitest
55
+
56
+ reporter.trace("Finished running tests.")
57
+
58
+ if runner.interrupted
59
+ reporter.error("Test run was interrupted.")
60
+ end
61
+
62
+ elsif defined?(::Test::Unit)
63
+ reporter.error("Sorry, but tconsole doesn't support Test::Unit")
64
+ end
65
+
66
+ result
67
+ end
68
+
69
+ if self.last_result == nil
70
+ # Just in case anything crazy goes down with marshalling
71
+ self.last_result = TConsole::TestResult.new
72
+ end
73
+
74
+ config.cache_test_ids(self.last_result)
75
+
76
+ true
77
+ end
78
+
79
+ reporter.info
80
+ reporter.info("Tests ran in #{"%0.6f" % time}s. Finished at #{Time.now.strftime('%Y-%m-%d %l:%M:%S %p')}.")
81
+ reporter.info
82
+ end
83
+
84
+ # Preloads our autocomplete cache
85
+ def preload_test_ids
86
+ result = run_in_fork do
87
+ paths = []
88
+ config.file_sets["all"].each do |glob|
89
+ paths.concat(Dir.glob(glob))
90
+ end
91
+
92
+ paths.each { |path| require File.expand_path(path) }
93
+
94
+ require File.join(File.dirname(__FILE__), "minitest_handler")
95
+ MiniTestHandler.preload_elements
96
+ end
97
+
98
+ config.cache_test_ids(result) unless result.nil?
99
+ end
100
+
101
+ # Runs all tests against the match patterns given
102
+ def run_all_tests(match_patterns = nil)
103
+ run_tests(config.file_sets["all"], match_patterns)
104
+ end
105
+
106
+ # Runs a file set out of the config
107
+ def run_file_set(set)
108
+ run_tests(config.file_sets[set], nil)
109
+ end
110
+
111
+ def run_failed
112
+ if last_result.failures.empty?
113
+ reporter.info("No tests failed in your last run, or you haven't run any tests in this session yet.")
114
+ reporter.info
115
+ else
116
+ run_tests(config.file_sets["all"], last_result.failures)
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,135 @@
1
+ module TConsole
2
+ class RSpecServer < Server
3
+
4
+ # Loads the files that match globs and then executes tests against them. Limit tests
5
+ # with class names, method names, and test ids using match_patterns.
6
+ def run_tests(globs, match_patterns, message = "Running tests...")
7
+ time = Benchmark.realtime do
8
+ reporter.info(message)
9
+ reporter.info
10
+
11
+ paths = []
12
+ globs.each do |glob|
13
+ paths.concat(Dir.glob(glob))
14
+ end
15
+
16
+ if paths.length == 0
17
+ reporter.warn("No test files match your requested test set: #{globs.join(",")}.")
18
+ reporter.warn("Skipping execution.")
19
+ return nil
20
+ end
21
+
22
+ self.last_result = run_in_fork do
23
+
24
+ # Make sure rspec is loaded up
25
+ require 'rspec'
26
+
27
+ paths.each do |path|
28
+ reporter.trace("Requested path `#{path}` doesn't exist.") unless File.exist?(path)
29
+ require File.expand_path(path)
30
+ end
31
+
32
+ reporter.trace("Running before_test_run callback")
33
+ config.before_test_run!
34
+ reporter.trace("Completed before_test_run callback")
35
+
36
+ result = nil
37
+ if defined?(::RSpec)
38
+ reporter.trace("Detected rspec.")
39
+
40
+ reporter.trace("Running tests.")
41
+
42
+ # Handle trapping interrupts
43
+ trap("SIGINT") do
44
+ reporter.warn
45
+ reporter.warn("Trapped interrupt. Halting tests.")
46
+ end
47
+
48
+ # Actually run the tests!
49
+ configuration = RSpec::configuration
50
+ world = RSpec::world
51
+ options = RSpec::Core::ConfigurationOptions.new([])
52
+ options.parse_options
53
+
54
+ configuration.error_stream = STDERR
55
+ configuration.output_stream = STDOUT
56
+
57
+ options.configure(configuration)
58
+
59
+ configuration.files_to_run = paths
60
+
61
+ configuration.reporter.report(world.example_count, configuration.randomize? ? configuration.seed : nil) do |reporter|
62
+ begin
63
+ configuration.run_hook(:before, :suite)
64
+ world.example_groups.ordered.map {|g| g.run(reporter)}.all? ? 0 : configuration.failure_exit_code
65
+ ensure
66
+ configuration.run_hook(:after, :suite)
67
+ end
68
+ end
69
+
70
+ # Patch RSpec to disable autorun
71
+ ::RSpec::Core::Runner.class_eval do
72
+ def self.run(args = [], err=$stderr, out=$stdout)
73
+ # do nothing
74
+ end
75
+ end
76
+
77
+ reporter.trace("Finished running tests.")
78
+ end
79
+
80
+ nil
81
+ end
82
+
83
+ if self.last_result == nil
84
+ # Just in case anything crazy goes down with marshalling
85
+ self.last_result = TConsole::TestResult.new
86
+ end
87
+
88
+ config.cache_test_ids(self.last_result)
89
+
90
+ true
91
+ end
92
+
93
+ reporter.info
94
+ reporter.info("Tests ran in #{"%0.6f" % time}s. Finished at #{Time.now.strftime('%Y-%m-%d %l:%M:%S %p')}.")
95
+ reporter.info
96
+ end
97
+
98
+ # Preloads our autocomplete cache
99
+ def preload_test_ids
100
+ result = nil
101
+ # result = run_in_fork do
102
+ # paths = []
103
+ # config.file_sets["all"].each do |glob|
104
+ # paths.concat(Dir.glob(glob))
105
+ # end
106
+ #
107
+ # paths.each { |path| require File.expand_path(path) }
108
+ #
109
+ # require File.join(File.dirname(__FILE__), "minitest_handler")
110
+ # MiniTestHandler.preload_elements
111
+ # end
112
+
113
+ config.cache_test_ids(result) unless result.nil?
114
+ end
115
+
116
+ # Runs all tests against the match patterns given
117
+ def run_all_tests(match_patterns = nil)
118
+ run_tests(config.file_sets["all"], match_patterns)
119
+ end
120
+
121
+ # Runs a file set out of the config
122
+ def run_file_set(set)
123
+ run_tests(config.file_sets[set], nil)
124
+ end
125
+
126
+ def run_failed
127
+ if last_result.failures.empty?
128
+ reporter.info("No tests failed in your last run, or you haven't run any tests in this session yet.")
129
+ reporter.info
130
+ else
131
+ run_tests(config.file_sets["all"], last_result.failures)
132
+ end
133
+ end
134
+ end
135
+ end
@@ -1,19 +1,21 @@
1
1
  module TConsole
2
2
  class Runner
3
3
 
4
- attr_accessor :config, :reporter, :console, :stty_save
4
+ attr_accessor :mode, :config, :reporter, :console, :stty_save
5
5
 
6
6
  # Public: Sets up the new runner's config.
7
- def initialize(argv = [])
7
+ def initialize(mode, argv = [])
8
+ self.mode = mode
9
+
8
10
  # try to load the default configs
9
11
  Config.load_config(File.join(Dir.home, ".tconsole"))
10
12
  Config.load_config(File.join(Dir.pwd, ".tconsole"))
11
- self.config = Config.configure(argv)
13
+ self.config = Config.configure(mode, argv)
12
14
  self.reporter = Reporter.new(config)
13
15
  end
14
16
 
15
- # Spawns a new environment. Looks at the results of the environment to determine whether to stop or
16
- # keep running
17
+ # Spawns a new environment. Looks at the results of the environment to determine
18
+ # whether to stop or keep running
17
19
  def run
18
20
  prepare_process
19
21
  reporter.welcome_message
@@ -108,7 +110,17 @@ module TConsole
108
110
  # Internal: Run loop for the server.
109
111
  def server_run_loop(pipe_server)
110
112
  pipe_server.callee!
111
- server = Server.new(config, reporter)
113
+
114
+ if mode == :minitest
115
+ server = MinitestServer.new(config, reporter)
116
+ elsif mode == :rspec
117
+ server = RSpecServer.new(config, reporter)
118
+ else
119
+ reporter.error
120
+ reporter.error("The given test mode isn't supported.")
121
+ reporter.error
122
+ exit
123
+ end
112
124
 
113
125
  while message = pipe_server.read
114
126
  reporter.trace("Server Received Message: #{message[:action]}")
@@ -214,6 +214,9 @@ module TConsole
214
214
  reporter.info("Defined Constants:")
215
215
  reporter.info(Module.constants.sort.join("\n"))
216
216
  reporter.info
217
+ reporter.info("Configuration:")
218
+ reporter.info("Mode: #{config.mode}")
219
+ reporter.info()
217
220
  reporter.info
218
221
  end
219
222
 
@@ -1,3 +1,3 @@
1
1
  module TConsole
2
- VERSION = "1.2.8"
3
- end
2
+ VERSION = "1.3.0.pre0"
3
+ end
@@ -25,5 +25,4 @@ Gem::Specification.new do |s|
25
25
  # s.add_development_dependency "rspec"
26
26
  s.add_runtime_dependency "chattyproc", "~> 1.0.0"
27
27
  s.add_runtime_dependency "term-ansicolor", "~> 1.0.7"
28
- s.add_runtime_dependency "minitest", "~> 4.3.0"
29
28
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tconsole
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.8
5
- prerelease:
4
+ version: 1.3.0.pre0
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Alan Johnson
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-21 00:00:00.000000000 Z
12
+ date: 2013-01-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chattyproc
@@ -43,22 +43,6 @@ dependencies:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
45
  version: 1.0.7
46
- - !ruby/object:Gem::Dependency
47
- name: minitest
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ~>
52
- - !ruby/object:Gem::Version
53
- version: 4.3.0
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: 4.3.0
62
46
  description: ! " tconsole allows Rails developers to easily and quickly run their
63
47
  tests as a whole or in subsets. It forks the testing processes from\n a preloaded
64
48
  test environment to ensure that developers don't have to reload their entire Rails
@@ -66,6 +50,7 @@ description: ! " tconsole allows Rails developers to easily and quickly run t
66
50
  email:
67
51
  - alan@commondream.net
68
52
  executables:
53
+ - rconsole
69
54
  - tconsole
70
55
  extensions: []
71
56
  extra_rdoc_files: []
@@ -75,13 +60,16 @@ files:
75
60
  - Gemfile
76
61
  - README.md
77
62
  - Rakefile
63
+ - bin/rconsole
78
64
  - bin/tconsole
79
65
  - cibuild
80
66
  - lib/tconsole.rb
81
67
  - lib/tconsole/config.rb
82
68
  - lib/tconsole/console.rb
83
69
  - lib/tconsole/minitest_handler.rb
70
+ - lib/tconsole/minitest_server.rb
84
71
  - lib/tconsole/reporter.rb
72
+ - lib/tconsole/rspec_server.rb
85
73
  - lib/tconsole/runner.rb
86
74
  - lib/tconsole/server.rb
87
75
  - lib/tconsole/test_result.rb
@@ -108,9 +96,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
96
  required_rubygems_version: !ruby/object:Gem::Requirement
109
97
  none: false
110
98
  requirements:
111
- - - ! '>='
99
+ - - ! '>'
112
100
  - !ruby/object:Gem::Version
113
- version: '0'
101
+ version: 1.3.1
114
102
  requirements: []
115
103
  rubyforge_project: tconsole
116
104
  rubygems_version: 1.8.24
@@ -123,3 +111,4 @@ test_files:
123
111
  - spec/sample_config
124
112
  - spec/spec_helper.rb
125
113
  - spec/util_spec.rb
114
+ has_rdoc: