ruber 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. data/CHANGES +42 -1
  2. data/lib/ruber/application/application.rb +25 -5
  3. data/lib/ruber/application/plugin.yaml +2 -10
  4. data/lib/ruber/component_manager.rb +2 -2
  5. data/lib/ruber/document_project.rb +5 -3
  6. data/lib/ruber/editor/document.rb +5 -4
  7. data/lib/ruber/editor/ktexteditor_wrapper.rb +1 -1
  8. data/lib/ruber/exception_widgets.rb +1 -1
  9. data/lib/ruber/main_window/main_window.rb +4 -3
  10. data/lib/ruber/main_window/main_window_actions.rb +2 -2
  11. data/lib/ruber/main_window/main_window_internal.rb +1 -1
  12. data/lib/ruber/output_widget.rb +17 -5
  13. data/lib/ruber/project.rb +34 -3
  14. data/lib/ruber/project_dir_scanner.rb +171 -0
  15. data/lib/ruber/settings_container.rb +7 -7
  16. data/lib/ruber/settings_dialog.rb +24 -24
  17. data/lib/ruber/version.rb +1 -1
  18. data/lib/ruber/world/environment.rb +1 -0
  19. data/lib/ruber/world/plugin.yaml +7 -2
  20. data/lib/ruber/{application → world}/project_files_widget.rb +0 -0
  21. data/lib/ruber/{application → world}/ui/project_files_rule_chooser_widget.rb +2 -2
  22. data/lib/ruber/{application → world}/ui/project_files_rule_chooser_widget.ui +0 -0
  23. data/lib/ruber/{application → world}/ui/project_files_widget.rb +2 -2
  24. data/lib/ruber/{application → world}/ui/project_files_widget.ui +0 -0
  25. data/plugins/auto_end/auto_end.rb +21 -18
  26. data/plugins/autosave/autosave.rb +1 -1
  27. data/plugins/find_in_files/find_in_files.rb +1 -1
  28. data/plugins/irb/irb.png +0 -0
  29. data/plugins/irb/irb.rb +142 -0
  30. data/plugins/irb/irb.svg +240 -0
  31. data/plugins/irb/irb_controller.rb +541 -0
  32. data/plugins/irb/irbrc.rb +21 -0
  33. data/plugins/irb/plugin.yaml +19 -0
  34. data/plugins/irb/ui/irb_config_widget.rb +151 -0
  35. data/plugins/irb/ui/irb_config_widget.ui +123 -0
  36. data/plugins/irb/ui/irb_tool_widget.rb +97 -0
  37. data/plugins/irb/ui/irb_tool_widget.ui +86 -0
  38. data/plugins/project_browser/project_browser.rb +1 -1
  39. data/plugins/rspec/plugin.yaml +6 -3
  40. data/plugins/rspec/rspec.rb +172 -473
  41. data/plugins/rspec/tool_widget.rb +462 -0
  42. data/plugins/rspec/ui/rspec_project_widget.rb +58 -38
  43. data/plugins/rspec/ui/rspec_project_widget.ui +68 -64
  44. data/plugins/ruberri/class_formatter.rb +126 -0
  45. data/plugins/ruberri/method_formatter.rb +90 -0
  46. data/plugins/ruberri/plugin.yaml +13 -0
  47. data/plugins/ruberri/ruberri.rb +226 -0
  48. data/plugins/ruberri/search.rb +111 -0
  49. data/plugins/ruberri/ui/tool_widget.rb +73 -0
  50. data/plugins/ruberri/ui/tool_widget.ui +49 -0
  51. data/plugins/ruby_runner/ruby_runner.rb +2 -2
  52. data/plugins/ruby_syntax_checker/plugin.yaml +11 -0
  53. data/plugins/ruby_syntax_checker/ruby_syntax_checker.rb +147 -0
  54. data/plugins/syntax_checker/plugin.yaml +10 -6
  55. data/plugins/syntax_checker/syntax_checker.rb +216 -520
  56. data/plugins/syntax_checker/ui/config_widget.rb +61 -0
  57. data/plugins/syntax_checker/ui/config_widget.ui +44 -0
  58. data/plugins/yaml_syntax_checker/plugin.yaml +11 -0
  59. data/plugins/yaml_syntax_checker/yaml_syntax_checker.rb +62 -0
  60. data/ruber.desktop +0 -0
  61. data/spec/auto_end_spec.rb +224 -186
  62. data/spec/document_project_spec.rb +9 -1
  63. data/spec/document_spec.rb +9 -0
  64. data/spec/environment_spec.rb +12 -0
  65. data/spec/output_widget_spec.rb +69 -2
  66. data/spec/project_dir_scanner_spec.rb +195 -0
  67. data/spec/project_spec.rb +43 -73
  68. data/spec/ruby_syntax_checker_spec.rb +361 -0
  69. data/spec/syntax_checker_spec.rb +1132 -0
  70. data/spec/yaml_syntax_checker_spec.rb +130 -0
  71. metadata +232 -225
  72. data/lib/ruber/application/project_files_list.rb +0 -320
  73. data/spec/project_files_list_spec.rb +0 -411
