pad_gem 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 602bb7d60ca867434085b6d007a21b5fd743ad8a
4
- data.tar.gz: bf41bed5fec927d4d6bcb57af6bca4e51cf6a2f0
3
+ metadata.gz: 8154431c41f9bb6f1393c6e6581a4193b3c5e32b
4
+ data.tar.gz: cc0f0753e9828c69f768ce9c7aeaa410402f5b19
5
5
  SHA512:
6
- metadata.gz: 8b511fcd973e24247d15718381da0304eed0825ccd815b0f7701289a6f4bff58c782910709bad15cf80c9d49e02557d91d46d08236e9d093b9128a5c3a0abe51
7
- data.tar.gz: 0eaba2da3b4a78cb4310c2c2af8ad02dc0174d00127d929c9c5591b5490d82366df14fb67ff4415f7ad173ce19da127314ec50b214b2553a12dead524bb7bca9
6
+ metadata.gz: b0953703fdce18f1ac98986bbe006918fbad14f04f5b4fe5a029654db6cef0350cf0a2239d45a517dd912dab35f05710c62f3ea2f907d02a7559ff166298ff3c
7
+ data.tar.gz: e631d90e32d9626ef9cbe904b32ec9460944b8a5f3025a7ec05c45d6f9f402160b57924d880d87c0da869dd096638686e9df2f63154e21e8db1f8817407bb18e
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gem "pad_utils", ">= 1.5"
3
+
4
+ gem 'PADGEM_GEM_RUBY_NAME', path: "../"
@@ -0,0 +1,15 @@
1
+ require 'pad_utils'
2
+
3
+ puts
4
+ name = PadUtils.question_menu("How do you want to name your test?")
5
+ name = PadUtils.sanitize name
6
+
7
+ underscored = PadUtils.underscore name
8
+ camel = PadUtils.camel_case underscored
9
+ file_name = "units/#{underscored}_test.rb"
10
+
11
+ PadUtils.copy_file("template/template.rb", file_name)
12
+ PadUtils.replace_in_file(file_name, /CLASS_TEST_NAME/, "#{camel}Test")
13
+ PadUtils.replace_in_file(file_name, /TEST_NAME/, camel)
14
+
15
+ puts
@@ -0,0 +1,15 @@
1
+ require 'pad_utils'
2
+
3
+ # TODO: Use a function from PadUtils
4
+ def time_diff_sec(start, finish)
5
+ result = ((finish - start)).to_i
6
+ result == 0 ? 1 : result
7
+ end
8
+
9
+ # TODO: Add this method to PadUtils
10
+ def get_class_name(file)
11
+ filename = File.basename file
12
+ filename_no_ext = filename.gsub(".rb", "")
13
+ class_name = PadUtils.camel_case(filename_no_ext)
14
+ class_name
15
+ end
@@ -0,0 +1,25 @@
1
+ A quick explanation of how to use this strange testing method
2
+ -------------------------------------------------------------
3
+
4
+ Why use this instead of well-known testing frameworks? Because it fits my workflow. You can of course obliterate this test/ directory and replace it with your method of choice. I mostly build gems that write to files and existing frameworks are overkill for what I'm trying to do. You don't hunt mosquitoes with a rocket launcher... .
5
+
6
+
7
+ Within the test/ directory, run:
8
+
9
+ bundle install
10
+
11
+
12
+ To create a new test, run:
13
+
14
+ ruby add_test.rb
15
+
16
+ There's no need to append "_test" to it. It's done automatically. Your new test will go to units/ directory.
17
+ Open your new test and fill in the required parts. You can have a look at sample_test.rb (delete it when done).
18
+
19
+
20
+ To execute the test suite, run:
21
+
22
+ ruby test_runner.rb
23
+
24
+ Use the fixtures/ directory for storing your fixtures.
25
+ Use results/ if you need to write to files.
@@ -0,0 +1,30 @@
1
+ require 'pad_utils'
2
+ require 'PADGEM_GEM_RUBY_NAME'
3
+ require_relative '../template/test'
4
+
5
+ # Test name
6
+ test_name = "TEST_NAME"
7
+
8
+ class CLASS_TEST_NAME < Test
9
+
10
+ def prepare
11
+ # Add test preparation here
12
+ end
13
+
14
+ def run_test
15
+ # Test code for TEST_NAME goes here
16
+ #
17
+ # Runtime errors will be handled by a Rescue in the parent class
18
+ #
19
+ # You can add error messages to @errors
20
+ # example: @errors << "Some error message"
21
+ # You can also add notes to @notes
22
+ # example: @notes << "Some note"
23
+ puts "TEST_NAME not implemented"
24
+ end
25
+
26
+ def cleanup
27
+ # Add cleanup code here
28
+ end
29
+
30
+ end
@@ -0,0 +1,87 @@
1
+ require 'pad_utils'
2
+ require 'PADGEM_GEM_RUBY_NAME'
3
+
4
+ class Test
5
+
6
+ attr_accessor :test_name, :errors, :notes, :result
7
+
8
+ def initialize(test_name)
9
+ @test_name = test_name
10
+ @errors = []
11
+ @notes = []
12
+ @result = {name: test_name, errors: @errors.length}
13
+ end
14
+
15
+ def explain
16
+ puts
17
+ PadUtils.puts_c "Running: #{@test_name}...", :green
18
+ puts
19
+ end
20
+
21
+ def raise_error(e)
22
+ puts
23
+ PadUtils.puts_c "Error in #{@test_name}: ", :error
24
+ puts "#{e.message} (#{e.class.name})"
25
+ stack = e.backtrace.inspect.split(",")
26
+ stack.each do |s|
27
+ puts "\t#{s}"
28
+ end
29
+ puts
30
+ end
31
+
32
+ def leave
33
+ puts
34
+ PadUtils.puts_c "Finished running: #{@test_name}", @errors.length < 1 ? :green : :error
35
+
36
+ if @errors.length < 1
37
+ PadUtils.puts_c "- 0 errors", :green
38
+ else
39
+ PadUtils.puts_c "- #{@errors.length} error(s):", :error
40
+ @errors.each do |error|
41
+ PadUtils.puts_c "--> #{error}"
42
+ end
43
+ end
44
+ puts
45
+
46
+ if @notes.length > 0
47
+ PadUtils.puts_c "- #{@notes.length} note(s):", :green
48
+ @notes.each do |note|
49
+ PadUtils.puts_c "--> #{note}"
50
+ end
51
+ puts
52
+ end
53
+
54
+ PadUtils.puts_c "--------------------", :green
55
+ puts
56
+ end
57
+
58
+ def run
59
+ explain
60
+ prepare
61
+ runner
62
+ cleanup
63
+ leave
64
+ @result[:errors] = @errors.length
65
+ @result
66
+ end
67
+
68
+ def runner
69
+ run_test
70
+ rescue Exception => e
71
+ @errors << "Error message: #{e.message}"
72
+ raise_error(e)
73
+ end
74
+
75
+ def run_test
76
+ PadUtils.puts_c "'#{@test_name} run_test method' not implemented!", :error
77
+ end
78
+
79
+ def prepare
80
+ PadUtils.puts_c "'#{@test_name} prepare method' not implemented!", :error
81
+ end
82
+
83
+ def cleanup
84
+ PadUtils.puts_c "'#{@test_name} cleanup method' not implemented!", :error
85
+ end
86
+
87
+ end
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+ require 'pad_utils'
5
+ require 'PADGEM_GEM_RUBY_NAME'
6
+ require_relative 'helper'
7
+
8
+ start_time = Time.now
9
+ number_of_tests = 0
10
+ errors_list = []
11
+
12
+ puts
13
+
14
+ PadUtils.puts_c "Running tests...", :blue
15
+
16
+ Dir["units/*_test.rb"].each do |file|
17
+ require_relative file
18
+
19
+ class_name = get_class_name(file)
20
+
21
+ clazz = Object.const_get(class_name)
22
+ c = clazz.new(class_name)
23
+ errors = c.run
24
+
25
+ if errors[:errors] > 0
26
+ errors_list << errors
27
+ end
28
+
29
+ number_of_tests += 1
30
+ end
31
+
32
+ end_time = Time.now
33
+
34
+ PadUtils.puts_c "Finished running #{number_of_tests} tests in #{time_diff_sec start_time, end_time} seconds", :blue
35
+ if errors_list.length > 0
36
+ PadUtils.puts_c "--> Failed (#{errors_list.length}): ", :error
37
+ errors_list.each do |err|
38
+ PadUtils.puts_c "- #{err[:name]}: #{err[:errors]} error(s)"
39
+ end
40
+ else
41
+ PadUtils.puts_c "--> 0 errors", :green
42
+ end
43
+ puts
@@ -0,0 +1,22 @@
1
+ require 'pad_utils'
2
+ require 'PADGEM_GEM_RUBY_NAME'
3
+ require_relative '../template/test'
4
+
5
+ # Test name
6
+ test_name = "Sample"
7
+
8
+ class SampleTest < Test
9
+
10
+ def prepare
11
+ puts "I'm preparing..."
12
+ end
13
+
14
+ def run_test
15
+ puts "Running the test..."
16
+ end
17
+
18
+ def cleanup
19
+ puts "Cleaning up after the test..."
20
+ end
21
+
22
+ end
@@ -64,6 +64,21 @@ module PadGem
64
64
  # lib/foundation/version.rb
