-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathcocoapods-service.ts
178 lines (160 loc) · 4.31 KB
/
cocoapods-service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import * as yok from "../lib/common/yok";
import {assert} from "chai";
import {CocoaPodsService} from "../lib/services/cocoapods-service";
import {EOL} from "os";
import Future = require("fibers/future");
interface IMergePodfileHooksTestCase {
input: string;
output: string;
testCaseDescription: string;
}
function createTestInjector(): IInjector {
let testInjector: IInjector = new yok.Yok();
testInjector.register("fs", {});
testInjector.register("cocoapodsService", CocoaPodsService);
return testInjector;
}
// The newline characters should be replaced with EOL because on Windows the EOL is \r\n
// but the character which is placed in `` for newline is only \n
// if we do not replace the newline characters the tests will pass only on linux and mac.
function changeNewLineCharacter(input: string): string {
return input ? input.replace(/\r?\n/g, EOL) : input;
}
describe("Cocoapods service", () => {
describe("merge Podfile hooks", () => {
let testInjector: IInjector;
let cocoapodsService: ICocoaPodsService;
let newPodfileContent: string;
let mockFileSystem = (injector: IInjector, podfileContent: string): void => {
let fs: IFileSystem = injector.resolve("fs");
fs.exists = () => Future.fromResult(true);
fs.readText = () => Future.fromResult(podfileContent);
fs.writeFile = (pathToFile: string, content: any) => {
newPodfileContent = content;
return Future.fromResult();
};
};
let testCaces: IMergePodfileHooksTestCase[] = [
{
input: `
target 'MyApp' do
pod 'GoogleAnalytics', '~> 3.1'
target 'MyAppTests' do
inherit! :search_paths
pod 'OCMock', '~> 2.0.1'
end
end
post_install do |installer|
installer.pods_project.targets.each do |target|
puts target.name
end
end
post_install do |installer|
installer.pods_project.targets.each do |target|
puts target.name
end
end
post_install do |installer|
installer.pods_project.targets.each do |target|
puts target.name
end
end`,
output: `
target 'MyApp' do
pod 'GoogleAnalytics', '~> 3.1'
target 'MyAppTests' do
inherit! :search_paths
pod 'OCMock', '~> 2.0.1'
end
end
def post_install1 (installer)
installer.pods_project.targets.each do |target|
puts target.name
end
end
def post_install2 (installer)
installer.pods_project.targets.each do |target|
puts target.name
end
end
def post_install3 (installer)
installer.pods_project.targets.each do |target|
puts target.name
end
end
post_install do |installer|
post_install1 installer
post_install2 installer
post_install3 installer
end`,
testCaseDescription: "should merge more than one hooks with block parameter correctly."
}, {
input: `
target 'MyApp' do
pod 'GoogleAnalytics', '~> 3.1'
target 'MyAppTests' do
inherit! :search_paths
pod 'OCMock', '~> 2.0.1'
end
post_install do |installer_representation|
installer_representation.pods_project.targets.each do |target|
puts target.name
end
end
post_install do
puts "Hello World!"
end
end`,
output: `
target 'MyApp' do
pod 'GoogleAnalytics', '~> 3.1'
target 'MyAppTests' do
inherit! :search_paths
pod 'OCMock', '~> 2.0.1'
end
def post_install1 (installer_representation)
installer_representation.pods_project.targets.each do |target|
puts target.name
end
end
def post_install2
puts "Hello World!"
end
end
post_install do |installer|
post_install1 installer
post_install2
end`,
testCaseDescription: "should merge more than one hooks with and without block parameter correctly."
}, {
input: `
target 'MyApp' do
pod 'GoogleAnalytics', '~> 3.1'
target 'MyAppTests' do
inherit! :search_paths
pod 'OCMock', '~> 2.0.1'
end
end
post_install do |installer|
installer.pods_project.targets.each do |target|
puts target.name
end
end`,
output: null,
testCaseDescription: "should not change the Podfile when there is only one hook."
}
];
beforeEach(() => {
testInjector = createTestInjector();
cocoapodsService = testInjector.resolve("cocoapodsService");
newPodfileContent = null;
});
_.each(testCaces, (testCase: IMergePodfileHooksTestCase) => {
it(testCase.testCaseDescription, () => {
mockFileSystem(testInjector, testCase.input);
cocoapodsService.mergePodfileHookContent("post_install", "").wait();
assert.deepEqual(changeNewLineCharacter(newPodfileContent), changeNewLineCharacter(testCase.output));
});
});
});
});