redcar 0.3.4.3 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) hide show
  1. data/CHANGES +45 -0
  2. data/README.md +2 -1
  3. data/ROADMAP.md +0 -1
  4. data/Rakefile +10 -4
  5. data/bin/redcar +2 -2
  6. data/lib/openssl/build.properties +7 -0
  7. data/lib/plugin_manager/lib/plugin_manager.rb +10 -0
  8. data/lib/plugin_manager/lib/plugin_manager/plugin_definition.rb +1 -13
  9. data/lib/redcar.rb +12 -8
  10. data/lib/redcar/installer.rb +16 -15
  11. data/lib/redcar/ruby_extensions.rb +146 -1
  12. data/lib/redcar/runner.rb +16 -7
  13. data/lib/redcar/usage.rb +4 -7
  14. data/lib/redcar_quick_start.rb +5 -5
  15. data/lib/regex_replace.rb +0 -7
  16. data/plugins/application/features/step_definitions/command_steps.rb +5 -0
  17. data/plugins/application/features/step_definitions/dialog_steps.rb +5 -0
  18. data/plugins/application/features/step_definitions/filter_list_dialog_steps.rb +38 -0
  19. data/plugins/application/features/step_definitions/window_steps.rb +1 -1
  20. data/plugins/application/features/support/env.rb +44 -8
  21. data/plugins/application/lib/application.rb +32 -33
  22. data/plugins/application/lib/application/command.rb +32 -2
  23. data/plugins/application/lib/application/command/executor.rb +2 -12
  24. data/plugins/application/lib/application/dialog.rb +14 -14
  25. data/plugins/application/lib/application/event_spewer.rb +32 -0
  26. data/plugins/application/lib/application/menu.rb +5 -5
  27. data/plugins/application/lib/application/menu/builder.rb +5 -0
  28. data/plugins/application/lib/application/menu/lazy_menu.rb +24 -0
  29. data/plugins/application/lib/application/notebook.rb +4 -3
  30. data/plugins/application/lib/application/tab.rb +6 -2
  31. data/plugins/application/lib/application/window.rb +8 -4
  32. data/plugins/application/spec/application/menu/builder_spec.rb +17 -1
  33. data/plugins/application/spec/application/notebook_spec.rb +1 -1
  34. data/plugins/application_swt/build.xml +74 -0
  35. data/plugins/application_swt/lib/application_swt.rb +79 -0
  36. data/plugins/application_swt/lib/application_swt/cucumber_patches.rb +6 -1
  37. data/plugins/application_swt/lib/application_swt/dialog_adapter.rb +25 -17
  38. data/plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb +50 -12
  39. data/plugins/application_swt/lib/application_swt/html_tab.rb +20 -0
  40. data/plugins/application_swt/lib/application_swt/menu.rb +26 -2
  41. data/plugins/application_swt/lib/application_swt/notebook.rb +10 -12
  42. data/plugins/application_swt/lib/application_swt/window.rb +11 -11
  43. data/plugins/application_swt/src/com/redcareditor/application_swt/CocoaUIEnhancer.java +313 -0
  44. data/plugins/auto_completer/lib/auto_completer.rb +74 -67
  45. data/plugins/auto_completer/lib/auto_completer/current_document_completion_source.rb +19 -0
  46. data/plugins/auto_completer/lib/auto_completer/document_controller.rb +2 -2
  47. data/plugins/auto_completer/lib/auto_completer/word_list.rb +8 -1
  48. data/plugins/auto_indenter/features/ruby_style_indentation.feature +24 -0
  49. data/plugins/auto_indenter/features/step_definitions/indentation_steps.rb +6 -0
  50. data/plugins/auto_indenter/features/support/env.rb +2 -0
  51. data/plugins/auto_indenter/lib/auto_indenter.rb +86 -0
  52. data/plugins/auto_indenter/lib/auto_indenter/analyzer.rb +91 -0
  53. data/plugins/auto_indenter/lib/auto_indenter/commands.rb +34 -0
  54. data/plugins/auto_indenter/lib/auto_indenter/document_controller.rb +67 -12
  55. data/plugins/auto_indenter/lib/auto_indenter/rules.rb +41 -0
  56. data/plugins/auto_indenter/spec/auto_indenter/analyzer_spec.rb +151 -0
  57. data/plugins/auto_indenter/spec/spec_helper.rb +5 -0
  58. data/plugins/auto_pairer/lib/auto_pairer.rb +1 -0
  59. data/plugins/auto_pairer/lib/auto_pairer/document_controller.rb +43 -42
  60. data/plugins/auto_pairer/lib/auto_pairer/pairs_for_scope.rb +1 -5
  61. data/plugins/core/lib/core.rb +12 -1
  62. data/plugins/core/lib/core/observable.rb +7 -7
  63. data/plugins/core/lib/core/persistent_cache.rb +14 -2
  64. data/plugins/core/lib/core/plugin.rb +7 -0
  65. data/plugins/core/lib/core/resource.rb +78 -0
  66. data/plugins/core/lib/core/task.rb +62 -0
  67. data/plugins/core/lib/core/task_queue.rb +72 -0
  68. data/plugins/core/spec/core/resource_spec.rb +124 -0
  69. data/plugins/core/spec/core/task_queue_spec.rb +202 -0
  70. data/plugins/core/spec/spec_helper.rb +23 -1
  71. data/plugins/declarations/TODO +3 -0
  72. data/plugins/declarations/lib/declarations.rb +144 -0
  73. data/plugins/declarations/lib/declarations/completion_source.rb +22 -0
  74. data/plugins/declarations/lib/declarations/file.rb +68 -0
  75. data/plugins/declarations/lib/declarations/parser.rb +94 -0
  76. data/plugins/declarations/lib/declarations/select_tag_dialog.rb +44 -0
  77. data/plugins/declarations/plugin.rb +7 -0
  78. data/plugins/declarations/spec/declarations/file_spec.rb +62 -0
  79. data/plugins/declarations/spec/fixtures/federalist.rb +15 -0
  80. data/plugins/declarations/spec/spec_helper.rb +4 -0
  81. data/plugins/edit_view/features/indentation_commands.feature +40 -0
  82. data/plugins/edit_view/features/line_delimiter.feature +40 -0
  83. data/plugins/edit_view/features/step_definitions/editing_steps.rb +16 -4
  84. data/plugins/edit_view/features/step_definitions/notebook_steps.rb +1 -1
  85. data/plugins/edit_view/features/step_definitions/tab_steps.rb +1 -1
  86. data/plugins/edit_view/features/step_definitions/window_steps.rb +5 -1
  87. data/plugins/edit_view/features/support/env.rb +3 -5
  88. data/plugins/edit_view/features/undo_and_redo.feature +21 -0
  89. data/plugins/edit_view/lib/edit_view.rb +57 -4
  90. data/plugins/edit_view/lib/edit_view/actions/arrow_keys.rb +19 -3
  91. data/plugins/edit_view/lib/edit_view/document.rb +46 -11
  92. data/plugins/edit_view/lib/edit_view/document/indentation.rb +35 -0
  93. data/plugins/edit_view/lib/edit_view/modified_tabs_checker.rb +35 -0
  94. data/plugins/edit_view/lib/edit_view/tab_settings.rb +13 -3
  95. data/plugins/edit_view/spec/edit_view/document/indentation_spec.rb +112 -0
  96. data/plugins/edit_view/spec/edit_view/document_spec.rb +22 -0
  97. data/plugins/edit_view/spec/spec_helper.rb +1 -0
  98. data/plugins/edit_view_swt/lib/edit_view_swt.rb +59 -7
  99. data/plugins/edit_view_swt/lib/edit_view_swt/document.rb +3 -3
  100. data/plugins/edit_view_swt/lib/edit_view_swt/word_movement.rb +2 -2
  101. data/plugins/edit_view_swt/vendor/java-mateview.rb +3 -2
  102. data/plugins/encryption/encryption.rb +13 -6
  103. data/plugins/execute_current_tab/lib/execute_current_tab.rb +25 -15
  104. data/plugins/html_view/assets/redcar.css +32 -1
  105. data/plugins/html_view/lib/html_view.rb +23 -3
  106. data/plugins/html_view/lib/html_view/html_tab.rb +4 -0
  107. data/plugins/my_plugin/lib/my_plugin.rb +4 -12
  108. data/plugins/plugin_manager_ui/lib/plugin_manager_ui.rb +1 -0
  109. data/plugins/plugin_manager_ui/views/index.html.erb +30 -37
  110. data/plugins/project/features/find_file.feature +75 -0
  111. data/plugins/project/features/open_and_save_files.feature +7 -7
  112. data/plugins/project/features/open_directory_tree.feature +11 -3
  113. data/plugins/project/features/refresh_directory_tree.feature +7 -1
  114. data/plugins/project/features/step_definitions/directory_steps.rb +11 -1
  115. data/plugins/project/features/step_definitions/file_steps.rb +10 -0
  116. data/plugins/project/features/support/env.rb +6 -1
  117. data/plugins/project/features/watch_for_modified_files.feature +79 -0
  118. data/plugins/project/lib/project.rb +72 -306
  119. data/plugins/project/lib/project/commands.rb +128 -0
  120. data/plugins/project/lib/project/dir_mirror.rb +5 -1
  121. data/plugins/project/lib/project/drb_service.rb +21 -31
  122. data/plugins/project/lib/project/file_list.rb +76 -0
  123. data/plugins/project/lib/project/file_mirror.rb +13 -1
  124. data/plugins/project/lib/project/find_file_dialog.rb +22 -52
  125. data/plugins/project/lib/project/manager.rb +210 -0
  126. data/plugins/project/lib/project/recent_directories.rb +16 -3
  127. data/plugins/project/plugin.rb +1 -1
  128. data/plugins/project/spec/fixtures/myproject/README +2 -0
  129. data/plugins/project/spec/fixtures/myproject/lib/foo_lib.rb +1 -0
  130. data/plugins/project/spec/fixtures/myproject/spec/foo_spec.rb +1 -0
  131. data/plugins/project/{features → spec}/fixtures/winter.txt +0 -0
  132. data/plugins/project/spec/project/dir_mirror_spec.rb +1 -12
  133. data/plugins/project/spec/project/file_list_spec.rb +140 -0
  134. data/plugins/project/spec/spec_helper.rb +20 -0
  135. data/plugins/redcar/plugin.rb +1 -0
  136. data/plugins/redcar/redcar.rb +254 -84
  137. data/plugins/redcar_debug/lib/redcar_debug.rb +58 -11
  138. data/plugins/redcar_debug/vendor/jruby-prof/README +46 -0
  139. data/plugins/redcar_debug/vendor/jruby-prof/Rakefile +36 -0
  140. data/plugins/redcar_debug/vendor/jruby-prof/build.xml +31 -0
  141. data/plugins/redcar_debug/vendor/jruby-prof/example/call_tree.html +22677 -0
  142. data/plugins/redcar_debug/vendor/jruby-prof/example/call_tree.txt +589 -0
  143. data/plugins/redcar_debug/vendor/jruby-prof/example/flat.txt +28 -0
  144. data/plugins/redcar_debug/vendor/jruby-prof/example/graph.html +1670 -0
  145. data/plugins/redcar_debug/vendor/jruby-prof/example/graph.txt +125 -0
  146. data/plugins/redcar_debug/vendor/jruby-prof/example/pidigits.rb +92 -0
  147. data/plugins/redcar_debug/vendor/jruby-prof/example/test.rb +28 -0
  148. data/plugins/redcar_debug/vendor/jruby-prof/example/test2.rb +29 -0
  149. data/plugins/redcar_debug/vendor/jruby-prof/example/test_exception.rb +28 -0
  150. data/plugins/redcar_debug/vendor/jruby-prof/example/test_overhead.rb +43 -0
  151. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof.rb +66 -0
  152. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/abstract_printer.rb +21 -0
  153. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/flat_text_printer.rb +35 -0
  154. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/graph_html_printer.rb +123 -0
  155. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/graph_text_printer.rb +45 -0
  156. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/invocation_set.rb +34 -0
  157. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/method.rb +107 -0
  158. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/profile_invocation.rb +43 -0
  159. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/simple_tree_printer.rb +27 -0
  160. data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/tree_html_printer.rb +144 -0
  161. data/plugins/redcar_debug/vendor/jruby-prof/src/org/jruby/prof/Invocation.java +14 -0
  162. data/plugins/redcar_debug/vendor/jruby-prof/src/org/jruby/prof/JRubyProf.java +94 -0
  163. data/plugins/redcar_debug/vendor/jruby-prof/src/org/jruby/prof/ProfEventHook.java +49 -0
  164. data/plugins/redcar_debug/vendor/jruby-prof/templates/graph_row.html.erb +18 -0
  165. data/plugins/redcar_debug/vendor/jruby-prof/test/basic_test.rb +291 -0
  166. data/plugins/redcar_debug/views/history.html.erb +33 -0
  167. data/plugins/redcar_debug/views/index.html.erb +33 -0
  168. data/plugins/repl/lib/repl/internal_mirror.rb +3 -15
  169. data/plugins/repl/spec/repl/internal_mirror_spec.rb +2 -2
  170. data/plugins/snippets/lib/snippets.rb +0 -1
  171. data/plugins/snippets/lib/snippets/document_controller.rb +7 -1
  172. data/plugins/task_manager/lib/task_manager.rb +28 -0
  173. data/plugins/task_manager/plugin.rb +11 -0
  174. data/plugins/task_manager/views/index.html.erb +67 -0
  175. data/plugins/textmate/lib/textmate.rb +17 -21
  176. data/plugins/textmate/lib/textmate/plist.rb +1 -2
  177. data/plugins/textmate/lib/textmate/preference.rb +5 -1
  178. data/plugins/textmate/lib/textmate/snippet.rb +6 -1
  179. data/plugins/tree_view_swt/lib/tree_view_swt.rb +0 -6
  180. data/textmate/Bundles/Cucumber.tmbundle/Preferences/Comments.tmPreferences +1 -1
  181. data/textmate/Bundles/Cucumber.tmbundle/Preferences/next_Cucumber_Plain_Text_Feature_Completions.tmPreferences +30 -0
  182. data/textmate/Bundles/Cucumber.tmbundle/Preferences/next_Symbol_list___Scenario.tmPreferences +19 -0
  183. data/textmate/Bundles/Cucumber.tmbundle/Syntaxes/next_Cucumber_Plain_Text_Feature.tmLanguage +221 -0
  184. data/textmate/Bundles/Cucumber.tmbundle/Syntaxes/next_Cucumber_Steps.tmLanguage +424 -0
  185. data/textmate/Bundles/Cucumber.tmbundle/Syntaxes/plaintext_template.erb +19 -77
  186. data/textmate/Bundles/Cucumber.tmbundle/info.plist +1 -20
  187. data/textmate/Bundles/Perl.tmbundle/Syntaxes/Perl.plist +1 -1
  188. data/textmate/Themes/Emacs Strict.tmTheme +241 -0
  189. data/textmate/Themes/IR_White.tmTheme +792 -0
  190. data/textmate/Themes/Monokai.tmTheme +291 -0
  191. data/textmate/Themes/WhysPoignant.tmTheme +191 -0
  192. metadata +92 -7
  193. data/plugins/application/features/main_window.feature +0 -8
  194. data/plugins/project/lib/project/project_command.rb +0 -5
  195. data/textmate/Bundles/Cucumber.tmbundle/Snippets/Scenario.tmSnippet +0 -22
  196. data/textmate/Bundles/Cucumber.tmbundle/Snippets/Story.tmSnippet +0 -25