@@ -240,7 +240,7 @@ describe Ruber::DocumentProject do
240
240
  prj = Ruber::DocumentProject.new doc
241
241
  prj.instance_variable_get(:@backend).should be_a(Ruber::DocumentProject::Backend)
242
242
  end
243
-
243
+
244
244
  context 'if the document is associated with a file' do
245
245
 
246
246
  before do
@@ -342,6 +342,14 @@ describe Ruber::DocumentProject do
342
342
  prj.match_rule?(o1).should be_false
343
343
  end
344
344
 
345
+ it 'considers documents not associated with a file as local files' do
346
+ doc = create_doc KDE::Url.new
347
+ prj = Ruber::DocumentProject.new doc
348
+ o1 = OS.new(:file_extension => [], :scope => [:document], :mimetype => [], :place => [:local])
349
+ flexmock(doc).should_receive(:file_type_match?).with([], []).and_return true
350
+ prj.match_rule?(o1).should be_true
351
+ end
352
+
345
353
  it 'returns true if both the mimetype and the file extension of the rule match those of the document and the rule\'s scope include :document' do
346
354
  doc = create_doc __FILE__
347
355
  prj = Ruber::DocumentProject.new doc
@@ -136,6 +136,15 @@ describe Ruber::Document do
136
136
  prj.project_name.should == KDE::Url.new(__FILE__).to_encoded.to_s
137
137
  end
138
138
 
139
+ it 'calls the finalize method of the the document project' do
140
+ mk = flexmock do |m|
141
+ m.should_ignore_missing
142
+ m.should_receive(:finalize).once
143
+ end
144
+ flexmock(Ruber::DocumentProject).should_receive(:new).and_return mk
145
+ Ruber::Document.new nil, @app
146
+ end
147
+
139
148
  it 'isn\'t active' do
140
149
  doc = Ruber::Document.new __FILE__, @app
141
150
  doc.should_not be_active
@@ -183,6 +183,18 @@ describe Ruber::World::Environment do
183
183
  env.views[0].document.text.should == ''
184
184
  env.views[0].document.object_name.should == 'default_document'
185
185
  end
186
+
187
+ it 'enables the close buttons on the tab bar if the workspace/close_buttons option is true' do
188
+ Ruber[:config][:workspace, :close_buttons] = true
189
+ env = Ruber::World::Environment.new nil
190
+ env.tab_widget.tabs_closable.should be_true
191
+ end
192
+
193
+ it 'doesn\'t enable the close buttons on the tab bar if the workspace/close_buttons option is false' do
194
+ Ruber[:config][:workspace, :close_buttons] = false
195
+ env = Ruber::World::Environment.new nil
196
+ env.tab_widget.tabs_closable.should be_false
197
+ end
186
198
 
187
199
  end
188
200
 
@@ -999,6 +999,24 @@ describe Ruber::OutputWidget do
999
999
  @ow.send :maybe_open_file, @mod.index(0,0)
1000
1000
  end
1001
1001
 
