-
Notifications
You must be signed in to change notification settings - Fork 169
/
test_jeweler.rb
174 lines (122 loc) · 4.01 KB
/
test_jeweler.rb
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
require 'test_helper'
class TestJeweler < Test::Unit::TestCase
def build_jeweler(base_dir = nil)
base_dir ||= git_dir_path
FileUtils.mkdir_p base_dir
Jeweler.new(build_spec, base_dir)
end
def git_dir_path
File.join(tmp_dir, 'git')
end
def non_git_dir_path
File.join(tmp_dir, 'nongit')
end
def build_git_dir
FileUtils.mkdir_p git_dir_path
Dir.chdir git_dir_path do
Git.init
end
end
def build_non_git_dir
FileUtils.mkdir_p non_git_dir_path
end
should 'raise an error if a nil gemspec is given' do
assert_raises Jeweler::GemspecError do
Jeweler.new(nil)
end
end
should 'know if it is in a git repo' do
build_git_dir
assert build_jeweler(git_dir_path).in_git_repo?
end
should 'know if it is not in a git repo' do
build_non_git_dir
jeweler = build_jeweler(non_git_dir_path)
assert !jeweler.in_git_repo?, "jeweler doesn't know that #{jeweler.base_dir} is not a git repository"
end
should 'find the base repo' do
jeweler = build_jeweler(File.dirname(File.expand_path(__FILE__)))
assert_equal File.dirname(File.dirname(File.expand_path(__FILE__))), jeweler.git_base_dir
end
should 'build and run write gemspec command when writing gemspec' do
jeweler = build_jeweler
command = Object.new
mock(command).run
mock(Jeweler::Commands::WriteGemspec).build_for(jeweler) { command }
jeweler.write_gemspec
end
should 'build and run validate gemspec command when validating gemspec' do
jeweler = build_jeweler
command = Object.new
mock(command).run
mock(Jeweler::Commands::ValidateGemspec).build_for(jeweler) { command }
jeweler.validate_gemspec
end
should 'build and run build gem command when building gem' do
jeweler = build_jeweler
command = Object.new
mock(command).run
mock(Jeweler::Commands::BuildGem).build_for(jeweler) { command }
jeweler.build_gem
end
should 'build and run build gem command when installing gem' do
jeweler = build_jeweler
command = Object.new
mock(command).run
mock(Jeweler::Commands::InstallGem).build_for(jeweler) { command }
jeweler.install_gem
end
should 'build and run bump major version command when bumping major version' do
jeweler = build_jeweler
command = Object.new
mock(command).run
mock(Jeweler::Commands::Version::BumpMajor).build_for(jeweler) { command }
jeweler.bump_major_version
end
should 'build and run bump minor version command when bumping minor version' do
jeweler = build_jeweler
command = Object.new
mock(command).run
mock(Jeweler::Commands::Version::BumpMinor).build_for(jeweler) { command }
jeweler.bump_minor_version
end
should 'build and run write version command when writing version' do
jeweler = build_jeweler
command = Object.new
mock(command).run
mock(command).major = 1
mock(command).minor = 5
mock(command).patch = 2
mock(command).build = 'a1'
mock(Jeweler::Commands::Version::Write).build_for(jeweler) { command }
jeweler.write_version(1, 5, 2, 'a1')
end
should 'build and run release to github command when running release_gemspec' do
jeweler = build_jeweler
args = {}
command = Object.new
mock(command).run(args)
mock(Jeweler::Commands::ReleaseGemspec).build_for(jeweler) { command }
jeweler.release_gemspec(args)
end
should 'build and run release to git command when running release_to_git' do
jeweler = build_jeweler
args = {}
command = Object.new
mock(command).run(args)
mock(Jeweler::Commands::ReleaseToGit).build_for(jeweler) { command }
jeweler.release_to_git(args)
end
should 'respond to gemspec_helper' do
assert_respond_to build_jeweler, :gemspec_helper
end
should 'respond to version_helper' do
assert_respond_to build_jeweler, :version_helper
end
should 'respond to repo' do
assert_respond_to build_jeweler, :repo
end
should 'respond to commit' do
assert_respond_to build_jeweler, :commit
end
end