@@ -0,0 +1,210 @@
1
+
2
+
3
+ module Redcar
4
+ class Project
5
+ class Manager
6
+
7
+ def self.open_projects
8
+ Project.window_projects.values
9
+ end
10
+
11
+ def self.in_window(window)
12
+ Project.window_projects[window]
13
+ end
14
+
15
+ def self.windows_without_projects
16
+ Redcar.app.windows.reject {|w| in_window(w) }
17
+ end
18
+
19
+ # this will restore open files unless other files or dirs were passed
20
+ # as command line parameters
21
+ def self.start(args)
22
+ unless handle_startup_arguments(args)
23
+ unless Redcar.environment == :test
24
+ restore_last_session
25
+ end
26
+ end
27
+ init_current_files_hooks
28
+ init_window_closed_hooks
29
+ init_drb_listener
30
+ end
31
+
32
+ def self.init_window_closed_hooks
33
+ Redcar.app.add_listener(:window_about_to_close) do |win|
34
+ project = in_window(win)
35
+ project.close if project
36
+ self.save_file_list(win)
37
+ end
38
+ end
39
+
40
+ def self.init_drb_listener
41
+ return if ARGV.include?("--multiple-instance")
42
+ @drb_service = DrbService.new
43
+ end
44
+
45
+ def self.storage
46
+ @storage ||= Plugin::Storage.new('project_plugin')
47
+ end
48
+
49
+ def self.filter_path
50
+ if Redcar.app.focussed_notebook_tab
51
+ if mirror = EditView.focussed_document_mirror and mirror.is_a?(FileMirror)
52
+ dir = File.dirname(mirror.path)
53
+ return dir
54
+ end
55
+ end
56
+ storage['last_dir'] || File.expand_path(Dir.pwd)
57
+ end
58
+
59
+ def self.sensitivities
60
+ [ @open_project_sensitivity =
61
+ Sensitivity.new(:open_project, Redcar.app, false, [:focussed_window]) do
62
+ if win = Redcar.app.focussed_window
63
+ win.treebook.trees.detect {|t| t.tree_mirror.is_a?(DirMirror) }
64
+ end
65
+ end
66
+ ]
67
+ end
68
+
69
+ # Finds an EditTab with a mirror for the given path.
70
+ #
71
+ # @param [String] path the path of the file being edited
72
+ # @return [EditTab, nil] the EditTab that is editing it, or nil
73
+ def self.find_open_file_tab(path)
74
+ path = File.expand_path(path)
75
+ all_tabs = Redcar.app.windows.map {|win| win.notebooks}.flatten.map {|nb| nb.tabs }.flatten
76
+ all_tabs.find do |t|
77
+ t.is_a?(Redcar::EditTab) and
78
+ t.edit_view.document.mirror and
79
+ t.edit_view.document.mirror.is_a?(FileMirror) and
80
+ File.expand_path(t.edit_view.document.mirror.path) == path
81
+ end
82
+ end
83
+
84
+ # Opens a new EditTab with a FileMirror for the given path.
85
+ #
86
+ # @path [String] path the path of the file to be edited
87
+ # @param [Window] win the Window to open the File in
88
+ def self.open_file_in_window(path, win)
89
+ tab = win.new_tab(Redcar::EditTab)
90
+ mirror = FileMirror.new(path)
91
+ tab.edit_view.document.mirror = mirror
92
+ tab.edit_view.reset_undo
93
+ tab.focus
94
+ end
95
+
96
+ def self.find_projects_containing_path(path)
97
+ open_projects.select {|project| project.contains_path?(path) }
98
+ end
99
+
100
+ def self.open_file(path)
101
+ if tab = find_open_file_tab(path)
102
+ tab.focus
103
+ return
104
+ end
105
+ if project = find_projects_containing_path(path).first
106
+ window = project.window
107
+ else
108
+ window = windows_without_projects.first || Redcar.app.new_window
109
+ end
110
+ open_file_in_window(path, window)
111
+ window.focus
112
+ end
113
+
114
+ # Opens a new Tree with a DirMirror and DirController for the given
115
+ # path, in a new window.
116
+ #
117
+ # @param [String] path the path of the directory to view
118
+ def self.open_project_for_path(path)
119
+ win = Redcar.app.new_window
120
+ project = Project.new(path)
121
+ project.open(win)
122
+ project
123
+ end
124
+
125
+ # The currently focussed Project, or nil if none.
126
+ #
127
+ # @return [Project]
128
+ def self.focussed_project
129
+ in_window(Redcar.app.focussed_window)
130
+ end
131
+
132
+ # saves away a list of the currently open files in
133
+ # @param [win]
134
+ def self.save_file_list(win)
135
+ # create a list of open files
136
+ file_list = []
137
+ win.notebooks[0].tabs.each do |tab|
138
+ if tab.document && tab.document.path
139
+ file_list << tab.document.path
140
+ end
141
+ end
142
+ storage['files_open_last_session'] = file_list
143
+ end
144
+
145
+ # handles files and/or dirs passed as command line arguments
146
+ def self.handle_startup_arguments(args)
147
+ found_path_args = false
148
+ args.each do |arg|
149
+ if File.directory?(arg)
150
+ found_path_args = true
151
+ DirectoryOpenCommand.new(arg).run
152
+ elsif File.file?(arg)
153
+ found_path_args = true
154
+ open_file(arg)
155
+ end
156
+ end
157
+ found_path_args
158
+ end
159
+
160
+ # Attaches a new listener to tab focus change events, so we can
161
+ # keep the current_files list.
162
+ def self.init_current_files_hooks
163
+ Redcar.app.add_listener(:tab_focussed) do |tab|
164
+ if tab and tab.document_mirror.respond_to?(:path)
165
+ if project = Manager.in_window(tab.notebook.window)
166
+ project.add_to_recent_files(tab.document_mirror.path)
167
+ end
168
+ end
169
+ end
170
+ attach_app_listeners
171
+ end
172
+
173
+ def self.attach_app_listeners
174
+ Redcar.app.add_listener(:lost_focus) do
175
+ Manager.open_projects.each {|project| project.lost_application_focus }
176
+ end
177
+
178
+ Redcar.app.add_listener(:window_focussed) do |win|
179
+ Manager.in_window(win).andand.gained_focus
180
+ end
181
+ end
182
+
183
+ # restores the directory/files in the last open window
184
+ def self.restore_last_session
185
+ if path = storage['last_open_dir']
186
+ s = Time.now
187
+ open_project_for_path(path)
188
+ puts "open project took #{Time.now - s}s"
189
+ end
190
+
191
+ if files = storage['files_open_last_session']
192
+ files.each do |path|
193
+ open_file(path)
194
+ end
195
+ end
196
+ end
197
+
198
+ def self.refresh_modified_file(path)
199
+ path = File.expand_path(path)
200
+ find_projects_containing_path(path).each do |project|
201
+ project.refresh_modified_file(path)
202
+ end
203
+ end
204
+
205
+ class << self
206
+ attr_reader :open_project_sensitivity
207
+ end
208
+ end
209
+ end
210
+ end
@@ -17,8 +17,16 @@ module Redcar
17
17
  def self.generate_menu(builder)
