analtester 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +1 -0
- data/README.md +5 -2
- data/Rakefile +1 -0
- data/analtester.gemspec +6 -1
- data/bin/analtester +22 -2
- data/lib/analtester.rb +91 -74
- data/templates/minispec/Rakefile +6 -0
- data/templates/minispec/spec.rb +6 -0
- data/templates/minispec/spec_helper.rb +1 -0
- data/templates/minitest/Rakefile +6 -0
- data/templates/minitest/test.rb +16 -0
- data/templates/minitest/test_helper.rb +1 -0
- data/templates/rspec/Rakefile +3 -0
- data/templates/rspec/spec.rb +6 -0
- data/templates/rspec/spec_helper.rb +1 -0
- data/test/analtester_test.rb +79 -12
- metadata +65 -46
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a07ccbbf6e2630d0d162ff267789005ca960310d
|
4
|
+
data.tar.gz: 7ad61f5804f7728144a305f12a167e457f3d5517
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d3d7c1c41e127183ebe5605559dfc929446ed1a7d40a3d26a1f2d10a618ea007c430169a422f989b3ed1948cd16078c1721aef7fbdcb819fa0a7651c4047faed
|
7
|
+
data.tar.gz: fcbf0c376d2d8efe33defc1737b7a42dce493d1e1437c61c3976b06e2cabe14fc0b4942d1939ecacc757fd26320e8634f48c0d78791f7ad654351882c7426b3f
|
data/.travis.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
language: ruby
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Analtester
|
2
2
|
|
3
|
-
A silly gem for generating minitest files
|
3
|
+
A silly gem for generating minitest files. If you have RSpec, it can use that,
|
4
|
+
too.
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
@@ -9,10 +10,12 @@ A silly gem for generating minitest files
|
|
9
10
|
## Usage
|
10
11
|
|
11
12
|
$ cd myproject
|
12
|
-
$ analtest
|
13
|
+
$ analtest -h
|
13
14
|
|
14
15
|
That's it.
|
15
16
|
|
17
|
+
[![Build Status](https://travis-ci.org/bjjb/analtester.svg?branch=master)](https://travis-ci.org/bjjb/analtester)
|
18
|
+
|
16
19
|
## Contributing
|
17
20
|
|
18
21
|
1. Fork it
|
data/Rakefile
CHANGED
data/analtester.gemspec
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'analtester'
|
4
5
|
|
5
6
|
Gem::Specification.new do |gem|
|
6
7
|
gem.name = "analtester"
|
7
|
-
gem.version =
|
8
|
+
gem.version = Analtester::VERSION
|
8
9
|
gem.authors = ["JJ Buckley"]
|
9
10
|
gem.email = ["jj@dawandamail.com"]
|
10
11
|
gem.description = %q{Makes some failing tests for you}
|
@@ -20,4 +21,8 @@ DESCRIPTION
|
|
20
21
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
21
22
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
22
23
|
gem.require_paths = ["lib"]
|
24
|
+
|
25
|
+
gem.add_dependency 'minitest' if RUBY_VERSION < "2.0"
|
26
|
+
gem.add_development_dependency 'rake'
|
27
|
+
gem.add_development_dependency 'rspec'
|
23
28
|
end
|
data/bin/analtester
CHANGED
@@ -1,4 +1,24 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
require 'optparse'
|
3
3
|
require 'analtester'
|
4
|
-
|
4
|
+
|
5
|
+
type = :minitest
|
6
|
+
OptionParser.new do |o|
|
7
|
+
o.on('-h', '--help', 'Print this message') do
|
8
|
+
puts o.to_s
|
9
|
+
exit(0)
|
10
|
+
end
|
11
|
+
o.on('-V', '--version', 'Show the version number') do
|
12
|
+
puts "Analtester v#{Analtester::VERSION}"
|
13
|
+
exit(0)
|
14
|
+
end
|
15
|
+
o.on('-t', '--type TYPE', 'Choose framework (minitest, minispec, rspec)') do |type|
|
16
|
+
unless %w[minitest minispec rspec].include?(type)
|
17
|
+
puts "Invalid type. Available types are minitest, minispec and rspec)"
|
18
|
+
exit(1)
|
19
|
+
end
|
20
|
+
type = type
|
21
|
+
end
|
22
|
+
end.parse!(ARGV)
|
23
|
+
|
24
|
+
Analtester.new(type).run
|
data/lib/analtester.rb
CHANGED
@@ -1,116 +1,133 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
require 'pathname'
|
2
3
|
require 'fileutils'
|
4
|
+
require 'forwardable'
|
5
|
+
require 'erb'
|
6
|
+
|
7
|
+
# An Analtester has a directory, and can scan the directory for library files,
|
8
|
+
# creating corresponding test files for them. It also makes sure there's a
|
9
|
+
# test helper file (like test/), and a make file (like Rakefile).
|
10
|
+
class Analtester < Pathname
|
11
|
+
VERSION = "0.0.2"
|
3
12
|
|
4
|
-
class Analtester
|
5
13
|
include FileUtils
|
6
|
-
|
7
|
-
|
14
|
+
include Comparable
|
15
|
+
|
16
|
+
attr_accessor :verbose
|
17
|
+
|
18
|
+
def initialize(framework = :minitest)
|
19
|
+
super('.')
|
20
|
+
send("initialize_#{framework}")
|
8
21
|
end
|
9
22
|
|
10
|
-
def
|
11
|
-
|
23
|
+
def <=>(another)
|
24
|
+
Pathname.new(self).realpath <=> Pathname.new(another).realpath
|
12
25
|
end
|
13
26
|
|
14
27
|
def run
|
15
|
-
|
16
|
-
|
28
|
+
make(runner, _runner)
|
29
|
+
make(helper, _helper)
|
30
|
+
tests.each { |test, template| make(test, template) }
|
17
31
|
end
|
18
32
|
|
19
|
-
def
|
20
|
-
|
33
|
+
def tests
|
34
|
+
libs.map { |f| [@test.call(f), _test] }
|
21
35
|
end
|
22
36
|
|
23
|
-
def
|
24
|
-
|
37
|
+
def libs
|
38
|
+
Dir[join(@_libs)].map { |f| join(f) }
|
25
39
|
end
|
26
40
|
|
27
|
-
def
|
28
|
-
|
41
|
+
def ext
|
42
|
+
@_ext
|
29
43
|
end
|
30
44
|
|
31
|
-
def
|
32
|
-
|
45
|
+
def runner
|
46
|
+
join(@_runner)
|
33
47
|
end
|
34
48
|
|
35
|
-
def
|
36
|
-
|
37
|
-
print test_helper + " "
|
38
|
-
if File.file?(test_helper)
|
39
|
-
puts "✓"
|
40
|
-
else
|
41
|
-
make_test_helper!
|
42
|
-
puts "Created"
|
43
|
-
end
|
49
|
+
def _runner
|
50
|
+
templates.join @__runner
|
44
51
|
end
|
45
52
|
|
46
|
-
def
|
47
|
-
|
48
|
-
if File.directory?(test_dir)
|
49
|
-
puts "✓"
|
50
|
-
else
|
51
|
-
make_test_directory!
|
52
|
-
puts "Created"
|
53
|
-
end
|
53
|
+
def helper
|
54
|
+
join @_helper
|
54
55
|
end
|
55
56
|
|
56
|
-
def
|
57
|
-
|
57
|
+
def _helper
|
58
|
+
templates.join @__helper
|
58
59
|
end
|
59
60
|
|
60
|
-
def
|
61
|
-
|
62
|
-
f.puts <<-RUBY
|
63
|
-
require 'minitest/autorun'
|
64
|
-
RUBY
|
65
|
-
end
|
61
|
+
def _test
|
62
|
+
templates.join @_test
|
66
63
|
end
|
67
64
|
|
68
|
-
def
|
69
|
-
|
70
|
-
print file, " "
|
71
|
-
if File.file?(file)
|
72
|
-
puts "✓"
|
73
|
-
else
|
74
|
-
make_test!(file)
|
75
|
-
puts "Created"
|
76
|
-
end
|
65
|
+
def templates
|
66
|
+
Pathname.new(__FILE__).parent.parent.join('templates').join(@_templates)
|
77
67
|
end
|
78
68
|
|
79
|
-
def
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
69
|
+
def make(target, template)
|
70
|
+
return if target.exist?
|
71
|
+
subject = classify(target)
|
72
|
+
library = library(target)
|
73
|
+
target.parent.mkpath
|
74
|
+
target.open('w') do |f|
|
75
|
+
f << ERB.new(template.read).result(binding)
|
86
76
|
end
|
87
77
|
end
|
88
78
|
|
89
|
-
def
|
90
|
-
#
|
91
|
-
|
92
|
-
basename.split('_').map { |s| s.chars.first.upcase + s.chars.to_a[1..-1].join }.join
|
79
|
+
def translate(s, x, y)
|
80
|
+
s = "#$1#{y}#$2_#{y}#$3" if s.to_s =~ %r{^(.*/?)#{x}(/.*)(\.[^.]+)$}
|
81
|
+
Pathname.new(s)
|
93
82
|
end
|
94
83
|
|
95
|
-
def
|
96
|
-
|
97
|
-
|
98
|
-
require 'test_helper'
|
84
|
+
def library(s)
|
85
|
+
s.to_s.split("#{@_type}/").last.split("_#{@_type}.rb").first
|
86
|
+
end
|
99
87
|
|
100
|
-
|
101
|
-
|
102
|
-
flunk "Write me."
|
88
|
+
def classify(s)
|
89
|
+
library(s).split('/').map { |x| camelize(x) }.join('::')
|
103
90
|
end
|
104
|
-
|
105
|
-
|
106
|
-
|
91
|
+
|
92
|
+
def camelize(s)
|
93
|
+
s.split('_').map { |x| x.capitalize }.join('')
|
94
|
+
end
|
95
|
+
|
96
|
+
def initialize_minitest
|
97
|
+
@_type = 'test'
|
98
|
+
@_runner = 'Rakefile'
|
99
|
+
@_helper = 'test/test_helper.rb'
|
100
|
+
@_templates = 'minitest'
|
101
|
+
@__runner = 'Rakefile'
|
102
|
+
@__helper = 'test_helper.rb'
|
103
|
+
@_libs = "lib/**/*.rb"
|
104
|
+
@test = lambda { |f| translate(f, 'lib', 'test') }
|
105
|
+
@_test = 'test.rb'
|
107
106
|
end
|
108
107
|
|
109
|
-
def
|
110
|
-
|
108
|
+
def initialize_rspec
|
109
|
+
@_type = 'spec'
|
110
|
+
@_runner = 'Rakefile'
|
111
|
+
@_helper = 'spec/spec_helper.rb'
|
112
|
+
@_templates = 'rspec'
|
113
|
+
@__runner = 'Rakefile'
|
114
|
+
@__helper = 'spec_helper.rb'
|
115
|
+
@_lib = 'lib'
|
116
|
+
@_libs = "lib/**/*.rb"
|
117
|
+
@test = lambda { |f| translate(f, 'lib', 'spec') }
|
118
|
+
@_test = 'spec.rb'
|
111
119
|
end
|
112
120
|
|
113
|
-
def
|
114
|
-
|
121
|
+
def initialize_minispec
|
122
|
+
@_type = 'spec'
|
123
|
+
@_runner = 'Rakefile'
|
124
|
+
@_helper = 'spec/spec_helper.rb'
|
125
|
+
@_templates = 'minispec'
|
126
|
+
@__runner = 'Rakefile'
|
127
|
+
@__helper = 'spec_helper.rb'
|
128
|
+
@_lib = 'lib'
|
129
|
+
@_libs = "lib/**/*.rb"
|
130
|
+
@test = lambda { |f| translate(f, 'lib', 'spec') }
|
131
|
+
@_test = 'spec.rb'
|
115
132
|
end
|
116
133
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'minitest/autorun'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'minitest/autorun'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rspec'
|
data/test/analtester_test.rb
CHANGED
@@ -1,27 +1,94 @@
|
|
1
1
|
require 'test_helper'
|
2
|
+
require 'pathname'
|
2
3
|
require 'tmpdir'
|
3
4
|
require 'fileutils'
|
4
5
|
|
5
|
-
class AnaltesterTest <
|
6
|
+
class AnaltesterTest < Minitest::Test
|
6
7
|
include FileUtils
|
7
8
|
|
8
9
|
def setup
|
9
10
|
@home = pwd
|
10
|
-
|
11
|
-
Dir.chdir(
|
11
|
+
dir = Dir.mktmpdir
|
12
|
+
Dir.chdir(dir)
|
13
|
+
@dir = Pathname.new(dir).realpath
|
14
|
+
touchfiles('lib/foo.rb', 'lib/foo/bar.rb')
|
15
|
+
@dir.join("lib/foo.rb").open('w') do |f|
|
16
|
+
f.write <<-EOF
|
17
|
+
module Foo
|
18
|
+
VERSION = "0.0.1"
|
19
|
+
end
|
20
|
+
EOF
|
21
|
+
end
|
22
|
+
@dir.join('lib/foo/bar.rb').open('w') do |f|
|
23
|
+
f.write <<-EOF
|
24
|
+
module Foo
|
25
|
+
class Bar
|
26
|
+
def hello
|
27
|
+
puts "Hello!"
|
28
|
+
end
|
12
29
|
end
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
touch %w(lib/foo.rb lib/foo/bar.rb lib/foo/bar/baz.rb)
|
17
|
-
Analtester.new(@test_directory).run
|
18
|
-
assert File.exists?('test/foo/bar/baz_test.rb')
|
19
|
-
assert File.exists?('test/foo/bar_test.rb')
|
20
|
-
assert File.exists?('test/foo_test.rb')
|
30
|
+
end
|
31
|
+
EOF
|
32
|
+
end
|
21
33
|
end
|
22
34
|
|
23
35
|
def teardown
|
24
36
|
Dir.chdir(@home)
|
25
|
-
rm_rf @
|
37
|
+
rm_rf @dir
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_minitest
|
41
|
+
Analtester.new.run
|
42
|
+
assert @dir.join("Rakefile").exist?
|
43
|
+
assert @dir.join("test/test_helper.rb").exist?
|
44
|
+
assert @dir.join("test/foo_test.rb").exist?
|
45
|
+
t = @dir.join("test/foo/bar_test.rb")
|
46
|
+
assert t.exist?
|
47
|
+
assert_match %r{require ['"]foo/bar["']}, t.read
|
48
|
+
assert_match %r{class Foo::BarTest}, t.read
|
49
|
+
out, err = capture_subprocess_io { system("rake") }
|
50
|
+
assert_empty err
|
51
|
+
assert_match /2 runs/, out
|
52
|
+
assert_match /2 skips/, out
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_minispec
|
56
|
+
touchfiles('lib/foo.rb', 'lib/foo/bar.rb')
|
57
|
+
Analtester.new(:minispec).run
|
58
|
+
assert @dir.join("Rakefile").exist?
|
59
|
+
assert @dir.join("spec/spec_helper.rb").exist?
|
60
|
+
assert @dir.join("spec/foo_spec.rb").exist?
|
61
|
+
t = @dir.join("spec/foo/bar_spec.rb")
|
62
|
+
assert t.exist?
|
63
|
+
assert_match %r{require ['"]foo/bar["']}, t.read
|
64
|
+
assert_match %r{describe Foo::Bar}, t.read
|
65
|
+
out, err = capture_subprocess_io { system("rake") }
|
66
|
+
assert_empty err
|
67
|
+
assert_match /2 runs/, out
|
68
|
+
assert_match /2 skips/, out
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_rspec
|
72
|
+
touchfiles('lib/foo.rb', 'lib/foo/bar.rb')
|
73
|
+
Analtester.new(:rspec).run
|
74
|
+
assert @dir.join("Rakefile").exist?
|
75
|
+
assert @dir.join("spec/spec_helper.rb").exist?
|
76
|
+
assert @dir.join("spec/foo_spec.rb").exist?
|
77
|
+
t = @dir.join("spec/foo/bar_spec.rb")
|
78
|
+
assert t.exist?
|
79
|
+
assert_match %r{require ['"]foo/bar["']}, t.read
|
80
|
+
assert_match %r{describe Foo::Bar}, t.read
|
81
|
+
out, err = capture_subprocess_io { system("rake") }
|
82
|
+
assert_empty err
|
83
|
+
assert_match /2 examples/, out
|
84
|
+
assert_match /2 pending/, out
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
def touchfiles(*files)
|
89
|
+
files.each do |f|
|
90
|
+
@dir.join(f).parent.mkpath
|
91
|
+
touch @dir.join(f)
|
92
|
+
end
|
26
93
|
end
|
27
94
|
end
|
metadata
CHANGED
@@ -1,35 +1,53 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: analtester
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease: false
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 1
|
10
|
-
version: 0.0.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- JJ Buckley
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
date: 2014-03-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
22
41
|
description: Makes some failing tests for you
|
23
|
-
email:
|
42
|
+
email:
|
24
43
|
- jj@dawandamail.com
|
25
|
-
executables:
|
44
|
+
executables:
|
26
45
|
- analtester
|
27
46
|
extensions: []
|
28
|
-
|
29
47
|
extra_rdoc_files: []
|
30
|
-
|
31
|
-
|
32
|
-
- .
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- ".travis.yml"
|
33
51
|
- Gemfile
|
34
52
|
- LICENSE.txt
|
35
53
|
- README.md
|
@@ -37,42 +55,43 @@ files:
|
|
37
55
|
- analtester.gemspec
|
38
56
|
- bin/analtester
|
39
57
|
- lib/analtester.rb
|
58
|
+
- templates/minispec/Rakefile
|
59
|
+
- templates/minispec/spec.rb
|
60
|
+
- templates/minispec/spec_helper.rb
|
61
|
+
- templates/minitest/Rakefile
|
62
|
+
- templates/minitest/test.rb
|
63
|
+
- templates/minitest/test_helper.rb
|
64
|
+
- templates/rspec/Rakefile
|
65
|
+
- templates/rspec/spec.rb
|
66
|
+
- templates/rspec/spec_helper.rb
|
40
67
|
- test/analtester_test.rb
|
41
68
|
- test/test_helper.rb
|
42
|
-
has_rdoc: true
|
43
69
|
homepage: http://github.com/jjbuckley/analtester
|
44
70
|
licenses: []
|
45
|
-
|
71
|
+
metadata: {}
|
46
72
|
post_install_message:
|
47
73
|
rdoc_options: []
|
48
|
-
|
49
|
-
require_paths:
|
74
|
+
require_paths:
|
50
75
|
- lib
|
51
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
-
|
53
|
-
requirements:
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
54
78
|
- - ">="
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
version: "0"
|
60
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
-
none: false
|
62
|
-
requirements:
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
63
83
|
- - ">="
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
|
66
|
-
segments:
|
67
|
-
- 0
|
68
|
-
version: "0"
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
69
86
|
requirements: []
|
70
|
-
|
71
87
|
rubyforge_project:
|
72
|
-
rubygems_version:
|
88
|
+
rubygems_version: 2.2.0
|
73
89
|
signing_key:
|
74
|
-
specification_version:
|
75
|
-
summary: analtester will look through your ./lib directory and create corresponding
|
76
|
-
|
90
|
+
specification_version: 4
|
91
|
+
summary: analtester will look through your ./lib directory and create corresponding
|
92
|
+
tests in test/. They will all fail, until you write them. Use it to quickly populate
|
93
|
+
an untested library with tests. Just run `analtester` from the command-line in your
|
94
|
+
project's root. Requires minitest.
|
95
|
+
test_files:
|
77
96
|
- test/analtester_test.rb
|
78
97
|
- test/test_helper.rb
|