calabash 2.0.0.pre10 → 2.0.0.pre11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -17
  3. data/bin/calabash +3 -4
  4. data/lib/calabash.rb +53 -10
  5. data/lib/calabash/android.rb +89 -28
  6. data/lib/calabash/android/adb.rb +32 -20
  7. data/lib/calabash/android/application.rb +1 -1
  8. data/lib/calabash/android/build/builder.rb +1 -1
  9. data/lib/calabash/android/build/java_keystore.rb +1 -1
  10. data/lib/calabash/android/build/resigner.rb +1 -1
  11. data/lib/calabash/android/device.rb +22 -66
  12. data/lib/calabash/android/device/helper_application.rb +95 -0
  13. data/lib/calabash/android/environment.rb +14 -1
  14. data/lib/calabash/android/gestures.rb +6 -22
  15. data/lib/calabash/android/interactions.rb +14 -17
  16. data/lib/calabash/android/lib/.irbrc +9 -1
  17. data/lib/calabash/android/lib/AndroidManifest.xml +23 -2
  18. data/lib/calabash/android/lib/HelperApplication.apk +0 -0
  19. data/lib/calabash/android/lib/HelperApplicationTestServer.apk +0 -0
  20. data/lib/calabash/android/lib/TestServer.apk +0 -0
  21. data/lib/calabash/android/life_cycle.rb +3 -3
  22. data/lib/calabash/android/orientation.rb +8 -8
  23. data/lib/calabash/android/physical_buttons.rb +19 -16
  24. data/lib/calabash/android/server.rb +1 -1
  25. data/lib/calabash/android/text.rb +12 -12
  26. data/lib/calabash/android/web.rb +12 -0
  27. data/lib/calabash/application.rb +3 -0
  28. data/lib/calabash/cli/generate.rb +8 -18
  29. data/lib/calabash/cli/helpers.rb +4 -9
  30. data/lib/calabash/cli/run.rb +1 -1
  31. data/lib/calabash/console_helpers.rb +179 -11
  32. data/lib/calabash/device.rb +4 -19
  33. data/lib/calabash/gestures.rb +292 -198
  34. data/lib/calabash/interactions.rb +3 -40
  35. data/lib/calabash/internal.rb +48 -0
  36. data/lib/calabash/ios.rb +76 -16
  37. data/lib/calabash/ios/automator.rb +9 -0
  38. data/lib/calabash/ios/automator/automator.rb +217 -0
  39. data/lib/calabash/ios/automator/coordinates.rb +37 -0
  40. data/lib/calabash/ios/automator/device_agent.rb +379 -0
  41. data/lib/calabash/ios/conditions.rb +1 -1
  42. data/lib/calabash/ios/console_helpers.rb +2 -2
  43. data/lib/calabash/ios/date_picker.rb +10 -8
  44. data/lib/calabash/ios/device.rb +0 -1
  45. data/lib/calabash/ios/device/device_implementation.rb +9 -21
  46. data/lib/calabash/ios/device/gestures_mixin.rb +53 -55
  47. data/lib/calabash/ios/device/keyboard_mixin.rb +21 -0
  48. data/lib/calabash/ios/device/rotation_mixin.rb +3 -65
  49. data/lib/calabash/ios/gestures.rb +24 -90
  50. data/lib/calabash/ios/interactions.rb +1 -6
  51. data/lib/calabash/ios/lib/.irbrc +9 -2
  52. data/lib/calabash/ios/orientation.rb +8 -8
  53. data/lib/calabash/ios/runtime.rb +14 -14
  54. data/lib/calabash/ios/scroll.rb +25 -17
  55. data/lib/calabash/ios/slider.rb +11 -18
  56. data/lib/calabash/ios/text.rb +20 -74
  57. data/lib/calabash/ios/uia.rb +1 -1
  58. data/lib/calabash/ios/web.rb +10 -0
  59. data/lib/calabash/lib/skeleton/{Gemfile → Gemfile.skeleton} +0 -0
  60. data/lib/calabash/lib/skeleton/config/{cucumber.yml → cucumber.yml.skeleton} +0 -0
  61. data/lib/calabash/lib/skeleton/features/{sample.feature → sample.feature.skeleton} +0 -0
  62. data/lib/calabash/lib/skeleton/features/step_definitions/{calabash_steps.rb → sample_steps.rb.skeleton} +8 -8
  63. data/lib/calabash/lib/skeleton/features/support/{dry_run.rb → dry_run.rb.skeleton} +2 -5
  64. data/lib/calabash/lib/skeleton/features/support/{env.rb → env.rb.skeleton} +2 -8
  65. data/lib/calabash/lib/skeleton/features/support/hooks.rb.skeleton +34 -0
  66. data/lib/calabash/life_cycle.rb +16 -8
  67. data/lib/calabash/location.rb +14 -15
  68. data/lib/calabash/orientation.rb +8 -8
  69. data/lib/calabash/page.rb +1 -4
  70. data/lib/calabash/retry.rb +33 -0
  71. data/lib/calabash/screenshot.rb +3 -3
  72. data/lib/calabash/stubs.rb +21 -0
  73. data/lib/calabash/text.rb +31 -19
  74. data/lib/calabash/utility.rb +41 -8
  75. data/lib/calabash/version.rb +1 -1
  76. data/lib/calabash/wait.rb +177 -192
  77. data/lib/calabash/web.rb +44 -0
  78. metadata +39 -32
  79. data/lib/calabash/ios/device/text_mixin.rb +0 -21
  80. data/lib/calabash/lib/skeleton/features/support/hooks.rb +0 -83