18
18
  directories = storage['list']
19
19
  directories.each do |dir|
20
- builder.item(File.basename(dir)) do
21
- Project.open_dir(dir)
20
+ if File.directory?(File.expand_path(dir))
21
+ builder.item(File.basename(dir)) do
22
+ if File.directory?(File.expand_path(dir))
23
+ Project::Manager.open_project_for_path(dir)
24
+ else
25
+ remove_path(dir)
26
+ end
27
+ end
28
+ else
29
+ remove_path(dir)
22
30
  end
23
31
  end
24
32
  end
@@ -34,7 +42,12 @@ module Redcar
34
42
  storage["list"].pop
35
43
  end
36
44
  storage.save
37
- Redcar.app.refresh_menu!
45
+ end
46
+
47
+ def self.remove_path(path)
48
+ path = File.expand_path(path)
49
+ storage["list"].delete(path)
50
+ storage.save
38
51
  end
39
52
  end
40
53
  end
@@ -3,6 +3,6 @@ Plugin.define do
3
3
  name "project"
4
4
  version "1.0"
5
5
  file "lib", "project"
6
- object "Redcar::Project"
6
+ object "Redcar::Project::Manager"
7
7
  dependencies "edit_view", ">0"
8
8
  end
@@ -0,0 +1,2 @@
1
+
2
+ This is an example Ruby project.
@@ -27,7 +27,7 @@ class Redcar::Project
27
27
  it "the nodes are the contents of the directory" do
