From 70ab1853636e1138eea0b0ecb1848d72a0142b01 Mon Sep 17 00:00:00 2001 From: James Treanor Date: Mon, 11 Dec 2017 14:10:38 +0000 Subject: [PATCH] Clean when building + specs --- lib/cocoapods_mangle/builder.rb | 5 ++-- spec/unit/builder_spec.rb | 42 +++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 spec/unit/builder_spec.rb diff --git a/lib/cocoapods_mangle/builder.rb b/lib/cocoapods_mangle/builder.rb index 6d41609..d8e31b5 100644 --- a/lib/cocoapods_mangle/builder.rb +++ b/lib/cocoapods_mangle/builder.rb @@ -5,7 +5,8 @@ module CocoapodsMangle # # This is useful for building pods for mangling purposes class Builder - BUILT_PRODUCTS_DIR = 'build/Release-iphonesimulator' + BUILD_DIR = 'build' + BUILT_PRODUCTS_DIR = "#{BUILD_DIR}/Release-iphonesimulator" # @param [String] pods_project_path # path to the pods project to build. @@ -19,7 +20,7 @@ def initialize(pods_project_path, pod_target_labels) # Build the pods project def build! - FileUtils.remove_dir(BUILT_PRODUCTS_DIR, true) + FileUtils.remove_dir(BUILD_DIR, true) @pod_target_labels.each { |target| build_target(target) } end diff --git a/spec/unit/builder_spec.rb b/spec/unit/builder_spec.rb new file mode 100644 index 0000000..cd1e553 --- /dev/null +++ b/spec/unit/builder_spec.rb @@ -0,0 +1,42 @@ +require File.expand_path('../../spec_helper', __FILE__) +require 'cocoapods_mangle/builder' + +describe CocoapodsMangle::Builder do + let(:pods_project_path) { 'path/to/Pods.xcodeproj' } + let(:pod_target_labels) { %w[Pod-A Pod-B] } + let(:subject) { CocoapodsMangle::Builder.new(pods_project_path, pod_target_labels) } + + context '.build!' do + before do + allow(FileUtils).to receive(:remove_dir).with(CocoapodsMangle::Builder::BUILD_DIR, true) + end + + it 'builds' do + expect(FileUtils).to receive(:remove_dir).with(CocoapodsMangle::Builder::BUILD_DIR, true) + expect(subject).to receive(:build_target).with('Pod-A') + expect(subject).to receive(:build_target).with('Pod-B') + subject.build! + end + end + + context '.binaries_to_mangle' do + let(:static_binaries) { %w[path/to/staticA.a path/to/staticB.a] } + let(:frameworks) { %w[path/to/FrameworkA.framework path/to/FrameworkB.framework] } + let(:framework_binaries) do + frameworks.map { |path| "#{path}/#{File.basename(path, '.framework')}" } + end + before do + allow(Dir).to receive(:glob) + .with("#{CocoapodsMangle::Builder::BUILT_PRODUCTS_DIR}/**/*.a") + .and_return(static_binaries + ['path/to/libPods-A.a']) + allow(Dir).to receive(:glob) + .with("#{CocoapodsMangle::Builder::BUILT_PRODUCTS_DIR}/**/*.framework") + .and_return(frameworks + ['path/to/Pods_A.framework']) + end + + it 'gives the static and framework binaries' do + binaries = static_binaries + framework_binaries + expect(subject.binaries_to_mangle).to match_array(binaries) + end + end +end