@@ -21,19 +21,19 @@ module Calabash
21
21
  raise 'No application given, and Application.default is not set'
22
22
  end
23
23
 
24
- Device.default.resume_app(path_or_application)
24
+ Calabash::Internal.with_default_device(required_os: :android) {|device| device.resume_app(path_or_application)}
25
25
 
26
26
  true
27
27
  end
28
28
 
29
29
  # @!visibility private
30
- def _send_current_app_to_background(for_seconds)
30
+ define_method(:_send_current_app_to_background) do |for_seconds|
31
31
  package = focused_package
32
32
  activity = focused_activity
33
33
 
34
34
  go_home
35
35
  sleep(for_seconds)
36
- Device.default.resume_activity(package, activity)
36
+ Calabash::Internal.with_default_device(required_os: :android) {|device| device.resume_activity(package, activity)}
37
37
  end
38
38
  end
39
39
  end
@@ -3,28 +3,28 @@ module Calabash
3
3
  # @!visibility private
4
4
  module Orientation
5
5
  # @!visibility private
6
- def _set_orientation_landscape
7
- Device.default.perform_action('set_activity_orientation', 'landscape')
6
+ define_method(:_set_orientation_landscape) do
7
+ Calabash::Internal.with_default_device(required_os: :android) {|device| device.perform_action('set_activity_orientation', 'landscape')}
8
8
  end
9
9
 
10
10
  # @!visibility private
11
- def _set_orientation_portrait
12
- Device.default.perform_action('set_activity_orientation', 'portrait')
11
+ define_method(:_set_orientation_portrait) do
12
+ Calabash::Internal.with_default_device(required_os: :android) {|device| device.perform_action('set_activity_orientation', 'portrait')}
13
13
  end
14
14
 
15
15
  # @!visibility private
16
- def _portrait?
16
+ define_method(:_portrait?) do
17
17
  _orientation == 'portrait'
18
18
  end
19
19
 
20
20
  # @!visibility private
21
- def _landscape?
21
+ define_method(:_landscape?) do
22
22
  _orientation == 'landscape'
23
23
  end
24
24
 
25
25
  # @!visibility private
26
- def _orientation
27
- Device.default.perform_action('get_activity_orientation')['message']
26
+ define_method(:_orientation) do
27
+ Calabash::Internal.with_default_device(required_os: :android) {|device| device.perform_action('get_activity_orientation')['message']}
28
28
  end
29
29
  end
30
30
  end
@@ -8,44 +8,47 @@ module Calabash
8
8
  module PhysicalButtons
9
9
 
10
10
  # @!visibility private
11
- def press_button(key)
12
- Device.default.perform_action('press_key', key)
11
+ def press_physical_button(key)
12
+ Calabash::Internal.with_default_device(required_os: :android) do |device|
13
+ device.perform_action('press_physical_key', key)
14
+ end
15
+
13
16
  true
14
17
  end
15
18
 
16
19
  # @!visibility private
17
- def press_back_button
18
- press_button('KEYCODE_BACK')
20
+ def press_physical_back_button
21
+ press_physical_button('KEYCODE_BACK')
19
22
  end
20
23
 
21
24
  # @!visibility private
22
- def press_menu_button
23
- press_button('KEYCODE_MENU')
25
+ def press_physical_menu_button
26
+ press_physical_button('KEYCODE_MENU')
24
27
  end
25
28
 
26
29
  # @!visibility private