65
65
  PadUtils.replace_in_file("lib/foundation/version.rb", /PADGEM_GEM_NAME/, options[:gem_name])
66
66
 
67
+ # test/test_runner.rb
68
+ PadUtils.replace_in_file("test/test_runner.rb", /PADGEM_GEM_RUBY_NAME/, options[:gem_ruby_name])
69
+
70
+ # test/Gemfile
71
+ PadUtils.replace_in_file("test/Gemfile", /PADGEM_GEM_RUBY_NAME/, options[:gem_ruby_name])
72
+
73
+ # test/units/sample_test.rb
74
+ PadUtils.replace_in_file("test/units/sample_test.rb", /PADGEM_GEM_RUBY_NAME/, options[:gem_ruby_name])
75
+
76
+ # test/template/template.rb
77
+ PadUtils.replace_in_file("test/template/template.rb", /PADGEM_GEM_RUBY_NAME/, options[:gem_ruby_name])
78
+
79
+ # test/template/test.rb
80
+ PadUtils.replace_in_file("test/template/test.rb", /PADGEM_GEM_RUBY_NAME/, options[:gem_ruby_name])
81
+
67
82
  end
68
83
  end
69
84
 
@@ -1,3 +1,3 @@
1
1
  module PadGem
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pad_gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nico Schuele
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-23 00:00:00.000000000 Z
11
+ date: 2016-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pad_utils
@@ -50,6 +50,14 @@ files:
50
50
  - lib/foundation/foundation.gemspec
51
51
  - lib/foundation/lib/foundation.rb
52
52
  - lib/foundation/lib/foundation/version.rb
53
+ - lib/foundation/test/Gemfile
54
+ - lib/foundation/test/add_test.rb
55
+ - lib/foundation/test/helper.rb
56
+ - lib/foundation/test/how_to_test.txt
57
+ - lib/foundation/test/template/template.rb
58
+ - lib/foundation/test/template/test.rb
59
+ - lib/foundation/test/test_runner.rb
60
+ - lib/foundation/test/units/sample_test.rb
53
61
  - lib/pad_gem.rb
54
62
  - lib/pad_gem/generator.rb
55
63
  - lib/pad_gem/menu.rb
@@ -79,3 +87,4 @@ signing_key:
79
87
  specification_version: 4
80
88
  summary: Gem generator
81
89
  test_files: []
90
+ has_rdoc: