alpacabuildtool 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +48 -0
  3. data/.rubocop.yml +12 -0
  4. data/.semver +6 -0
  5. data/.travis.yml +10 -0
  6. data/CHANGELOG +18 -0
  7. data/Gemfile +7 -0
  8. data/LICENSE +22 -0
  9. data/README.md +235 -0
  10. data/README.rdoc +39 -0
  11. data/Rakefile +74 -0
  12. data/alpacabuildtool.gemspec +34 -0
  13. data/alpacabuildtool.rdoc +5 -0
  14. data/alpacabuildtool.todo +9 -0
  15. data/bin/alpaca +142 -0
  16. data/features/alpaca.feature +8 -0
  17. data/features/step_definitions/alpaca_steps.rb +13 -0
  18. data/features/step_definitions/visual_studio_solutions_steps.rb +47 -0
  19. data/features/support/env.rb +10 -0
  20. data/features/visual_studio_solutions.feature +43 -0
  21. data/lib/alpacabuildtool.rb +4 -0
  22. data/lib/alpacabuildtool/application.rb +195 -0
  23. data/lib/alpacabuildtool/configuration.rb +209 -0
  24. data/lib/alpacabuildtool/data/.alpaca.conf +148 -0
  25. data/lib/alpacabuildtool/data/doom.flf +826 -0
  26. data/lib/alpacabuildtool/data/logo.jpg +0 -0
  27. data/lib/alpacabuildtool/entities/nuspec.rb +107 -0
  28. data/lib/alpacabuildtool/entities/project.rb +54 -0
  29. data/lib/alpacabuildtool/entities/solution.rb +104 -0
  30. data/lib/alpacabuildtool/entities/xml.rb +41 -0
  31. data/lib/alpacabuildtool/entities/xml_node.rb +75 -0
  32. data/lib/alpacabuildtool/log/font.rb +92 -0
  33. data/lib/alpacabuildtool/log/log.rb +15 -0
  34. data/lib/alpacabuildtool/log/rainbowify_formatter.rb +70 -0
  35. data/lib/alpacabuildtool/log/rainbowify_logger.rb +47 -0
  36. data/lib/alpacabuildtool/managers/build_manager.rb +32 -0
  37. data/lib/alpacabuildtool/managers/package_manager.rb +136 -0
  38. data/lib/alpacabuildtool/managers/report_manager.rb +33 -0
  39. data/lib/alpacabuildtool/managers/test_manager.rb +35 -0
  40. data/lib/alpacabuildtool/os.rb +29 -0
  41. data/lib/alpacabuildtool/package_types/project_package.rb +44 -0
  42. data/lib/alpacabuildtool/package_types/tool_package.rb +53 -0
  43. data/lib/alpacabuildtool/tools/git.rb +22 -0
  44. data/lib/alpacabuildtool/tools/msbuild.rb +29 -0
  45. data/lib/alpacabuildtool/tools/nuget.rb +49 -0
  46. data/lib/alpacabuildtool/tools/nunit.rb +28 -0
  47. data/lib/alpacabuildtool/tools/nunit_orange.rb +18 -0
  48. data/lib/alpacabuildtool/tools/open_cover.rb +29 -0
  49. data/lib/alpacabuildtool/tools/report_generator.rb +25 -0
  50. data/lib/alpacabuildtool/tools/tool.rb +84 -0
  51. data/lib/alpacabuildtool/tools/wrapper.rb +66 -0
  52. data/lib/alpacabuildtool/versioning/version.rb +163 -0
  53. data/lib/alpacabuildtool/versioning/versioning.rb +84 -0
  54. data/spec/lib/alpacabuildtool/configuration_spec.rb +201 -0
  55. data/spec/lib/alpacabuildtool/entities/xml_spec.rb +39 -0
  56. data/spec/lib/alpacabuildtool/versioning/version_spec.rb +86 -0
  57. data/spec/lib/alpacabuildtool/versioning/versioning_spec.rb +194 -0
  58. data/spec/spec_helper.rb +3 -0
  59. data/spec/support/coverage.rb +26 -0
  60. data/test_data/sln1/.alpaca.conf +11 -0
  61. data/test_data/sln1/.semver +6 -0
  62. data/test_data/sln1/TestSolution.sln +22 -0
  63. data/test_data/sln1/TestSolution/App.config +6 -0
  64. data/test_data/sln1/TestSolution/Program.cs +16 -0
  65. data/test_data/sln1/TestSolution/Properties/AssemblyInfo.cs +36 -0
  66. data/test_data/sln1/TestSolution/TestSolution.csproj +59 -0
  67. data/test_data/sln2/.alpaca.conf +8 -0
  68. data/test_data/sln2/.semver +6 -0
  69. data/test_data/sln2/ProjectName/ProjectName.csproj +54 -0
  70. data/test_data/sln2/ProjectName/Properties/AssemblyInfo.cs +36 -0
  71. data/test_data/sln2/ProjectName/SomeFolderInProject/SomeClass.cs +16 -0
  72. data/test_data/sln2/ProjectName2/ProjectName2.csproj +58 -0
  73. data/test_data/sln2/ProjectName2/Properties/AssemblyInfo.cs +37 -0
  74. data/test_data/sln2/SolutionName.sln +34 -0
  75. data/test_data/sln2/Unit.Tests/Properties/AssemblyInfo.cs +36 -0
  76. data/test_data/sln2/Unit.Tests/SomeClassTests.cs +21 -0
  77. data/test_data/sln2/Unit.Tests/Unit.Tests.csproj +65 -0
  78. data/test_data/sln2/Unit.Tests/packages.config +4 -0
  79. data/test_data/sln3/TestSolution.nobuild.sln +22 -0
  80. data/test_data/sln3/TestSolution/App.config +6 -0
  81. data/test_data/sln3/TestSolution/Program.cs +16 -0
  82. data/test_data/sln3/TestSolution/Properties/AssemblyInfo.cs +36 -0
  83. data/test_data/sln3/TestSolution/TestSolution.nobuild.csproj +59 -0
  84. metadata +309 -0