28
28
  top_nodes = @mirror.top
29
29
  top_nodes.length.should == 3
30
- top_nodes.map {|n| n.text}.should == %w(Carnegie Rockefeller subdir)
30
+ top_nodes.map {|n| n.text}.should == %w(subdir Carnegie Rockefeller)
31
31
  end
32
32
 
33
33
  it "files are leaf nodes" do
@@ -61,16 +61,5 @@ class Redcar::Project
61
61
  FileUtils.rm_r(@dirname)
62
62
  end
63
63
 
64
- def write_dir_contents(dirname, files)
65
- FileUtils.mkdir_p(dirname)
66
- files.each do |filename, contents|
67
- if contents.is_a?(Hash)
68
- write_dir_contents(dirname + "/" + filename, contents)
69
- else
70
- File.open(dirname + "/" + filename, "w") {|f| f.print contents}
71
- end
72
- end
73
- end
74
-
75
64
  end
76
65
  end
@@ -0,0 +1,140 @@
1
+
2
+ require File.join(File.dirname(__FILE__), *%w".. spec_helper")
3
+
4
+ FileList = Redcar::Project::FileList
5
+
6
+ describe FileList do
7
+ def fixture_path
8
+ File.expand_path(File.join(File.dirname(__FILE__), *%w".. fixtures myproject"))
9
+ end
10
+
11
+ def relative_path(*path)
12
+ File.join(fixture_path, *path)
13
+ end
14
+
15
+ before do
16
+ @file_list = FileList.new(fixture_path)
17
+ FileUtils.rm_f(relative_path("tags"))
18
+ end
19
+
20
+ it "should return an empty list initially" do
21
+ @file_list.all_files.should be_empty
22
+ end
23
+
24
+ describe "file list" do
25
+ before do
26
+ @file_list.update
27
+ end
28
+
29
+ it "should return a list of files in the directory" do
30
+ @file_list.all_files.include?(relative_path("README")).should be_true
31
+ @file_list.all_files.include?(relative_path("lib", "foo_lib.rb")).should be_true
32
+ @file_list.all_files.length.should == 3
33
+ end
34
+ end
35
+
36
+ describe "update information" do
37
+ before do
38
+ @dirname = "project_spec_testdir"
39
+ @files = {"Carnegie" => "steel",
40
+ "Rockefeller" => "oil",
41
+ "subdir" => {
42
+ "Ford" => "cars"
43
+ }}
44
+ write_dir_contents(@dirname, @files)
45
+ @file_list = FileList.new(@dirname)
46
+ @file_list.update
47
+ end
48
+
49
+ after do
50
+ FileUtils.rm_r(@dirname)
51
+ end
52
+
53
+ describe "after files have been added" do
54
+ before do
55
+ @time = Time.now
56
+ write_file(@dirname, "Branson", "balloons")
57
+ @file_name = File.expand_path(File.join(@dirname, "Branson"))
58
+ end
59
+
60
+ describe "on general update" do
61
+ it "should add the file to the list" do
62
+ @file_list.update
63
+ @file_list.all_files.include?(@file_name).should be_true
64
+ end
65
+
66
+ it "should be changed_since" do
67
+ @file_list.update
68
+ @file_list.changed_since(@time).keys.include?(@file_name).should be_true
69
+ end
70
+ end
71
+
72
+ describe "on specific update" do
73
+ it "should add the file to the list" do
74
+ @file_list.update(@file_name)
75
+ @file_list.all_files.include?(@file_name).should be_true
76
+ end
77
+
78
+ it "should not add other new files to the list" do
79
+ write_file(@dirname, "Kurzweil", "theories")
80
+ file_name2 = File.expand_path(File.join(@dirname, "Kurzweil"))
81
+
82
+ @file_list.update(@file_name)
83
+ @file_list.all_files.include?(@file_name).should be_true
84
+ @file_list.all_files.include?(file_name2).should be_false
85
+ end
86
+
87
+ it "should not remove files that are already there" do
88
+ write_file(@dirname, "Kurzweil", "theories")
89
+ file_name2 = File.expand_path(File.join(@dirname, "Kurzweil"))
90
+
91
+ @file_list.update(file_name2)
92
+ @file_list.all_files.include?(file_name2).should be_true
93
+ @file_list.all_files.include?(File.expand_path(File.join(@dirname, "Carnegie"))).should be_true
94
+ end
95
+ end
96
+ end
97
+
98
+ describe "after files have been modified" do
99
+ before do
100
+ @time = Time.now
101
+ sleep 1
102
+ write_file(@dirname, "Carnegie", "peace")
103
+ @file_name = File.expand_path(File.join(@dirname, "Carnegie"))
104
+ end
105
+
106
+
107
+ it "should still be in the file list" do
108
+ @file_list.update
109
+ @file_list.all_files.include?(@file_name).should be_true
110
+ end
111
+
112
+ it "should be changed since" do
113
+ @file_list.update
114
+ @file_list.changed_since(@time).keys.include?(@file_name).should be_true
115
+ end
116
+ end
117
+
118
+ describe "after files have been deleted" do
119
+ before do
120
+ remove_file(@dirname, "Rockefeller")
121
+ @file_name = File.expand_path(File.join(@dirname, "Rockefeller"))
122
+ end
123
+
124
+ it "should not be in the file list" do
125
+ @file_list.update
126
+ @file_list.all_files.include?(@file_name).should be_false
127
+ end
128
+ end
129
+ end
130
+ end
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
+
@@ -1,4 +1,24 @@
1
1
  $:.push File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')
2
2
 
3
3
  require 'redcar'
4
+ Redcar.environment = :test
4
5
  Redcar.load
6
+
7
+ def write_dir_contents(dirname, files)
8
+ FileUtils.mkdir_p(dirname)
9
+ files.each do |filename, contents|
10
+ if contents.is_a?(Hash)
11
+ write_dir_contents(dirname + "/" + filename, contents)
12
+ else
13
+ File.open(dirname + "/" + filename, "w") {|f| f.print contents}
14
+ end
15
+ end
16
+ end
17
+
18
+ def write_file(dirname, file, content)
19
+ File.open(File.join(dirname, file), "w") {|f| f.puts content }
20
+ end
21
+
22
+ def remove_file(dirname, file)
23
+ FileUtils.rm_f(File.join(dirname, file))
24
+ end