Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/generamba/cli/gen_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def gen(module_name, template_name)
code_module = CodeModule.new(module_name, module_description, rambafile, options)

DependencyChecker.check_all_required_dependencies_has_in_podfile(template.dependencies, code_module.podfile_path)
DependencyChecker.check_all_required_dependencies_has_in_cartfile(template.dependencies, code_module.cartfile_path)

project = XcodeprojHelper.obtain_project(code_module.xcodeproj_path)
module_group_already_exists = XcodeprojHelper.module_with_group_path_already_exists(project, code_module.module_group_path)
Expand Down
4 changes: 3 additions & 1 deletion lib/generamba/code_generation/code_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class CodeModule
:test_group_path,
:project_targets,
:test_targets,
:podfile_path
:podfile_path,
:cartfile_path

def initialize(name, description, rambafile, options)
# Base initialization
Expand Down Expand Up @@ -65,6 +66,7 @@ def initialize(name, description, rambafile, options)
@test_group_path = Pathname.new(options[:test_path]).join(@name) if options[:test_path]

@podfile_path = rambafile[PODFILE_PATH_KEY] if rambafile[PODFILE_PATH_KEY] != nil
@cartfile_path = rambafile[CARTFILE_PATH_KEY] if rambafile[CARTFILE_PATH_KEY] != nil
end
end
end
24 changes: 23 additions & 1 deletion lib/generamba/helpers/dependency_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Generamba
# Provides methods for check dependencies from rambaspec in podfile
class DependencyChecker

# Check podfile for dependencies
# Check Podfile for dependencies
# @param dependencies [Array] Array of dependencies name
# @param podfile_path [String] String of Podfile path
#
Expand All @@ -31,6 +31,28 @@ def self.check_all_required_dependencies_has_in_podfile(dependencies, podfile_pa
end
end

# Check Cartfile for dependencies
# @param dependencies [Array] Array of dependencies name
# @param cartfile_path [String] String of Podfile path
#
# @return [void]
def self.check_all_required_dependencies_has_in_cartfile(dependencies, cartfile_path)
return if !dependencies or dependencies.count == 0 or !cartfile_path

cartfile_string = File.read(cartfile_path)

not_existing_dependency = []
dependencies.each do |dependency_name|
unless cartfile_string.include?(dependency_name)
not_existing_dependency.push(dependency_name)
end
end

if not_existing_dependency.count > 0
puts "[Warning] Dependencies #{not_existing_dependency} missed in Cartfile".yellow
end
end

end

end
32 changes: 32 additions & 0 deletions spec/dependency_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,36 @@
end
end

describe 'method check_all_required_dependencies_has_in_cartfile' do
it 'should do nothing' do
dependencies = ['ViperMcFlurry']
cartfile_path = 'Cartfile'

expect(STDOUT).not_to receive(:puts).with("[Warning] Dependencies #{dependencies} missed in Cartfile".yellow)

@checker.check_all_required_dependencies_has_in_cartfile(dependencies, nil)
@checker.check_all_required_dependencies_has_in_cartfile(nil, cartfile_path)
end

it 'should show warning message if dependency missing' do
dependencies = ['ViperMcFlurry']
cartfile_path = 'Cartfile'

allow(File).to receive(:read).and_return('Typhoon')
expect(STDOUT).to receive(:puts).with("[Warning] Dependencies #{dependencies} missed in Cartfile".yellow)

@checker.check_all_required_dependencies_has_in_cartfile(dependencies, cartfile_path)
end

it 'should not show warning message if dependency is in place' do
dependencies = ['ViperMcFlurry']
cartfile_path = 'Cartfile'

allow(File).to receive(:read).and_return('github "Rambler-iOS/ViperMcFlurry"')
expect(STDOUT).not_to receive(:puts).with("[Warning] Dependencies #{dependencies} missed in Cartfile".yellow)

@checker.check_all_required_dependencies_has_in_cartfile(dependencies, cartfile_path)
end
end

end