1002
+ it 'doesn\'t hide the tool widget if the user pressed the middle mouse button' do
1003
+ flexmock(Ruber::Application).should_receive(:mouse_buttons).and_return(Qt::MidButton)
1004
+ flexmock(@ow).should_receive(:pinned_down?).and_return false
1005
+ @mw.should_receive(:hide_tool).with(@ow).never
1006
+ @ow.send :maybe_open_file, @mod.index(0,0)
1007
+ end
1008
+
1009
+ it 'gives focus to the editor' do
1010
+ ed = flexmock{|m| m.should_receive(:set_focus).once}
1011
+ @mw.should_receive(:display_document).once.and_return(ed)
1012
+ @ow.send :maybe_open_file, @mod.index(0,0)
1013
+ end
1014
+
1015
+ it 'doesn\'t attempt to give focus to the editor if no editor is found' do
1016
+ @mw.should_receive(:display_document).once.and_return nil
1017
+ lambda{@ow.send :maybe_open_file, @mod.index(0,0)}.should_not raise_error
1018
+ end
1019
+
1002
1020
  it 'does nothing if the Control and/or Shift modifiers are pressed' do
1003
1021
  flexmock(@ow).should_receive(:find_filename_in_index).never
1004
1022
  flexmock(Ruber::Application).should_receive(:keyboard_modifiers).once.and_return(Qt::ShiftModifier.to_i)
@@ -1039,25 +1057,74 @@ describe Ruber::OutputWidget do
1039
1057
  before do
1040
1058
  @ow = Ruber::OutputWidget.new
1041
1059
  @cfg = flexmock{|m| m.should_ignore_missing}
1060
+ @world = flexmock{|m| m.should_ignore_missing}
1061
+ flexmock(Ruber).should_receive(:[]).with(:main_window).and_return(@mw).by_default
1042
1062
  flexmock(Ruber).should_receive(:[]).with(:config).and_return(@cfg).by_default
1063
+ flexmock(Ruber).should_receive(:[]).with(:world).and_return(@world).by_default
1043
1064
  end
1044
1065
 
1045
1066
  context 'when the general/tool_open_files setting is :split_horizontally' do
1046
1067
 
1068
+ before do
1069
+ @cfg.should_receive(:[]).with(:general, :tool_open_files).and_return(:split_horizontally).by_default
1070
+ end
1071
+
1047
1072
  it 'returns {:new => :current_tab, :split => :horizontal}' do
1048
- @cfg.should_receive(:[]).with(:general, :tool_open_files).and_return(:split_horizontally)
1049
1073
  @ow.send(:hints).should == {:new => :current_tab, :split => :horizontal}
1050
1074
  end
1051
1075
 
1076
+ it 'returns {:new => :new_tab} if there is more than one view in the current tab' do
1077
+ views = Array.new(2){|i| flexmock("view #{i}")}
1078
+ tab = flexmock{|m| m.should_receive(:views).and_return views}
1079
+ env = flexmock do |m|
1080
+ m.should_receive(:tab).with(views[1]).and_return tab
1081
+ m.should_receive(:active_editor).once.and_return views[1]
1082
+ end
1083
+ @world.should_receive(:active_environment).once.and_return env
1084
+ @ow.send(:hints).should == {:new => :new_tab}
1085
+ end
1086
+
1087
+ it 'returns {:new => :new_tab} if there are no tabs' do
1088
+ env = flexmock do |m|
1089
+ m.should_receive(:tab).and_return nil
1090
+ m.should_receive(:active_editor).and_return nil
1091
+ end
1092
+ @world.should_receive(:active_environment).once.and_return env
1093
+ @ow.send(:hints).should == {:new => :new_tab}
1094
+ end
1095
+
1052
1096
  end
1053
1097
 
1054
1098
  context 'when the general/tool_open_files setting is :split_vertically' do
1055
1099
 
1100
+ before do
1101
+ @cfg.should_receive(:[]).with(:general, :tool_open_files).and_return(:split_vertically).by_default
1102
+ end
1103
+
1056
1104
  it 'returns {:new => :current_tab, :split => :vertical}' do
1057
- @cfg.should_receive(:[]).with(:general, :tool_open_files).and_return(:split_vertically)
1058
1105
  @ow.send(:hints).should == {:new => :current_tab, :split => :vertical}
1059
1106
  end
1060
1107
 
