-
Notifications
You must be signed in to change notification settings - Fork 169
/
test_helper.rb
177 lines (143 loc) · 4.29 KB
/
test_helper.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
175
176
177
require 'test/unit'
require 'rubygems'
require 'rake'
begin
require 'ruby-debug'
rescue LoadError
end
begin
require 'shoulda'
require 'rr'
require 'redgreen'
rescue LoadError => e
puts "*" * 80
puts "Some dependencies needed to run tests were missing. Run the following command to find them:"
puts
puts "\trake check_dependencies:development"
puts "*" * 80
exit 1
end
require 'time'
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
require 'jeweler'
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'shoulda_macros/jeweler_macros'
TMP_DIR = '/tmp/jeweler_test'
FIXTURE_DIR = File.expand_path('../fixtures', __FILE__)
class RubyForgeStub
attr_accessor :userconfig, :autoconfig
def initialize
@userconfig = {}
@autoconfig = {}
end
end
class Test::Unit::TestCase
include RR::Adapters::TestUnit unless include?(RR::Adapters::TestUnit)
def tmp_dir
TMP_DIR
end
def fixture_dir
File.join(FIXTURE_DIR, 'bar')
end
def remove_tmpdir!
FileUtils.rm_rf(tmp_dir)
end
def create_tmpdir!
FileUtils.mkdir_p(tmp_dir)
end
def build_spec(*files)
Gem::Specification.new do |s|
s.name = "bar"
s.summary = "Simple and opinionated helper for creating Rubygem projects on GitHub"
s.email = "josh@technicalpickles.com"
s.homepage = "http://github.com/technicalpickles/jeweler"
s.description = "Simple and opinionated helper for creating Rubygem projects on GitHub"
s.authors = ["Josh Nichols"]
s.files = FileList[*files] unless files.empty?
s.version = '0.1.1'
end
end
def self.gemcutter_command_context(description, &block)
context description do
setup do
@command = eval(self.class.name.gsub(/::Test/, '::')).new
if @command.respond_to? :gemspec_helper=
@gemspec_helper = Object.new
@command.gemspec_helper = @gemspec_helper
end
if @command.respond_to? :output
@output = StringIO.new
@command.output = @output
end
end
context "", &block
end
end
def self.rubyforge_command_context(description, &block)
context description do
setup do
@command = eval(self.class.name.gsub(/::Test/, '::')).new
if @command.respond_to? :gemspec=
@gemspec = Object.new
@command.gemspec = @gemspec
end
if @command.respond_to? :gemspec_helper=
@gemspec_helper = Object.new
@command.gemspec_helper = @gemspec_helper
end
if @command.respond_to? :rubyforge=
@rubyforge = RubyForgeStub.new
@command.rubyforge = @rubyforge
end
if @command.respond_to? :output
@output = StringIO.new
@command.output = @output
end
if @command.respond_to? :repo
@repo = Object.new
@command.repo = @repo
end
end
context "", &block
end
end
def self.build_command_context(description, &block)
context description do
setup do
@repo = Object.new
@version_helper = Object.new
@gemspec = Object.new
@commit = Object.new
@version = Object.new
@output = Object.new
@base_dir = Object.new
@gemspec_helper = Object.new
@rubyforge = Object.new
@jeweler = Object.new
stub(@jeweler).repo { @repo }
stub(@jeweler).version_helper { @version_helper }
stub(@jeweler).gemspec { @gemspec }
stub(@jeweler).commit { @commit }
stub(@jeweler).version { @version }
stub(@jeweler).output { @output }
stub(@jeweler).gemspec_helper { @gemspec_helper }
stub(@jeweler).base_dir { @base_dir }
stub(@jeweler).rubyforge { @rubyforge }
end
context "", &block
end
end
def stub_git_config(options = {})
stub(Git).global_config() { options }
end
def set_default_git_config
@project_name = 'the-perfect-gem'
@git_name = 'foo'
@git_email = 'bar@example.com'
@github_user = 'technicalpickles'
@github_token = 'zomgtoken'
end
def valid_git_config
{ 'user.name' => @git_name, 'user.email' => @git_email, 'github.user' => @github_user, 'github.token' => @github_token }
end
end