27
- def press_down_button
28
- press_button('KEYCODE_DPAD_DOWN')
30
+ def press_physical_down_button
31
+ press_physical_button('KEYCODE_DPAD_DOWN')
29
32
  end
30
33
 
31
34
  # @!visibility private
32
- def press_up_button
33
- press_button('KEYCODE_DPAD_UP')
35
+ def press_physical_up_button
36
+ press_physical_button('KEYCODE_DPAD_UP')
34
37
  end
35
38
 
36
39
  # @!visibility private
37
- def press_left_button
38
- press_button('KEYCODE_DPAD_LEFT')
40
+ def press_physical_left_button
41
+ press_physical_button('KEYCODE_DPAD_LEFT')
39
42
  end
40
43
 
41
44
  # @!visibility private
42
- def press_right_button
43
- press_button('KEYCODE_DPAD_RIGHT')
45
+ def press_physical_right_button
46
+ press_physical_button('KEYCODE_DPAD_RIGHT')
44
47
  end
45
48
 
46
49
  # @!visibility private
47
- def press_enter_button
48
- press_button('KEYCODE_ENTER')
50
+ def press_physical_enter_button
51
+ press_physical_button('KEYCODE_ENTER')
49
52
  end
50
53
  end
51
54
  end
@@ -10,7 +10,7 @@ module Calabash
10
10
 
11
11
  def self.default_helper
12
12
  endpoint = Environment::DEVICE_HELPER_ENDPOINT
13
- Server.new(endpoint, 8102)
13
+ Server.new(endpoint, 8081)
14
14
  end
15
15
  end
16
16
  end
@@ -6,46 +6,46 @@ module Calabash
6
6
  # pressing the back button if the keyboard is showing. If the keyboard is
7
7
  # already hidden/dismissed, nothing is done.
8
8
  def dismiss_keyboard
9
- Device.default.perform_action('hide_soft_keyboard')
9
+ Calabash::Internal.with_default_device(required_os: :android) {|device| device.perform_action('hide_soft_keyboard')}
10
10
  sleep 0.5
11
11
  end
12
12
 
13
13
  # @!visibility private
14
- def _clear_text
15
- Device.default.perform_action('clear_text')
14
+ define_method(:_clear_text) do
15
+ Calabash::Internal.with_default_device(required_os: :android) {|device| device.perform_action('clear_text')}
16
16
  end
17
17
 
18
18
  # @!visibility private
19
- def _clear_text_in(view)
19
+ define_method(:_clear_text_in) do |view|
20
20
  tap(view)
21
21
  sleep 0.5
22
22
  clear_text
23
23
  end
24
24
 
25
25
  # @!visibility private
26
- def _enter_text(text)
27
- Device.default.enter_text(text)
26
+ define_method(:_enter_text) do |text|
27
+ Calabash::Internal.with_default_device(required_os: :android) {|device| device.enter_text(text)}
28
28
  end
29
29
 
30
30
  # @!visibility private
31
- def _enter_text_in(view, text)
31
+ define_method(:_enter_text_in) do |view, text|
32
32
  tap(view)
33
33
  sleep 0.5
34
34
  enter_text(text)
35
35
  end
36
36
 
37
37
  # @!visibility private
38
- def _tap_keyboard_action_key(action_key)
38
+ define_method(:_tap_keyboard_action_key) do |action_key|
39
39
  if action_key.nil?
40
- Device.default.perform_action('press_user_action_button')
40
+ Calabash::Internal.with_default_device(required_os: :android) {|device| device.perform_action('press_user_action_button')}
41
41
  else
42
- Device.default.perform_action('press_user_action_button', action_key.to_s)
42
+ Calabash::Internal.with_default_device(required_os: :android) {|device| device.perform_action('press_user_action_button', action_key.to_s)}
43
43
  end
44
44
  end
45
45
 
46
46
  # @!visibility private
47
- def _keyboard_visible?
48
- Device.default.keyboard_visible?
47
+ define_method(:_keyboard_visible?) do
48
+ Calabash::Internal.with_default_device(required_os: :android) {|device| device.keyboard_visible?}
49
49
  end
50
50
  end
51
51
  end
@@ -0,0 +1,12 @@
1
+ module Calabash
2
+ module Android
3
+ module Web
4
+ # @!visibility private
5
+ define_method(:_evaluate_javascript_in) do |query, javascript|
6
+ Calabash::Internal.with_default_device(required_os: :android) do |device|
7
+ device.evaluate_javascript_in(query, javascript)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -3,6 +3,9 @@ require 'digest'
3
3
  module Calabash
