hotcocoa 0.5.1 → 0.6.0pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. data/.yardopts +14 -0
  2. data/History.txt +21 -0
  3. data/README.markdown +84 -0
  4. data/Rakefile +47 -0
  5. data/bin/hotcocoa +20 -10
  6. data/docs/Contributors.markdown +25 -0
  7. data/docs/Mappings.markdown +352 -0
  8. data/docs/MappingsExplained.markdown +22 -0
  9. data/docs/Overview.markdown +58 -0
  10. data/docs/Resources.markdown +25 -0
  11. data/docs/Tutorial.markdown +3 -0
  12. data/lib/hotcocoa/application/builder.rb +237 -0
  13. data/lib/hotcocoa/application/specification.rb +373 -0
  14. data/lib/hotcocoa/application_builder.rb +338 -242
  15. data/lib/hotcocoa/attributed_string_helpers.rb +128 -0
  16. data/lib/hotcocoa/behaviors.rb +39 -6
  17. data/lib/hotcocoa/core_extensions/kernel.rb +67 -0
  18. data/lib/hotcocoa/core_extensions/nsarray.rb +15 -0
  19. data/lib/hotcocoa/core_extensions/nsmutable_attributed_string.rb +74 -0
  20. data/lib/hotcocoa/core_extensions/nsstring.rb +36 -0
  21. data/lib/hotcocoa/core_extensions/nsurl.rb +6 -0
  22. data/lib/hotcocoa/core_extensions/numeric.rb +9 -0
  23. data/lib/hotcocoa/core_extensions/object.rb +36 -0
  24. data/lib/hotcocoa/core_extensions/range.rb +30 -0
  25. data/lib/hotcocoa/core_extensions.rb +8 -0
  26. data/lib/hotcocoa/data_sources/combo_box_data_source.rb +38 -38
  27. data/lib/hotcocoa/data_sources/outline_view_data_source.rb +33 -0
  28. data/lib/hotcocoa/data_sources/table_data_source.rb +12 -13
  29. data/lib/hotcocoa/data_sources.rb +3 -0
  30. data/lib/hotcocoa/delegate_builder.rb +114 -79
  31. data/lib/hotcocoa/graphics/canvas.rb +211 -214
  32. data/lib/hotcocoa/graphics/color.rb +89 -91
  33. data/lib/hotcocoa/graphics/elements/particle.rb +16 -19
  34. data/lib/hotcocoa/graphics/elements/rope.rb +12 -14
  35. data/lib/hotcocoa/graphics/elements/sandpainter.rb +11 -13
  36. data/lib/hotcocoa/graphics/gradient.rb +13 -14
  37. data/lib/hotcocoa/graphics/image.rb +110 -83
  38. data/lib/hotcocoa/graphics/path.rb +44 -50
  39. data/lib/hotcocoa/graphics/pdf.rb +17 -19
  40. data/lib/hotcocoa/graphics.rb +21 -20
  41. data/lib/hotcocoa/kvo_accessors.rb +10 -11
  42. data/lib/hotcocoa/layout_view.rb +394 -379
  43. data/lib/hotcocoa/mapper.rb +346 -207
  44. data/lib/hotcocoa/mapping_methods.rb +107 -37
  45. data/lib/hotcocoa/mappings/appkit/alert.rb +25 -0
  46. data/lib/hotcocoa/mappings/appkit/application.rb +112 -0
  47. data/lib/hotcocoa/mappings/{array_controller.rb → appkit/array_controller.rb} +33 -35
  48. data/lib/hotcocoa/mappings/appkit/box.rb +37 -0
  49. data/lib/hotcocoa/mappings/appkit/button.rb +88 -0
  50. data/lib/hotcocoa/mappings/appkit/collection_view.rb +42 -0
  51. data/lib/hotcocoa/mappings/appkit/color.rb +40 -0
  52. data/lib/hotcocoa/mappings/appkit/column.rb +19 -0
  53. data/lib/hotcocoa/mappings/appkit/combo_box.rb +22 -0
  54. data/lib/hotcocoa/mappings/appkit/control.rb +31 -0
  55. data/lib/hotcocoa/mappings/appkit/font.rb +58 -0
  56. data/lib/hotcocoa/mappings/appkit/gradient.rb +19 -0
  57. data/lib/hotcocoa/mappings/appkit/image.rb +15 -0
  58. data/lib/hotcocoa/mappings/appkit/image_view.rb +41 -0
  59. data/lib/hotcocoa/mappings/appkit/label.rb +23 -0
  60. data/lib/hotcocoa/mappings/appkit/layout_view.rb +9 -0
  61. data/lib/hotcocoa/mappings/appkit/line.rb +16 -0
  62. data/lib/hotcocoa/mappings/appkit/menu.rb +78 -0
  63. data/lib/hotcocoa/mappings/appkit/menu_item.rb +47 -0
  64. data/lib/hotcocoa/mappings/appkit/outline_view.rb +62 -0
  65. data/lib/hotcocoa/mappings/appkit/popup.rb +106 -0
  66. data/lib/hotcocoa/mappings/appkit/progress_indicator.rb +61 -0
  67. data/lib/hotcocoa/mappings/appkit/scroll_view.rb +28 -0
  68. data/lib/hotcocoa/mappings/appkit/search_field.rb +9 -0
  69. data/lib/hotcocoa/mappings/appkit/secure_text_field.rb +15 -0
  70. data/lib/hotcocoa/mappings/appkit/segmented_control.rb +103 -0
  71. data/lib/hotcocoa/mappings/appkit/slider.rb +23 -0
  72. data/lib/hotcocoa/mappings/appkit/sound.rb +9 -0
  73. data/lib/hotcocoa/mappings/appkit/speech_synthesizer.rb +22 -0
  74. data/lib/hotcocoa/mappings/appkit/split_view.rb +19 -0
  75. data/lib/hotcocoa/mappings/appkit/status_bar.rb +7 -0
  76. data/lib/hotcocoa/mappings/appkit/status_item.rb +9 -0
  77. data/lib/hotcocoa/mappings/appkit/table_view.rb +108 -0
  78. data/lib/hotcocoa/mappings/appkit/text_field.rb +36 -0
  79. data/lib/hotcocoa/mappings/appkit/text_view.rb +13 -0
  80. data/lib/hotcocoa/mappings/appkit/toolbar.rb +99 -0
  81. data/lib/hotcocoa/mappings/appkit/toolbar_item.rb +36 -0
  82. data/lib/hotcocoa/mappings/appkit/tracking_area.rb +24 -0
  83. data/lib/hotcocoa/mappings/appkit/view.rb +65 -0
  84. data/lib/hotcocoa/mappings/appkit/window.rb +124 -0
  85. data/lib/hotcocoa/mappings/foundation/net_service.rb +65 -0
  86. data/lib/hotcocoa/mappings/foundation/net_service_browser.rb +27 -0
  87. data/lib/hotcocoa/mappings/foundation/notification.rb +24 -0
  88. data/lib/hotcocoa/mappings/foundation/sort_descriptor.rb +17 -0
  89. data/lib/hotcocoa/mappings/foundation/timer.rb +38 -0
  90. data/lib/hotcocoa/mappings/foundation/user_defaults.rb +43 -0
  91. data/lib/hotcocoa/mappings/foundation/xml_parser.rb +44 -0
  92. data/lib/hotcocoa/mappings/qtkit/movie.rb +15 -0
  93. data/lib/hotcocoa/mappings/qtkit/movie_view.rb +28 -0
  94. data/lib/hotcocoa/mappings/webkit/web_view.rb +20 -0
  95. data/lib/hotcocoa/mappings.rb +57 -111
  96. data/lib/hotcocoa/mvc.rb +90 -81
  97. data/lib/hotcocoa/notification_listener.rb +135 -58
  98. data/lib/hotcocoa/standard_rake_tasks.rb +17 -9
  99. data/lib/hotcocoa/target_action_convenience.rb +39 -0
  100. data/lib/hotcocoa/template.rb +90 -21
  101. data/lib/hotcocoa/version.rb +3 -0
  102. data/lib/hotcocoa.rb +12 -14
  103. data/template/Rakefile +31 -3
  104. data/template/__APPLICATION_NAME__.appspec +8 -0
  105. data/template/lib/application.rb +14 -17
  106. data/template/lib/menu.rb +11 -11
  107. data/test/application/test_builder.rb +28 -0
  108. data/test/application/test_specification.rb +280 -0
  109. data/test/core_extensions/test_kernel.rb +66 -0
  110. data/test/core_extensions/test_nsarray.rb +9 -0
  111. data/test/core_extensions/test_nsmutable_attributed_string.rb +86 -0
  112. data/test/core_extensions/test_nsstring.rb +20 -0
  113. data/test/core_extensions/test_nsurl.rb +9 -0
  114. data/test/core_extensions/test_numeric.rb +10 -0
  115. data/test/core_extensions/test_object.rb +37 -0
  116. data/test/core_extensions/test_range.rb +28 -0
  117. data/test/helper.rb +30 -0
  118. data/test/mappings/test_bonjour.rb +79 -0
  119. data/test/mappings/test_color.rb +16 -0
  120. data/test/mappings/test_font.rb +21 -0
  121. data/test/mappings/test_tracking_area.rb +18 -0
  122. data/test/test_application_builder.rb +95 -0
  123. data/test/test_attributed_string_helpers.rb +63 -0
  124. data/test/test_behaviours.rb +26 -0
  125. data/test/test_bin.rb +75 -0
  126. data/test/test_mapper.rb +100 -0
  127. data/test/test_mapping_methods.rb +67 -0
  128. data/test/test_mappings.rb +68 -0
  129. data/test/test_notification_listener.rb +19 -0
  130. data/test/test_template.rb +65 -0
  131. metadata +217 -90
  132. data/lib/hotcocoa/attributed_string.rb +0 -143
  133. data/lib/hotcocoa/kernel_ext.rb +0 -14
  134. data/lib/hotcocoa/mappings/alert.rb +0 -25
  135. data/lib/hotcocoa/mappings/application.rb +0 -112
  136. data/lib/hotcocoa/mappings/box.rb +0 -39
  137. data/lib/hotcocoa/mappings/button.rb +0 -92
  138. data/lib/hotcocoa/mappings/collection_view.rb +0 -44
  139. data/lib/hotcocoa/mappings/color.rb +0 -28
  140. data/lib/hotcocoa/mappings/column.rb +0 -21
  141. data/lib/hotcocoa/mappings/combo_box.rb +0 -24
  142. data/lib/hotcocoa/mappings/control.rb +0 -33
  143. data/lib/hotcocoa/mappings/font.rb +0 -44
  144. data/lib/hotcocoa/mappings/gradient.rb +0 -15
  145. data/lib/hotcocoa/mappings/image.rb +0 -15
  146. data/lib/hotcocoa/mappings/image_view.rb +0 -43
  147. data/lib/hotcocoa/mappings/label.rb +0 -25
  148. data/lib/hotcocoa/mappings/layout_view.rb +0 -9
  149. data/lib/hotcocoa/mappings/menu.rb +0 -71
  150. data/lib/hotcocoa/mappings/menu_item.rb +0 -47
  151. data/lib/hotcocoa/mappings/movie.rb +0 -13
  152. data/lib/hotcocoa/mappings/movie_view.rb +0 -27
  153. data/lib/hotcocoa/mappings/notification.rb +0 -17
  154. data/lib/hotcocoa/mappings/popup.rb +0 -110
  155. data/lib/hotcocoa/mappings/progress_indicator.rb +0 -68
  156. data/lib/hotcocoa/mappings/scroll_view.rb +0 -29
  157. data/lib/hotcocoa/mappings/search_field.rb +0 -9
  158. data/lib/hotcocoa/mappings/secure_text_field.rb +0 -17
  159. data/lib/hotcocoa/mappings/segmented_control.rb +0 -97
  160. data/lib/hotcocoa/mappings/slider.rb +0 -25
  161. data/lib/hotcocoa/mappings/sort_descriptor.rb +0 -13
  162. data/lib/hotcocoa/mappings/sound.rb +0 -9
  163. data/lib/hotcocoa/mappings/speech_synthesizer.rb +0 -25
  164. data/lib/hotcocoa/mappings/split_view.rb +0 -21
  165. data/lib/hotcocoa/mappings/status_bar.rb +0 -7
  166. data/lib/hotcocoa/mappings/status_item.rb +0 -9
  167. data/lib/hotcocoa/mappings/table_view.rb +0 -110
  168. data/lib/hotcocoa/mappings/text_field.rb +0 -41
  169. data/lib/hotcocoa/mappings/text_view.rb +0 -13
  170. data/lib/hotcocoa/mappings/timer.rb +0 -25
  171. data/lib/hotcocoa/mappings/toolbar.rb +0 -100
  172. data/lib/hotcocoa/mappings/toolbar_item.rb +0 -36
  173. data/lib/hotcocoa/mappings/view.rb +0 -67
  174. data/lib/hotcocoa/mappings/web_view.rb +0 -22
  175. data/lib/hotcocoa/mappings/window.rb +0 -118
  176. data/lib/hotcocoa/mappings/xml_parser.rb +0 -41
  177. data/lib/hotcocoa/object_ext.rb +0 -22
  178. data/lib/hotcocoa/plist.rb +0 -45
  179. data/template/config/build.yml +0 -8
  180. data/test/test_helper.rb +0 -3
  181. data/test/test_hotcocoa.rb +0 -11
