gemgen 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,12 +7,12 @@ module Gemgen
7
7
  # Define arguments and options
8
8
  argument :gem_name
9
9
  class_option :test_framework, :default => :mini_test
10
- class_option :test_type, :default => :unit
10
+ class_option :test_type, :default => "unit"
11
11
 
12
12
  def self.source_root
13
13
  File.expand_path(File.dirname(__FILE__) +'/templates')
14
14
  end
15
-
15
+
16
16
  def run_bundle_gem
17
17
  run "bundle gem #{gem_name}", :verbose => true
18
18
  commit "$> bundle gem #{gem_name}"
@@ -48,29 +48,56 @@ EOF
48
48
  end
49
49
 
50
50
  def create_test_file
51
- test = options[:test_framework] == "rspec" ? :spec : :test
51
+ test = options[:test_type] == "spec" ? :spec : :test
52
52
  test_path = "#{gem_name}/#{test}/"
53
53
  helper_file = "#{test}_helper.rb"
54
54
  create_file test_path + helper_file do
55
- str = <<EOF
55
+ unit_str = <<EOF
56
56
  $:.unshift File.expand_path('..', __FILE__)
57
57
  $:.unshift File.expand_path('../../lib', __FILE__)
58
58
  require 'minitest/unit'
59
59
  require 'minitest/autorun'
60
60
  EOF
61
+ spec_str = <<EOF
62
+ $:.unshift File.expand_path('..', __FILE__)
63
+ $:.unshift File.expand_path('../../lib', __FILE__)
64
+ require '#{gem_name}'
65
+ require 'minitest/spec'
66
+ require 'minitest/autorun'
67
+
68
+ module SpecHelper
69
+ end
70
+ EOF
71
+ test == :spec ? spec_str : unit_str
61
72
  end
62
73
  create_file test_path + "#{gem_name}_#{test}.rb" do
63
- str = <<EOF
74
+ unit_str = <<EOF
64
75
  require '#{File.basename(helper_file, ".rb")}'
65
76
 
66
77
  module #{module_name}
67
78
  class #{module_name}Test < MiniTest::Unit::TestCase
68
79
  def test_truth
69
- assert true
80
+ assert true
70
81
  end
71
82
  end
72
83
  end
73
84
  EOF
85
+ spec_str = <<EOF
86
+ require File.expand_path('../spec_helper', __FILE__)
87
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
88
+
89
+ include SpecHelper
90
+
91
+ describe #{module_name} do
92
+ before do
93
+ end
94
+
95
+ it "should test truth" do
96
+ true.must_equal true
97
+ end
98
+ end
99
+ EOF
100
+ test == :spec ? spec_str : unit_str
74
101
  end
75
102
  commit("Create test scaffold file")
76
103
  end
@@ -100,5 +127,9 @@ EOF
100
127
  def module_name
101
128
  Thor::Util.camel_case(gem_name)
102
129
  end
130
+
131
+ def test_type
132
+ @test_type ||= options[:test_type].to_s == "spec" ? :spec : :test
133
+ end
103
134
  end
104
135
  end
@@ -4,12 +4,19 @@ Bundler.require(:default, :development)
4
4
  require 'bundler/gem_tasks'
5
5
 
6
6
  require 'rake/testtask'
7
-
7
+ <%if test_type == :spec%>
8
+ Rake::TestTask.new do |t|
9
+ t.pattern = "spec/*_spec.rb"
10
+ # To avoid requirement of File.expand_path(File.dirname(__FILE__) + 'spec_helper') from test files
11
+ t.libs << 'spec'
12
+ end
13
+ <% else %>
8
14
  Rake::TestTask.new do |t|
9
15
  t.pattern = "test/*_test.rb"
10
16
  # To avoid requirement of File.expand_path(File.dirname(__FILE__) + 'test_helper') from test files
11
17
  t.libs << 'test'
12
18
  end
13
-
19
+ <% end %>
20
+
14
21
  task :default => [:test]
15
22
 
@@ -1,3 +1,3 @@
1
1
  module Gemgen
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/test/gemgen_test.rb CHANGED
@@ -1,6 +1,41 @@
1
1
  require 'test_helper'
2
- class GemgenTest < MiniTest::Unit::TestCase
3
- def test_truth
4
- assert true
5
- end
6
- end
2
+ require 'gemgen/generator'
3
+ require 'pry'
4
+
5
+ module Gemgen
6
+ class GemgenTest < MiniTest::Unit::TestCase
7
+ def setup
8
+ if File.exist? tmp_dir
9
+ rm_rf tmp_dir
10
+ end
11
+ mkdir tmp_dir
12
+ end
13
+
14
+ def test_that_minitest_unit_tests_runs
15
+ gem_name = 'minitest_unit'
16
+ Dir.chdir(tmp_dir) do |dir|
17
+ @cli = Gemgen::Generator.new([gem_name])
18
+ @cli.invoke_all
19
+ assert(File.exist? 'minitest_test')
20
+
21
+ Dir.chdir(gem_name) do
22
+ output = `bundle exec rake`
23
+ assert_match /1 tests, 1 assertions, 0 failures, 0 errors, 0 skips/, output
24
+ end
25
+ end
26
+ end
27
+
28
+ def test_that_minitest_spec_tests_runs
29
+ gem_name = 'minitest_spec'
30
+ Dir.chdir(tmp_dir) do |dir|
31
+ @cli = Gemgen::Generator.new([gem_name], :test_type => "spec")
32
+ @cli.invoke_all
33
+ assert(File.exist? 'minitest_spec')
34
+ Dir.chdir(gem_name) do
35
+ output = `bundle exec rake`
36
+ assert_match /1 tests, 1 assertions, 0 failures, 0 errors, 0 skips/, output
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
data/test/test_helper.rb CHANGED
@@ -2,3 +2,23 @@ $:.unshift File.expand_path('..', __FILE__)
2
2
  $:.unshift File.expand_path('../../lib', __FILE__)
3
3
  require 'minitest/unit'
4
4
  require 'minitest/autorun'
5
+ require 'fileutils'
6
+
7
+ module Gemgen
8
+ class MiniTest::Unit::TestCase
9
+ include FileUtils
10
+ def tmp_dir
11
+ File.expand_path('../../tmp', __FILE__)
12
+ end
13
+
14
+ def local_io(in_str = "")
15
+ old_stdin, old_stdout = $stdin, $stdout
16
+ $stdin = StringIO.new(in_str)
17
+ $stdout = StringIO.new
18
+ yield
19
+ out_str = $stdout.string
20
+ $stdin, $stdout = old_stdin, old_stdout
21
+ out_str
22
+ end
23
+ end
24
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemgen
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Martin Chabot