tconsole 0.0.1.pre → 0.0.2.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +80 -0
- data/bin/tconsole +1 -1
- data/lib/tconsole.rb +46 -20
- data/lib/tconsole/version.rb +1 -1
- metadata +3 -3
- data/TODO +0 -3
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
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 has only been tested with Rails 3 with Ruby 1.9.3 with MiniTest as the testing framework (the Rails default) on a Mac. This is super mega alpha at this point, so your mileage may vary. I'd love to hear how it works for you, though!
|
10
|
+
|
11
|
+
Why use tconsole?
|
12
|
+
------
|
13
|
+
|
14
|
+
* A large amount of time is wasted loading the Rails environment each time you run the Rails testing rake tasks. tconsole loads the environment when you start the console and whenever you reload the environment, but doesn't have to reload the environment for each test execution.
|
15
|
+
* The Rails rake task syntax `bundle exec rake test:units TEST=test/unit/user_test.rb` can be pretty verbose when you're running specific tests. Yeah, there are tricks you can use to shorten things up, but still, that's crazy long. tconsole lets you just type `test/unit/user_test.rb` to get that specific test file to run. I'm working on fuzzy matching, too, so that you can just type 'user' and get the user test to run.
|
16
|
+
|
17
|
+
What about Spork?
|
18
|
+
------
|
19
|
+
Spork's really cool, but I've always felt like using DRb and having extra consoles open feels a bit heavy for what I want to do. Beyond that, I couldn't ever figure out how to get Spork to work with test/unit, and since me and DHH are the only two people who still use test/unit someone's got to carry the torch for test/unit awesomeness. Really, though, if Spork's your cup of tea, stop reading this and use what you like.
|
20
|
+
|
21
|
+
Installing tconsole
|
22
|
+
------
|
23
|
+
gem install tconsole --pre
|
24
|
+
|
25
|
+
How to use tconsole
|
26
|
+
------
|
27
|
+
In your shell of choice, cd into your Rails project's directory and then run the `tconsole` command to fire up the console. You should see something like this:
|
28
|
+
|
29
|
+
tconsole
|
30
|
+
|
31
|
+
Loading your Rails environment...
|
32
|
+
Environment loaded in 7.160264s.
|
33
|
+
|
34
|
+
>
|
35
|
+
|
36
|
+
Now that you're in the console, let's test out the all command! Running all from the console runs all of your unit, functional, and integration tests:
|
37
|
+
|
38
|
+
> all
|
39
|
+
Running tests...
|
40
|
+
|
41
|
+
Run options:
|
42
|
+
|
43
|
+
# Running tests:
|
44
|
+
|
45
|
+
....................................................................................
|
46
|
+
|
47
|
+
Finished tests in 6.054574s, 6.4999 tests/s, 10.5822 assertions/s.
|
48
|
+
|
49
|
+
39 tests, 45 assertions, 0 failures, 0 errors, 0 skips
|
50
|
+
|
51
|
+
Test time (including load): 82.806741s
|
52
|
+
|
53
|
+
>
|
54
|
+
|
55
|
+
If you want to focus in on a particular subset of your tests, like units, functionals, or integration, just enter that keyword:
|
56
|
+
|
57
|
+
> units
|
58
|
+
|
59
|
+
> functionals
|
60
|
+
|
61
|
+
> integration
|
62
|
+
|
63
|
+
You can also focus in on just the tests in a given filename by entering a test file name into tconsole:
|
64
|
+
|
65
|
+
> test/unit/user_test.rb
|
66
|
+
|
67
|
+
If you update your environment, maybe by editing your Gemfile or changing one of your application's configuration files, you can use the `reload` command to reload the entire environment:
|
68
|
+
|
69
|
+
> reload
|
70
|
+
|
71
|
+
And then finally, you can run the `exit` command to quit:
|
72
|
+
|
73
|
+
> exit
|
74
|
+
|
75
|
+
Reporting Issues and Contributing
|
76
|
+
------
|
77
|
+
|
78
|
+
Feel free to report issues in the issue tracker at https://github.com/commondream/tconsole/issues. For bonus points, fork the project and send me a pull request with the fix for the issue you're seeing.
|
79
|
+
|
80
|
+
tconsole is just a quick idea I had that I wanted to spike out, so there aren't any tests yet. Hopefully that will change in the near future!
|
data/bin/tconsole
CHANGED
data/lib/tconsole.rb
CHANGED
@@ -8,54 +8,62 @@ module TConsole
|
|
8
8
|
# Spawns a new environment. Looks at the results of the environment to determine whether to stop or
|
9
9
|
# keep running
|
10
10
|
def self.run
|
11
|
+
|
12
|
+
stty_save = `stty -g`.chomp
|
13
|
+
|
14
|
+
# We're only going to handle interrupts on the inner process
|
15
|
+
trap("SIGINT", "IGNORE");
|
11
16
|
running = true
|
12
17
|
|
13
18
|
while running
|
14
|
-
read, write = IO.pipe
|
15
19
|
pid = fork do
|
16
|
-
|
17
|
-
write.puts [Marshal.dump(response)].pack("m")
|
20
|
+
exit run_environment ? 0 : 1
|
18
21
|
end
|
19
|
-
write.close
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
running = Marshal.load(response.unpack("m")[0])
|
24
|
-
read.close
|
23
|
+
pid, status = Process.wait2(pid)
|
24
|
+
running = false if status.exitstatus != 0
|
25
25
|
end
|
26
26
|
|
27
27
|
puts
|
28
28
|
puts "Exiting. Bye!"
|
29
|
+
system("stty", stty_save);
|
29
30
|
end
|
30
31
|
|
31
32
|
# Starts our Rails environment and listens for console commands
|
32
33
|
# Returns true if we should keep running or false if we need to exit
|
33
|
-
def self.run_environment
|
34
|
+
def self.run_environment
|
35
|
+
|
36
|
+
trap("SIGINT", "SYSTEM_DEFAULT");
|
34
37
|
|
35
38
|
puts
|
36
39
|
puts "Loading Rails environment..."
|
37
40
|
time = Benchmark.realtime do
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
begin
|
42
|
+
# Ruby environment loading is shamelessly borrowed from spork
|
43
|
+
ENV["RAILS_ENV"] ||= "test"
|
44
|
+
$:.unshift("./test")
|
45
|
+
|
46
|
+
require 'rake'
|
47
|
+
Rake.application.init
|
48
|
+
Rake.application.load_rakefile
|
49
|
+
Rake.application.invoke_task("test:prepare")
|
50
|
+
rescue Exception => e
|
51
|
+
puts "Error: Loading your environment failed."
|
52
|
+
puts " #{e.message}"
|
53
|
+
return false
|
54
|
+
end
|
44
55
|
end
|
45
56
|
|
46
57
|
puts "Environment loaded in #{time}s."
|
47
58
|
puts
|
48
59
|
|
49
|
-
# Store the state of the terminal
|
50
|
-
stty_save = `stty -g`.chomp
|
51
|
-
#trap('INT') { system('stty', stty_save); exit }
|
52
|
-
|
53
|
-
|
54
60
|
while line = Readline.readline('> ', true)
|
55
61
|
if line == "exit"
|
56
62
|
return false
|
57
63
|
elsif line == "reload"
|
58
64
|
return true
|
65
|
+
elsif line == "help"
|
66
|
+
help
|
59
67
|
elsif line == "units"
|
60
68
|
run_tests(["test/unit/**/*_test.rb"])
|
61
69
|
elsif line == "functionals"
|
@@ -68,6 +76,8 @@ module TConsole
|
|
68
76
|
run_tests([line])
|
69
77
|
end
|
70
78
|
end
|
79
|
+
|
80
|
+
return false
|
71
81
|
end
|
72
82
|
|
73
83
|
# Taks an array of globs and loads all of the files in the globs
|
@@ -75,6 +85,7 @@ module TConsole
|
|
75
85
|
def self.run_tests(globs)
|
76
86
|
time = Benchmark.realtime do
|
77
87
|
pid = fork do
|
88
|
+
|
78
89
|
puts "Running tests..."
|
79
90
|
puts
|
80
91
|
|
@@ -95,5 +106,20 @@ module TConsole
|
|
95
106
|
puts "Test time (including load): #{time}s"
|
96
107
|
puts
|
97
108
|
end
|
109
|
+
|
110
|
+
# Prints a list of available commands
|
111
|
+
def self.help
|
112
|
+
puts
|
113
|
+
puts "Available commands:"
|
114
|
+
puts
|
115
|
+
puts "all # Run all test types (units, functionals, integration)"
|
116
|
+
puts "units # Run unit tests"
|
117
|
+
puts "functionals # Run functional tests"
|
118
|
+
puts "integration # Run integration tests"
|
119
|
+
puts "[filename] # Run the tests contained in the given file"
|
120
|
+
puts "reload # Reload your Rails environment"
|
121
|
+
puts "exit # Exit the console"
|
122
|
+
puts
|
123
|
+
end
|
98
124
|
end
|
99
125
|
end
|
data/lib/tconsole/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tconsole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2.pre
|
5
5
|
prerelease: 6
|
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: 2011-12-
|
12
|
+
date: 2011-12-11 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: tconsole gives you a helpful console for running Rails tests
|
15
15
|
email:
|
@@ -21,8 +21,8 @@ extra_rdoc_files: []
|
|
21
21
|
files:
|
22
22
|
- .gitignore
|
23
23
|
- Gemfile
|
24
|
+
- README.md
|
24
25
|
- Rakefile
|
25
|
-
- TODO
|
26
26
|
- bin/tconsole
|
27
27
|
- lib/tconsole.rb
|
28
28
|
- lib/tconsole/version.rb
|