4
4
  # A representation of an application that is under test.
5
5
  class Application
6
+ require 'calabash/android/application'
7
+ require 'calabash/ios/application'
8
+
6
9
  # @!visibility private
7
10
  include Calabash::Utility
8
11
 
@@ -17,24 +17,14 @@ module Calabash
17
17
  exit 1
18
18
  end
19
19
 
20
- reset_between = :features
21
- reset_method = :clear
20
+ cucumber_config = File.read(file(File.join('config', 'cucumber.yml.skeleton')))
22
21
 
23
- cucumber_config = File.read(file(File.join('config', 'cucumber.yml')))
22
+ env = File.read(file(File.join('features', 'support', 'env.rb.skeleton')))
23
+ dry_run = File.read(file(File.join('features', 'support', 'dry_run.rb.skeleton')))
24
+ sample_feature = File.read(file(File.join('features', 'sample.feature.skeleton')))
25
+ calabash_steps = File.read(file(File.join('features', 'step_definitions', 'sample_steps.rb.skeleton')))
24
26
 
25
- env = File.read(file(File.join('features', 'support', 'env.rb')))
26
- dry_run = File.read(file(File.join('features', 'support', 'dry_run.rb')))
27
- sample_feature = File.read(file(File.join('features', 'sample.feature')))
28
- calabash_steps = File.read(file(File.join('features', 'step_definitions', 'calabash_steps.rb')))
29
-
30
- hooks = File.read(file(File.join('features', 'support', 'hooks.rb')))
31
- hooks.sub!("#!DEFAULT_RESET_BETWEEN#!", ":#{reset_between}")
32
-
33
- if reset_method.nil?
34
- hooks.sub!("#!DEFAULT_RESET_METHOD#!", 'nil')
35
- else
36
- hooks.sub!("#!DEFAULT_RESET_METHOD#!", ":#{reset_method}")
37
- end
27
+ hooks = File.read(file(File.join('features', 'support', 'hooks.rb.skeleton')))
38
28
 
39
29
  FileUtils.mkdir('config')
40
30
 
@@ -45,12 +35,12 @@ module Calabash
45
35
  FileUtils.mkdir('features/support')
46
36
 
47
37
  File.open(File.join('features', 'sample.feature'), 'w') {|file| file.write(sample_feature) }
48
- File.open(File.join('features', 'step_definitions', 'calabash_steps.rb'), 'w') {|file| file.write(calabash_steps) }
38
+ File.open(File.join('features', 'step_definitions', 'sample_steps.rb'), 'w') {|file| file.write(calabash_steps) }
49
39
  File.open(File.join('features', 'support', 'hooks.rb'), 'w') {|file| file.write(hooks) }
50
40
  File.open(File.join('features', 'support', 'env.rb'), 'w') {|file| file.write(env) }
51
41
  File.open(File.join('features', 'support', 'dry_run.rb'), 'w') {|file| file.write(dry_run) }
52
42
 
53
- gemfile = File.readlines(file(File.join('Gemfile')))
43
+ gemfile = File.readlines(file(File.join('Gemfile.skeleton')))
54
44
 
55
45
  unless File.exist?('Gemfile')
56
46
  File.open('Gemfile', 'w') do |file|
@@ -6,8 +6,7 @@ module Calabash
6
6
  # @!visibility private
