vipergen-afnan 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +157 -0
  4. data/bin/vipergen +9 -0
  5. data/lib/templates/MAU/objc/Application Logic/DataManager/API/VIPERAPIDataManager.h +15 -0
  6. data/lib/templates/MAU/objc/Application Logic/DataManager/API/VIPERAPIDataManager.m +13 -0
  7. data/lib/templates/MAU/objc/Application Logic/DataManager/Local/VIPERLocalDataManager.h +15 -0
  8. data/lib/templates/MAU/objc/Application Logic/DataManager/Local/VIPERLocalDataManager.m +13 -0
  9. data/lib/templates/MAU/objc/Application Logic/Interactor/VIPERInteractor.h +19 -0
  10. data/lib/templates/MAU/objc/Application Logic/Interactor/VIPERInteractor.m +14 -0
  11. data/lib/templates/MAU/objc/Application Logic/Interactor/VIPERItem.h +13 -0
  12. data/lib/templates/MAU/objc/Application Logic/Interactor/VIPERItem.m +13 -0
  13. data/lib/templates/MAU/objc/Module Interface/VIPERProtocols.h +83 -0
  14. data/lib/templates/MAU/objc/User Interface/Presenter/VIPERPresenter.h +20 -0
  15. data/lib/templates/MAU/objc/User Interface/Presenter/VIPERPresenter.m +14 -0
  16. data/lib/templates/MAU/objc/User Interface/View/VIPERView.h +16 -0
  17. data/lib/templates/MAU/objc/User Interface/View/VIPERView.m +35 -0
  18. data/lib/templates/MAU/objc/User Interface/WireFrame/VIPERWireFrame.h +21 -0
  19. data/lib/templates/MAU/objc/User Interface/WireFrame/VIPERWireFrame.m +35 -0
  20. data/lib/templates/MAU/swift/Application Logic/DataManager/API/VIPERAPIDataManager.swift +14 -0
  21. data/lib/templates/MAU/swift/Application Logic/DataManager/Local/VIPERLocalDataManager.swift +14 -0
  22. data/lib/templates/MAU/swift/Application Logic/Interactor/VIPERInteractor.swift +18 -0
  23. data/lib/templates/MAU/swift/Application Logic/Interactor/VIPERItem.swift +16 -0
  24. data/lib/templates/MAU/swift/Module Interface/VIPERProtocols.swift +73 -0
  25. data/lib/templates/MAU/swift/User Interface/Presenter/VIPERPresenter.swift +18 -0
  26. data/lib/templates/MAU/swift/User Interface/View/VIPERView.swift +15 -0
  27. data/lib/templates/MAU/swift/User Interface/WireFrame/VIPERWireFrame.swift +31 -0
  28. data/lib/templates/MAU/viperspec.yml +4 -0
  29. data/lib/templates/default/objc/DataManager/API/VIPERAPIDataManager.h +12 -0
  30. data/lib/templates/default/objc/DataManager/API/VIPERAPIDataManager.m +10 -0
  31. data/lib/templates/default/objc/DataManager/Local/VIPERLocalDataManager.h +12 -0
  32. data/lib/templates/default/objc/DataManager/Local/VIPERLocalDataManager.m +10 -0
  33. data/lib/templates/default/objc/Interactor/VIPERInteractor.h +16 -0
  34. data/lib/templates/default/objc/Interactor/VIPERInteractor.m +10 -0
  35. data/lib/templates/default/objc/Interactor/VIPERItem.h +10 -0
  36. data/lib/templates/default/objc/Interactor/VIPERItem.m +10 -0
  37. data/lib/templates/default/objc/Presenter/VIPERPresenter.h +17 -0
  38. data/lib/templates/default/objc/Presenter/VIPERPresenter.m +11 -0
  39. data/lib/templates/default/objc/Protocols/VIPERProtocols.h +80 -0
  40. data/lib/templates/default/objc/View/VIPERView.h +13 -0
  41. data/lib/templates/default/objc/View/VIPERView.m +32 -0
  42. data/lib/templates/default/objc/WireFrame/VIPERWireFrame.h +18 -0
  43. data/lib/templates/default/objc/WireFrame/VIPERWireFrame.m +32 -0
  44. data/lib/templates/default/swift/DataManager/API/VIPERAPIDataManager.swift +11 -0
  45. data/lib/templates/default/swift/DataManager/Local/VIPERLocalDataManager.swift +11 -0
  46. data/lib/templates/default/swift/Interactor/VIPERInteractor.swift +15 -0
  47. data/lib/templates/default/swift/Interactor/VIPERItem.swift +13 -0
  48. data/lib/templates/default/swift/Presenter/VIPERPresenter.swift +15 -0
  49. data/lib/templates/default/swift/Protocols/VIPERProtocols.swift +70 -0
  50. data/lib/templates/default/swift/View/VIPERView.swift +12 -0
  51. data/lib/templates/default/swift/WireFrame/VIPERWireFrame.swift +29 -0
  52. data/lib/templates/default/viperspec.yml +4 -0
  53. data/lib/templates/testable/objc/DataManager/VIPERDataManager.h +15 -0
  54. data/lib/templates/testable/objc/DataManager/VIPERDataManager.m +11 -0
  55. data/lib/templates/testable/objc/Interactor/VIPERInteractor.h +16 -0
  56. data/lib/templates/testable/objc/Interactor/VIPERInteractor.m +10 -0
  57. data/lib/templates/testable/objc/Interactor/VIPERInteractorSpec.m +31 -0
  58. data/lib/templates/testable/objc/Presenter/VIPERPresenter.h +18 -0
  59. data/lib/templates/testable/objc/Presenter/VIPERPresenter.m +11 -0
  60. data/lib/templates/testable/objc/Presenter/VIPERPresenterSpec.m +31 -0
  61. data/lib/templates/testable/objc/Protocols/VIPERProtocols.h +64 -0
  62. data/lib/templates/testable/objc/ViewController/VIPERViewController.h +13 -0
  63. data/lib/templates/testable/objc/ViewController/VIPERViewController.m +32 -0
  64. data/lib/templates/testable/objc/ViewController/VIPERViewControllerSpec.m +31 -0
  65. data/lib/templates/testable/objc/WireFrame/VIPERWireFrame.h +19 -0
  66. data/lib/templates/testable/objc/WireFrame/VIPERWireFrame.m +31 -0
  67. data/lib/templates/testable/swift/DataManager/API/VIPERAPIDataManager.swift +11 -0
  68. data/lib/templates/testable/swift/DataManager/Local/VIPERLocalDataManager.swift +11 -0
  69. data/lib/templates/testable/swift/Interactor/VIPERInteractor.swift +15 -0
  70. data/lib/templates/testable/swift/Interactor/VIPERInteractorSpec.swift +22 -0
  71. data/lib/templates/testable/swift/Interactor/VIPERItem.swift +13 -0
  72. data/lib/templates/testable/swift/Presenter/VIPERPresenter.swift +15 -0
  73. data/lib/templates/testable/swift/Presenter/VIPERPresenterSpec.swift +22 -0
  74. data/lib/templates/testable/swift/Protocols/VIPERProtocols.swift +70 -0
  75. data/lib/templates/testable/swift/View/VIPERView.swift +12 -0
  76. data/lib/templates/testable/swift/View/VIPERViewSpec.swift +22 -0
  77. data/lib/templates/testable/swift/WireFrame/VIPERWireFrame.swift +29 -0
  78. data/lib/templates/testable/viperspec.yml +4 -0
  79. data/lib/vipergen.rb +6 -0
  80. data/lib/vipergen/dirutils.rb +17 -0
  81. data/lib/vipergen/filemanager.rb +51 -0
  82. data/lib/vipergen/generator.rb +74 -0
  83. data/lib/vipergen/templatemanager.rb +53 -0
  84. data/lib/vipergen/version.rb +4 -0
  85. data/lib/vipergen/viperthor.rb +23 -0
  86. data/spec/spec_helper.rb +4 -0
  87. data/spec/vipergen/vipergen_spec.rb +133 -0
  88. metadata +206 -0
