testifier 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9374e925a7f9fb194071dd3bc8dfc901fb0307ae
4
+ data.tar.gz: f1a755b0d8b54b63ab391b2f43dd37338c11e788
5
+ SHA512:
6
+ metadata.gz: 3b418774ae1d1b82447489e594cde072ab3f35811836b13ddca27ecfaf908f0415bc7bd9277b62cb0d65bb6ed4ac33e13afa7a28e45c3b10370cc4d05aa7bfa6
7
+ data.tar.gz: abb598c2bf3c643a41da0839deee03b5447d75d84305abedf1865ff1e35ba7d4e5274da7a8393fa571fedb07159040d8584c99c24f198e0cc5875c7b39491934
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ *.gem
2
+ Gemfile.lock
3
+ .bundle
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ maketest
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Testify creates class and test files
2
+
3
+ The idea is to lower the barrier just a bit to doing TDD when writing small scripts.
4
+
5
+ I'd be surprised if there weren't good alternatives out there already. But no, "use an IDE" isn't one of them. If god had meant us to use an IDE, he wouldn't have given us vim.
6
+
7
+ ## To use:
8
+
9
+ testify some_new_filename
10
+
11
+ This creates two new files:
12
+
13
+ lib/some_new_filename.rb
14
+ spec/lib/some_new_filename_spec.rb
15
+
16
+ And the files are populated:
17
+
18
+ % cat lib/some_new_filename.rb
19
+ class SomeNewFilename
20
+ end
21
+
22
+ % cat spec/lib/some_new_filename_spec.rb
23
+ require "lib/some_new_filename"
24
+
25
+ describe SomeNewFilename do
26
+ end
27
+
28
+ Testify won't write over existing files.
29
+
30
+ Testify creates directories under lib if they don't already exist:
31
+
32
+ testify some/path/foo_bar.rb
33
+
34
+ creates
35
+
36
+ lib/some/path/foo_bar.rb
37
+ spec/lib/some/path/foo_bar_spec.rb
38
+
39
+ There is a shorter version of the command:
40
+
41
+ ty some_new_filename
42
+
43
+ ## To install:
44
+
45
+ gem install testify
data/bin/testify ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+ require "testifier"
3
+ require "optparse"
4
+
5
+ module Testifier
6
+ class TestifyRunner
7
+ def parse
8
+ @options = {}
9
+ OptionParser.new do |opts|
10
+ opts.on("-v", "--version", "Show version") do |v|
11
+ @options[:version] = true
12
+ end
13
+ end.parse!
14
+ end
15
+
16
+ def print_version
17
+ puts Testifier::VERSION
18
+ end
19
+
20
+ def print_banner
21
+ puts "Usage: testify [options] file"
22
+ end
23
+
24
+ def make_files(filename)
25
+ FileMaker.new(filename).create_files
26
+ end
27
+
28
+ def run
29
+ if @options[:version]
30
+ print_version
31
+ elsif ARGV.empty?
32
+ print_banner
33
+ else
34
+ make_files(ARGV[0])
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ runner = Testifier::TestifyRunner.new
41
+ runner.parse
42
+ runner.run
data/bin/ty ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+ require "testifier"
3
+ require "optparse"
4
+
5
+ module Testifier
6
+ class TestifyRunner
7
+ def parse
8
+ @options = {}
9
+ OptionParser.new do |opts|
10
+ opts.on("-v", "--version", "Show version") do |v|
11
+ @options[:version] = true
12
+ end
13
+ end.parse!
14
+ end
15
+
16
+ def print_version
17
+ puts Testifier::VERSION
18
+ end
19
+
20
+ def print_banner
21
+ puts "Usage: testify [options] file"
22
+ end
23
+
24
+ def make_files(filename)
25
+ FileMaker.new(filename).create_files
26
+ end
27
+
28
+ def run
29
+ if @options[:version]
30
+ print_version
31
+ elsif ARGV.empty?
32
+ print_banner
33
+ else
34
+ make_files(ARGV[0])
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ runner = Testifier::TestifyRunner.new
41
+ runner.parse
42
+ runner.run
@@ -0,0 +1,84 @@
1
+ require "active_support/all"
2
+ require "fileutils"
3
+
4
+ module Testifier
5
+ class FileMaker
6
+ def initialize(path)
7
+ @initial_path = path
8
+ end
9
+
10
+ def target_dir
11
+ "lib/#{dirname}"
12
+ end
13
+
14
+ def test_dir
15
+ "spec/lib/#{dirname}"
16
+ end
17
+
18
+ def class_file
19
+ "lib/#{dirname}#{basename}.rb"
20
+ end
21
+
22
+ def test_file
23
+ "spec/lib/#{dirname}#{basename}_spec.rb"
24
+ end
25
+
26
+ def basename
27
+ File.basename(@initial_path, File.extname(@initial_path))
28
+ end
29
+
30
+ def create_files
31
+ make_dir_if_necessary(target_dir)
32
+ make_dir_if_necessary(test_dir)
33
+ create_class_file
34
+ create_test_file
35
+ end
36
+
37
+ def create_class_file
38
+ unless File.exist?(class_file)
39
+ puts "creating #{class_file}"
40
+ File.open(class_file, "w") { |file| file.puts class_definition }
41
+ end
42
+ end
43
+
44
+ def create_test_file
45
+ unless File.exist?(test_file)
46
+ puts "creating #{test_file}"
47
+ File.open(test_file, "w") { |file| file.puts test_definition }
48
+ end
49
+ end
50
+
51
+ def class_definition
52
+ <<-CLASS
53
+ class #{class_name}
54
+ end
55
+ CLASS
56
+ end
57
+
58
+ def test_definition
59
+ <<-TEST
60
+ require "#{dirname}#{basename}"
61
+
62
+ describe #{class_name} do
63
+ end
64
+ TEST
65
+ end
66
+
67
+ private
68
+
69
+ def class_name
70
+ basename.camelize
71
+ end
72
+
73
+ def make_dir_if_necessary(filename)
74
+ unless File.exist?(filename)
75
+ FileUtils.mkdir_p(filename)
76
+ end
77
+ end
78
+
79
+ def dirname
80
+ dir = "#{File.dirname(@initial_path)}/"
81
+ dir == "./" ? "" : dir
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,3 @@
1
+ module Testifier
2
+ VERSION = "0.1.0"
3
+ end
data/lib/testifier.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "testifier/file_maker"
2
+ require "testifier/version"
@@ -0,0 +1,106 @@
1
+ require "testifier/file_maker"
2
+
3
+ module Testifier
4
+ describe FileMaker do
5
+ let(:file1) { "maketest/foo" }
6
+ let(:maker) { FileMaker.new(file1) }
7
+ let(:mock_class_file) { double("file") }
8
+ let(:mock_test_file) { double("file") }
9
+
10
+ before do
11
+ allow(FileUtils).to receive(:mkdir_p)
12
+ allow(File).to receive(:exist?)
13
+ allow(File).to receive(:open).with(maker.class_file, anything).and_yield(mock_class_file)
14
+ allow(File).to receive(:open).with(maker.test_file, anything).and_yield(mock_test_file)
15
+ allow(mock_class_file).to receive(:puts)
16
+ allow(mock_test_file).to receive(:puts)
17
+ allow(maker).to receive(:puts)
18
+ end
19
+
20
+ it "ignores the file suffix when creating new files" do
21
+ expect(FileMaker.new("whatever.txt").class_file).to eql("lib/whatever.rb")
22
+ end
23
+
24
+ it "gets the class file name from the passed path" do
25
+ expect(maker.class_file).to eql("lib/maketest/foo.rb")
26
+ end
27
+
28
+ it "gets the test file name from the passed path" do
29
+ expect(maker.test_file).to eql("spec/lib/maketest/foo_spec.rb")
30
+ end
31
+
32
+ it "gets the file basename from the passed path" do
33
+ expect(maker.basename).to eql("foo")
34
+ end
35
+
36
+ it "returns the target directory" do
37
+ expect(maker.target_dir).to eql("lib/maketest/")
38
+ end
39
+
40
+ it "returns the test directory" do
41
+ expect(maker.test_dir).to eql("spec/lib/maketest/")
42
+ end
43
+
44
+ describe "#create_files" do
45
+ it "creates the target dir if needed" do
46
+ allow(File).to receive(:exist?).with(maker.target_dir).and_return(false)
47
+ expect(FileUtils).to receive(:mkdir_p).with(maker.target_dir)
48
+ maker.create_files
49
+ end
50
+
51
+ it "doesn't create the target dir if not needed" do
52
+ allow(File).to receive(:exist?).with(maker.target_dir).and_return(true)
53
+ expect(Dir).to_not receive(:mkdir).with(maker.target_dir)
54
+ maker.create_files
55
+ end
56
+
57
+ it "creates the test dir if needed" do
58
+ allow(File).to receive(:exist?).with(maker.test_dir).and_return(false)
59
+ expect(FileUtils).to receive(:mkdir_p).with(maker.test_dir)
60
+ maker.create_files
61
+ end
62
+ end
63
+
64
+ describe "#class_definition" do
65
+ it "includes the class name" do
66
+ maker = FileMaker.new("some_class_name")
67
+ expect(maker.class_definition).to include("class SomeClassName")
68
+ end
69
+ end
70
+
71
+ describe "#test_definition" do
72
+ it "includes the class name" do
73
+ maker = FileMaker.new("some_class_name")
74
+ expect(maker.test_definition).to include("describe SomeClassName")
75
+ end
76
+ end
77
+
78
+ describe "#create_class_file" do
79
+ it "creates the class file" do
80
+ allow(File).to receive(:exist?).and_return(false)
81
+ expect(mock_class_file).to receive(:puts).with(maker.class_definition)
82
+ maker.create_class_file
83
+ end
84
+
85
+ it "doesn't overwrite an existing class file" do
86
+ allow(File).to receive(:exist?).and_return(true)
87
+ expect(mock_class_file).to_not receive(:puts).with(maker.class_definition)
88
+ maker.create_class_file
89
+ end
90
+ end
91
+
92
+ describe "#create_spec_file" do
93
+ it "doesn't overwrite an existing spec file" do
94
+ allow(File).to receive(:exist?).and_return(true)
95
+ expect(mock_test_file).to_not receive(:puts).with(maker.test_definition)
96
+ maker.create_test_file
97
+ end
98
+
99
+ it "creates the spec file" do
100
+ allow(File).to receive(:exist?).and_return(false)
101
+ expect(mock_test_file).to receive(:puts).with(maker.test_definition)
102
+ maker.create_test_file
103
+ end
104
+ end
105
+ end
106
+ end
data/testifier.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require "testifier/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "testifier"
6
+ s.version = Testifier::VERSION
7
+ s.summary = "Test file and class file creator"
8
+ s.description = "Creates test and class files"
9
+ s.authors = ["Jeff Roush"]
10
+ s.email = "jeff@jeffroush.com"
11
+ s.homepage = "https://github.com/jeff-r/testify"
12
+ s.license = "MIT"
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_runtime_dependency "activesupport", "~> 4"
20
+ s.add_development_dependency "rspec", "~> 3"
21
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: testifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeff Roush
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3'
41
+ description: Creates test and class files
42
+ email: jeff@jeffroush.com
43
+ executables:
44
+ - testify
45
+ - ty
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".ruby-gemset"
51
+ - ".ruby-version"
52
+ - Gemfile
53
+ - README.md
54
+ - bin/testify
55
+ - bin/ty
56
+ - lib/testifier.rb
57
+ - lib/testifier/file_maker.rb
58
+ - lib/testifier/version.rb
59
+ - spec/lib/testifier/file_maker_spec.rb
60
+ - testifier.gemspec
61
+ homepage: https://github.com/jeff-r/testify
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.2.0
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Test file and class file creator
85
+ test_files:
86
+ - spec/lib/testifier/file_maker_spec.rb