@@ -0,0 +1,10 @@
1
+ class TestNumericExt < MiniTest::Unit::TestCase
2
+
3
+ def test_negative?
4
+ assert -1.negative?
5
+ assert -1.1.negative?
6
+ refute 1.negative?
7
+ refute 1.1.negative?
8
+ end
9
+
10
+ end
@@ -0,0 +1,37 @@
1
+ # Originally imported from MacRuby sources
2
+
3
+ module TestNamespaceForConstLookup
4
+ def self.const_missing(const)
5
+ @missing_const = const
6
+ end
7
+
8
+ def self.missing_const
9
+ @missing_const
10
+ end
11
+ end
12
+
13
+ class TestObjectFullConstGet < MiniTest::Unit::TestCase
14
+ def test_returns_a_constant_by_FQ_name_in_receiver_namespace
15
+ assert_equal HotCocoa, Object.full_const_get('HotCocoa')
16
+ assert_equal HotCocoa::Mappings, Object.full_const_get('HotCocoa::Mappings')
17
+ assert_equal HotCocoa, HotCocoa.full_const_get('HotCocoa')
18
+ assert_equal HotCocoa::Mappings, HotCocoa.full_const_get('HotCocoa::Mappings')
19
+ assert_equal HotCocoa::Mappings, HotCocoa.full_const_get('Mappings')
20
+ end
21
+
22
+ def test_calls_const_missing_on_namespaces_which_do_not_exist
23
+ Object.full_const_get('TestNamespaceForConstLookup::DoesNotExist')
24
+ assert_equal 'DoesNotExist', TestNamespaceForConstLookup.missing_const
25
+ end
26
+
27
+ def test_raises_a_NameError_if_a_const_cannot_be_found
28
+ assert_raises NameError do
29
+ Object.full_const_get('DoesNotExist::ForSure')
30
+ end
31
+ end
32
+
33
+ def test_ignores_leading_namespace_separator
34
+ assert_equal HotCocoa, Object.full_const_get('::HotCocoa')
35
+ assert_equal HotCocoa::Mappings, Object.full_const_get('::HotCocoa::Mappings')
36
+ end
37
+ end
@@ -0,0 +1,28 @@
1
+ class TestRangeToNSRange < MiniTest::Unit::TestCase
2
+
3
+ def test_raises_error
4
+ assert_raises ArgumentError do
5
+ (1..-1).to_NSRange
6
+ end
7
+ end
8
+
9
+ def array
10
+ @@array ||= (0..10).to_a
11
+ end
12
+
13
+ def run_test range, *arg
14
+ assert_equal array.slice(range), array.subarrayWithRange(range.to_NSRange(*arg)), range
15
+ end
16
+
17
+ def test_cases
18
+ run_test 0..10
19
+ run_test 1..10
20
+ run_test 2..-1, array.size
21
+ run_test 3..-2, array.size
22
+ run_test 4...-1, array.size
23
+ run_test -3...-1, array.size
24
+ run_test -5..-1, array.size
25
+ # run_test -1..-2, array.size # returns an empty array, is a fucked up case to begin with
26
+ end
27
+
28
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'rubygems'
2
+ gem 'minitest'
3
+ require 'minitest/autorun'
4
+
5
+ if ENV['BENCH']
6
+ require 'minitest/benchmark'
7
+ else
8
+ require 'minitest/pride'
9
+ end
10
+
11
+ $LOAD_PATH.unshift File.join( File.dirname(__FILE__), '..', 'lib' )
12
+ require 'hotcocoa'
13
+
14
+ class MiniTest::Unit::TestCase
15
+ def run_run_loop time = 1.5
16
+ NSRunLoop.currentRunLoop.runUntilDate( Time.now + time )
17
+ end
18
+
19
+ def self.bench_range
20
+ bench_exp 10, 10_000
21
+ end
22
+ end
23
+
24
+ class SampleClass
25
+ def some_method
26
+ false
27
+ end
28
+ end
29
+
30
+ SOURCE_ROOT = `git rev-parse --show-toplevel`.chomp
@@ -0,0 +1,79 @@
1
+ ##
2
+ # @todo In this test class, there is a base set of tests
3
+ # that each mapping should have
4
+ class TestBonjourMappings < MiniTest::Unit::TestCase
5
+ include HotCocoa
6
+
7
+ def test_defaults_kick_in
8
+ b = bonjour_service type:'_http._tcp.', name:'Defaults Test'
9
+
10
+ assert_equal '', b.domain
11
+ assert_equal -1, b.port
12
+ end
13
+
14
+ def test_defaults_can_be_overridden
15
+ b = bonjour_service type:'_http._tcp.', name:'Defaults Test',
16
+ domain: 'local.', port: 9090
17
+
18
+ assert_equal 'local.', b.domain
19
+ assert_equal 9090, b.port
20
+ end
21
+
22
+ def test_delegation_publishing_success
23
+ b = bonjour_service type:'_http._tcp.', name:'HotCocoa Test', port: 9091
24
+ will_publish = did_publish = did_stop = false
25
+
26
+ b.will_publish { will_publish = true }
27
+ b.did_publish { did_publish = true }
28
+ b.did_stop { did_stop = true }
29
+
30
+ b.publish
31
+ assert will_publish
32
+
33
+ run_run_loop
34
+ assert did_publish
35
+
36
+ b.stop
37
+ assert did_stop
38
+ end
39
+
40
+ def test_delegation_publishing_failure
41
+ b = bonjour_service type:'fake', name:'HotCocoa Test', port: 9091
42
+
43
+ did_not_publish = false
44
+
45
+ b.did_not_publish { |error_dict| did_not_publish = error_dict }
46
+
47
+ b.publish
48
+ run_run_loop
49
+
50
+ assert_equal NSNetServicesBadArgumentError,
51
+ did_not_publish["NSNetServicesErrorCode"]
52
+ end
53
+
54
+ def test_delegating_resolving
55
+ service = bonjour_service type:'_fake._tcp.',
56
+ name:'HotCocoa Test',
57
+ port: 9091
58
+ service.publish
59
+ found_service = nil
60
+
61
+ browser = bonjour_browser
62
+ browser.did_find_service { |new_service, more|
63
+ found_service = new_service
64
+ }
65
+ browser.search_for_services '_fake._tcp.'
66
+
67
+ run_run_loop
68
+ refute_nil found_service
69
+ found_service.resolve
70
+
71
+ run_run_loop
72
+ assert_equal 9091, found_service.port
73
+ end
74
+
75
+ def test_delegation_TXT_record
76
+ skip 'TODO'
77
+ end
78
+
79
+ end
@@ -0,0 +1,16 @@
1
+ class TestColorMappings < MiniTest::Unit::TestCase
2
+
3
+ def test_given_a_name
4
+ assert_equal NSColor.redColor, HotCocoa.color(name: 'red')
5
+ assert_equal NSColor.greenColor, HotCocoa.color(name: 'green')
6
+ assert_equal NSColor.lightGrayColor, HotCocoa.color(name: 'lightGray')
7
+ end
8
+
9
+ def bench_create_color
10
+ color = 'red'
11
+ assert_performance_linear do |n|
12
+ n.times { HotCocoa.color(name: color) }
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,21 @@
1
+ class TestFontMappings < MiniTest::Unit::TestCase
2
+
3
+ def test_options
4
+ assert_equal NSFont.labelFontOfSize(10), HotCocoa.font(label: 10)
5
+ assert_equal NSFont.systemFontOfSize(15), HotCocoa.font(system: 15)
6
+ assert_equal NSFont.controlContentFontOfSize(12), HotCocoa.font(control_content: 12)
7
+ assert_equal NSFont.toolTipsFontOfSize(20), HotCocoa.font(tool_tip: 20)
8
+ assert_equal NSFont.paletteFontOfSize(32), HotCocoa.font(palette: 32)
9
+ end
10
+
11
+ def test_size
12
+ assert_equal 10.0, HotCocoa.font(label: 10).size
13
+ end
14
+
15
+ def bench_create_font
16
+ assert_performance_linear do |n|
17
+ n.times { HotCocoa.font(label: 10) }
18
+ end
19
+ end
20
+
21
+ end
@@ -0,0 +1,18 @@
1
+ class TestTrackingAreaMappings < MiniTest::Unit::TestCase
2
+
3
+ def test_given_a_name
4
+ tracking_area = HotCocoa.tracking_area(rect: [0,0,10,10],
5
+ options: [:mouse_entered_and_exited, :active_in_key_window],
6
+ owner: self)
7
+ assert_instance_of(NSTrackingArea, tracking_area)
8
+ assert_equal NSMakeRect(0,0,10,10), tracking_area.rect
9
+ assert_equal self, tracking_area.owner
10
+ assert_equal NSTrackingMouseEnteredAndExited | NSTrackingActiveInKeyWindow, tracking_area.options
11
+ end
12
+
13
+ def bench_create_tracking_area
14
+ assert_performance_linear do |n|
15
+ n.times { HotCocoa.tracking_area }
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,95 @@
1
+ require 'fileutils'
2
+ require 'yaml'
3
+
4
+ require 'hotcocoa/application_builder'
5
+
6
+ class TestConfiguration < MiniTest::Unit::TestCase
7
+
8
+ Configuration = HotCocoa::ApplicationBuilder::Configuration
9
+ TEST_DIR = File.join( ENV['TMPDIR'], 'test_app_builder' )
10
+
11
+ # Some HotCocoa build.yml files, borrowed from projects on Github
12
+ HOTCONSOLE = 'test/fixtures/hotconsole.yml'
13
+ CALCULATOR = 'test/fixtures/calculator.yml'
14
+ STOPWATCH = 'test/fixtures/stopwatch.yml'
15
+ EMPTY_APP = 'test/fixtures/empty.yml'
16
+
17
+ def setup; FileUtils.mkdir TEST_DIR; end
18
+ def teardown; FileUtils.rm_rf TEST_DIR; end
19
+
20
+ def test_reads_attributes
21
+ conf = Configuration.new HOTCONSOLE
22
+ assert_equal 'HotConsole', conf.name
23
+ assert_equal '1.0', conf.version
24
+ assert_equal 'resources/HotConsole.icns', conf.icon
25
+ assert_equal ['resources/**/*.*'], conf.resources
26
+ assert_equal ['lib/**/*.rb'], conf.sources
27
+
28
+ conf = Configuration.new CALCULATOR
29
+ assert_equal 'Calculator', conf.name
30
+ assert_equal '2.0', conf.version
31
+ end
32
+
33
+ def test_version_defaults_to_1_if_not_set
34
+ conf = Configuration.new STOPWATCH
35
+ refute_nil conf.version
36
+ assert_equal '1.0', conf.version
37
+ end
38
+
39
+ def test_sources_resources_and_data_models_are_initialized_to_an_empty_array_if_not_provided
40
+ conf = Configuration.new EMPTY_APP
41
+ assert_empty conf.sources
42
+ assert_empty conf.resources
43
+ assert_empty conf.data_models
44
+ end
45
+
46
+ def test_overwirte_attribute
47
+ conf = Configuration.new EMPTY_APP
48
+ refute conf.overwrite?
49
+
50
+ conf = Configuration.new STOPWATCH
51
+ assert conf.overwrite?
52
+ end
53
+
54
+ def test_agent_attribute
55
+ conf = Configuration.new EMPTY_APP
56
+ assert_equal '0', conf.agent
57
+
58
+ conf = Configuration.new STOPWATCH
59
+ assert_equal '1', conf.agent
60
+ end
61
+
62
+ def test_stdlib_attribute
63
+ conf = Configuration.new HOTCONSOLE
64
+ assert_equal true, conf.stdlib
65
+
66
+ conf = Configuration.new STOPWATCH
67
+ assert_equal false, conf.stdlib
68
+ end
69
+
70
+ def test_type_attribute
71
+ conf = Configuration.new HOTCONSOLE
72
+ assert_equal 'APPL', conf.type
73
+
74
+ conf = Configuration.new EMPTY_APP
75
+ assert_equal 'BNDL', conf.type
76
+ end
77
+
78
+ def test_signature_attribute
79
+ conf = Configuration.new EMPTY_APP
80
+ assert_equal '????', conf.signature
81
+
82
+ conf = Configuration.new HOTCONSOLE
83
+ assert_equal 'girb', conf.signature
84
+ end
85
+
86
+ def test_icon_exists?
87
+ conf = Configuration.new HOTCONSOLE
88
+ refute conf.icon_exists?
89
+
90
+ # works because this project uses the icon from a system app
91
+ conf = Configuration.new CALCULATOR
92
+ assert conf.icon_exists?
93
+ end
94
+
95
+ end
@@ -0,0 +1,63 @@
1
+ class TestAttributedStringHelpers < MiniTest::Unit::TestCase
2
+
3
+ def attrs
4
+ {
5
+ NSFontAttributeName => NSFont.toolTipsFontOfSize(10),
6
+ NSObliquenessAttributeName => 5.0,
7
+ NSToolTipAttributeName => 'Some tool tip text',
8
+ NSStrikethroughColorAttributeName => NSColor.redColor
9
+ }
10
+ end
11
+
12
+ def attr_string value = 'test'
13
+ string = NSMutableAttributedString.alloc.initWithString value,
14
+ attributes: attrs
15
+ end
16
+
17
+ def string_proxy value = 'test'
18
+ string = attr_string value
19
+ HotCocoa::NSRangedProxyAttributedString.new string, 0..-1
20
+ end
21
+
22
+ def test_proxy_attributed_string
23
+ string = attr_string
24
+ range = 0..-1
25
+ proxy = HotCocoa::NSRangedProxyAttributedString.new string, range
26
+ assert_same string, proxy.string
27
+ assert_same range, proxy.range
28
+ end
29
+
30
+ def test_proxy_attribute_hash_reads_attributes_correctly
31
+ attributes = string_proxy.attributes
32
+ assert_equal attrs[NSFontAttributeName], attributes[:font]
33
+ assert_equal attrs[NSObliquenessAttributeName], attributes[:obliqueness]
34
+ assert_equal attrs[NSToolTipAttributeName], attributes[:tool_tip]
35
+ assert_equal attrs[NSStrikethroughColorAttributeName], attributes[:strikethrough_color]
36
+ end
37
+
38
+ def test_proxy_attribute_hash_writes_attributes_correctly
39
+ proxy = string_proxy
40
+ attributes = proxy.attributes
41
+ attributes[:tool_tip] = 'lol'
42
+ value = proxy.string.attribute NSToolTipAttributeName, atIndex: 0, effectiveRange: nil
43
+ assert_equal 'lol', value
44
+ end
45
+
46
+ def test_proxy_attribute_hash_appends_correctly
47
+ proxy = string_proxy
48
+ attributes = proxy.attributes
49
+ attributes << { tool_tip: 'lol', colour: NSColor.greenColor }
50
+ tip = proxy.string.attribute NSToolTipAttributeName, atIndex: 0, effectiveRange: nil
51
+ colour = proxy.string.attribute NSForegroundColorAttributeName, atIndex: 0, effectiveRange: nil
52
+ assert_equal NSColor.greenColor, colour
53
+ assert_equal 'lol', tip
54
+ end
55
+
56
+ def test_proxy_attribute_hash_inspect
57
+ assert_equal attrs, string_proxy.attributes.to_hash
58
+ # names are not translated
59
+ pattern = /#{attrs.keys.first.inspect}=>#{attrs.values.first.inspect}/
60
+ assert_match pattern, string_proxy.attributes.inspect
61
+ end
62
+
63
+ end
@@ -0,0 +1,26 @@
1
+ class BehaviorsTestView < NSView
2
+ include HotCocoa::Behaviors
3
+ end
4
+ class BehaviorsTest < NSNetServiceBrowser
5
+ include HotCocoa::Behaviors
6
+ end
7
+
8
+ class TestBehaviors < MiniTest::Unit::TestCase
9
+
10
+ def test_behaviours_is_alias_to_behaviors
11
+ assert_equal HotCocoa::Behaviors, HotCocoa::Behaviours
12
+ end
13
+
14
+ def test_inherits_custom_methods
15
+ assert_respond_to BehaviorsTest.new, :search_for_domains
16
+ end
17
+
18
+ def test_inherits_delegate_methods
19
+ assert_respond_to BehaviorsTest.new, :did_find_domain
20
+ end
21
+
22
+ def test_inherits_bindings
23
+ assert_respond_to BehaviorsTestView.new, :hidden=
24
+ end
25
+
26
+ end
data/test/test_bin.rb ADDED
@@ -0,0 +1,75 @@
1
+ class TestHotCocoaBinary < MiniTest::Unit::TestCase
2
+
3
+ def hotcocoa *args
4
+ ruby = ENV['RUBY_VERSION'] ? 'ruby' : 'macruby'
5
+ `#{ruby} -I#{SOURCE_ROOT}/lib #{SOURCE_ROOT}/bin/hotcocoa #{args.join(' ')}`.chomp
6
+ end
7
+
8
+ end
9
+
10
+
11
+ class TestHotCocoaBinaryOptions < TestHotCocoaBinary
12
+
13
+ def test_shows_version
14
+ pattern = /Hot\s?Cocoa\s+#{HotCocoa::VERSION}/i
15
+ assert_match pattern, hotcocoa('-v')
16
+ assert_match pattern, hotcocoa('--version')
17
+ end
18
+
19
+ def test_shows_usage
20
+ assert_equal 'Usage: hotcocoa <project name>', hotcocoa
21
+ assert_equal 'Usage: hotcocoa <project name>', hotcocoa('-h')
22
+ assert_equal 'Usage: hotcocoa <project name>', hotcocoa('--help')
23
+ end
24
+
25
+ end
26
+
27
+
28
+ class TestHotCocoaBinaryUsesTemplate < TestHotCocoaBinary
29
+
30
+ def setup
31
+ @dir = File.join(ENV['TMPDIR'], 'hot_cocoa_test')
32
+ Dir.mkdir @dir
33
+ end
34
+
35
+ def teardown
36
+ FileUtils.rm_rf @dir
37
+ end
38
+
39
+ def test_uses_given_name
40
+ app_name = 'The answer to life, the universe, and everything'
41
+ Dir.chdir(@dir) do
42
+ hotcocoa app_name.inspect
43
+ assert Dir.exists? app_name
44
+ end
45
+ end
46
+
47
+ def test_uses_camel_case_name_for_appspec
48
+ app_name = 'CamelCase'
49
+ Dir.chdir(@dir) do
50
+ hotcocoa app_name.inspect
51
+ assert Dir.new(app_name).entries.include? "#{app_name}.appspec"
52
+ end
53
+ end
54
+
55
+ def test_converts_non_alphanumeric_characters_to_camelcase
56
+ app_name = 'The answer to life, the universe, and everything'
57
+ Dir.chdir(@dir) do
58
+ hotcocoa app_name.inspect
59
+ assert Dir.new(app_name).entries.include? "TheAnswerToLifeTheUniverseAndEverything.appspec"
60
+ end
61
+ end
62
+
63
+ # this is a weird edge case that was programmed in
64
+ # so we will preseve it for the time being
65
+ def test_moves_existing_rb_file_into_the_project
66
+ app_name = 'blah blah.rb'
67
+ Dir.chdir(@dir) do
68
+ File.open(app_name, 'w') { |f| f.write 'ZOMG' }
69
+ hotcocoa app_name.inspect
70
+ app = File.read(File.join(app_name.chomp('.rb'),'lib','application.rb'))
71
+ assert_equal 'ZOMG', app
72
+ end
73
+ end
74
+
75
+ end
@@ -0,0 +1,100 @@
1
+ # Originally imported from MacRuby sources
2
+
3
+ class TestMapperDetails < MiniTest::Unit::TestCase
4
+ include HotCocoa::Mappings
5
+
6
+ def test_module_has_bindings_and_delegate_caches
7
+ assert_instance_of Hash, Mapper.bindings_modules
8
+ assert_instance_of Hash, Mapper.delegate_modules
9
+ end
10
+
11
+ def test_exposes_control_class
12
+ assert_respond_to sample_mapper, :control_class
13
+ refute_respond_to sample_mapper, :control_class=
14
+ end
15
+
16
+ def test_exposes_builder_method
17
+ assert_respond_to sample_mapper, :builder_method
18
+ refute_respond_to sample_mapper, :builder_method=
19
+ end
20
+
21
+ def test_exposes_control_module
22
+ assert_respond_to sample_mapper, :control_module
23
+ refute_respond_to sample_mapper, :control_module=
24
+ end
25
+
26
+ def test_exposes_map_bindings
27
+ assert_respond_to sample_mapper, :map_bindings
28
+ assert_respond_to sample_mapper, :map_bindings=
29
+ end
30
+
31
+ def test_sets_its_control_class_on_initialization
32
+ assert_equal sample_mapper(true).control_class, SampleClass
33
+ end
34
+
35
+ def test_include_in_class
36
+ m = sample_mapper true
37
+ m.include_in_class
38
+
39
+ assert_equal m.instance_variable_get(:@extension_method), :include
40
+
41
+ skip 'Pending.'
42
+ end
43
+
44
+
45
+ private
46
+
47
+ def sample_mapper flush = false
48
+ @mapper = nil if flush
49
+ @mapper ||= Mapper.new(SampleClass)
50
+ end
51
+
52
+ end
53
+
54
+
55
+ class TestMapperFeatures < MiniTest::Unit::TestCase
56
+
57
+ def teardown
58
+ HotCocoa::Mappings.mappings.delete :sample
59
+ end
60
+
61
+ def test_handle_block_called_if_implemented
62
+ HotCocoa::Mappings.map sample: SampleClass do
63
+ def alloc_with_options opts
64
+ SampleClass.new
65
+ end
66
+ def handle_block inst
67
+ inst.instance_variable_set(:@cache, yield(inst))
68
+ end
69
+ end
70
+ object = HotCocoa.sample { |_| :cake_is_the_truth }
71
+ assert_equal :cake_is_the_truth, object.instance_variable_get(:@cache)
72
+ end
73
+
74
+ def test_block_is_executed_if_given
75
+ HotCocoa::Mappings.map sample: SampleClass do
76
+ def alloc_with_options opts
77
+ SampleClass.new
78
+ end
79
+ end
80
+ yielded = false
81
+ object = HotCocoa.sample { |inst| yielded = inst }
82
+ assert_equal object, yielded
83
+ end
84
+
85
+ def test_custom_methods_override_existing_methods
86
+ HotCocoa::Mappings.map sample: SampleClass do
87
+ def alloc_with_options opts
88
+ SampleClass.new
89
+ end
90
+ custom_methods do
91
+ def some_method
92
+ true
93
+ end
94
+ end
95
+ end
96
+ object = HotCocoa.sample
97
+ assert_equal true, object.some_method
98
+ end
99
+
100
+ end
@@ -0,0 +1,67 @@
1
+ class TestMappingMethods < MiniTest::Unit::TestCase
2
+ class MappingMethodsTestClass
3
+ end
4
+
5
+ def setup
6
+ @klass = MappingMethodsTestClass.new
7
+ @klass.extend HotCocoa::MappingMethods
8
+ end
9
+
10
+ def test_there_can_only_be_one_defaults
11
+ first_defaults = { first_key: 'first_value' }
12
+ second_defaults = { second_key: 'second_value' }
13
+
14
+ @klass.defaults first_defaults
15
+ assert_equal first_defaults, @klass.defaults
16
+
17
+ @klass.defaults second_defaults
18
+ assert_equal second_defaults, @klass.defaults
19
+ end
20
+
21
+ def test_there_can_only_be_one_custom_methods
22
+ first_custom_methods = Proc.new do
23
+ def first_method
24
+ end
25
+ end
26
+ second_custom_methods = Proc.new do
27
+ def second_method
28
+ end
29
+ end
30
+
31
+ @klass.custom_methods &first_custom_methods
32
+ assert_includes @klass.custom_methods.instance_methods, :first_method
33
+
34
+ @klass.custom_methods &second_custom_methods
35
+ assert_includes @klass.custom_methods.instance_methods, :second_method
36
+ end
37
+
38
+ def test_caches_are_initialized
39
+ assert_kind_of Hash, @klass.constants_map
40
+ assert_kind_of Hash, @klass.delegate_map
41
+ end
42
+
43
+ def test_constants_are_cached
44
+ first_mapping = { nice_const: 1, other: 'two' }
45
+ second_mapping = { a: 2, b: 'three' }
46
+
47
+ @klass.constant :x, first_mapping
48
+ assert_equal first_mapping, @klass.constants_map[:x]
49
+
50
+ @klass.constant :y, second_mapping
51
+ assert_equal second_mapping, @klass.constants_map[:y]
52
+ assert_equal first_mapping, @klass.constants_map[:x]
53
+ end
54
+
55
+ def test_delegate_mappings_are_cached
56
+ first_delegate = { to: :other_thingy }
57
+ second_delegate = { to: :a_method, parameters: [1, 2, 3] }
58
+
59
+ @klass.delegating :thingy, first_delegate
60
+ assert_equal first_delegate, @klass.delegate_map[:thingy]
61
+
62
+ @klass.delegating :thingy2, second_delegate
63
+ assert_equal second_delegate, @klass.delegate_map[:thingy2]
64
+ assert_equal first_delegate, @klass.delegate_map[:thingy]
65
+ end
66
+
67
+ end