7
7
  HELP = {
8
8
  help: 'help',
9
- generate: 'generate',
10
- run: 'run [application] [cucumber options]',
9
+ :'generate-cucumber' => 'generate-cucumber',
11
10
  console: 'console [application]',
12
11
  version: 'version',
13
12
  setup_keystore: 'setup-keystore',
@@ -35,7 +34,7 @@ EOF
35
34
  else
36
35
  output.write <<EOF
37
36
  Usage:
38
- calabash [options] #{HELP[key]}
37
+ #{Calabash::Utility.bundle_exec_prepend}calabash [options] #{HELP[key]}
39
38
  EOF
40
39
  end
41
40
  end
@@ -43,18 +42,14 @@ EOF
43
42
  # @!visibility private
44
43
  def print_usage(output=STDOUT)
45
44
  output.write <<EOF
46
- Usage: calabash [options] <command-name> [command specific options]
45
+ Usage: #{Calabash::Utility.bundle_exec_prepend}calabash [options] <command-name> [command specific options]
47
46
  <command-name> can be one of
48
47
  #{HELP[:help]} [command]
49
48
  print help information.
50
49
 
51
- #{HELP[:generate]}
50
+ #{HELP[:'generate-cucumber']}
52
51
  generate a Cucumber project folder structure.
53
52
 
54
- #{HELP[:run]}
55
- runs Cucumber in the current folder with the environment needed.
56
- the cucumber options will be passed unchanged to cucumber
57
-
58
53
  #{HELP[:console]}
59
54
  starts an interactive console to interact with your app via Calabash
60
55
 
@@ -87,7 +87,7 @@ module Calabash
87
87
  begin
88
88
  require 'cucumber'
89
89
  rescue LoadError => _
90
- unless Object.const_defined?(:Bundler)
90
+ unless Calabash::Utility.used_bundler?
91
91
  $stderr.puts "Warning! Could not load cucumber. Make sure it is installed."
92
92
  end
93
93
  end
@@ -5,21 +5,99 @@ module Calabash
5
5
  # Methods you can use in the Calabash console to help you
6
6
  # interact with your app.
7
7
  module ConsoleHelpers
8
+ # Reloads all required files that have git changes
9
+ def reload_git_files
10
+ files_to_reload =
11
+ (`cd ../../../ && git status`.lines.grep(/modified/).map{|l| l.split(" ").last.gsub('../', '')} +
12
+ `cd ../../../ && git ls-files --others --exclude-standard`.lines).map(&:chomp)
13
+
14
+ $LOADED_FEATURES.each do |file|
15
+ files_to_reload.each do |reload_name|
16
+ if file.end_with?(reload_name)
17
+ puts "LOADING #{file}"
18
+ load file
19
+ break
20
+ end
21
+ end
22
+ end
23
+
24
+ true
25
+ end
26
+
27
+ # Outputs all calabash methods
28
+ def cal_methods
29
+ c = Class.new(BasicObject) do
30
+ include Calabash
31
+ end
32
+
33
+ ConsoleHelpers.puts_unbound_methods(c, 'cal.')
34
+ true
35
+ end
36
+
37
+ # Outputs a calabash method
38
+ def cal_method(method)
39
+ c = Class.new(BasicObject) do
40
+ include Calabash
41
+ end
42
+
43
+ ConsoleHelpers.puts_unbound_method(c, method.to_sym, 'cal.')
44
+ true
45
+ end
46
+
47
+ # Outputs all calabash iOS methods
48
+ def cal_ios_methods
49
+ c = Class.new(BasicObject) do
50
+ include Calabash::IOSInternal
51
+ end
52
+
53
+ ConsoleHelpers.puts_unbound_methods(c, 'cal_ios.')
54
+ true
55
+ end
56
+
57
+ # Outputs a calabash Android method
58
+ def cal_ios_method(method)
59
+ c = Class.new(BasicObject) do
60
+ include Calabash::IOSInternal
61
+ end
62
+
63
+ ConsoleHelpers.puts_unbound_method(c, method.to_sym, 'cal_ios.')
64
+ true
65
+ end
66
+
67
+ # Outputs all calabash Android methods
68
+ def cal_android_methods
69
+ c = Class.new(BasicObject) do
70
+ include Calabash::AndroidInternal
71
+ end
72
+
73
+ ConsoleHelpers.puts_unbound_methods(c, 'cal_android.')
74
+ true
75
+ end
76
+
77
+ # Outputs a calabash Android method
78
+ def cal_android_method(method)
79
+ c = Class.new(BasicObject) do
80
+ include Calabash::AndroidInternal
81
+ end
82
+
83
+ ConsoleHelpers.puts_unbound_method(c, method.to_sym, 'cal_android.')
84
+ true
85
+ end
8
86
 
9
87
  # Outputs all visible elements as a tree.
10
88
  def tree
11
- ConsoleHelpers.dump(Device.default.dump)
89
+ ConsoleHelpers.dump(Calabash::Internal.with_default_device {|device| device.dump})
12
90
  true
13
91
  end
14
92
 
15
93
  # List the visible element classes.
16
94
  def classes
17
- query("*").map{|e| e['class']}.uniq
95
+ cal.query("*").map{|e| e['class']}.uniq
18
96
  end
19
97
 
20
98
  # List the visible element ids.
21
99
  def ids
22
- query("*").map{|e| e['id']}.compact
100
+ cal.query("*").map{|e| e['id']}.compact
23
101
  end
24
102
 
25
103
  # Copy all the commands entered in the current console session into the OS
@@ -92,14 +170,31 @@ module Calabash
92
170
  # @!visibility private
93
171
  def puts_console_details
94
172
  puts ''
95
- puts Color.blue('# => Useful Methods <= #')
96
- puts Color.cyan('> ids => List all the visible ids.')
97
- puts Color.cyan('> classes => List all the visible classes.')
98
- puts Color.cyan("> tree => The app's visible view hierarchy.")
99
- puts Color.cyan('> copy => Copy console commands to the Clipboard.')
100
- puts Color.cyan('> clear => Clear the console.')
101
- puts Color.cyan('> verbose => Turn debug logging on.')
102
- puts Color.cyan('> quiet => Turn debug logging off.')
173
+ puts '# => Useful Console Methods <= #'
174
+ puts Color.cyan('> ids => List all the visible ids.')
175
+ puts Color.cyan('> classes => List all the visible classes.')
176
+ puts Color.cyan("> tree => The app's visible view hierarchy.")
177
+ puts Color.cyan('> copy => Copy console commands to the Clipboard.')
178
+ puts Color.cyan('> clear => Clear the console.')
179
+ puts Color.cyan('> verbose => Turn debug logging on.')
180
+ puts Color.cyan('> quiet => Turn debug logging off.')
181
+ puts Color.cyan('> cal_methods => Print all cross-platform Calabash methods.')
182
+ puts Color.cyan('> cal_method(method) => Print all information about a Calabash method')
183
+
184
+ if defined?(Calabash::AndroidInternal)
185
+ puts ''
186
+ puts 'Android specific'
187
+ puts Color.cyan('> cal_android_methods => Print all Android-specific Calabash methods.')
188
+ puts Color.cyan('> cal_android_method(method) => Print all information about an Android-specific Calabash method.')
189
+ end
190
+
191
+ if defined?(Calabash::IOSInternal)
192
+ puts ''
193
+ puts 'iOS specific'
194
+ puts Color.cyan('> cal_ios_methods => Print all iOS-specific Calabash methods.')
195
+ puts Color.cyan('> cal_ios_method(method) => Print all information about an ios-specific Calabash method.')
196
+ end
197
+
103
198
  puts ''
104
199
  end
105
200
 
@@ -191,5 +286,78 @@ module Calabash
191
286
  def self.visible?(data)
192
287
  raise AbstractMethodError
193
288
  end
289
+
290
+ # @!visibility private
291
+ def self.puts_unbound_methods(clazz, prefix)
292
+ (clazz.instance_methods - BasicObject.instance_methods).each do |method_sym|
293
+ signature,description = method_signature(clazz.instance_method(method_sym))
294
+
295
+ puts_method(signature, description, prefix)
296
+ end
297
+ end
298
+
299
+ # @!visibility private
300
+ def self.puts_unbound_method(clazz, method, prefix)
301
+ signature,description = method_signature(clazz.instance_method(method), true)
302
+
303
+ puts_method(signature, description, prefix)
304
+ end
305
+
306
+ # @!visibility private
307
+ def self.puts_method(signature, description, prefix)
308
+ if signature != nil
309
+ puts Color.yellow(description)
310
+ puts Color.blue("#{prefix}#{signature}")
311
+ puts ''
312
+ end
313
+ end
314
+
315
+ # @!visibility private
316
+ def self.method_signature(method, full_description = false)
317
+ file_name, line = method.source_location
318
+
319
+ file = File.open(file_name, 'r')
320
+
321
+ description = nil
322
+ read_next_lines = false
323
+
324
+ (line-1).times do
325
+ line = file.gets.strip
326
+
327
+ if line.start_with?('#')
328
+ if line.length == 1 || line.start_with?("# @")
329
+ read_next_lines = false
330
+ end
331
+
332
+ if description.nil?
333
+ description = line[2..-1]
334
+ read_next_lines = true
335
+ elsif read_next_lines || full_description
336
+ description = "#{description}\n#{line[2..-1]}"
337
+ end
338
+ else
339
+ description = nil
340
+ end
341
+ end
342
+
343
+ signature = file.gets.strip[4..-1]
344
+
345
+ method_name = if signature.index('(')
346
+ signature[0,signature.index('(')]
347
+ else
348
+ signature
349
+ end
350
+
351
+ # Remove alias'ed methods
352
+ if method_name != method.name.to_s
353
+ signature = nil
354
+ end
355
+
356
+ if description && description.start_with?("@!visibility private")
357
+ signature = nil
358
+ end
359
+
360
+ [signature,description]
361
+ end
194
362
  end
195
363
  end