1108
+ it 'returns {:new => :new_tab} if there is more than one view in the current tab' do
1109
+ views = Array.new(2){|i| flexmock("view #{i}")}
1110
+ tab = flexmock{|m| m.should_receive(:views).and_return views}
1111
+ env = flexmock do |m|
1112
+ m.should_receive(:tab).with(views[1]).and_return tab
1113
+ m.should_receive(:active_editor).once.and_return views[1]
1114
+ end
1115
+ @world.should_receive(:active_environment).once.and_return env
1116
+ @ow.send(:hints).should == {:new => :new_tab}
1117
+ end
1118
+
1119
+ it 'returns {:new => :new_tab} if there are no tabs' do
1120
+ env = flexmock do |m|
1121
+ m.should_receive(:tab).and_return nil
1122
+ m.should_receive(:active_editor).and_return nil
1123
+ end
1124
+ @world.should_receive(:active_environment).once.and_return env
1125
+ @ow.send(:hints).should == {:new => :new_tab}
1126
+ end
1127
+
1061
1128
  end
1062
1129
 
1063
1130
  context 'when the general/tool_open_files setting is :new_tab' do
@@ -0,0 +1,195 @@
1
+ require 'spec/framework'
2
+ require 'spec/common'
3
+
4
+ require 'tempfile'
5
+ require 'fileutils'
6
+ require 'set'
7
+
8
+ require 'lib/ruber/project_dir_scanner'
9
+
10
+ describe Ruber::ProjectDirScanner do
11
+
12
+ before do
13
+ @dir = File.join Dir.tmpdir, random_string(10)
14
+ FileUtils.mkdir @dir
15
+ @prj = Ruber::Project.new File.join(@dir, 'xyz.ruprj'), 'XYZ'
16
+ @scanner = Ruber::ProjectDirScanner.new @prj
17
+ end
18
+
19
+ after do
20
+ FileUtils.rm_rf @dir
21
+ end
22
+
23
+ it 'derives from Qt::Object' do
24
+ Ruber::ProjectDirScanner.ancestors.should include(Qt::Object)
25
+ end
26
+
27
+ context 'when created' do
28
+ it 'takes a Ruber::Project as argument' do
29
+ lambda{Ruber::ProjectDirScanner.new(@prj)}.should_not raise_error
30
+ end
31
+ end
32
+
33
+ context 'whenever the general/project_files project setting changes' do
34
+
35
+ it 'updates its rules' do
36
+ @scanner.file_in_project?('abc').should be_false
37
+ @prj[:general, :project_files] = {:include => ['abc'], :exclude => [], :extensions => ['*.rb']}
38
+ @scanner.file_in_project?('abc').should be_true
39
+ end
40
+
41
+ it 'emits the :rules_changed signal' do
42
+ mk = flexmock{|m| m.should_receive(:rules_changed).once}
43
+ @scanner.connect(SIGNAL(:rules_changed)){mk.rules_changed}
44
+ @prj[:general, :project_files] = {:include => ['abc'], :exclude => [], :extensions => ['*.rb']}
45
+ end
46
+
47
+ end
48
+
49
+ describe '#file_in_project?' do
50
+
51
+ it 'returns true if the argument matches one of the exact include rules' do
52
+ @prj[:general, :project_files] = {:include => %w[./xyz ./abc ./123], :exclude => [], :extensions => ['*.rb']}
53
+ @scanner.file_in_project?(File.join(@prj.project_dir, 'abc')).should be_true
54
+ end
55
+
56
+ it 'returns true if the argument matches one of the regexp include rules' do
57
+ @prj[:general, :project_files] = {:include => [/a/, /x/], :exclude => [], :extensions => ['*.rb']}
58
+ @scanner.file_in_project?(File.join(@prj.project_dir, 'xyz')).should be_true
59
+ end
60
+
61
+ it 'returns true if the argument matches one of the include extensions' do
62
+ @prj[:general, :project_files] = {:include => [], :exclude => [], :extensions => ['*.rb', '*.yaml']}
63
+ @scanner.file_in_project?(File.join(@prj.project_dir, 'abc.rb')).should be_true
64
+ end
65
+
66
+ it 'returns false if the file isn\'t in the project directory' do
67
+ @prj[:general, :project_files] = {:include => %w[xyz abc 123], :exclude => [], :extensions => ['*.rb']}
68
+ @scanner.file_in_project?('/usr/abc').should be_false
69
+ end
70
+
71
+ it 'treats the argument as a path relative to the project directory if it isn\'t an absolute path' do
72
+ @prj[:general, :project_files] = {:include => %w[xyz abc 123], :exclude => [], :extensions => ['*.rb']}
73
+ @scanner.file_in_project?('abc').should be_true
74
+ end
75
+
76
+ it 'returns false if the file doesn\'t match any include rule' do
77
+ @scanner.file_in_project?(File.join(@prj.project_dir, 'abc.xyz')).should be_false
78
+ end
79
+
80
+ it 'returns false if the file matches one of the file exclude rules' do
81
+ @prj[:general, :project_files] = {:include => %w[xyz abc 123], :exclude => ['abc', 'AbC.rb'], :extensions => ['*.rb']}
82
+ @scanner.file_in_project?(File.join(@prj.project_dir, 'abc')).should be_false
83
+ @scanner.file_in_project?(File.join(@prj.project_dir, 'AbC.rb')).should be_false
84
+ end
85
+
86
+ it 'returns false if the file matches one of the exclude regexps' do
87
+ @prj[:general, :project_files] = {:include => [/a/], :exclude => [/a/], :extensions => []}
88
+ @scanner.file_in_project?(File.join(@prj.project_dir, 'abc')).should be_false
89
+ end
90
+
91
+ it 'it considers the whole path of the file, not just the filename' do
92
+ @prj[:general, :project_files] = {:include => [%r{a/.*}], :exclude => [%r{b/.*}], :extensions => ['*.rb']}
93
+ @scanner.file_in_project?(File.join(@prj.project_dir, 'a', 'xyz')).should be_true
94
+ @scanner.file_in_project?(File.join(@prj.project_dir, 'b', 'xyz.rb')).should be_false
95
+ end
96
+
97
+ it 'returns nil if the file name ends with a slash' do
98
+ @prj[:general, :project_files] = {:include => [%r{a/.*}], :exclude => [%r{b/.*}], :extensions => ['*.rb']}
99
+ @scanner.file_in_project?('xyz/').should be_nil
100
+ end
101
+
102
+ it 'returns false if the path represents a remote URL' do
103
+ @prj[:general, :project_files] = {:include => [], :exclude => [], :extensions => ['*.rb']}
104
+ @scanner.file_in_project?("http://#{@dir}/abc.xyz.rb").should be_false
105
+ end
106
+
107
+ it 'works normally if the path represents a local url' do
108
+ @prj[:general, :project_files] = {:include => [], :exclude => [], :extensions => ['*.rb']}
109
+ @scanner.file_in_project?("file://#{@dir}/abc.xyz.rb").should be_true
110
+ end
111
+
112
+ end
113
+
114
+ describe '#project_files' do
115
+
116
+ it 'returns a set of all the files belonging to the project' do
117
+ tree = ['f1.rb', 'f2.rb', ['d1', 'f3.rb', 'f4.rb', 'f5.rb'], 'f6', 'f7.xyz']
118
+ base = make_dir_tree tree, @dir
119
+ base.sub! %r{^#{@dir}/?}, ''
120
+ @prj[:general, :project_files] = {:include => [File.join(base, 'f7.xyz')], :exclude => [File.join(base, 'f2.rb'), File.join(base, 'd1/f4.rb')], :extensions => ['*.rb']}
121
+ res = @scanner.project_files
122
+ res.should be_a Set
123
+ exp = Set.new(%w[f1.rb d1/f3.rb d1/f5.rb f7.xyz].map{|f| File.join @dir, base, f})
124
+ res.should == exp
125
+ end
126
+
127
+ end
128
+
129
+ context 'when a new file is created in the project directory' do
130
+
131
+ #Testing this correctly would need an event loop running, which we can't have
132
+ #inside tests. So we have to manually have the dir watcher emit signals
133
+
134
+ before do
135
+ @prj[:general, :project_files] = {:include => [], :exclude => [], :extensions => ['*.rb']}
136
+ end
137
+
138
+ context 'and the file belongs to the project' do
139
+
140
+ it 'emits the file_added signal passing the absolute name of the file' do
141
+ file = File.join @dir, 'test.rb'
142
+ mk = flexmock{|m| m.should_receive(:file_added).once.with File.join(@dir, 'test.rb')}
143
+ @scanner.connect(SIGNAL('file_added(QString)')){|f| mk.file_added f}
144
+ @scanner.instance_variable_get(:@watcher).instance_eval{emit created(file)}
145
+ end
146
+
147
+ end
148
+
149
+ context 'and the file doesn\'t belong to the project' do
150
+
151
+ it 'does nothing' do
152
+ file = File.join @dir, 'test.xyz'
153
+ mk = flexmock{|m| m.should_receive(:file_added).never}
154
+ @scanner.connect(SIGNAL('file_added(QString)')){|f| mk.file_added f}
155
+ @scanner.instance_variable_get(:@watcher).instance_eval{emit created(file)}
156
+ end
157
+
158
+ end
159
+
160
+ end
161
+
162
+ context 'when a new file is removed from the project directory' do
163
+
164
+ #Testing this correctly would need an event loop running, which we can't have
165
+ #inside tests. So we have to manually have the dir watcher emit signals
166
+
167
+ before do
168
+ @prj[:general, :project_files] = {:include => [], :exclude => [], :extensions => ['*.rb']}
169
+ end
170
+
171
+ context 'and the file used to belong to the project' do
172
+
173
+ it 'emits the file_removed signal passing the absolute name of the file' do
174
+ file = File.join @dir, 'test.rb'
175
+ mk = flexmock{|m| m.should_receive(:file_removed).once.with File.join(@dir, 'test.rb')}
176
+ @scanner.connect(SIGNAL('file_removed(QString)')){|f| mk.file_removed f}
177
+ @scanner.instance_variable_get(:@watcher).instance_eval{emit deleted(file)}
178
+ end
179
+
180
+ end
181
+
182
+ context 'and the file doesn\'t belong to the project' do
183
+
184
+ it 'does nothing' do
185
+ file = File.join @dir, 'test.xyz'
186
+ mk = flexmock{|m| m.should_receive(:file_removed).never}
187
+ @scanner.connect(SIGNAL('file_removed(QString)')){|f| mk.file_removed f}
188
+ @scanner.instance_variable_get(:@watcher).instance_eval{emit deleted(file)}
189
+ end
190
+
191
+ end
192
+
193
+ end
194
+
195
+ end
@@ -8,6 +8,7 @@ require 'pathname'
8
8
  require 'ostruct'
9
9
  require 'forwardable'
10
10
  require 'dictionary'
11
+ require 'fileutils'
11
12
 
12
13
  require 'ruber/project'
13
14
  require 'ruber/plugin'
@@ -73,7 +74,7 @@ describe 'Ruber::AbstractProject, when created' do
73
74
  contents = <<-EOS
74
75
  :general:
75
76
  :project_name: Test
76
- EOS
77
+ EOS
77
78
  @dir = make_dir_tree ['f1.ruprj'], '/tmp', {'f1.ruprj'=>contents}
78
79
  @file = File.join @dir, 'f1.ruprj'
79
80
  end
@@ -276,7 +277,7 @@ describe 'Ruber::AbstractProject#[]=' do
276
277
  :g2:
277
278
  :o2: xyz
278
279
  :o3: [a, b]
279
- EOS
280
+ EOS
280
281
  @dir = make_dir_tree ['test.ruprj'], '/tmp', {'test.ruprj' => contents}
281
282
  @file = File.join @dir, 'test.ruprj'
282
283
  @options = [
@@ -695,15 +696,6 @@ describe Ruber::Project do
695
696
  describe 'when created' do
696
697
 
697
698
  before do
698
- @comp = TestComponentManager.new
699
- @projects = Qt::Object.new
700
- @fake_app = Application.new
701
- @dlg = flexmock('dialog', :read_settings => nil, :dispose => nil)
702
- @mw = Qt::Widget.new
703
- flexmock(Ruber).should_receive(:[]).with(:components).and_return( @comp).by_default
704
- flexmock(Ruber).should_receive(:[]).with(:app).and_return( @fake_app).by_default
705
- flexmock(Ruber).should_receive(:[]).with(:main_window).and_return( @mw).by_default
706
- flexmock(Ruber).should_receive(:[]).with(:projects).and_return( @projects).by_default
707
699
  @file = File.join Dir.pwd, 'test.ruprj'
708
700
  @dir = nil
709
701
  end
@@ -712,9 +704,9 @@ describe Ruber::Project do
712
704
  FileUtils.rm_rf @dir if @dir
713
705
  end
714
706
 
715
- it 'uses the projects component as parent' do
707
+ it 'uses the world component as parent' do
716
708
  prj = Ruber::Project.new @file, 'Test'
717
- prj.parent.should equal(@projects)
709
+ prj.parent.should equal(Ruber[:world])
718
710
  end
719
711
 
720
712
  it 'uses Ruber::ProjectBackend as backend' do
@@ -741,15 +733,6 @@ describe Ruber::Project do
741
733
  describe ', when closing' do
742
734
 
743
735
  before do
744
- @comp = TestComponentManager.new
745
- @fake_app = Application.new
746
- @dlg = flexmock('dialog', :read_settings => nil, :dispose => nil)
747
- @mw = Qt::Widget.new
748
- @projects = Qt::Object.new
749
- flexmock(Ruber).should_receive(:[]).with(:components).and_return( @comp).by_default
750
- flexmock(Ruber).should_receive(:[]).with(:app).and_return( @fake_app).by_default
751
- flexmock(Ruber).should_receive(:[]).with(:main_window).and_return( @mw).by_default
752
- flexmock(Ruber).should_receive(:[]).with(:projects).and_return( @projects).by_default
753
736
  @file = File.join Dir.pwd, 'test.ruprj'
754
737
  end
755
738
 
@@ -797,15 +780,6 @@ describe Ruber::Project do
797
780
  describe '#activate' do
798
781
 
799
782
  before do
800
- @comp = TestComponentManager.new
801
- @fake_app = Application.new
802
- @dlg = flexmock('dialog', :read_settings => nil, :dispose => nil)
803
- @mw = Qt::Widget.new
804
- @projects = Qt::Object.new
805
- flexmock(Ruber).should_receive(:[]).with(:components).and_return( @comp).by_default
806
- flexmock(Ruber).should_receive(:[]).with(:app).and_return( @fake_app).by_default
807
- flexmock(Ruber).should_receive(:[]).with(:main_window).and_return( @mw).by_default
808
- flexmock(Ruber).should_receive(:[]).with(:projects).and_return( @projects).by_default
809
783
  @file = File.join Dir.pwd, 'test.ruprj'
810
784
  end
811
785
 
@@ -835,15 +809,6 @@ describe Ruber::Project do
835
809
  describe '#deactivate' do
836
810
 
837
811
  before do
838
- @comp = TestComponentManager.new
839
- @fake_app = Application.new
840
- @dlg = flexmock('dialog', :read_settings => nil, :dispose => nil)
841
- @mw = Qt::Widget.new
842
- @projects = Qt::Object.new
843
- flexmock(Ruber).should_receive(:[]).with(:components).and_return( @comp).by_default
844
- flexmock(Ruber).should_receive(:[]).with(:app).and_return( @fake_app).by_default
845
- flexmock(Ruber).should_receive(:[]).with(:main_window).and_return( @mw).by_default
846
- flexmock(Ruber).should_receive(:[]).with(:projects).and_return( @projects).by_default
847
812
  @file = File.join Dir.pwd, 'test.ruprj'
848
813
  end
849
814
 
@@ -872,16 +837,8 @@ describe Ruber::Project do
872
837
  end
873
838
 
874
839
  describe '#scope' do
840
+
875
841
  before do
876
- @comp = TestComponentManager.new
877
- @fake_app = Application.new
878
- @dlg = flexmock('dialog', :read_settings => nil, :dispose => nil)
879
- @mw = Qt::Widget.new
880
- @projects = Qt::Object.new
881
- flexmock(Ruber).should_receive(:[]).with(:components).and_return( @comp).by_default
882
- flexmock(Ruber).should_receive(:[]).with(:app).and_return( @fake_app).by_default
883
- flexmock(Ruber).should_receive(:[]).with(:main_window).and_return( @mw).by_default
884
- flexmock(Ruber).should_receive(:[]).with(:projects).and_return( @projects).by_default
885
842
  @file = File.join Dir.pwd, 'test.ruprj'
886
843
  end
887
844
 
@@ -893,15 +850,6 @@ describe Ruber::Project do
893
850
  describe '#add_option' do
894
851
 
895
852
  before do
896
- @comp = TestComponentManager.new
897
- @fake_app = Application.new
898
- @dlg = flexmock('dialog', :read_settings => nil, :dispose => nil)
899
- @mw = Qt::Widget.new
900
- @projects = Qt::Object.new
901
- flexmock(Ruber).should_receive(:[]).with(:components).and_return( @comp).by_default
902
- flexmock(Ruber).should_receive(:[]).with(:app).and_return( @fake_app).by_default
903
- flexmock(Ruber).should_receive(:[]).with(:main_window).and_return( @mw).by_default
904
- flexmock(Ruber).should_receive(:[]).with(:projects).and_return( @projects).by_default
905
853
  @file = File.join Dir.pwd, 'test.ruprj'
906
854
  @prj = Ruber::Project.new(@file, 'Test')
907
855
  end
@@ -926,24 +874,46 @@ describe Ruber::Project do
926
874
  describe '#files' do
927
875
 
928
876
  before do
929
- @comp = TestComponentManager.new
930
- @fake_app = Application.new
931
- @dlg = flexmock('dialog', :read_settings => nil, :dispose => nil)
932
- @mw = Qt::Widget.new
933
- @projects = Qt::Object.new
934
- flexmock(Ruber).should_receive(:[]).with(:components).and_return( @comp).by_default
935
- flexmock(Ruber).should_receive(:[]).with(:app).and_return( @fake_app).by_default
936
- flexmock(Ruber).should_receive(:[]).with(:main_window).and_return( @mw).by_default
937
- flexmock(Ruber).should_receive(:[]).with(:projects).and_return( @projects).by_default
938
- @file = File.join Dir.pwd, 'test.ruprj'
877
+ @dir = make_dir_tree %w[f1.rb f2.rb f3.rb f4.xyz f5.xyz f6.xyz]
878
+ @file = File.join @dir, 'test.ruprj'
939
879
  @prj = Ruber::Project.new(@file, 'Test')
880
+ @prj[:general, :project_files] = {:extensions => ['*.rb'], :include => [], :exclude => []}
881
+ end
882
+
883
+ after do
884
+ FileUtils.rm_rf @dir
885
+ end
886
+
887
+ it 'returns a ProjectFiles object containing all the files in the project' do
888
+ res = @prj.files
889
+ res.should be_a(Ruber::ProjectFiles)
890
+ exp = Dir.entries(@dir).select{|f| f.end_with?('.rb')}.map{|f| File.join @dir, f}
891
+ res.should == Set.new(exp)
892
+ end
893
+
894
+ it 'takes into account files added after previous calls to this method' do
895
+ @prj.files
896
+ file = File.join @dir, 'f8.rb'
897
+ `touch #{file}`
898
+ @prj.instance_variable_get(:@dir_scanner).instance_eval{emit file_added(file)}
899
+ exp = exp = Dir.entries(@dir).select{|f| f.end_with?('.rb')}.map{|f| File.join @dir, f}
900
+ @prj.files.should == Set.new(exp)
901
+ end
902
+
903
+ it 'takes into account files removed after previous calls to this method' do
904
+ @prj.files
905
+ file = File.join @dir, 'f1.rb'
906
+ `rm #{file}`
907
+ @prj.instance_variable_get(:@dir_scanner).instance_eval{emit file_removed(file)}
908
+ exp = exp = Dir.entries(@dir).select{|f| f.end_with?('.rb')}.map{|f| File.join @dir, f}
909
+ @prj.files.should == Set.new(exp)
940
910
  end
941
911
 
942
- it 'returns an array containing the files belonging to the project' do
943
- files = %w[/a /b /c]
944
- project_files = flexmock{|m| m.should_receive(:project_files).once.and_return files}
945
- @prj.instance_variable_get(:@project_extensions)[:project_files] = project_files
946
- @prj.files.should == %w[/a /b /c]
912
+ it 'takes into account rule changes after previous calls to this method' do
913
+ @prj.files
914
+ @prj[:general, :project_files] = {:extensions => ['*.xyz'], :include => [], :exclude => []}
915
+ exp = exp = Dir.entries(@dir).select{|f| f.end_with?('.xyz')}.map{|f| File.join @dir, f}
916
+ @prj.files.should == Set.new(exp)
947
917
  end
948
918
 
949
919
  end