tconsole-rails4 2.2.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 727e3e5b196fe93217c38ecac412d29386f85bd3
4
+ data.tar.gz: 86daceb46835fe5f7dcfa1b82d868834335cff76
5
+ SHA512:
6
+ metadata.gz: 33ced7d8bdd58a228239a840e5d8e938a7eb54843baa53e3e8d53829eeec34ef32e48b50cbed41af9b50658a42d666a661cccfafbd3394df131961ca1472b90e
7
+ data.tar.gz: e8e317d473e6c1914a8897feacf6ede04462237cc217cb369f8bf2aa9e8addcd7850ad1e604518801a150059826b7fdfe13ad2d2296ef32bc9d86581bcbda45a
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rvmrc
6
+ .rspec
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "bundle/nerdcommenter"]
2
+ path = bundle/nerdcommenter
3
+ url = git://github.com/scrooloose/nerdcommenter.git
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in tconsole.gemspec
4
+ gemspec
5
+
6
+ gem 'rake'
7
+ gem 'rspec'
8
+ gem 'minitest', '5.0.2'
data/README.md ADDED
@@ -0,0 +1,293 @@
1
+ TConsole
2
+ ======
3
+
4
+ TConsole is a testing console for Rails. It allows you to issue commands
5
+ concerning what tests to run, and see their test output. It's also got a
6
+ helpful reload command for when your Rails environment needs to be
7
+ restarted.
8
+
9
+ TConsole should work in pretty much any Unix environment and will work
10
+ with apps running Ruby 1.9. It can be run on pretty much any test suite
11
+ that uses MiniTest, including Rails test suites (though MiniTest::Spec
12
+ isn't supported, unfortunately).
13
+
14
+ It was written by [Alan Johnson][], who passed maintainership over to
15
+ [Graham Ashton][] in July 2013.
16
+
17
+ [Alan Johnson]: https://github.com/commondream
18
+ [Graham Ashton]: https://github.com/gma
19
+
20
+ See it in Action
21
+ ------
22
+
23
+ There's a quick screencast on Vimeo about TConsole's basic features:
24
+ [Meet TConsole!](https://vimeo.com/37641415)
25
+
26
+ Why use TConsole?
27
+ ------
28
+
29
+ * A large amount of time is wasted loading the Rails environment each
30
+ time you run the Rails testing rake tasks. TConsole loads the
31
+ environment when you start the console and whenever you reload the
32
+ environment, but doesn't have to reload the environment for each test
33
+ execution.
34
+ * The Rails rake task syntax `bundle exec rake test:units
35
+ TEST=test/unit/user_test.rb` can be pretty verbose when you're running
36
+ specific tests. Yeah, there are tricks you can use to shorten things
37
+ up, but still, that's crazy long. tconsole lets you just type
38
+ `test/unit/user_test.rb` to get that specific test file to run. With
39
+ TConsole you can just type `UserTest` and the test runs!
40
+ * TConsole makes it dead simple to review how long your tests are taking
41
+ to run and pinpoint your slowest running tests.
42
+ * Re-running failed tests is as easy as typing `!failed` with TConsole.
43
+
44
+ What about Spork?
45
+ ------
46
+
47
+ [Spork](https://github.com/sporkrb/spork)'s really cool, and it was my
48
+ primary motivation behind writing tconsole, but I've always felt like
49
+ having an extra console open for my spork server and another to run my
50
+ commands is a bit heavy for what I want to do. Beyond that, I couldn't
51
+ ever figure out how to get Spork to work with test/unit, and since me
52
+ and DHH are the only two people who still use test/unit I figured it was
53
+ up to me to come up with something that worked great. If Spork's your
54
+ cup of tea, though, stop reading this and use what you like.
55
+
56
+ What about rspec?
57
+ ------
58
+
59
+ We've decided to focus on integrating with MiniTest as tightly as
60
+ possible, rather than worrying about rspec support.
61
+
62
+ Installing TConsole
63
+ ------
64
+ gem install tconsole
65
+
66
+ Prereleases of TConsole come out pretty frequently. You can install the
67
+ latest prerelease version with:
68
+
69
+ gem install tconsole --pre
70
+
71
+ If you're using bundler, you probably want to simply add TConsole to
72
+ your Gemfile:
73
+
74
+ gem "tconsole"
75
+
76
+ How to use TConsole
77
+ ------
78
+
79
+ In your shell of choice, cd into your Rails project's directory and then
80
+ run `bundle exec tconsole` to fire up the console. You should see
81
+ something like this:
82
+
83
+ bundle exec tconsole
84
+
85
+ Loading your Rails environment...
86
+ Environment loaded in 7.160264s.
87
+
88
+ >
89
+
90
+ Now that you're in the console, let's test out the `all` command!
91
+ Running `all` from the console runs all of your unit, functional, and
92
+ integration tests:
93
+
94
+ > all
95
+ Running tests...
96
+
97
+ Run options:
98
+
99
+ # Running tests:
100
+
101
+ ....................................................................................
102
+
103
+ Finished tests in 6.054574s, 6.4999 tests/s, 10.5822 assertions/s.
104
+
105
+ 39 tests, 45 assertions, 0 failures, 0 errors, 0 skips
106
+
107
+ Test time (including load): 82.806741s
108
+
109
+ >
110
+
111
+ If you want to focus in on a particular subset of your tests, like
112
+ units, functionals, or integration, just enter that keyword:
113
+
114
+ > units
115
+
116
+ > functionals
117
+
118
+ > integration
119
+
120
+ You can also specify to run all tests in a specific class:
121
+
122
+ > UserTest
123
+
124
+ You can dig a bit deeper and just run a particular test in that file as
125
+ well:
126
+
127
+ > UserTest#test_that_user_is_healthy
128
+
129
+ You can list more than just one class or class and method to run, and
130
+ TConsole will run them all.
131
+
132
+ > UserTest InvoiceTest SubscriptionTest#test_that_renew_renews_the_subscription
133
+
134
+ There are a few special ! commands that use data from past test runs.
135
+ The `!failed` command will rerun the set of tests that failed during the
136
+ last run:
137
+
138
+ > !failed
139
+
140
+ There's also a `!timings` command that will show you a listing of your last test run's test times, sorted to help you
141
+ improve slow tests:
142
+
143
+ > !timings
144
+
145
+ Timings from last run:
146
+
147
+ 0.042632s PostTest#test_new_post_should_not_be_published
148
+ 0.033892s PostTest#test_post_should_have_a_title
149
+ 0.033134s PostsControllerTest#test_can_reach_all_posts
150
+ 0.007098s PostsControllerTest#test_grabs_posts
151
+ 0.006212s PostsControllerTest#test_displays_published_posts_by_default
152
+ 0.006107s PostTest#test_post_cannot_have_an_empty_body
153
+ 0.002197s PostTest#test_post_should_have_a_publish_date_set_when_published
154
+ 0.001937s PostTest#test_post_cannot_have_an_empty_title
155
+ 0.001232s PostTest#test_post_should_have_an_initial_state
156
+ 0.001128s PostTest#test_post's_state_should_change_when_published
157
+ 0.001056s PostTest#test_returning_only_published_posts
158
+ 0.000923s PostTest#test_post_should_have_respond_to_published_appropriately
159
+ 0.000770s PostTest#test_post_should_have_a_body
160
+
161
+ You can turn on the Fail Fast feature to cause TConsole to stop running
162
+ tests as soon as the first test fails. To enable fail fast simply enter:
163
+
164
+ > set fast on
165
+
166
+ In the console. You can disable Fail Fast again with:
167
+
168
+ > set fast off
169
+
170
+ If you update your environment, maybe by editing your Gemfile or
171
+ changing one of your application's configuration files, you can use the
172
+ `reload` command to reload the entire environment:
173
+
174
+ > reload
175
+
176
+ And then finally, you can run the `exit` command to quit:
177
+
178
+ > exit
179
+
180
+ Command Line Options
181
+ -----
182
+
183
+ Since TConsole is primarily meant to be run as an interactive console,
184
+ it doesn't have many command line arguments, but there are a few.
185
+ TConsole also passes any parameters that it doesn't know through to be
186
+ run as its initial command. So, for example:
187
+
188
+ ```
189
+ > tconsole all
190
+ ```
191
+
192
+ passes `all` through as the first command to be run, so that command
193
+ would start TConsole and immediately run all tests. There's a `--once`
194
+ option that can be used if you'd simply like to run a single command by
195
+ passing it to the TConsole command in then exit.
196
+
197
+ The only other TConsole command line option is `--trace`. `--trace` is
198
+ primarily useful for diagnosing problems with TConsole.
199
+
200
+
201
+ Configuration Files
202
+ ------
203
+
204
+ TConsole attempts to load a .tconsole file in your home directory and in
205
+ your project directory, in that order, to configure your preferred
206
+ defaults for TConsole. In many situations you won't need to edit your
207
+ TConsole configuration files to run TConsole, because it includes a sane
208
+ set of defaults and attempts to auto-detect Rails applications.
209
+
210
+ Here's a commented example configuration file:
211
+
212
+ ``` ruby
213
+ TConsole::Config.run do |config|
214
+ # Configures the directory where your tests are located
215
+ config.test_dir = "./test"
216
+
217
+ # Include paths that should be added to Ruby's load path
218
+ config.include_paths = ["./test", "./lib"]
219
+
220
+ # Paths that should be preloaded. You'll have to run the reload
221
+ # command to reload these paths in TConsole
222
+ config.preload_paths = ["./config/application"]
223
+
224
+ # File sets are the named sets of files that can be executed. A file
225
+ # set named "all" must be included.
226
+ config.file_sets = {
227
+ "all" => ["test/**/*_test.rb"],
228
+ "units" => ["test/units/**/*_test.rb"]
229
+ }
230
+
231
+ # Fail fast specifies whether or not tests should stop executing once
232
+ # the first failure occurs.
233
+ config.fail_fast = true
234
+
235
+ # Specifies code to be run before loading the environment
236
+ config.before_load do
237
+ ENV["RAILS_ENV"] ||= "test"
238
+ end
239
+
240
+ # Specifies code to be run after loading the environment
241
+ config.after_load do
242
+ ::Rails.application
243
+ ::Rails::Engine.class_eval do
244
+ def eager_load!
245
+ # turn off eager_loading
246
+ end
247
+ end
248
+ end
249
+
250
+ # Specifies code to be run before each test execution
251
+ config.before_test_run do
252
+ puts "I'm about to run!!!"
253
+ end
254
+ end
255
+ ```
256
+
257
+
258
+ Reporting Issues and Contributing
259
+ ------
260
+
261
+ Feel free to report issues in the issue tracker at
262
+ https://github.com/gma/tconsole/issues. Be sure to include the versions
263
+ of Ruby, Rails, and your operating system. For bonus points, fork the
264
+ project and send me a pull request with the fix for the issue you're
265
+ seeing.
266
+
267
+ *How embarrassing?!?! A testing tool with no tests?* At first TConsole
268
+ was just a bit of experimental code, so test coverage is light. I am
269
+ working on improving that, though.
270
+
271
+ License
272
+ -----
273
+
274
+ Copyright (c) 2012 Alan Johnson
275
+
276
+ Permission is hereby granted, free of charge, to any person obtaining a
277
+ copy of this software and associated documentation files (the
278
+ "Software"), to deal in the Software without restriction, including
279
+ without limitation the rights to use, copy, modify, merge, publish,
280
+ distribute, sublicense, and/or sell copies of the Software, and to
281
+ permit persons to whom the Software is furnished to do so, subject to
282
+ the following conditions:
283
+
284
+ The above copyright notice and this permission notice shall be included
285
+ in all copies or substantial portions of the Software.
286
+
287
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
288
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
289
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
290
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
291
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
292
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
293
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/rconsole ADDED
@@ -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
data/bin/tconsole ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.join(File.dirname(__FILE__), "..", "lib", "tconsole")
4
+
5
+ TConsole::Runner.new(:minitest, ARGV).run
data/cibuild ADDED
@@ -0,0 +1,4 @@
1
+ mkdir -p vendor
2
+ bundle install --path vendor/gems --binstubs
3
+
4
+ rake test
data/lib/tconsole.rb ADDED
@@ -0,0 +1,18 @@
1
+ require "tconsole/version"
2
+
3
+ require "chattyproc"
4
+ require "optparse"
5
+ require "readline"
6
+ require "benchmark"
7
+ require "term/ansicolor"
8
+ require "shellwords"
9
+
10
+ require "tconsole/config"
11
+ require "tconsole/reporter"
12
+ require "tconsole/console"
13
+ require "tconsole/server"
14
+ require "tconsole/minitest_server"
15
+ require "tconsole/rspec_server"
16
+ require "tconsole/test_result"
17
+ require "tconsole/util"
18
+ require "tconsole/runner"
@@ -0,0 +1,251 @@
1
+ module TConsole
2
+ class Config
3
+ # Lets us know if we're running rspec or minitest
4
+ attr_accessor :mode
5
+
6
+ # Lets us know if we should include trace output
7
+ attr_accessor :trace_execution
8
+
9
+ # Lets us know if we should include trace output.
10
+ # Defaults to false.
11
+ attr_accessor :trace
12
+
13
+ # Test directory for the app we're testing.
14
+ # Defaults to ./test.
15
+ attr_accessor :test_dir
16
+
17
+ # Paths to add to the ruby include path.
18
+ # Defaults to ./test, ./lib
19
+ attr_accessor :include_paths
20
+
21
+ # Paths we want to preload. Defaults to nil.
22
+ attr_accessor :preload_paths
23
+
24
+ # Whether or not our test runs should stop when the first
25
+ # test fails. Defaults to false.
26
+ attr_accessor :fail_fast
27
+
28
+ # Defines the file set commands that are available
29
+ attr_accessor :file_sets
30
+
31
+ # Counts of tests in suites
32
+ attr_accessor :cached_suite_counts
33
+
34
+ # Element names we know
35
+ attr_accessor :cached_elements
36
+
37
+ # First command to run when tconsole loads
38
+ attr_accessor :run_command
39
+
40
+ # Only runs the command passed on the command line, and then exits
41
+ attr_accessor :once
42
+
43
+ def initialize(mode, argv = [])
44
+ self.mode = mode
45
+
46
+ self.trace_execution = false
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
+
56
+ self.preload_paths = []
57
+ self.fail_fast = false
58
+
59
+ if mode == :rspec
60
+ self.file_sets = {
61
+ "all" => ["#{test_dir}/**/*_spec.rb"]
62
+ }
63
+
64
+ # build file sets dynamically based on directories under the test
65
+ # directory
66
+ sets = Dir.entries(test_dir).select {|entry| File.directory?(File.join(test_dir,entry)) and !(entry =='.' || entry == '..') }
67
+ sets.each do |set|
68
+ self.file_sets[set] = ["#{test_dir}/#{set}/**/*_spec.rb"]
69
+ end
70
+ else
71
+ self.file_sets = {
72
+ "all" => ["#{test_dir}/**/*_test.rb"]
73
+ }
74
+ end
75
+
76
+ # load any args into this config that were passed
77
+ load_args(argv)
78
+
79
+ @after_load = nil
80
+ @before_load = nil
81
+ @before_test_run = nil
82
+
83
+ @cached_suite_counts = {}
84
+ @cached_elements = {}
85
+ end
86
+
87
+ # Returns the string name of our current app, i.e. tconsole or rconsole
88
+ def app
89
+ Config.app(mode)
90
+ end
91
+
92
+ def option_parser
93
+ @option_parser ||= OptionParser.new do |opts|
94
+ opts.on("-t", "--trace", "Enable verbose output.") do
95
+ self.trace_execution = true
96
+ end
97
+
98
+ opts.on("-o", "--once", "Run whatever command is passed and then exit.") do
99
+ self.once = true
100
+ end
101
+ end
102
+ end
103
+
104
+ # Public: Loads any passed command line arguments into the config.
105
+ #
106
+ # argv - The array of command line arguments we're loading
107
+ def load_args(argv)
108
+ args = argv.clone
109
+
110
+ option_parser.parse!(args)
111
+ self.run_command = args.join(" ")
112
+ end
113
+
114
+ def trace?
115
+ self.trace_execution
116
+ end
117
+
118
+ def fail_fast?
119
+ self.fail_fast
120
+ end
121
+
122
+ # Code to run before loading the environment
123
+ def before_load(&block)
124
+ @before_load = block
125
+ end
126
+
127
+ # Calls the before load callback
128
+ def before_load!
129
+ @before_load.call unless @before_load.nil?
130
+ end
131
+
132
+ # Code to run after loading the environment
133
+ def after_load(&block)
134
+ @after_load = block
135
+ end
136
+
137
+ # Calls the after load callback
138
+ def after_load!
139
+ @after_load.call unless @after_load.nil?
140
+ end
141
+
142
+ # Calls before each test execution
143
+ def before_test_run(&block)
144
+ @before_test_run = block
145
+ end
146
+
147
+ def before_test_run!
148
+ @before_test_run.call unless @before_test_run.nil?
149
+ end
150
+
151
+ def cache_test_ids(result)
152
+ self.cached_suite_counts = result.suite_counts
153
+ self.cached_elements = result.elements
154
+ end
155
+
156
+ # Returns true if this config is valid or false otherwise
157
+ def validation_errors
158
+ errors = []
159
+
160
+ unless Dir.exists?(test_dir)
161
+ errors << "Couldn't find test directory `#{test_dir}`. Exiting."
162
+ end
163
+
164
+ unless file_sets.is_a?(Hash) && !file_sets["all"].nil?
165
+ errors << "No `all` file set is defined in your configuration. Exiting."
166
+ end
167
+
168
+ errors
169
+ end
170
+
171
+ # Loads up a config file
172
+ def self.load_config(path)
173
+ if File.exist?(path)
174
+ load path
175
+ end
176
+ end
177
+
178
+ # Saves a configuration block that we can apply to the configuration once it's
179
+ # loaded
180
+ def self.run(&block)
181
+ @loaded_configs ||= []
182
+ @loaded_configs << block
183
+ end
184
+
185
+ def self.clear_loaded_configs
186
+ @loaded_configs = nil
187
+ end
188
+
189
+ # Returns an appropriate tconsole config based on the environment
190
+ def self.configure(mode, argv = [])
191
+ config = Config.new(mode, argv)
192
+
193
+ if is_rails?
194
+ config.preload_paths = ["./config/application"]
195
+
196
+ if mode == :minitest
197
+ config.include_paths = ["./test"]
198
+ config.file_sets = {
199
+ "all" => [
200
+ "#{config.test_dir}/controllers/**/*_test.rb",
201
+ "#{config.test_dir}/decorators/**/*_test.rb",
202
+ "#{config.test_dir}/helpers/**/*_test.rb",
203
+ "#{config.test_dir}/mailers/**/*_test.rb",
204
+ "#{config.test_dir}/models/**/*_test.rb"
205
+ ],
206
+ "models" => ["#{config.test_dir}/models/**/*_test.rb"],
207
+ "decorators" => ["#{config.test_dir}/decorators/**/*_test.rb"],
208
+ "controllers" => ["#{config.test_dir}/controllers/**/*_test.rb"],
209
+ "integration" => ["#{config.test_dir}/integration/**/*_test.rb"]
210
+ }
211
+ end
212
+
213
+ config.before_load do
214
+ ENV["RAILS_ENV"] ||= "test"
215
+ end
216
+
217
+ config.after_load do
218
+ ::Rails.application
219
+ ::Rails::Engine.class_eval do
220
+ def eager_load!
221
+ # turn off eager_loading
222
+ end
223
+ end
224
+ end
225
+
226
+ config.before_test_run do
227
+ if defined? ::ActiveRecord
228
+ ::ActiveRecord::Base.clear_active_connections!
229
+ ::ActiveRecord::Base.establish_connection
230
+ end
231
+ end
232
+ end
233
+
234
+ @loaded_configs ||= []
235
+ @loaded_configs.each do |block|
236
+ block.call(config)
237
+ end
238
+
239
+ config
240
+ end
241
+
242
+ def self.is_rails?
243
+ @rails ||= !!File.exist?("./config/application.rb")
244
+ end
245
+
246
+ # Public: Returns the app name based on the given mode.
247
+ def self.app(mode)
248
+ mode == :minitest ? "tconsole" : "rconsole"
249
+ end
250
+ end
251
+ end