@@ -0,0 +1,12 @@
1
+ //
2
+ // Created by AUTHOR.
3
+ // Copyright (c) YEAR AUTHOR. All rights reserved.
4
+ //
5
+
6
+ import Foundation
7
+ import UIKit
8
+
9
+ class VIPERView: UIViewController, VIPERViewProtocol
10
+ {
11
+ var presenter: VIPERPresenterProtocol?
12
+ }
@@ -0,0 +1,22 @@
1
+ //
2
+ // Created by AUTHOR.
3
+ // Copyright (c) YEAR AUTHOR. All rights reserved.
4
+ //
5
+
6
+ import Quick
7
+ import Nimble
8
+
9
+ @testable import SWIFT_MODULE
10
+
11
+ class VIPERViewSpec: QuickSpec{
12
+
13
+ class Mock{
14
+
15
+ }
16
+
17
+ override func spec(){
18
+ describe(""){
19
+
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,29 @@
1
+ //
2
+ // Created by AUTHOR.
3
+ // Copyright (c) YEAR AUTHOR. All rights reserved.
4
+ //
5
+
6
+ import Foundation
7
+
8
+ class VIPERWireFrame: VIPERWireFrameProtocol
9
+ {
10
+ class func presentVIPERModule(fromView view: AnyObject)
11
+ {
12
+ // Generating module components
13
+ let view: VIPERViewProtocol = VIPERView()
14
+ let presenter: protocol<VIPERPresenterProtocol, VIPERInteractorOutputProtocol> = VIPERPresenter()
15
+ let interactor: VIPERInteractorInputProtocol = VIPERInteractor()
16
+ let APIDataManager: VIPERAPIDataManagerInputProtocol = VIPERAPIDataManager()
17
+ let localDataManager: VIPERLocalDataManagerInputProtocol = VIPERLocalDataManager()
18
+ let wireFrame: VIPERWireFrameProtocol = VIPERWireFrame()
19
+
20
+ // Connecting
21
+ view.presenter = presenter
22
+ presenter.view = view
23
+ presenter.wireFrame = wireFrame
24
+ presenter.interactor = interactor
25
+ interactor.presenter = presenter
26
+ interactor.APIDataManager = APIDataManager
27
+ interactor.localDatamanager = localDataManager
28
+ }
29
+ }
@@ -0,0 +1,4 @@
1
+ author: Michal Wojtysiak (Roche)
2
+ author_email: michal.wojtysiak@roche.com
3
+ template_description: Template for VIPER structure including Tests (BDD/TDD), Swift 2.0 compatible. Quick&Nible for Swift, Specta, Expecta, OCMockito for Obj-C
4
+ updated_at: 2015-09-30
data/lib/vipergen.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'vipergen/generator'
2
+ require 'vipergen/filemanager'
3
+ require 'vipergen/dirutils'
4
+ require 'vipergen/version'
5
+ require 'vipergen/viperthor'
6
+ require 'vipergen/templatemanager'
@@ -0,0 +1,17 @@
1
+ module Vipergen
2
+ class DirUtils
3
+ # Return a directory with the project libraries.
4
+ def self.gem_libdir
5
+ t = ["#{File.dirname(File.expand_path($0))}/../lib/#{Vipergen::NAME}",
6
+ "#{Gem.dir}/gems/#{Vipergen::NAME}-#{Vipergen::VERSION}/lib/#{Vipergen::NAME}"]
7
+ t.each {|i| return i if File.readable?(i) }
8
+ raise "both paths are invalid: #{t}"
9
+ end
10
+
11
+ # Returns the directories inside a given one
12
+ def self.directories_in(directory)
13
+ expanded_dir = File.expand_path(directory)
14
+ return Dir.glob(File.join(expanded_dir,'*')).select {|f| File.directory? f}
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,51 @@
1
+ module Vipergen
2
+ # File manager class
3
+ class FileManager
4
+
5
+ # Returns if the template is valid by the VIPER generator
6
+ def self.is_template_valid(template)
7
+ return Vipergen::TemplateManager.templates.include? template
8
+ end
9
+
10
+ # Returns if the language is valid by the VIPER generator
11
+ def self.is_language_valid(language)
12
+ return (Vipergen::Generator::LANGUAGES).include? language
13
+ end
14
+
15
+ # Return the path if valid template and language
16
+ # @return String with valid path
17
+ def self.path_from(template, language)
18
+ return nil if !is_language_valid(language) || !is_template_valid(template)
19
+ return File.join(Vipergen::TemplateManager.templates_dir, template, language)
20
+ end
21
+
22
+ # Returns an array with files in a given path
23
+ # @return Array with the files in a given path
24
+ def self.files_in_path(path)
25
+ return Dir[File.join("#{path}","/**/*")].select {|f| File.file?(f)}
26
+ end
27
+
28
+ # Returns the destination viper path
29
+ # @return Destination root path
30
+ def self.destination_viper_path(path, name)
31
+ expand_path = File.expand_path(path)
32
+ return File.join(expand_path,name)
33
+ end
34
+
35
+ # Copy a system item to another place
36
+ def self.copy(from, to)
37
+ to_expand_path = File.expand_path(to)
38
+ from_expand_path = File.expand_path(from)
39
+ FileUtils.mkdir_p (to_expand_path)
40
+ FileUtils.copy_entry(from_expand_path, to_expand_path)
41
+ end
42
+
43
+ # Move a system item to another place
44
+ def self.move(from, to)
45
+ to_expand_path = File.expand_path(to)
46
+ from_expand_path = File.expand_path(from)
47
+ FileUtils.move(from_expand_path, to_expand_path)
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,74 @@
1
+ module Vipergen
2
+ # Cosntants
3
+ class Generator
4
+ # Constants
5
+ LANGUAGES = ["swift", "objc"]
6
+ REPLACEMENT_KEY = "VIPER"
7
+ AUTHOR_REPLACEMENT_KEY = "AUTHOR"
8
+ YEAR_REPLACEMENT_KEY = "YEAR"
9
+ DATE_REPLACEMENT_KEY = "DATE"
10
+ PROJECT_REPLACEMENT_KEY = "PROJECT"
11
+ COMPANY_REPLACEMENT_KEY = "COMPANY"
12
+ SWIFT_MODULE_REPLACEMENT_KEY = "SWIFT_MODULE"
13
+
14
+ # Main method that generate the VIPER files structure
15
+ def self.generate_viper(template, language, name, path, author, project, company, swift_module)
16
+ puts "Generating VIPER-Module"
17
+ puts "Template: #{template}"
18
+ puts "Language: #{language}"
19
+ puts "Name: #{name}"
20
+ puts "Path: #{path}"
21
+ puts "Author: #{author}"
22
+ puts "Project: #{project}"
23
+ puts "Company: #{company}"
24
+ puts "Module: #{swift_module}"
25
+ path_from = Vipergen::FileManager.path_from(template, language)
26
+ path_to = Vipergen::FileManager.destination_viper_path(path, name)
27
+ Vipergen::FileManager.copy(path_from, path_to)
28
+ files = Vipergen::FileManager.files_in_path(path_to)
29
+ rename_files(files, name, author, project, company, swift_module)
30
+ end
31
+
32
+ # Rename all the files in the files array
33
+ # - It renames the name of the file
34
+ # - It renames the content of the file
35
+ def self.rename_files(files, name, author, project, company, swift_module)
36
+ files.each do |file|
37
+ raise SyntaxError unless file.include? (Vipergen::Generator::REPLACEMENT_KEY)
38
+ rename_file(file, name, author, project, company, swift_module)
39
+ end
40
+ end
41
+
42
+ # Rename a given file
43
+ # - It renames the name of the file
44
+ # - It renames the content of the file
45
+ def self.rename_file(file, name, author, project, company, swift_module)
46
+ new_path = file.gsub((Vipergen::Generator::REPLACEMENT_KEY), name)
47
+ Vipergen::FileManager.move(file, new_path)
48
+ rename_file_content(new_path, name, author, project, company, swift_module)
49
+ end
50
+
51
+ # Rename the file content
52
+ # @return: An String with the every VIPER replaced by 'name'
53
+ def self.rename_file_content(filename, name, author, project, company, swift_module)
54
+ # Reading content
55
+ file = File.open(filename, "rb")
56
+ content = file.read
57
+ file.close
58
+
59
+ # Replacing content
60
+ content = content.gsub((Vipergen::Generator::REPLACEMENT_KEY), name)
61
+ content = content.gsub((Vipergen::Generator::AUTHOR_REPLACEMENT_KEY), author)
62
+ content = content.gsub((Vipergen::Generator::PROJECT_REPLACEMENT_KEY), project)
63
+ content = content.gsub((Vipergen::Generator::COMPANY_REPLACEMENT_KEY), company)
64
+ content = content.gsub((Vipergen::Generator::SWIFT_MODULE_REPLACEMENT_KEY), swift_module)
65
+ content = content.gsub((Vipergen::Generator::YEAR_REPLACEMENT_KEY), "#{Time.new.year}")
66
+ content = content.gsub((Vipergen::Generator::DATE_REPLACEMENT_KEY), "#{Time.now.strftime("%d/%m/%y")}")
67
+
68
+ # Saving content with replaced string
69
+ File.open(filename, "w+") do |file|
70
+ file.write(content)
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,53 @@
1
+ require 'yaml'
2
+ module Vipergen
3
+ class TemplateManager
4
+
5
+ # Returns the templates dir
6
+ def self.templates_dir
7
+ t = "#{File.expand_path File.dirname(__FILE__)}/../templates"
8
+ end
9
+
10
+ # Get the available templates paths
11
+ # @return Array[String] with available templates paths
12
+ def self.templates_paths()
13
+ template_dir = Vipergen::TemplateManager.templates_dir
14
+ return Vipergen::DirUtils.directories_in(template_dir)
15
+ end
16
+
17
+ # Get the templates names
18
+ # @return Array[String] with templates names (got from the folder)
19
+ def self.templates()
20
+ templates_paths.map{|template_path| template_name_from_path(template_path)}
21
+ end
22
+
23
+ # Returns the template name from a given template_path
24
+ # @return String with the template name
25
+ def self.template_name_from_path(template_path)
26
+ return template_path.split("/").last
27
+ end
28
+
29
+ # Returns the description of all the templates available
30
+ # @return String with the entire description
31
+ def self.templates_description()
32
+ description = "\nAvailable templates \n"
33
+ description += "------------------- \n"
34
+ self.templates_paths.each do |template_path|
35
+ description += "> #{template_description(template_path)} \n"
36
+ end
37
+ return description
38
+ end
39
+
40
+ # Returns the description of a given template
41
+ # @param template String with the template path whose description is going to be returned
42
+ # @return String with the template description
43
+ def self.template_description(template_path)
44
+ template_description = ""
45
+
46
+ # Reading yaml
47
+ template_content = YAML.load_file(File.join(template_path,'viperspec.yml'))
48
+
49
+ # Generating string
50
+ template_description+= "| #{template_name_from_path(template_path)} by #{template_content["author"]} |: #{template_content["template_description"]}"
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,4 @@
1
+ module Vipergen
2
+ NAME = "vipergen"
3
+ VERSION = "0.2.7"
4
+ end
@@ -0,0 +1,23 @@
1
+ require 'thor'
2
+ require 'vipergen'
3
+
4
+ module Vipergen
5
+ class ViperThor < Thor
6
+ desc "generate", "Generate a VIPER module"
7
+ option :language, :required => false, :default => 'objc', :type => :string, :desc => "The language of the generated module (swift, objc)"
8
+ option :template, :required => false, :default => 'default', :type => :string , :desc => "Template for the generation"
9
+ option :path, :required => true, :type => :string , :desc => "Path where the output module is going to be saved"
10
+ option :author, :required => false, :default => 'VIPER', :type => :string , :desc => "Author to be specified on the file's header. Otherwise VIPER will be used"
11
+ option :project, :required => false, :default => 'VIPER', :type => :string , :desc => "Project to be specified on the file's header. Otherwise VIPER will be used"
12
+ option :company, :required => false, :default => 'VIPER', :type => :string , :desc => "Company to be specified on the file's header. Otherwise VIPER will be used"
13
+ option :swift_module, :required => false, :default => 'VIPER', :type => :string , :desc => "Swift module name to be specified on the @testable directive. Otherwise VIPER will be used"
14
+ def generate(name)
15
+ Vipergen::Generator.generate_viper(options[:template], options[:language], name, options[:path], options[:author], options[:project], options[:company], options[:swift_module])
16
+ end
17
+
18
+ desc "templates", "Get a list of available templates"
19
+ def templates()
20
+ puts Vipergen::TemplateManager.templates_description()
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,4 @@
1
+ require 'vipergen'
2
+ require "codeclimate-test-reporter"
3
+
4
+ CodeClimate::TestReporter.start
@@ -0,0 +1,133 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vipergen do
4
+ context "when generating path" do
5
+ it "should return nil if no valid template" do
6
+ valid_template = Vipergen::FileManager.is_template_valid("asdgas")
7
+ expect(valid_template).to be(false)
8
+ end
9
+ it "should return nil if no valid language" do
10
+ valid_template = Vipergen::FileManager.is_template_valid("asdgas")
11
+ expect(valid_template).to be(false)
12
+ end
13
+ it "should return nil if no valid language when getting path" do
14
+ path = Vipergen::FileManager.path_from("default", "asgass")
15
+ expect(path).to be(nil)
16
+ end
17
+ it "should return nil if no valid template when getting path" do
18
+ path = Vipergen::FileManager.path_from("asga", "swift")
19
+ expect(path).to be(nil)
20
+ end
21
+ it "should append the name to the given user path" do
22
+ to_path = Vipergen::FileManager.destination_viper_path("path/", "pepito")
23
+ expect(to_path).to eq(File.join(File.expand_path("path/"),"pepito"))
24
+ end
25
+ end
26
+ context "copying a folder to a diferent place" do
27
+ before (:each) do
28
+ Dir.mkdir 'foo'
29
+ Dir.mkdir 'foo/subfoo'
30
+ end
31
+
32
+ it "should copy a given folder properly" do
33
+ Vipergen::FileManager.copy('foo','test_foo')
34
+ expect(File.directory?('test_foo/subfoo')).to eq(true)
35
+ end
36
+
37
+ after (:each) do
38
+ FileUtils.rm_rf('foo')
39
+ FileUtils.rm_rf('test_foo')
40
+ end
41
+ end
42
+ end
43
+
44
+ describe Vipergen::Generator do
45
+ context "when renaming file content" do
46
+ before (:each) do
47
+ File.open("test.txt", 'w') {|f| f.write("I'm a #{Vipergen::Generator::REPLACEMENT_KEY} file by #{Vipergen::Generator::AUTHOR_REPLACEMENT_KEY} on #{Vipergen::Generator::YEAR_REPLACEMENT_KEY}") }
48
+ end
49
+
50
+ it "should rename every VIPER word to the given name" do
51
+ Vipergen::Generator.rename_file_content("test.txt","RENAMED", "pepito")
52
+ file = File.open("test.txt", "rb")
53
+ content = file.read
54
+ expect(content).to eq("I'm a RENAMED file by pepito on #{Time.new.year}")
55
+ end
56
+
57
+ after (:each) do
58
+ FileUtils.rm('test.txt')
59
+ end
60
+ end
61
+
62
+ context "when renaming file" do
63
+ before (:each) do
64
+ File.open("#{Vipergen::Generator::REPLACEMENT_KEY}test.txt", 'w') {|f| f.write("I'm a #{Vipergen::Generator::REPLACEMENT_KEY} file") }
65
+ end
66
+
67
+ it "every file should be renamed in rename_files" do
68
+ expect(Vipergen::Generator).to receive(:rename_file)
69
+ Vipergen::Generator.rename_files(["#{Vipergen::Generator::REPLACEMENT_KEY}file.txt"], "MyModule", "Pepi")
70
+ end
71
+
72
+ it "should raise a SyntaxError exeption if there's a file in the template without the proper name" do
73
+ expect{Vipergen::Generator.rename_files(["asgasgs.txt"], "MyModule", "Pepi")}.to raise_error
74
+ end
75
+
76
+ it "should rename the VIPER in name to the given name" do
77
+ file = "#{Vipergen::Generator::REPLACEMENT_KEY}test.txt"
78
+ name = "RENAMED"
79
+ author = "PEPI"
80
+ Vipergen::Generator.rename_file(file, name, author)
81
+ expect(File.exist? "RENAMEDtest.txt").to eq(true)
82
+ end
83
+
84
+ it "should rename the file content after the file name rename" do
85
+ file = "#{Vipergen::Generator::REPLACEMENT_KEY}test.txt"
86
+ name = "RENAMED"
87
+ author = "PEPI"
88
+ expect(Vipergen::Generator).to receive(:rename_file_content)
89
+ Vipergen::Generator.rename_file(file, name, author)
90
+ end
91
+
92
+ after (:each) do
93
+ File.delete "#{Vipergen::Generator::REPLACEMENT_KEY}test.txt" if File.exist? "#{Vipergen::Generator::REPLACEMENT_KEY}test.txt"
94
+ File.delete "RENAMEDtest.txt" if File.exist? "RENAMEDtest.txt"
95
+ end
96
+ end
97
+ end
98
+
99
+ describe Vipergen::DirUtils do
100
+ context "getting directories" do
101
+ before (:each) do
102
+ Dir.mkdir 'foo'
103
+ Dir.mkdir 'foo/subfoo'
104
+ end
105
+
106
+ it "should return the directories inside a given one" do
107
+ expect(Vipergen::DirUtils.directories_in('foo').count).to eq(1)
108
+ end
109
+
110
+ after (:each) do
111
+ FileUtils.rm_rf('foo')
112
+ end
113
+ end
114
+ end
115
+
116
+ describe Vipergen::TemplateManager do
117
+ context "getting templates" do
118
+ before (:each) do
119
+ Dir.mkdir 'foo'
120
+ Dir.mkdir 'foo/subfoo'
121
+ Dir.mkdir 'foo/subfoo2'
122
+ end
123
+
124
+ it "should return the proper templates in templates directory" do
125
+ Vipergen::TemplateManager.stub(:templates_dir).and_return('foo/')
126
+ expect(Vipergen::TemplateManager.templates_paths.count).to eq(2)
127
+ end
128
+
129
+ after (:each) do
130
+ FileUtils.rm_rf('foo')
131
+ end
132
+ end
133
+ end