forked from richkilmer/hotcocoa
-
Notifications
You must be signed in to change notification settings - Fork 8
/
test_bin.rb
75 lines (59 loc) · 1.96 KB
/
test_bin.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
class TestHotCocoaBinary < MiniTest::Unit::TestCase
def hotcocoa *args
ruby = ENV['RUBY_VERSION'] ? 'ruby' : 'macruby'
`#{ruby} -I#{SOURCE_ROOT}/lib #{SOURCE_ROOT}/bin/hotcocoa #{args.join(' ')}`.chomp
end
end
class TestHotCocoaBinaryOptions < TestHotCocoaBinary
def test_shows_version
pattern = /Hot\s?Cocoa\s+#{HotCocoa::VERSION}/i
assert_match pattern, hotcocoa('-v')
assert_match pattern, hotcocoa('--version')
end
def test_shows_usage
assert_equal 'Usage: hotcocoa <project name>', hotcocoa
assert_equal 'Usage: hotcocoa <project name>', hotcocoa('-h')
assert_equal 'Usage: hotcocoa <project name>', hotcocoa('--help')
end
end
class TestHotCocoaBinaryUsesTemplate < TestHotCocoaBinary
def setup
@dir = File.join(ENV['TMPDIR'], 'hot_cocoa_test')
Dir.mkdir @dir
end
def teardown
FileUtils.rm_rf @dir
end
def test_uses_given_name
app_name = 'The answer to life, the universe, and everything'
Dir.chdir(@dir) do
hotcocoa app_name.inspect
assert Dir.exists? app_name
end
end
def test_uses_camel_case_name_for_appspec
app_name = 'CamelCase'
Dir.chdir(@dir) do
hotcocoa app_name.inspect
assert Dir.new(app_name).entries.include? "#{app_name}.appspec"
end
end
def test_converts_non_alphanumeric_characters_to_camelcase
app_name = 'The answer to life, the universe, and everything'
Dir.chdir(@dir) do
hotcocoa app_name.inspect
assert Dir.new(app_name).entries.include? "TheAnswerToLifeTheUniverseAndEverything.appspec"
end
end
# this is a weird edge case that was programmed in
# so we will preseve it for the time being
def test_moves_existing_rb_file_into_the_project
app_name = 'blah blah.rb'
Dir.chdir(@dir) do
File.open(app_name, 'w') { |f| f.write 'ZOMG' }
hotcocoa app_name.inspect
app = File.read(File.join(app_name.chomp('.rb'),'lib','application.rb'))
assert_equal 'ZOMG', app
end
end
end