ruber 0.0.1.1
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.
- data/COPYING +339 -0
- data/INSTALL +137 -0
- data/LICENSE +8 -0
- data/bin/ruber +65 -0
- data/data/share/apps/ruber/core_components.yaml +31 -0
- data/data/share/apps/ruber/ruberui.rc +109 -0
- data/data/share/icons/ruber.png +0 -0
- data/data/share/pixmaps/ruby.png +0 -0
- data/icons/ruber-16.png +0 -0
- data/icons/ruber-32.png +0 -0
- data/icons/ruber-48.png +0 -0
- data/icons/ruber-8.png +0 -0
- data/lib/ruber/application/application.rb +288 -0
- data/lib/ruber/application/plugin.yaml +11 -0
- data/lib/ruber/component_manager.rb +899 -0
- data/lib/ruber/config/config.rb +82 -0
- data/lib/ruber/config/plugin.yaml +3 -0
- data/lib/ruber/document_project.rb +209 -0
- data/lib/ruber/documents/document_list.rb +416 -0
- data/lib/ruber/documents/plugin.yaml +4 -0
- data/lib/ruber/editor/document.rb +506 -0
- data/lib/ruber/editor/editor_view.rb +167 -0
- data/lib/ruber/editor/ktexteditor_wrapper.rb +202 -0
- data/lib/ruber/exception_widgets.rb +245 -0
- data/lib/ruber/external_program_plugin.rb +397 -0
- data/lib/ruber/filtered_output_widget.rb +342 -0
- data/lib/ruber/gui_states_handler.rb +231 -0
- data/lib/ruber/kde_config_option_backend.rb +167 -0
- data/lib/ruber/kde_sugar.rb +249 -0
- data/lib/ruber/main_window/choose_plugins_dlg.rb +353 -0
- data/lib/ruber/main_window/main_window.rb +524 -0
- data/lib/ruber/main_window/main_window_actions.rb +537 -0
- data/lib/ruber/main_window/main_window_internal.rb +239 -0
- data/lib/ruber/main_window/open_file_in_project_dlg.rb +212 -0
- data/lib/ruber/main_window/output_color_widget.rb +35 -0
- data/lib/ruber/main_window/plugin.yaml +58 -0
- data/lib/ruber/main_window/save_modified_files_dlg.rb +89 -0
- data/lib/ruber/main_window/status_bar.rb +156 -0
- data/lib/ruber/main_window/ui/choose_plugins_widget.rb +90 -0
- data/lib/ruber/main_window/ui/choose_plugins_widget.ui +77 -0
- data/lib/ruber/main_window/ui/main_window_settings_widget.rb +108 -0
- data/lib/ruber/main_window/ui/main_window_settings_widget.ui +89 -0
- data/lib/ruber/main_window/ui/new_project_widget.rb +119 -0
- data/lib/ruber/main_window/ui/new_project_widget.ui +178 -0
- data/lib/ruber/main_window/ui/open_file_in_project_dlg.rb +109 -0
- data/lib/ruber/main_window/ui/open_file_in_project_dlg.ui +168 -0
- data/lib/ruber/main_window/ui/output_color_widget.rb +241 -0
- data/lib/ruber/main_window/ui/output_color_widget.ui +204 -0
- data/lib/ruber/main_window/workspace.rb +442 -0
- data/lib/ruber/output_widget.rb +1093 -0
- data/lib/ruber/plugin.rb +264 -0
- data/lib/ruber/plugin_like.rb +589 -0
- data/lib/ruber/plugin_specification.rb +106 -0
- data/lib/ruber/plugin_specification_reader.rb +451 -0
- data/lib/ruber/project.rb +493 -0
- data/lib/ruber/project_backend.rb +105 -0
- data/lib/ruber/projects/plugin.yaml +11 -0
- data/lib/ruber/projects/project_files_list.rb +314 -0
- data/lib/ruber/projects/project_files_widget.rb +301 -0
- data/lib/ruber/projects/project_list.rb +314 -0
- data/lib/ruber/projects/ui/project_files_rule_chooser_widget.rb +74 -0
- data/lib/ruber/projects/ui/project_files_rule_chooser_widget.ui +61 -0
- data/lib/ruber/projects/ui/project_files_widget.rb +117 -0
- data/lib/ruber/projects/ui/project_files_widget.ui +123 -0
- data/lib/ruber/qt_sugar.rb +673 -0
- data/lib/ruber/settings_container.rb +515 -0
- data/lib/ruber/settings_dialog.rb +244 -0
- data/lib/ruber/settings_dialog_manager.rb +503 -0
- data/lib/ruber/utils.rb +414 -0
- data/lib/ruber/yaml_option_backend.rb +159 -0
- data/outsider_files +15 -0
- data/plugins/autosave/autosave.rb +404 -0
- data/plugins/autosave/plugin.yaml +16 -0
- data/plugins/autosave/ui/autosave_config_widget.rb +83 -0
- data/plugins/autosave/ui/autosave_config_widget.ui +68 -0
- data/plugins/command/command.png +0 -0
- data/plugins/command/command.rb +74 -0
- data/plugins/command/plugin.yaml +11 -0
- data/plugins/find_in_files/find_in_files.rb +337 -0
- data/plugins/find_in_files/find_in_files_dlg.rb +411 -0
- data/plugins/find_in_files/find_in_files_ui.rc +11 -0
- data/plugins/find_in_files/find_in_files_widgets.rb +485 -0
- data/plugins/find_in_files/plugin.yaml +23 -0
- data/plugins/find_in_files/ui/config_widget.rb +58 -0
- data/plugins/find_in_files/ui/config_widget.ui +41 -0
- data/plugins/find_in_files/ui/find_in_files_widget.rb +260 -0
- data/plugins/find_in_files/ui/find_in_files_widget.ui +324 -0
- data/plugins/project_browser/plugin.yaml +10 -0
- data/plugins/project_browser/project_browser.rb +245 -0
- data/plugins/rake/plugin.yaml +39 -0
- data/plugins/rake/rake.png +0 -0
- data/plugins/rake/rake.rb +567 -0
- data/plugins/rake/rake_extension.rb +153 -0
- data/plugins/rake/rake_widgets.rb +615 -0
- data/plugins/rake/rakeui.rc +27 -0
- data/plugins/rake/ui/add_quick_task_widget.rb +71 -0
- data/plugins/rake/ui/add_quick_task_widget.ui +59 -0
- data/plugins/rake/ui/choose_task_widget.rb +77 -0
- data/plugins/rake/ui/choose_task_widget.ui +72 -0
- data/plugins/rake/ui/config_widget.rb +127 -0
- data/plugins/rake/ui/config_widget.ui +123 -0
- data/plugins/rake/ui/project_widget.rb +217 -0
- data/plugins/rake/ui/project_widget.ui +246 -0
- data/plugins/rspec/plugin.yaml +30 -0
- data/plugins/rspec/rspec.png +0 -0
- data/plugins/rspec/rspec.rb +945 -0
- data/plugins/rspec/rspec.svg +90 -0
- data/plugins/rspec/rspecui.rc +20 -0
- data/plugins/rspec/ruber_rspec_formatter.rb +312 -0
- data/plugins/rspec/ui/rspec_project_widget.rb +170 -0
- data/plugins/rspec/ui/rspec_project_widget.ui +193 -0
- data/plugins/ruby_development/plugin.yaml +27 -0
- data/plugins/ruby_development/ruby_development.png +0 -0
- data/plugins/ruby_development/ruby_development.rb +453 -0
- data/plugins/ruby_development/ruby_developmentui.rc +19 -0
- data/plugins/ruby_development/ui/project_widget.rb +112 -0
- data/plugins/ruby_development/ui/project_widget.ui +108 -0
- data/plugins/ruby_runner/config_widget.rb +116 -0
- data/plugins/ruby_runner/plugin.yaml +26 -0
- data/plugins/ruby_runner/project_widget.rb +62 -0
- data/plugins/ruby_runner/ruby.png +0 -0
- data/plugins/ruby_runner/ruby_interpretersui.rc +26 -0
- data/plugins/ruby_runner/ruby_runner.rb +411 -0
- data/plugins/ruby_runner/ui/config_widget.rb +92 -0
- data/plugins/ruby_runner/ui/config_widget.ui +91 -0
- data/plugins/ruby_runner/ui/project_widget.rb +60 -0
- data/plugins/ruby_runner/ui/project_widget.ui +48 -0
- data/plugins/ruby_runner/ui/ruby_runnner_plugin_option_widget.rb +59 -0
- data/plugins/ruby_runner/ui/ruby_runnner_plugin_option_widget.ui +44 -0
- data/plugins/state/plugin.yaml +28 -0
- data/plugins/state/state.rb +520 -0
- data/plugins/state/ui/config_widget.rb +92 -0
- data/plugins/state/ui/config_widget.ui +89 -0
- data/plugins/syntax_checker/plugin.yaml +18 -0
- data/plugins/syntax_checker/syntax_checker.rb +662 -0
- data/ruber.desktop +10 -0
- data/spec/annotation_model_spec.rb +174 -0
- data/spec/common.rb +119 -0
- data/spec/component_manager_spec.rb +1259 -0
- data/spec/document_list_spec.rb +626 -0
- data/spec/document_project_spec.rb +373 -0
- data/spec/document_spec.rb +779 -0
- data/spec/editor_view_spec.rb +167 -0
- data/spec/external_program_plugin_spec.rb +676 -0
- data/spec/filtered_output_widget_spec.rb +642 -0
- data/spec/gui_states_handler_spec.rb +304 -0
- data/spec/kde_config_option_backend_spec.rb +214 -0
- data/spec/kde_sugar_spec.rb +101 -0
- data/spec/ktexteditor_wrapper_spec.rb +305 -0
- data/spec/output_widget_spec.rb +1703 -0
- data/spec/plugin_spec.rb +1393 -0
- data/spec/plugin_specification_reader_spec.rb +1765 -0
- data/spec/plugin_specification_spec.rb +401 -0
- data/spec/project_backend_spec.rb +172 -0
- data/spec/project_files_list_spec.rb +401 -0
- data/spec/project_list_spec.rb +511 -0
- data/spec/project_spec.rb +990 -0
- data/spec/qt_sugar_spec.rb +328 -0
- data/spec/settings_container_spec.rb +617 -0
- data/spec/settings_dialog_manager_spec.rb +773 -0
- data/spec/settings_dialog_spec.rb +419 -0
- data/spec/state_spec.rb +991 -0
- data/spec/utils_spec.rb +406 -0
- data/spec/workspace_spec.rb +869 -0
- data/spec/yaml_option_backend_spec.rb +246 -0
- metadata +284 -0
|
@@ -0,0 +1,626 @@
|
|
|
1
|
+
require './spec/common'
|
|
2
|
+
require 'pathname'
|
|
3
|
+
|
|
4
|
+
require 'ruber/utils'
|
|
5
|
+
require 'ruber/documents/document_list'
|
|
6
|
+
require 'ruber/plugin_specification'
|
|
7
|
+
|
|
8
|
+
describe Ruber::DocumentList do
|
|
9
|
+
|
|
10
|
+
before do
|
|
11
|
+
@app = KDE::Application.instance
|
|
12
|
+
@pdf = Ruber::PluginSpecification.full({:name => :documents, :class => Ruber::DocumentList})
|
|
13
|
+
@manager = flexmock("manager"){|m| m.should_ignore_missing}
|
|
14
|
+
flexmock(Ruber).should_receive(:[]).with(:app).and_return @app
|
|
15
|
+
flexmock(Ruber).should_receive(:[]).with(:components).and_return @manager
|
|
16
|
+
flexmock(Ruber).should_receive(:[]).with(:config).and_return nil
|
|
17
|
+
@mw = Qt::Widget.new
|
|
18
|
+
flexmock(Ruber).should_receive(:[]).with(:main_window).and_return @mw
|
|
19
|
+
@keeper = Ruber::DocumentList.new @manager, @pdf
|
|
20
|
+
flexmock(Ruber).should_receive(:[]).with(:docs).and_return @keeper
|
|
21
|
+
flexmock(Ruber).should_receive(:[]).with(:documents).and_return @keeper
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
after do
|
|
25
|
+
@keeper.instance_variable_get(:@docs).each{|d| d.dispose rescue nil}
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'should be Enumerable' do
|
|
29
|
+
Ruber::DocumentList.ancestors.include?(Enumerable).should be_true
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'should have no documents when created' do
|
|
33
|
+
@keeper.should be_empty
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'should call the initialize_plugin method' do
|
|
37
|
+
@keeper.plugin_description.should == @pdf
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe 'Ruber::DocumentList#[]' do
|
|
41
|
+
|
|
42
|
+
context 'when called with an integer argument' do
|
|
43
|
+
|
|
44
|
+
before do
|
|
45
|
+
@docs = 4.times.map do
|
|
46
|
+
doc = Ruber::Document.new Ruber[:main_window]
|
|
47
|
+
@keeper.add_document doc
|
|
48
|
+
doc
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'returns the document in the given position' do
|
|
53
|
+
res = []
|
|
54
|
+
4.times{|i| res[i] = @keeper[i]}
|
|
55
|
+
res.should == @docs
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it 'returns nil if the index is out of range' do
|
|
59
|
+
@keeper[5].should be_nil
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
context 'when called with a string representing an absolute path' do
|
|
65
|
+
|
|
66
|
+
it 'returns the document associated with the path' do
|
|
67
|
+
doc = Ruber::Document.new Ruber[:main_window], __FILE__
|
|
68
|
+
@keeper.add_document doc
|
|
69
|
+
@keeper[File.expand_path(__FILE__)].should == doc
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it 'returns nil if a document for that file doesn\'t exist' do
|
|
73
|
+
@keeper[`which ruby`].should be_nil
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
context 'when called with a string which doensn\'t represent an absolute path' do
|
|
79
|
+
|
|
80
|
+
it 'returns the document with the given document_name' do
|
|
81
|
+
doc = Ruber::Document.new Ruber[:main_window], __FILE__
|
|
82
|
+
@keeper.add_document doc
|
|
83
|
+
@keeper[doc.document_name].should == doc
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it 'returns nil if no document with the given document name exists' do
|
|
87
|
+
@keeper['abcd'].should be_nil
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
context 'when called with a KDE::Url' do
|
|
93
|
+
|
|
94
|
+
it 'returns the document associated with the url' do
|
|
95
|
+
url = KDE::Url.new 'http://github.com/stcrocco/ruber/raw/master/ruber.gemspec'
|
|
96
|
+
doc = Ruber::Document.new Ruber[:main_window], url
|
|
97
|
+
@keeper.add_document doc
|
|
98
|
+
@keeper[url].should == doc
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it 'returns nil if no document is associated with the given url' do
|
|
102
|
+
url = KDE::Url.new 'http://github.com/stcrocco/ruber/raw/master/ruber.gemspec'
|
|
103
|
+
@keeper[url].should be_nil
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
context 'when called with any other argument' do
|
|
109
|
+
|
|
110
|
+
it 'raises TypeError' do
|
|
111
|
+
doc = @keeper.document __FILE__
|
|
112
|
+
lambda{@keeper[1.2]}.should raise_error(TypeError)
|
|
113
|
+
lambda{@keeper[{}]}.should raise_error(TypeError)
|
|
114
|
+
lambda{@keeper[:xyz]}.should raise_error(TypeError)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
describe 'Ruber::Document#document_for_file' do
|
|
122
|
+
|
|
123
|
+
it 'returns the document corresponding to the given absolute path or nil' do
|
|
124
|
+
doc = @keeper.document __FILE__
|
|
125
|
+
@keeper.document_for_file( File.expand_path(__FILE__)).should == doc
|
|
126
|
+
@keeper.document_for_file('/test').should be_nil
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
it 'returns the document corresponding to the given relative path (expanding it) or nil' do
|
|
130
|
+
doc = @keeper.document __FILE__
|
|
131
|
+
@keeper.document_for_file( __FILE__).should == doc
|
|
132
|
+
@keeper.document_for_file('test').should be_nil
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
describe 'Ruber::Document#document_with_name' do
|
|
138
|
+
|
|
139
|
+
it 'should return the document with the given document_name or nil' do
|
|
140
|
+
doc = @keeper.document __FILE__
|
|
141
|
+
@keeper.document_with_name( File.basename(__FILE__)).should == doc
|
|
142
|
+
@keeper.document_for_file('test').should be_nil
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
describe '#document_for_url' do
|
|
148
|
+
|
|
149
|
+
it 'returns the document associated with the given KDE::Url' do
|
|
150
|
+
url = KDE::Url.new 'http://github.com/stcrocco/ruber/raw/master/ruber.gemspec'
|
|
151
|
+
doc = Ruber::Document.new Ruber[:main_window], url
|
|
152
|
+
@keeper.add_document doc
|
|
153
|
+
@keeper.document_for_url(url).should == doc
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it 'converts the argoment to a KDE::Url if it\'s a string' do
|
|
157
|
+
str = 'http://github.com/stcrocco/ruber/raw/master/ruber.gemspec'
|
|
158
|
+
url = KDE::Url.new str
|
|
159
|
+
doc = Ruber::Document.new Ruber[:main_window], url
|
|
160
|
+
@keeper.add_document doc
|
|
161
|
+
@keeper.document_for_url(str).should == doc
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
it 'returns nil if no document corresponding to the url exists' do
|
|
165
|
+
url = 'http://github.com/stcrocco/ruber/raw/master/ruber.gemspec'
|
|
166
|
+
@keeper.document_for_url(KDE::Url.new(url)).should be_nil
|
|
167
|
+
@keeper.document_for_url(url).should be_nil
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
describe '#each' do
|
|
173
|
+
|
|
174
|
+
context 'when called with a block' do
|
|
175
|
+
|
|
176
|
+
it 'allows to iterate on all documents (in creation order)' do
|
|
177
|
+
docs = 4.times.map{@keeper.new_document}
|
|
178
|
+
res = []
|
|
179
|
+
@keeper.each{|d| res << d}
|
|
180
|
+
res.should == docs
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
it 'returns self' do
|
|
184
|
+
docs = 4.times.map{@keeper.new_document}
|
|
185
|
+
@keeper.each{|d| d}.should equal(@keeper)
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
context 'when called without a block' do
|
|
191
|
+
|
|
192
|
+
it 'returns an enumerator which allows to iterate on all documents in creation order and returns the list' do
|
|
193
|
+
docs = 4.times.map{@keeper.new_document}
|
|
194
|
+
e = @keeper.each
|
|
195
|
+
e.should be_an(Enumerable)
|
|
196
|
+
res = []
|
|
197
|
+
obj = e.each{|d| res << d}
|
|
198
|
+
res.should == docs
|
|
199
|
+
obj.should == @keeper
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
describe 'Ruber::Document#each_document' do
|
|
208
|
+
|
|
209
|
+
it 'should allow to iterate on all documents (in creation order) when called with a block' do
|
|
210
|
+
docs = 4.times.map{@keeper.new_document}
|
|
211
|
+
res = []
|
|
212
|
+
@keeper.each_document{|d| res << d}
|
|
213
|
+
res.should == docs
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
it 'should return an enumerator which allows to iterate on all documents in creation order when called without a block' do
|
|
217
|
+
docs = 4.times.map{@keeper.new_document}
|
|
218
|
+
e = @keeper.each_document
|
|
219
|
+
e.should be_an(Enumerable)
|
|
220
|
+
res = []
|
|
221
|
+
e.each{|d| res << d}
|
|
222
|
+
res.should == docs
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
describe 'Ruber::Document#documents' do
|
|
228
|
+
|
|
229
|
+
it 'should return an array with all the documents, in an arbitrary order' do
|
|
230
|
+
docs = 4.times.map{@keeper.new_document}
|
|
231
|
+
res = @keeper.documents
|
|
232
|
+
res.should be_kind_of(Array)
|
|
233
|
+
res.should == docs
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
describe 'Ruber::Document#to_a' do
|
|
239
|
+
|
|
240
|
+
it 'should return an array with all the documents, in an arbitrary order' do
|
|
241
|
+
docs = 4.times.map{@keeper.new_document}
|
|
242
|
+
res = @keeper.to_a
|
|
243
|
+
res.should be_kind_of(Array)
|
|
244
|
+
res.should == docs
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
describe 'Ruber::Document#document_for_file?' do
|
|
250
|
+
|
|
251
|
+
it 'should tell whether there\'s a document for the given filename if called with an absolute filename' do
|
|
252
|
+
@keeper.document __FILE__
|
|
253
|
+
@keeper.document_for_file?( File.expand_path(__FILE__) ).should be_true
|
|
254
|
+
@keeper.document_for_file?('/test').should be_false
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
it 'should tell whether there\'s a document for the given filename if called with a relative filename (which will be expanded)' do
|
|
258
|
+
@keeper.document __FILE__
|
|
259
|
+
@keeper.document_for_file?( __FILE__ ).should be_true
|
|
260
|
+
@keeper.document_for_file?('test').should be_false
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
describe '#document_for_url?' do
|
|
266
|
+
|
|
267
|
+
it 'returns true if a document associated with the given KDE::Url exists' do
|
|
268
|
+
url = KDE::Url.new 'http://github.com/stcrocco/ruber/raw/master/ruber.gemspec'
|
|
269
|
+
doc = Ruber::Document.new Ruber[:main_window], url
|
|
270
|
+
@keeper.add_document doc
|
|
271
|
+
@keeper.document_for_url?(url).should be_true
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
it 'converts the argoment to a KDE::Url if it\'s a string' do
|
|
275
|
+
str = 'http://github.com/stcrocco/ruber/raw/master/ruber.gemspec'
|
|
276
|
+
url = KDE::Url.new str
|
|
277
|
+
doc = Ruber::Document.new Ruber[:main_window], url
|
|
278
|
+
@keeper.add_document doc
|
|
279
|
+
@keeper.document_for_url?(str).should be_true
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
it 'returns false if no document corresponding to the url exists' do
|
|
283
|
+
url = 'http://github.com/stcrocco/ruber/raw/master/ruber.gemspec'
|
|
284
|
+
@keeper.document_for_url(KDE::Url.new(url)).should be_false
|
|
285
|
+
@keeper.document_for_url(url).should be_false
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
describe 'Ruber::Document#document_with_name' do
|
|
291
|
+
|
|
292
|
+
it 'should tell whether there\'s a document with the given document_name' do
|
|
293
|
+
@keeper.document __FILE__
|
|
294
|
+
@keeper.document_with_name?( File.basename(__FILE__ )).should be_true
|
|
295
|
+
@keeper.document_with_name?('test').should be_false
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
describe 'Ruber::Document#documents_with_file' do
|
|
301
|
+
|
|
302
|
+
before do
|
|
303
|
+
@all_docs = []
|
|
304
|
+
@empty_docs = []
|
|
305
|
+
@local_docs = []
|
|
306
|
+
@remote_docs = []
|
|
307
|
+
@empty_docs << Ruber::Document.new << Ruber::Document.new
|
|
308
|
+
@local_docs << Ruber::Document.new(nil, __FILE__) << Ruber::Document.new(nil, File.join(File.dirname(__FILE__), 'common.rb'))
|
|
309
|
+
@remote_docs << Ruber::Document.new(nil, KDE::Url.new('http://github.com/stcrocco/ruber/raw/master/ruber.gemspec')) << Ruber::Document.new(nil,
|
|
310
|
+
KDE::Url.new('http://github.com/stcrocco/ruber/raw/master/bin/ruber'))
|
|
311
|
+
@all_docs << @empty_docs[0] << @local_docs[0] << @remote_docs[0] << @remote_docs[1] << @local_docs[1] << @empty_docs[1]
|
|
312
|
+
@all_docs.each{|d| @keeper.add_document d}
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
describe 'when called with the :local argument' do
|
|
316
|
+
it 'returns an array containing only the documents associated with local files' do
|
|
317
|
+
@keeper.documents_with_file(:local).should == @local_docs
|
|
318
|
+
end
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
describe 'when called with the :remote argument' do
|
|
322
|
+
it 'returns an array containing only the documents associated with remote files' do
|
|
323
|
+
@keeper.documents_with_file(:remote).should == @remote_docs
|
|
324
|
+
end
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
describe 'when called with the :any argument' do
|
|
328
|
+
it 'returns an array containing the documents associated with any file' do
|
|
329
|
+
@keeper.documents_with_file(:any).should == [@local_docs[0], @remote_docs[0], @remote_docs[1], @local_docs[1]]
|
|
330
|
+
end
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
describe 'when called with no arguments' do
|
|
334
|
+
it 'returns an array containing the documents associated with any file' do
|
|
335
|
+
@keeper.documents_with_file.should == [@local_docs[0], @remote_docs[0], @remote_docs[1], @local_docs[1]]
|
|
336
|
+
end
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
describe 'Ruber::DocumentList#close_all' do
|
|
342
|
+
|
|
343
|
+
before do
|
|
344
|
+
flexmock(@mw).should_receive(:save_documents).by_default.and_return(true)
|
|
345
|
+
pdf = Ruber::PluginSpecification.full({:name => :documents, :class => Ruber::DocumentList})
|
|
346
|
+
@docs = Array.new(5){|i| flexmock("doc #{i}"){|m| m.should_receive(:close).and_return(true).by_default}}
|
|
347
|
+
5.times {|i| flexmock(Ruber::Document).should_receive(:new).and_return(@docs[i])}
|
|
348
|
+
@keeper.instance_variable_set :@docs, @docs.dup
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
it 'should call Ruber[:main_window].save_documents passing it all the documents, if the argument is true' do
|
|
352
|
+
@mw.should_receive(:save_documents).once.with(@docs).and_return true
|
|
353
|
+
@keeper.close_all
|
|
354
|
+
end
|
|
355
|
+
|
|
356
|
+
it 'should return immediately if the call Ruber[:main_window].save_documents returns false' do
|
|
357
|
+
@mw.should_receive(:save_documents).once.with(@docs).and_return false
|
|
358
|
+
@docs.each{|d| d.should_receive(:close).never}
|
|
359
|
+
@keeper.close_all
|
|
360
|
+
end
|
|
361
|
+
|
|
362
|
+
it 'shouldn\'t call Ruber[:main_window].save_documents if the argument is false' do
|
|
363
|
+
@mw.should_receive(:save_documents).never
|
|
364
|
+
@keeper.close_all false
|
|
365
|
+
end
|
|
366
|
+
|
|
367
|
+
it 'should close each document, passing false argument as argument' do
|
|
368
|
+
@mw.should_receive(:save_documents).and_return true
|
|
369
|
+
@docs.each{|d| d.should_receive(:close).once.and_return true}
|
|
370
|
+
@keeper.close_all false
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
it 'should return true if the documents where closed and false otherwise' do
|
|
374
|
+
@mw.should_receive(:save_documents).once.with(@docs).and_return true
|
|
375
|
+
@keeper.close_all.should be_true
|
|
376
|
+
@mw.should_receive(:save_documents).once.with(@docs).and_return false
|
|
377
|
+
@keeper.close_all.should_not be
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
end
|
|
381
|
+
|
|
382
|
+
describe 'Ruber::DocumentList, when a document is closed' do
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
it 'should emit the "document_closing(QObject*)" signal, passing the document as argument' do
|
|
386
|
+
doc = @keeper.new_document
|
|
387
|
+
exp = doc.object_id
|
|
388
|
+
m = flexmock{|mk| mk.should_receive(:closing_document).once.with(exp)}
|
|
389
|
+
@keeper.connect(SIGNAL('closing_document(QObject*)')){|d| m.closing_document d.object_id}
|
|
390
|
+
doc.close
|
|
391
|
+
end
|
|
392
|
+
|
|
393
|
+
it 'should remove the closed file from the list, without leaving a hole' do
|
|
394
|
+
docs = 3.times.map{ @keeper.new_document}
|
|
395
|
+
docs[1].close false
|
|
396
|
+
@keeper.size.should == docs.size - 1
|
|
397
|
+
@keeper[0].should == docs[0]
|
|
398
|
+
@keeper[1].should == docs[2]
|
|
399
|
+
@keeper.to_a.should == @keeper.to_a.compact
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
end
|
|
403
|
+
|
|
404
|
+
describe 'Ruber::DocumentList#new_document' do
|
|
405
|
+
|
|
406
|
+
it 'should create and return a new empty document' do
|
|
407
|
+
doc = @keeper.new_document
|
|
408
|
+
doc.should be_kind_of(Ruber::Document)
|
|
409
|
+
doc.should be_pristine
|
|
410
|
+
end
|
|
411
|
+
|
|
412
|
+
it 'should add the new document to the list' do
|
|
413
|
+
doc = @keeper.new_document
|
|
414
|
+
@keeper.documents.should == [doc]
|
|
415
|
+
end
|
|
416
|
+
|
|
417
|
+
it 'should connect the "closing(QObject*)" signal of the document to the "close_document(QObject*) slot' do
|
|
418
|
+
doc = Ruber::Document.new
|
|
419
|
+
flexmock(Ruber::Document).should_receive(:new).with(@mw).once.and_return(doc)
|
|
420
|
+
flexmock(@keeper).should_receive(:close_document).once
|
|
421
|
+
@keeper.new_document
|
|
422
|
+
doc.close
|
|
423
|
+
end
|
|
424
|
+
|
|
425
|
+
it 'should emit the "document_created(QObject*)" signal passing the document as argument' do
|
|
426
|
+
doc = Ruber::Document.new
|
|
427
|
+
exp = doc.object_id
|
|
428
|
+
flexmock(Ruber::Document).should_receive(:new).with(@mw).once.and_return(doc)
|
|
429
|
+
m = flexmock{|mk| mk.should_receive(:document_created).with(exp).once}
|
|
430
|
+
@keeper.connect(SIGNAL('document_created(QObject*)')){|d| m.document_created d.object_id}
|
|
431
|
+
@keeper.new_document
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
end
|
|
435
|
+
|
|
436
|
+
describe '#document' do
|
|
437
|
+
|
|
438
|
+
context 'when a document for the given file or url already exists' do
|
|
439
|
+
|
|
440
|
+
it 'doesn\'t create a new document but return the existing one if a document for the given file or url already exists in the list' do
|
|
441
|
+
url = KDE::Url.new 'http://github.com/stcrocco/ruber/raw/ruber.gemspec'
|
|
442
|
+
doc1 = Ruber::Document.new nil, __FILE__
|
|
443
|
+
doc2 = Ruber::Document.new nil, url
|
|
444
|
+
@keeper.add_document doc1
|
|
445
|
+
@keeper.add_document doc2
|
|
446
|
+
flexmock(Ruber::Document).should_receive(:new).never
|
|
447
|
+
@keeper.document(__FILE__).should equal(doc1)
|
|
448
|
+
#Since the tests are run from the top directory, we need to prepend the spec directory
|
|
449
|
+
@keeper.document(File.expand_path(File.join('spec', File.basename(__FILE__)))).should equal(doc1)
|
|
450
|
+
@keeper.document(url).should equal(doc2)
|
|
451
|
+
end
|
|
452
|
+
|
|
453
|
+
end
|
|
454
|
+
|
|
455
|
+
context 'when a document for the given file or url doesn\'t exist' do
|
|
456
|
+
|
|
457
|
+
context 'and the second argument is false' do
|
|
458
|
+
|
|
459
|
+
it 'returns nil' do
|
|
460
|
+
@keeper.document( File.expand_path(__FILE__), false).should be_nil
|
|
461
|
+
@keeper.document(KDE::Url.new('http://github.com/stcrocco/ruber/raw/ruber.gemspec'), false).should be_nil
|
|
462
|
+
@keeper.documents.should == []
|
|
463
|
+
end
|
|
464
|
+
|
|
465
|
+
end
|
|
466
|
+
|
|
467
|
+
context 'and the second argument is true' do
|
|
468
|
+
|
|
469
|
+
it 'creates a new document for the given file or url' do
|
|
470
|
+
url = KDE::Url.new 'http://github.com/stcrocco/ruber/raw/ruber.gemspec'
|
|
471
|
+
doc = @keeper.document __FILE__
|
|
472
|
+
doc.should be_kind_of( Ruber::Document)
|
|
473
|
+
doc.path.should == __FILE__
|
|
474
|
+
doc.text.should == File.read( __FILE__)
|
|
475
|
+
doc = @keeper.document url
|
|
476
|
+
doc.url.should == url
|
|
477
|
+
end
|
|
478
|
+
|
|
479
|
+
it 'raises ArgumentError if the argument is a string or local url and the corresponding file doesn\'t exist' do
|
|
480
|
+
lambda{@keeper.document 'test'}.should raise_error(ArgumentError, "File #{File.expand_path 'test'} doesn't exist")
|
|
481
|
+
lambda{@keeper.document File.expand_path('test')}.should raise_error(ArgumentError, "File #{File.expand_path 'test'} doesn't exist")
|
|
482
|
+
lambda{@keeper.document KDE::Url.new('file:///test')}.should raise_error(ArgumentError, "File #{'/test'} doesn't exist")
|
|
483
|
+
end
|
|
484
|
+
|
|
485
|
+
it 'doesn\'t raise ArgumentError if the argument is a remote url which doesn\'t exist' do
|
|
486
|
+
lambda{@keeper.document KDE::Url.new('http://xyz/abc.def')}.should_not raise_error
|
|
487
|
+
end
|
|
488
|
+
|
|
489
|
+
it 'adds the new document to the list of documents' do
|
|
490
|
+
doc = @keeper.document __FILE__
|
|
491
|
+
@keeper.documents.size.should == 1
|
|
492
|
+
@keeper.documents.include?(doc).should be_true
|
|
493
|
+
end
|
|
494
|
+
|
|
495
|
+
it 'connects the "closing(QObject*)" signal of the new document to the "close_document(QObject*) slot' do
|
|
496
|
+
file = File.expand_path(__FILE__)
|
|
497
|
+
doc = Ruber::Document.new @keeper, file
|
|
498
|
+
flexmock(Ruber::Document).should_receive(:new).with(@mw, file).once.and_return(doc)
|
|
499
|
+
flexmock(@keeper).should_receive(:close_document).once
|
|
500
|
+
@keeper.document __FILE__
|
|
501
|
+
doc.close
|
|
502
|
+
end
|
|
503
|
+
|
|
504
|
+
it 'emits the "document_created(QObject*)" signal passing the new document as argument' do
|
|
505
|
+
file = File.expand_path(__FILE__)
|
|
506
|
+
doc = Ruber::Document.new nil, file
|
|
507
|
+
exp = doc.object_id
|
|
508
|
+
flexmock(Ruber::Document).should_receive(:new).with(@mw, file).once.and_return(doc)
|
|
509
|
+
m = flexmock{|mk| mk.should_receive(:document_created).with(exp).once}
|
|
510
|
+
@keeper.connect(SIGNAL('document_created(QObject*)')){|d| m.document_created d.object_id}
|
|
511
|
+
@keeper.document __FILE__
|
|
512
|
+
end
|
|
513
|
+
|
|
514
|
+
it 'closes the already-existing document when called with a path and the only existing document is pristine' do
|
|
515
|
+
old = @keeper.new_document
|
|
516
|
+
Qt::Object.connect old, SIGNAL('closing(QObject*)'), @keeper, SLOT('close_document(QObject*)')
|
|
517
|
+
doc = @keeper.document __FILE__
|
|
518
|
+
@keeper[0].should == doc
|
|
519
|
+
@keeper.size.should == 1
|
|
520
|
+
end
|
|
521
|
+
|
|
522
|
+
end
|
|
523
|
+
|
|
524
|
+
end
|
|
525
|
+
|
|
526
|
+
it 'expands the given file name relative to the current directory if the file name is relative' do
|
|
527
|
+
flexmock(Ruber::Document).should_receive(:new).with(@mw, File.expand_path(__FILE__))
|
|
528
|
+
doc = @keeper.document __FILE__
|
|
529
|
+
# this is necessary because otherwise the 'after' block fails (because the document list contains nil)
|
|
530
|
+
@keeper.instance_variable_get(:@docs).clear
|
|
531
|
+
end
|
|
532
|
+
|
|
533
|
+
end
|
|
534
|
+
|
|
535
|
+
describe '#add_document' do
|
|
536
|
+
|
|
537
|
+
it 'adds the given document to the list of documents' do
|
|
538
|
+
doc = Ruber::Document.new
|
|
539
|
+
@keeper.add_document doc
|
|
540
|
+
@keeper.documents.size.should == 1
|
|
541
|
+
@keeper.documents.include?(doc).should be_true
|
|
542
|
+
end
|
|
543
|
+
|
|
544
|
+
it 'connects the "closing(QObject*)" signal of the given document to the "close_document(QObject*) slot' do
|
|
545
|
+
file = File.expand_path(__FILE__)
|
|
546
|
+
doc = Ruber::Document.new @keeper, file
|
|
547
|
+
flexmock(@keeper).should_receive(:close_document).once
|
|
548
|
+
@keeper.add_document doc
|
|
549
|
+
doc.close
|
|
550
|
+
end
|
|
551
|
+
|
|
552
|
+
end
|
|
553
|
+
|
|
554
|
+
describe '#save_documents' do
|
|
555
|
+
|
|
556
|
+
before do
|
|
557
|
+
@docs = [@keeper.document(__FILE__), @keeper.new_document, @keeper.new_document]
|
|
558
|
+
end
|
|
559
|
+
|
|
560
|
+
it 'saves all the documents passed as argument' do
|
|
561
|
+
@docs.each{|d| flexmock(d).should_receive(:save).once}
|
|
562
|
+
@keeper.save_documents @docs
|
|
563
|
+
end
|
|
564
|
+
|
|
565
|
+
it 'returns an empty array if all the documents were saved successfully' do
|
|
566
|
+
@docs.each{|d| flexmock(d).should_receive(:save).once.and_return true}
|
|
567
|
+
@keeper.save_documents( @docs).should == []
|
|
568
|
+
end
|
|
569
|
+
|
|
570
|
+
it 'returns an array containing the documents for which save returned false, if the second argument is false' do
|
|
571
|
+
flexmock(@docs[0]).should_receive(:save).once.and_return true
|
|
572
|
+
flexmock(@docs[2]).should_receive(:save).once.and_return true
|
|
573
|
+
flexmock(@docs[1]).should_receive(:save).once.and_return false
|
|
574
|
+
@keeper.save_documents( @docs, false).should == [@docs[1]]
|
|
575
|
+
end
|
|
576
|
+
|
|
577
|
+
it 'doesn\'t call the save method on all remaining documents if one fails, if the second argument is true' do
|
|
578
|
+
flexmock(@docs[0]).should_receive(:save).once.and_return true
|
|
579
|
+
flexmock(@docs[1]).should_receive(:save).once.and_return false
|
|
580
|
+
flexmock(@docs[2]).should_receive(:save).never
|
|
581
|
+
@keeper.save_documents( @docs, true)
|
|
582
|
+
end
|
|
583
|
+
|
|
584
|
+
it 'returns an array containing the first document for which save returned false and all the documents which weren\'t saved if the second argument is true' do
|
|
585
|
+
flexmock(@docs[0]).should_receive(:save).once.and_return true
|
|
586
|
+
flexmock(@docs[1]).should_receive(:save).once.and_return false
|
|
587
|
+
flexmock(@docs[2]).should_receive(:save).never
|
|
588
|
+
@keeper.save_documents( @docs, true).should == @docs[1..-1]
|
|
589
|
+
end
|
|
590
|
+
|
|
591
|
+
end
|
|
592
|
+
|
|
593
|
+
describe '#save_settings' do
|
|
594
|
+
|
|
595
|
+
it 'calls the save_settings method of each document\'s own project' do
|
|
596
|
+
docs = [@keeper.document(__FILE__), @keeper.new_document, @keeper.new_document]
|
|
597
|
+
docs.each{|d| flexmock(d).should_receive(:save_settings).once}
|
|
598
|
+
@keeper.save_settings
|
|
599
|
+
end
|
|
600
|
+
|
|
601
|
+
end
|
|
602
|
+
|
|
603
|
+
describe '#query_close' do
|
|
604
|
+
|
|
605
|
+
before do
|
|
606
|
+
@docs = [@keeper.document(__FILE__), @keeper.new_document, @keeper.new_document]
|
|
607
|
+
end
|
|
608
|
+
|
|
609
|
+
it 'calls the query_close method of each document\'s own project and returns false if one of them returns false' do
|
|
610
|
+
flexmock(@docs[0].own_project).should_receive(:query_close).once.and_return true
|
|
611
|
+
flexmock(@docs[1].own_project).should_receive(:query_close).once.and_return false
|
|
612
|
+
flexmock(@docs[2].own_project).should_receive(:query_close).never.and_return(true)
|
|
613
|
+
@keeper.query_close.should be_false
|
|
614
|
+
end
|
|
615
|
+
|
|
616
|
+
it 'calls the main window\'s close_documents method and return its value' do
|
|
617
|
+
@docs.each{|d| flexmock(d.own_project).should_receive(:query_close).twice.and_return true}
|
|
618
|
+
flexmock(@mw).should_receive(:save_documents).once.with_no_args.and_return true
|
|
619
|
+
flexmock(@mw).should_receive(:save_documents).once.with_no_args.and_return false
|
|
620
|
+
@keeper.query_close.should be_true
|
|
621
|
+
@keeper.query_close.should be_false
|
|
622
|
+
end
|
|
623
|
+
|
|
624
|
+
end
|
|
625
|
+
|
|
626
|
+
end
|