@@ -0,0 +1,84 @@
1
+ require 'fileutils'
2
+ require 'yaml'
3
+ require 'pathname'
4
+ require 'alpacabuildtool/versioning/version'
5
+
6
+ module AlpacaBuildTool
7
+ ##
8
+ # Versioning provides methods to load and save version
9
+ # for solutions
10
+ module Versioning
11
+ ##
12
+ # File name where semantic version is stored
13
+ FILE_NAME = '.semver'
14
+
15
+ ##
16
+ # Error thrown by versioning if version file not found
17
+ SemVerFileNotFound = Class.new(StandardError)
18
+
19
+ ##
20
+ # Initializes semantic versioning
21
+ #
22
+ # +[dir]+:: directory where to place .semver(current working
23
+ # directory by default)
24
+ def self.init(dir = '')
25
+ hash = { major: 0, minor: 0, patch: 0, special: '', metadata: '' }
26
+ FileUtils.mkdir_p(dir) unless File.directory?(dir)
27
+ file = File.join dir, FILE_NAME
28
+ open(file, 'w') { |io| io.write YAML.dump(hash) }
29
+ hash[:file] = file
30
+ Version.new hash
31
+ end
32
+
33
+ ##
34
+ # Returns Version instance from .semver file found
35
+ # by reverse search from current working directory/dir
36
+ # up to root directory
37
+ #
38
+ # +[solution_folder]+:: directory from which to start searching
39
+ # .semver file(nil by default)
40
+ # +[dir]+:: base directory for .semver file(current working
41
+ # directory by default)
42
+ def self.find(solution_folder = nil, dir = '')
43
+ solution_folder = Pathname.new(solution_folder) if solution_folder
44
+ semver = find_file FILE_NAME, dir, solution_folder || Pathname.new('.')
45
+ fail SemVerFileNotFound if semver.nil?
46
+ hash = YAML.load_file(semver) || {}
47
+ hash[:file] = semver
48
+ Version.new hash
49
+ end
50
+
51
+ ##
52
+ # Helper method to recursivly find file
53
+ #
54
+ # +name+:: file name to find
55
+ # +dir+:: relative path to file
56
+ # +cur+:: current folder to start searching from
57
+ def self.find_file(name, dir, cur)
58
+ file = File.join(cur.expand_path, dir, name)
59
+ return file if File.exist?(file)
60
+ return nil if cur.expand_path.root?
61
+ find_file(name, dir, cur.parent)
62
+ end
63
+
64
+ ##
65
+ # Returns Version instance from specific file
66
+ #
67
+ # +[file]+:: path to file that contains .semver content
68
+ def self.parse(file)
69
+ hash = YAML.load_file(file)
70
+ hash[:file] = file
71
+ Version.new hash
72
+ end
73
+
74
+ ##
75
+ # Save changes done to version
76
+ #
77
+ # +version+:: instance of Version class
78
+ # +file+:: specific file to save to(nil by default)
79
+ def self.save(version, file = nil)
80
+ file ||= version.file
81
+ open(file, 'w') { |io| io.write version.to_yaml }
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,201 @@
1
+ require 'spec_helper'
2
+ require 'alpacabuildtool/configuration'
3
+ require 'fakefs/spec_helpers'
4
+ require 'ostruct'
5
+
6
+ describe AlpacaBuildTool::Configuration do
7
+ include FakeFS::SpecHelpers
8
+
9
+ describe '.set' do
10
+ let(:file) { File.expand_path '~/.alpaca.conf' }
11
+
12
+ context 'when global configuration file does not exist' do
13
+ before(:each) { FileUtils.mkdir_p(File.dirname(file)) }
14
+ let(:properties) { ['hello.world=hi'] }
15
+ let(:expected_content) { "---\nhello:\n world: hi\n" }
16
+
17
+ it 'then it creates "~/.alpaca.config" file' do
18
+ AlpacaBuildTool::Configuration.set properties
19
+ expect(File.exist? file).to be true
20
+ end
21
+
22
+ it 'and it saves property to file' do
23
+ AlpacaBuildTool::Configuration.set properties
24
+ expect(File.read file).to eq expected_content
25
+ end
26
+ end
27
+
28
+ context 'when global configuration file exist' do
29
+ let(:content) { "---\nhello:\n world: hi\n" }
30
+ before(:each) do
31
+ FileUtils.mkdir_p(File.dirname(file))
32
+ File.open(file, 'w+') { |f| f.write content }
33
+ end
34
+
35
+ context 'and requested property update' do
36
+ let(:properties) { ['hello.world=update'] }
37
+ let(:updated_content) { "---\nhello:\n world: update\n" }
38
+ it 'then it updates property' do
39
+ AlpacaBuildTool::Configuration.set properties
40
+ expect(File.read file).to eq updated_content
41
+ end
42
+ end
43
+
44
+ context 'and adding new property' do
45
+ let(:properties) { ['hello.my_world=kitty'] }
46
+ let(:expected_content) { content + " my_world: kitty\n" }
47
+ it 'then it saves property to file' do
48
+ AlpacaBuildTool::Configuration.set properties
49
+ expect(File.read file).to eq expected_content
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ describe '#set' do
56
+ let(:file_path) do
57
+ require 'rbconfig'
58
+ case RbConfig::CONFIG['host_os']
59
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
60
+ 'd:\solution'
61
+ else
62
+ '/home/solution'
63
+ end
64
+ end
65
+ let(:file) { File.join file_path, '.alpaca.conf' }
66
+ let(:solution) do
67
+ solution = OpenStruct.new
68
+ solution.file = File.join(file_path, 'some.sln')
69
+ solution.dir = file_path
70
+ solution
71
+ end
72
+ subject do
73
+ data_dir = AlpacaBuildTool::Configuration.const_get(:DATA_DIR)
74
+ default_config = File.join(data_dir, '.alpaca.conf')
75
+ FileUtils.mkdir_p File.dirname(default_config)
76
+ File.open(default_config, 'w+') do |f|
77
+ f.write "---\nlocal_configuration: '.alpaca.conf'"
78
+ end
79
+ c = AlpacaBuildTool::Configuration.new solution
80
+ c.set properties
81
+ end
82
+
83
+ context 'when local configuration file does not exist' do
84
+ before(:each) { FileUtils.mkdir_p(File.dirname(file)) }
85
+ let(:properties) { ['hello.world=hi'] }
86
+ let(:expected_content) { "---\nhello:\n world: hi\n" }
87
+
88
+ it 'then it creates "solution_directory\.alpaca.conf" file' do
89
+ subject
90
+ expect(File.exist? file).to be true
91
+ end
92
+
93
+ it 'and it saves property to file' do
94
+ subject
95
+ expect(File.read file).to eq expected_content
96
+ end
97
+ end
98
+
99
+ context 'when local configuration file exist' do
100
+ let(:content) { "---\nhello:\n world: hi\n" }
101
+ before(:each) do
102
+ FileUtils.mkdir_p(File.dirname(file))
103
+ File.open(file, 'w+') { |f| f.write content }
104
+ end
105
+
106
+ context 'and requested property update' do
107
+ let(:properties) { ['hello.world=update'] }
108
+ let(:updated_content) { "---\nhello:\n world: update\n" }
109
+ it 'then it updates property' do
110
+ subject
111
+ expect(File.read file).to eq updated_content
112
+ end
113
+ end
114
+
115
+ context 'and adding new property' do
116
+ let(:properties) { ['hello.my_world=kitty'] }
117
+ let(:expected_content) { content + " my_world: kitty\n" }
118
+ it 'then it saves property to file' do
119
+ subject
120
+ expect(File.read file).to eq expected_content
121
+ end
122
+ end
123
+ end
124
+ end
125
+
126
+ describe '.new' do
127
+ context 'when global configuration exist' do
128
+ context 'and local configuration overrides it' do
129
+ let(:default_config) do
130
+ data_dir = AlpacaBuildTool::Configuration.const_get(:DATA_DIR)
131
+ File.join(data_dir, '.alpaca.conf')
132
+ end
133
+ let(:global_config) { File.expand_path '~/.alpaca.conf' }
134
+ let(:global_content) do
135
+ "---\nlocal_configuration: '.alpaca.conf'\n"\
136
+ "Tool:\n property: old_value\n target: "\
137
+ "'\#{solution_name}.new'\n property2:\n "\
138
+ ":windows: '\#{solution_directory}'\n "\
139
+ ":linux: '/usr/alpaca'"
140
+ end
141
+ let(:solution_dir) do
142
+ require 'rbconfig'
143
+ case RbConfig::CONFIG['host_os']
144
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
145
+ 'd:\solution'
146
+ else
147
+ '/home/solution'
148
+ end
149
+ end
150
+ let(:local_config) { File.expand_path "#{solution_dir}/.alpaca.conf" }
151
+ let(:local_content) { "---\nTool:\n property: new_value" }
152
+ let(:solution) do
153
+ solution = OpenStruct.new
154
+ solution.file = File.join solution_dir, 'alpaca.sln'
155
+ solution.dir = solution_dir
156
+ solution
157
+ end
158
+ subject { AlpacaBuildTool::Configuration.new solution }
159
+
160
+ def create_config(file, content)
161
+ FileUtils.mkdir_p(File.dirname(file))
162
+ File.open(file, 'w+') { |f| f.write content }
163
+ end
164
+
165
+ before(:each) do
166
+ create_config default_config, "---\n"
167
+ create_config global_config, global_content
168
+ create_config local_config, local_content
169
+ gc_var = :@@global_configuration
170
+ if AlpacaBuildTool::Configuration.class_variable_defined? gc_var
171
+ AlpacaBuildTool::Configuration.remove_class_variable gc_var
172
+ end
173
+ allow(AlpacaBuildTool::Os).to receive(:os).and_return(:windows)
174
+ end
175
+
176
+ it 'merges global with local with higher priority to local' do
177
+ value = subject.instance_variable_get(:@configuration)
178
+ expect(value['local_configuration']).to eq '.alpaca.conf'
179
+ expect(value['Tool']['property']).to eq 'new_value'
180
+ expect(value['Tool']['target']).to_not be nil
181
+ expect(value['Tool']['property2']).to_not be nil
182
+ end
183
+
184
+ it 'detokenize OS from configuration' do
185
+ value = subject.instance_variable_get(:@configuration)
186
+ expect(value['Tool']['property2']).to_not eq 'usr/alpaca'
187
+ end
188
+
189
+ it 'detokenize solution variable #{solution_name}' do
190
+ value = subject.instance_variable_get(:@configuration)
191
+ expect(value['Tool']['target']).to eq 'alpaca.new'
192
+ end
193
+
194
+ it 'detokenize solution variable #{solution_directory}' do
195
+ value = subject.instance_variable_get(:@configuration)
196
+ expect(value['Tool']['property2']).to eq solution.dir
197
+ end
198
+ end
199
+ end
200
+ end
201
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ require 'alpacabuildtool/entities/xml'
3
+
4
+ describe AlpacaBuildTool::Xml do
5
+ describe '.to_s' do
6
+ context 'with simple nuspec like structure' do
7
+ subject do
8
+ AlpacaBuildTool::Xml.new '1.0' do
9
+ node 'root' do
10
+ node 'files' do
11
+ node 'file' do
12
+ attribute('src', 'A.txt')
13
+ end
14
+ node 'file' do
15
+ attribute 'src', 'B.txt'
16
+ attribute 'help', 'B file'
17
+ end
18
+ end
19
+ node 'metadata'
20
+ end
21
+ end
22
+ end
23
+
24
+ let(:xml_content) do
25
+ "<?xml version=\"1.0\"?>\n" \
26
+ "<root>\n" \
27
+ "\t<files>\n" \
28
+ "\t\t<file src=\"A.txt\"/>\n" \
29
+ "\t\t<file src=\"B.txt\" help=\"B file\"/>\n" \
30
+ "\t</files>\n" \
31
+ "\t<metadata/>\n" \
32
+ '</root>'
33
+ end
34
+ it 'returns well formatted xml' do
35
+ expect(subject.to_s).to eq xml_content
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+ require 'alpacabuildtool/versioning/version'
3
+ require 'fakefs/spec_helpers'
4
+
5
+ describe AlpacaBuildTool::Version do
6
+ include FakeFS::SpecHelpers
7
+ def set_version(a, b, c, d, e)
8
+ open('.semver', 'w') { |io| io.write 'mock file presense' }
9
+ { file: '.semver', major: a, minor: b, patch: c, special: d, metadata: e }
10
+ end
11
+
12
+ describe '#increase :major' do
13
+ it 'increase major and reset lover(v1.2.3-rc+03fb4 -> v2.0.0-rc+03fb4)' do
14
+ v = AlpacaBuildTool::Version.new(set_version 1, 2, 3, 'rc', '03fb4')
15
+ v.increase :major
16
+ expect(v.to_s).to eq 'v2.0.0-rc+03fb4'
17
+ end
18
+ end
19
+ describe '#increase :minor' do
20
+ it 'increase monir and reset lover(v1.2.3-rc+03fb4 -> v1.3.0-rc+03fb4)' do
21
+ v = AlpacaBuildTool::Version.new(set_version 1, 2, 3, 'rc', '03fb4')
22
+ v.increase :minor
23
+ expect(v.to_s).to eq 'v1.3.0-rc+03fb4'
24
+ end
25
+ end
26
+ describe '#increase :patch' do
27
+ it 'increase patch only(v1.2.3-rc+03fb4 -> v1.2.4-rc+03fb4)' do
28
+ v = AlpacaBuildTool::Version.new(set_version 1, 2, 3, 'rc', '03fb4')
29
+ v.increase :patch
30
+ expect(v.to_s).to eq 'v1.2.4-rc+03fb4'
31
+ end
32
+ end
33
+ describe '#increase :prerelease' do
34
+ it 'update "alpha" to "beta"(v1.2.3-alpha+03fb4 -> v1.2.3-beta+03fb4)' do
35
+ v = AlpacaBuildTool::Version.new(set_version 1, 2, 3, 'alpha', '03fb4')
36
+ v.increase :prerelease
37
+ expect(v.to_s).to eq 'v1.2.3-beta+03fb4'
38
+ end
39
+ it 'update "beta" to "rc"(v1.2.3-beta+03fb4 -> v1.2.3-rc+03fb4)' do
40
+ v = AlpacaBuildTool::Version.new(set_version 1, 2, 3, 'beta', '03fb4')
41
+ v.increase :prerelease
42
+ expect(v.to_s).to eq 'v1.2.3-rc+03fb4'
43
+ end
44
+ it 'fail to increase "rc" as it is last pre-release stage' do
45
+ v = AlpacaBuildTool::Version.new(set_version 1, 2, 3, 'rc', '03fb4')
46
+ expect { v.increase :prerelease }.to raise_error(
47
+ AlpacaBuildTool::Version::PreReleaseTagReachedFinalVersion)
48
+ end
49
+ it 'fail to increase prerelease tag for release package' do
50
+ v = AlpacaBuildTool::Version.new(set_version 1, 2, 3, '', '')
51
+ expect { v.increase :prerelease }
52
+ .to raise_error(AlpacaBuildTool::Version::NotPreRelease)
53
+ end
54
+ end
55
+ describe '#metadata 334f666' do
56
+ it 'update metadata to new value' do
57
+ v = AlpacaBuildTool::Version.new(set_version 1, 2, 3, 'rc', '03fb4')
58
+ v.metadata = '334f666'
59
+ expect(v.to_s).to eq 'v1.2.3-rc+334f666'
60
+ end
61
+ end
62
+ describe '#release' do
63
+ it 'Clean pre-release tag and metadata(v1.2.3-rc+03fb4 -> v1.2.3)' do
64
+ v = AlpacaBuildTool::Version.new(set_version 1, 2, 3, 'rc', '03fb4')
65
+ v.release
66
+ expect(v.to_s).to eq 'v1.2.3'
67
+ end
68
+ it 'Fail to release version that is already released' do
69
+ v = AlpacaBuildTool::Version.new(set_version 1, 2, 3, '', '')
70
+ expect { v.release }
71
+ .to raise_error(AlpacaBuildTool::Version::AlreadyRelease)
72
+ end
73
+ end
74
+ describe '#make_prerelease' do
75
+ it 'Fail to make version pre-release if it is already pre-release' do
76
+ v = AlpacaBuildTool::Version.new(set_version 1, 2, 3, 'rc', '03fb4')
77
+ v.increase :major
78
+ expect(v.to_s).to eq 'v2.0.0-rc+03fb4'
79
+ end
80
+ it 'Add pre-release tag' do
81
+ v = AlpacaBuildTool::Version.new(set_version 1, 2, 3, 'rc', '03fb4')
82
+ v.increase :major
83
+ expect(v.to_s).to eq 'v2.0.0-rc+03fb4'
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,194 @@
1
+ require 'spec_helper'
2
+ require 'alpacabuildtool/versioning/versioning'
3
+ require 'fakefs/spec_helpers'
4
+
5
+ describe AlpacaBuildTool::Versioning do
6
+ include FakeFS::SpecHelpers
7
+ describe '::init' do
8
+ let(:content) do
9
+ "---\n:major: 0\n:minor: 0\n:patch: 0\n:special: ''\n:metadata: ''\n"
10
+ end
11
+
12
+ context 'When base directory not passed' do
13
+ let(:file) { '.semver' }
14
+ subject { AlpacaBuildTool::Versioning.init }
15
+ before(:each) { subject }
16
+
17
+ it 'Creates new .semver file in current directory' do
18
+ expect(File.exist?(file)).to be true
19
+ end
20
+
21
+ it 'Stores versioning information to .semver file' do
22
+ expect(File.read(file)).to eq content
23
+ end
24
+
25
+ it 'Returns instance of Version class' do
26
+ expect(subject).to be_an_instance_of(AlpacaBuildTool::Version)
27
+ end
28
+
29
+ it 'with 0 major version' do
30
+ expect(subject.major).to eq 0
31
+ end
32
+
33
+ it 'with 0 minor version' do
34
+ expect(subject.minor).to eq 0
35
+ end
36
+
37
+ it 'with 0 patch version' do
38
+ expect(subject.patch).to eq 0
39
+ end
40
+
41
+ it 'with empty special' do
42
+ expect(subject.special).to eq ''
43
+ end
44
+
45
+ it 'with empty metadata' do
46
+ expect(subject.metadata).to eq ''
47
+ end
48
+ end
49
+
50
+ context 'When base directory passed' do
51
+ let(:file) { 'funny_dir/.semver' }
52
+ subject { AlpacaBuildTool::Versioning.init 'funny_dir' }
53
+ before(:each) { subject }
54
+
55
+ it 'Creates new .semver file in specific directory' do
56
+ expect(File.exist?(file)).to be true
57
+ end
58
+
59
+ it 'Stores versioning information to .semver file' do
60
+ expect(File.read(file)).to eq content
61
+ end
62
+
63
+ it 'Returns instance of Version class' do
64
+ expect(subject).to be_an_instance_of(AlpacaBuildTool::Version)
65
+ end
66
+
67
+ it 'with 0 major version' do
68
+ expect(subject.major).to eq 0
69
+ end
70
+
71
+ it 'with 0 minor version' do
72
+ expect(subject.minor).to eq 0
73
+ end
74
+
75
+ it 'with 0 patch version' do
76
+ expect(subject.patch).to eq 0
77
+ end
78
+
79
+ it 'with empty special' do
80
+ expect(subject.special).to eq ''
81
+ end
82
+
83
+ it 'with empty metadata' do
84
+ expect(subject.metadata).to eq ''
85
+ end
86
+ end
87
+ end
88
+
89
+ describe '::find' do
90
+ let(:file) { '.semver' }
91
+ let(:content) do
92
+ "---\n:major: 1\n:minor: 2\n:patch: 3\n:special: 'rc'\n:metadata: 'e4'\n"
93
+ end
94
+
95
+ context 'When base directory not passed' do
96
+ subject { AlpacaBuildTool::Versioning.find }
97
+ before(:each) do
98
+ open(file, 'w') { |io| io.write content }
99
+ subject
100
+ end
101
+
102
+ it 'Then returns Version instance' do
103
+ expect(subject).to be_an_instance_of(AlpacaBuildTool::Version)
104
+ end
105
+ end
106
+
107
+ context 'When base directory is passed' do
108
+ let(:dir) { 'funny' }
109
+ subject { AlpacaBuildTool::Versioning.find nil, dir }
110
+ before(:each) do
111
+ FileUtils.mkdir_p(dir)
112
+ open(File.join(dir, file), 'w') { |io| io.write content }
113
+ subject
114
+ end
115
+
116
+ it 'Then returns Version instance' do
117
+ expect(subject).to be_an_instance_of(AlpacaBuildTool::Version)
118
+ end
119
+ end
120
+
121
+ context 'When file does not found' do
122
+ let(:dir) { 'funny' }
123
+ subject { AlpacaBuildTool::Versioning.find nil, dir }
124
+ before(:each) do
125
+ open(file, 'w') { |io| io.write content }
126
+ end
127
+
128
+ it 'Then fails with SemVerFileNotFound' do
129
+ expect { subject }
130
+ .to raise_error AlpacaBuildTool::Versioning::SemVerFileNotFound
131
+ end
132
+ end
133
+
134
+ context 'When file is corrupted' do
135
+ let(:corrupted_content) do
136
+ "---\n:major: 1\n:patch: 3\n:special: 'rc'\n:metadata: 'e4'\n"
137
+ end
138
+ subject { AlpacaBuildTool::Versioning.find }
139
+ before(:each) do
140
+ open(file, 'w') { |io| io.write corrupted_content }
141
+ end
142
+
143
+ it 'Then fails with InvalidSemVerFile' do
144
+ expect { subject }.to raise_error AlpacaBuildTool::Version::InvalidFile
145
+ end
146
+ end
147
+
148
+ context 'When solution folder passed' do
149
+ let(:sln) do
150
+ cur = File.dirname(File.expand_path(__FILE__))
151
+ File.join(cur, '../test_data/sln1')
152
+ end
153
+ subject { AlpacaBuildTool::Versioning.find sln }
154
+ before(:each) do
155
+ FileUtils.mkdir_p(sln)
156
+ open(File.join(sln, file), 'w') { |io| io.write content }
157
+ end
158
+
159
+ it 'Then returns Version instance' do
160
+ expect(subject).to be_an_instance_of(AlpacaBuildTool::Version)
161
+ end
162
+ end
163
+ end
164
+
165
+ describe '::save' do
166
+ let(:version) do
167
+ AlpacaBuildTool::Version.new(file: '.semver',
168
+ major: 1, minor: 2, patch: 3,
169
+ special: 'rc', metadata: '4e')
170
+ end
171
+ let(:content) do
172
+ "---\n:major: 1\n:minor: 2\n:patch: 3\n:special: rc\n:metadata: 4e\n"
173
+ end
174
+ before(:each) do
175
+ open('.semver', 'w') { |io| io.write 'bad text' }
176
+ AlpacaBuildTool::Versioning.save version
177
+ end
178
+ it 'Then write into file used to initialize version' do
179
+ expect(File.exist?('.semver')).to be true
180
+ end
181
+
182
+ it 'And save semantic version data into file used for initialization' do
183
+ expect(File.read(version.file)).to eq content
184
+ end
185
+
186
+ context 'When file name passed as argument' do
187
+ it 'Then write into specified file' do
188
+ open('.semver', 'w') { |io| io.write 'bad text' }
189
+ AlpacaBuildTool::Versioning.save version, 'new.semver'
190
+ expect(File.exist?('new.semver')).to be true
191
+ end
192
+ end
193
+ end
194
+ end