Skip to content

Commit

Permalink
Merge pull request #11 from intercom/james/builder_spec
Browse files Browse the repository at this point in the history
Clean when building + specs
  • Loading branch information
jtreanor authored Dec 11, 2017
2 parents 26357fe + 70ab185 commit 01e4c83
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/cocoapods_mangle/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
42 changes: 42 additions & 0 deletions spec/unit/builder_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 01e4c83

Please sign in to comment.