tdd 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/tdd +10 -52
- data/lib/tdd.rb +1 -0
- data/lib/tdd/command_line_parser.rb +66 -0
- data/lib/tdd/version.rb +1 -1
- metadata +5 -4
data/bin/tdd
CHANGED
@@ -67,60 +67,19 @@ test file for changes.
|
|
67
67
|
__
|
68
68
|
|
69
69
|
def run
|
70
|
+
print_usage_and_exit if ARGV.empty?
|
70
71
|
parse_the_command_line
|
71
72
|
print_a_summary_of_watched_files
|
72
73
|
loop_watching_files_and_running_commands
|
73
74
|
end
|
74
75
|
|
75
|
-
def
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
pos = ARGV.index('--')
|
82
|
-
if pos
|
83
|
-
@paths = ARGV[0 ... pos]
|
84
|
-
@test_args = ARGV[pos + 1 .. -1].join(' ')
|
85
|
-
else
|
86
|
-
@paths = %w[app lib config test spec]
|
87
|
-
@test_args = ARGV[0..-1].join(' ')
|
88
|
-
end
|
89
|
-
|
90
|
-
@test_file = @test_args.scan(/^.+.rb/).first
|
91
|
-
|
92
|
-
if @paths.first == "glob"
|
93
|
-
search = File.basename(@test_file).gsub(/(_spec|_test)/, '')
|
94
|
-
@paths = Dir.glob("**/#{search}")
|
95
|
-
@paths << @test_file
|
96
|
-
end
|
97
|
-
|
98
|
-
if @paths.first == "controller"
|
99
|
-
resource = File.basename(@test_file).gsub(/(_controller_spec.rb|_controller_test.rb)/, '')
|
100
|
-
search = File.basename(@test_file).gsub(/(_spec|_test)/, '')
|
101
|
-
puts "="*45
|
102
|
-
puts resource
|
103
|
-
puts "="*45
|
104
|
-
@paths = Dir.glob("app/views/#{resource}/**")
|
105
|
-
@paths += Dir.glob("**/#{search}")
|
106
|
-
@paths << @test_file
|
107
|
-
end
|
108
|
-
|
109
|
-
test_command = 'rspec' if @test_args.match(/^spec$/) || @test_file && @test_file.match(/_spec.rb/)
|
110
|
-
test_command = 'ruby -Itest' if @test_file && @test_file.match(/_test.rb/)
|
111
|
-
if @test_args.match(/^rake/)
|
112
|
-
test_command = @test_args
|
113
|
-
@test_args = nil
|
114
|
-
end
|
115
|
-
|
116
|
-
if test_command.nil?
|
117
|
-
say("No test or spec command could be built.", :color => :red)
|
118
|
-
say("Pass -h option to see examples.", :color => :red)
|
119
|
-
exit 1
|
120
|
-
end
|
121
|
-
|
122
|
-
@command = "#{test_command} #{@test_args}"
|
76
|
+
def print_usage_and_exit
|
77
|
+
puts usage['examples']
|
78
|
+
exit 1
|
79
|
+
end
|
123
80
|
|
81
|
+
def parse_the_command_line
|
82
|
+
@paths, @command = Tdd::CommandLineParser.parse
|
124
83
|
@paths = %w[.] if @paths.empty?
|
125
84
|
|
126
85
|
@paths.map!{|path| test(?d, path) ? [path, Dir.glob(File.join(path, '**/**'))] : path}
|
@@ -138,14 +97,13 @@ test file for changes.
|
|
138
97
|
end
|
139
98
|
|
140
99
|
def print_a_summary_of_watched_files
|
141
|
-
puts "
|
142
|
-
puts "#"
|
100
|
+
puts "Running: #{ @command }"
|
143
101
|
if @paths.length > 15
|
144
|
-
|
102
|
+
puts "Watching: #{@paths.length} files"
|
145
103
|
else
|
104
|
+
puts "Watching:"
|
146
105
|
puts @paths.join("\n")
|
147
106
|
end
|
148
|
-
puts
|
149
107
|
end
|
150
108
|
|
151
109
|
def loop_watching_files_and_running_commands
|
data/lib/tdd.rb
CHANGED
@@ -0,0 +1,66 @@
|
|
1
|
+
class Tdd::CommandLineParser
|
2
|
+
def self.parse
|
3
|
+
parser = self.new
|
4
|
+
[parser.paths, parser.test_command]
|
5
|
+
end
|
6
|
+
|
7
|
+
attr_accessor :paths, :test_framework
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
pos = ARGV.index('--')
|
11
|
+
if pos
|
12
|
+
@paths = ARGV[0 ... pos]
|
13
|
+
@test_args = ARGV[pos + 1 .. -1].join(' ')
|
14
|
+
else
|
15
|
+
@paths = %w[app lib config test spec]
|
16
|
+
@test_args = ARGV[0..-1].join(' ')
|
17
|
+
end
|
18
|
+
@test_file = @test_args.scan(/^.+.rb/).first
|
19
|
+
parse_glob_mode
|
20
|
+
parse_controller_mode
|
21
|
+
parse_test_framework
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_command
|
25
|
+
"#{@test_framework} #{@test_args}"
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def exit_if_no_test_framework
|
31
|
+
say("No test or spec command could be built.", :color => :red)
|
32
|
+
say("Pass -h option to see examples.", :color => :red)
|
33
|
+
exit 1
|
34
|
+
end
|
35
|
+
|
36
|
+
def parse_glob_mode
|
37
|
+
if @paths.first == "glob"
|
38
|
+
search = File.basename(@test_file).gsub(/(_spec|_test)/, '')
|
39
|
+
@paths = Dir.glob("**/#{search}")
|
40
|
+
@paths << @test_file
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def parse_controller_mode
|
45
|
+
if @paths.first == "controller"
|
46
|
+
resource = File.basename(@test_file).gsub(/(_controller_spec.rb|_controller_test.rb)/, '')
|
47
|
+
search = File.basename(@test_file).gsub(/(_spec|_test)/, '')
|
48
|
+
@paths = Dir.glob("app/views/#{resource}/**")
|
49
|
+
@paths += Dir.glob("**/#{search}")
|
50
|
+
@paths << @test_file
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def parse_test_framework
|
55
|
+
if @test_args.match(/^spec/) || @test_file && @test_file.match(/_spec.rb/)
|
56
|
+
@test_framework = 'rspec'
|
57
|
+
elsif @test_file && @test_file.match(/_test.rb/)
|
58
|
+
@test_framework = 'ruby -Itest'
|
59
|
+
elsif @test_args.match(/^rake/)
|
60
|
+
@test_framework = @test_args
|
61
|
+
@test_args = nil
|
62
|
+
else
|
63
|
+
exit_if_no_test_framework
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/tdd/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tdd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 2
|
10
|
+
version: 1.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tyler Montgomery
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2013-01-
|
18
|
+
date: 2013-01-16 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: main
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- Rakefile
|
65
65
|
- bin/tdd
|
66
66
|
- lib/tdd.rb
|
67
|
+
- lib/tdd/command_line_parser.rb
|
67
68
|
- lib/tdd/version.rb
|
68
69
|
- tdd.gemspec
|
69
70
|
homepage: ""
|