ruber 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/CHANGES +21 -0
  2. data/data/share/apps/ruber/ruberui.rc +3 -1
  3. data/lib/ruber/application/application.rb +22 -23
  4. data/lib/ruber/application/plugin.yaml +7 -2
  5. data/lib/ruber/{projects → application}/project_files_list.rb +0 -0
  6. data/lib/ruber/{projects → application}/project_files_widget.rb +0 -0
  7. data/lib/ruber/application/ui/project_files_rule_chooser_widget.rb +74 -0
  8. data/lib/ruber/{projects → application}/ui/project_files_rule_chooser_widget.ui +0 -0
  9. data/lib/ruber/application/ui/project_files_widget.rb +117 -0
  10. data/lib/ruber/{projects → application}/ui/project_files_widget.ui +0 -0
  11. data/lib/ruber/component_manager.rb +14 -9
  12. data/lib/ruber/editor/document.rb +35 -5
  13. data/lib/ruber/kde_sugar.rb +16 -0
  14. data/lib/ruber/main_window/choose_plugins_dlg.rb +7 -4
  15. data/lib/ruber/main_window/main_window.rb +131 -193
  16. data/lib/ruber/main_window/main_window_actions.rb +157 -58
  17. data/lib/ruber/main_window/main_window_internal.rb +145 -54
  18. data/lib/ruber/main_window/open_file_in_project_dlg.rb +4 -4
  19. data/lib/ruber/main_window/plugin.yaml +3 -6
  20. data/lib/ruber/main_window/ui/workspace_settings_widget.rb +2 -2
  21. data/lib/ruber/main_window/workspace.rb +62 -32
  22. data/lib/ruber/output_widget.rb +20 -16
  23. data/lib/ruber/pane.rb +11 -5
  24. data/lib/ruber/project.rb +27 -12
  25. data/lib/ruber/projects/ui/project_files_rule_chooser_widget.rb +2 -2
  26. data/lib/ruber/projects/ui/project_files_widget.rb +2 -2
  27. data/lib/ruber/utils.rb +37 -4
  28. data/lib/ruber/version.rb +1 -1
  29. data/lib/ruber/world/document_factory.rb +121 -0
  30. data/lib/ruber/world/document_list.rb +396 -0
  31. data/lib/ruber/world/environment.rb +470 -0
  32. data/lib/ruber/{main_window → world}/hint_solver.rb +1 -1
  33. data/lib/ruber/world/plugin.yaml +11 -0
  34. data/lib/ruber/world/project_factory.rb +131 -0
  35. data/lib/ruber/world/project_list.rb +265 -0
  36. data/lib/ruber/world/ui/workspace_settings_widget.rb +51 -0
  37. data/lib/ruber/{main_window → world}/ui/workspace_settings_widget.ui +0 -0
  38. data/lib/ruber/world/world.rb +307 -0
  39. data/plugins/auto_end/auto_end.rb +135 -9
  40. data/plugins/autosave/autosave.rb +4 -4
  41. data/plugins/find_in_files/find_in_files.rb +5 -5
  42. data/plugins/find_in_files/find_in_files_widgets.rb +1 -1
  43. data/plugins/project_browser/project_browser.rb +4 -4
  44. data/plugins/rake/rake.rb +4 -4
  45. data/plugins/rake/rake_extension.rb +1 -1
  46. data/plugins/rspec/rspec.rb +4 -4
  47. data/plugins/rspec/ruber_rspec_formatter.rb +2 -2
  48. data/plugins/ruby_development/ruby_development.rb +3 -3
  49. data/plugins/ruby_runner/ruby_runner.rb +2 -2
  50. data/plugins/state/plugin.yaml +6 -8
  51. data/plugins/state/state.rb +201 -391
  52. data/plugins/state/ui/config_widget.rb +5 -5
  53. data/plugins/state/ui/config_widget.ui +3 -3
  54. data/plugins/syntax_checker/syntax_checker.rb +4 -0
  55. data/spec/annotation_model_spec.rb +1 -1
  56. data/spec/auto_end_spec.rb +98 -47
  57. data/spec/component_manager_spec.rb +80 -21
  58. data/spec/document_factory_spec.rb +115 -0
  59. data/spec/document_list_spec.rb +560 -450
  60. data/spec/document_spec.rb +143 -55
  61. data/spec/editor_view_spec.rb +2 -2
  62. data/spec/environment_spec.rb +1900 -0
  63. data/spec/hint_solver_spec.rb +5 -5
  64. data/spec/kde_sugar_spec.rb +16 -0
  65. data/spec/output_widget_spec.rb +177 -51
  66. data/spec/pane_spec.rb +29 -5
  67. data/spec/plugin_spec.rb +1 -1
  68. data/spec/project_factory_spec.rb +104 -0
  69. data/spec/project_list_spec.rb +352 -447
  70. data/spec/project_spec.rb +34 -33
  71. data/spec/qt_sugar_spec.rb +2 -2
  72. data/spec/state_spec.rb +508 -811
  73. data/spec/utils_spec.rb +149 -98
  74. data/spec/workspace_spec.rb +120 -9
  75. data/spec/world_spec.rb +1219 -0
  76. metadata +23 -14
  77. data/lib/ruber/documents/document_list.rb +0 -412
  78. data/lib/ruber/documents/plugin.yaml +0 -4
  79. data/lib/ruber/main_window/view_manager.rb +0 -431
  80. data/lib/ruber/projects/plugin.yaml +0 -11
  81. data/lib/ruber/projects/project_list.rb +0 -314
@@ -1,4 +1,5 @@
1
- require 'spec/common'
1
+ require './spec/framework'
2
+ require './spec/common'
2
3
 
3
4
  require 'set'
4
5
  require 'stringio'
@@ -12,47 +13,47 @@ require 'ruber/project'
12
13
  require 'ruber/plugin'
13
14
  require 'ruber/plugin_specification'
14
15
 
15
- class TestComponentManager < Qt::Object
16
-
17
- extend Forwardable
18
-
19
- def_delegators :@data, :[], :<<
20
- def_delegator :@data, :each, :each_component
21
-
22
- signals 'component_loaded(QObject*)', 'unloading_component(QObject*)'
23
-
24
- def initialize
25
- super
26
- @data = []
27
- end
28
-
29
- def emit_signal sig, obj
30
- emit method(sig).call(obj)
31
- end
32
-
33
- end
16
+ # class TestComponentManager < Qt::Object
17
+ #
18
+ # extend Forwardable
19
+ #
20
+ # def_delegators :@data, :[], :<<
21
+ # def_delegator :@data, :each, :each_component
22
+ #
23
+ # signals 'component_loaded(QObject*)', 'unloading_component(QObject*)'
24
+ #
25
+ # def initialize
26
+ # super
27
+ # @data = []
28
+ # end
29
+ #
30
+ # def emit_signal sig, obj
31
+ # emit method(sig).call(obj)
32
+ # end
33
+ #
34
+ # end
34
35
 
35
- class Application < Qt::Object
36
- signals 'plugins_changed()'
37
- end
36
+ # class Application < Qt::Object
37
+ # signals 'plugins_changed()'
38
+ # end
38
39
 
39
40
  unless defined? OS
40
41
  OS = OpenStruct
41
42
  end
42
43
 
43
- describe 'an_abstract_project_spec_method', :shared => true do
44
+ shared_examples_for 'an_abstract_project_spec_method' do
44
45
 
45
46
  include FlexMock::ArgumentTypes
46
47
 
47
- before do
48
- @comp = TestComponentManager.new
49
- @fake_app = Application.new
50
- @dlg = flexmock('dialog', :read_settings => nil, :dispose => nil)
51
- @mw = Qt::Widget.new
52
- flexmock(Ruber).should_receive(:[]).with(:components).and_return( @comp).by_default
53
- flexmock(Ruber).should_receive(:[]).with(:app).and_return( @fake_app).by_default
54
- flexmock(Ruber).should_receive(:[]).with(:main_window).and_return( @mw).by_default
55
- end
48
+ # before do
49
+ # @comp = TestComponentManager.new
50
+ # @fake_app = Application.new
51
+ # @dlg = flexmock('dialog', :read_settings => nil, :dispose => nil)
52
+ # @mw = Qt::Widget.new
53
+ # flexmock(Ruber).should_receive(:[]).with(:components).and_return( @comp).by_default
54
+ # flexmock(Ruber).should_receive(:[]).with(:app).and_return( @fake_app).by_default
55
+ # flexmock(Ruber).should_receive(:[]).with(:main_window).and_return( @mw).by_default
56
+ # end
56
57
 
57
58
  after do
58
59
  FileUtils.rm_f 'test.ruprj'
@@ -298,13 +298,13 @@ describe 'Qt::Base#named_connect' do
298
298
 
299
299
  end
300
300
 
301
- describe 'Qt::Base#named_connect' do
301
+ describe 'Qt::Base#named_disconnect' do
302
302
 
303
303
  before do
304
304
  @sender = QtNamedConnectSpec::Sender.new
305
305
  end
306
306
 
307
- it 'should allow to disconnect the block' do
307
+ it 'allows to disconnect the block' do
308
308
  m = flexmock{|mk| mk.should_receive(:test).never}
309
309
  @sender.named_connect(SIGNAL('s1()'), 'test'){m.test}
310
310
  @sender.named_disconnect 'test'
@@ -10,15 +10,170 @@ require 'ruber/pane'
10
10
 
11
11
  require 'plugins/state/state'
12
12
 
13
+ shared_examples_for 'a component of the state plugin saving an environment' do
14
+
15
+ before :all do
16
+ default_keys = {:tabs => :tabs, :cursor_positions => :cursor_positions, :active_view => :active_view}
17
+ @keys = default_keys.merge(@keys || {})
18
+ end
19
+
20
+ it 'stores a tree of the open editors for each tab under the state/tabs entry' do
21
+ docs = [nil, __FILE__, File.join(File.dirname(__FILE__), 'common.rb'), nil].map! do |f|
22
+ f ? Ruber[:world].document(f) : Ruber[:world].new_document
23
+ end
24
+ views = [
25
+ docs[1].create_view,
26
+ docs[0].create_view,
27
+ docs[3].create_view,
28
+ docs[2].create_view,
29
+ docs[1].create_view,
30
+ docs[0].create_view
31
+ ]
32
+ tab1 = Ruber::Pane.new views[0]
33
+ tab1.split views[0], views[1], Qt::Vertical
34
+ tab1.split views[0], views[2], Qt::Horizontal
35
+ tab2 = Ruber::Pane.new views[3]
36
+ tab2.split views[3], views[4], Qt::Horizontal
37
+ tab3 = Ruber::Pane.new views[5]
38
+ flexmock(@env).should_receive(:tabs).and_return [tab1, tab2, tab3]
39
+ flexmock(@env).should_receive(:documents).and_return(docs)
40
+ exp = [
41
+ [Qt::Vertical, [Qt::Horizontal, 'file://' + __FILE__, 1], 0],
42
+ [Qt::Horizontal, 'file://' + File.join(File.dirname(__FILE__), 'common.rb'), 'file://' + __FILE__],
43
+ [0]
44
+ ]
45
+ @state.save_settings
46
+ @container[:state, @keys[:tabs]].should == exp
47
+ end
48
+
49
+ it 'uses arrays with a single element in the :tabs entry to represent tabs with a single view' do
50
+ docs = [__FILE__, nil].map{|f| f ? Ruber[:world].document(f) : Ruber[:world].new_document}
51
+ flexmock(@env).should_receive(:documents).and_return(docs)
52
+ views = docs.reverse.map{|d| d.create_view}
53
+ tabs = views.map{|v| Ruber::Pane.new v}
54
+ flexmock(@env).should_receive(:tabs).and_return tabs
55
+ exp = [[0], ['file://' + __FILE__]]
56
+ @state.save_settings
57
+ @container[:state, @keys[:tabs]].should == exp
58
+ end
59
+
60
+ it 'stores an empty array under the tabs entry if there aren\'t open editors' do
61
+ docs = [
62
+ Ruber[:world].new_document,
63
+ Ruber[:world].document(__FILE__),
64
+ ]
65
+ flexmock(@env).should_receive(:documents).and_return([])
66
+ @state.save_settings
67
+ @container[:state, @keys[:tabs]].should == []
68
+ end
69
+
70
+ it 'stores the active view as an array of integers referring to the tabs entry in the active_view entry' do
71
+ docs = [
72
+ Ruber[:world].new_document,
73
+ Ruber[:world].document(__FILE__),
74
+ Ruber[:world].document(File.join(File.dirname(__FILE__), 'common.rb')),
75
+ Ruber[:world].new_document,
76
+ ]
77
+ flexmock(@env).should_receive(:documents).and_return(docs)
78
+ views = [
79
+ docs[1].create_view,
80
+ docs[0].create_view,
81
+ docs[3].create_view,
82
+ docs[2].create_view,
83
+ docs[1].create_view,
84
+ docs[0].create_view
85
+ ]
86
+ tab1 = Ruber::Pane.new views[0]
87
+ tab1.split views[0], views[1], Qt::Vertical
88
+ tab1.split views[0], views[2], Qt::Horizontal
89
+ tab2 = Ruber::Pane.new views[3]
90
+ tab2.split views[3], views[4], Qt::Horizontal
91
+ tab3 = Ruber::Pane.new views[5]
92
+ flexmock(@env).should_receive(:tabs).and_return [tab1, tab2, tab3]
93
+ exp = [
94
+ [Qt::Vertical, [Qt::Horizontal, 'file://' + __FILE__, 1], 0],
95
+ [Qt::Horizontal, 'file://' + File.join(File.dirname(__FILE__), 'common.rb'), 'file://' + __FILE__],
96
+ [0]
97
+ ]
98
+ sorted_views = [2,1,3,5,4].map{|i| views[i]}
99
+ flexmock(@env).should_receive(:views).and_return(sorted_views)
100
+ flexmock(@env).should_receive(:tab).with(sorted_views[0]).and_return tab1
101
+ @state.save_settings
102
+ @container[:state, @keys[:active_view]].should == [0, 1]
103
+ end
104
+
105
+ it 'sets the active_view entry to nil if there is no view' do
106
+ docs = [
107
+ Ruber[:world].new_document,
108
+ Ruber[:world].document(__FILE__),
109
+ ]
110
+ flexmock(@env).should_receive(:documents).and_return(docs)
111
+ @state.save_settings
112
+ @container[:state, @keys[:active_view]].should be_nil
113
+ end
114
+
115
+ it 'stores the cursor position for each view in each tab in the cursor_positions entry' do
116
+ docs = [
117
+ Ruber[:world].new_document,
118
+ Ruber[:world].document(__FILE__),
119
+ Ruber[:world].document(File.join(File.dirname(__FILE__), 'common.rb')),
120
+ Ruber[:world].new_document,
121
+ ]
122
+ flexmock(@env).should_receive(:documents).and_return docs
123
+ views = [
124
+ docs[1].create_view,
125
+ docs[0].create_view,
126
+ docs[3].create_view,
127
+ docs[2].create_view,
128
+ docs[1].create_view,
129
+ docs[0].create_view
130
+ ]
131
+ tab1 = Ruber::Pane.new views[0]
132
+ tab1.split views[0], views[1], Qt::Vertical
133
+ tab1.split views[1], views[2], Qt::Horizontal
134
+ tab2 = Ruber::Pane.new views[3]
135
+ tab2.split views[3], views[4], Qt::Horizontal
136
+ tab3 = Ruber::Pane.new views[5]
137
+ cursor_positions = [
138
+ [[5, 1], [95,102], [1, 4]],
139
+ [[0,0], [45,93]],
140
+ [[12,42]]
141
+ ]
142
+ i = 0
143
+ cursor_positions.each do |t|
144
+ t.each do |pos|
145
+ flexmock(views[i]).should_receive(:cursor_position).and_return(KTextEditor::Cursor.new(*pos))
146
+ i += 1
147
+ end
148
+ end
149
+ flexmock(@env).should_receive(:tabs).and_return [tab1, tab2, tab3]
150
+ @state.save_settings
151
+ @container[:state, @keys[:cursor_positions]].should == cursor_positions
152
+ end
153
+
154
+ it 'stores an empty array under the cursor_positions entry if there is no view in the environment' do
155
+ docs = [
156
+ Ruber[:world].new_document,
157
+ Ruber[:world].document(__FILE__),
158
+ ]
159
+ flexmock(@env).should_receive(:documents).and_return(docs)
160
+ @state.save_settings
161
+ @container[:state, @keys[:cursor_positions]].should == []
162
+ end
163
+
164
+ end
165
+
13
166
  describe Ruber::State::Plugin do
14
167
 
15
168
  before do
16
- Ruber[:documents].close_all(false)
169
+ Ruber[:world].close_all :all, :false
17
170
  Ruber[:components].load_plugin 'plugins/state/'
171
+ Ruber[:world].close_all :all, :false
18
172
  @plug = Ruber[:components][:state]
19
173
  end
20
174
 
21
175
  after do
176
+ Ruber[:world].close_all :all, :false
22
177
  Ruber[:components].unload_plugin(:state)
23
178
  end
24
179
 
@@ -43,38 +198,46 @@ describe Ruber::State::Plugin do
43
198
  describe '#delayed_initialize' do
44
199
 
45
200
  it 'calls the restore_last_state method if there\'s no open project and the only open document is pristine' do
46
- Ruber[:documents].new_document
201
+ Ruber[:world].new_document
47
202
  flexmock(@plug).should_receive(:restore_last_state).once
48
203
  @plug.send :delayed_initialize
49
204
  end
50
205
 
51
206
  it 'doesn\'t call the restore_last_state method if there are open projects' do
52
207
  prj = flexmock('project')
53
- flexmock(Ruber[:projects]).should_receive(:to_a).once.and_return [prj]
208
+ flexmock(Ruber[:world]).should_receive(:projects).once.and_return [prj]
54
209
  flexmock(@plug).should_receive(:restore_last_state).never
55
210
  @plug.send :delayed_initialize
56
211
  end
57
212
 
58
213
  it 'doesn\'t call the restore_last_state method if there is more than one open document' do
59
- 2.times{Ruber[:documents].new_document}
214
+ 2.times{Ruber[:world].new_document}
60
215
  flexmock(@plug).should_receive(:restore_last_state).never
61
216
  @plug.send :delayed_initialize
62
217
  end
63
218
 
64
219
  it 'doesn\'t call the restore_last_state method if there aren\'t open documents' do
220
+ flexmock(Ruber[:world]).should_receive(:documents).and_return []
65
221
  flexmock(@plug).should_receive(:restore_last_state).never
66
222
  @plug.send :delayed_initialize
67
223
  end
68
224
 
69
225
  it 'doesn\'t call the restore_last_state method if the only open document isn\'t pristine' do
70
- doc = Ruber[:documents].new_document
226
+ doc = Ruber[:world].new_document
71
227
  doc.text = 'xyz'
72
228
  flexmock(@plug).should_receive(:restore_last_state).never
73
229
  @plug.send :delayed_initialize
74
230
  end
75
231
 
232
+ it 'passes the :force argument to restore_last_state if restoring session' do
233
+ Ruber[:world].new_document
234
+ flexmock(Ruber[:app]).should_receive(:sessionRestored?).and_return true
235
+ flexmock(@plug).should_receive(:restore_last_state).once.with(:force)
236
+ @plug.send :delayed_initialize
237
+ end
238
+
76
239
  it 'does nothing if the application is already running' do
77
- doc = Ruber[:documents].new_document
240
+ doc = Ruber[:world].new_document
78
241
  flexmock(KDE::Application.instance).should_receive(:starting?).and_return false
79
242
  flexmock(@plug).should_receive(:restore_last_state).never
80
243
  @plug.send :delayed_initialize
@@ -82,827 +245,413 @@ describe Ruber::State::Plugin do
82
245
 
83
246
  end
84
247
 
85
- describe '#gather_settings' do
86
-
87
- it 'stores a list with the project file of each open project under the :open_projects key' do
88
- prjs = 5.times.map{|i| flexmock(i.to_s){|m| m.should_receive(:project_file).and_return i.to_s}}
89
- flexmock(Ruber[:projects]).should_receive(:projects).once.and_return(prjs)
90
- flexmock(Ruber[:projects]).should_receive(:current).once.and_return(nil)
91
- @plug.send(:gather_settings).should have_entries(:open_projects => (0...5).map(&:to_s))
92
- end
93
-
94
- it 'puts the file corresponding to the open project at the beginning of the :open_projects entry' do
95
- prjs = 5.times.map{|i| flexmock(i.to_s, :project_file => i.to_s)}
96
- flexmock(Ruber[:projects]).should_receive(:projects).once.and_return(prjs)
97
- flexmock(Ruber[:projects]).should_receive(:current).once.and_return prjs[2]
98
- @plug.send(:gather_settings).should have_entries(:open_projects => %w[2 0 1 3 4])
99
- end
100
-
101
- it 'stores the project files in an arbitrary order if there\'s no active project' do
102
- prjs = 5.times.map{|i| flexmock(i.to_s){|m| m.should_receive(:project_file).and_return i.to_s}}
103
- flexmock(Ruber[:projects]).should_receive(:projects).once.and_return(prjs)
104
- flexmock(Ruber[:projects]).should_receive(:current).once.and_return nil
105
- @plug.send(:gather_settings).should have_entries(:open_projects => (0...5).map(&:to_s))
106
- end
107
-
108
- it 'stores an empty array under the :open_projects key if there are no open projects' do
109
- @plug.send(:gather_settings).should have_entries(:open_projects => [])
110
- end
111
-
112
- it 'stores a list of the URLs of the files associated with all open documents under the :open_files key' do
113
- docs = 5.times.map{|i| flexmock(i.to_s, :has_file? => true, :view => flexmock){|m| m.should_receive(:url).and_return KDE::Url.new("file:///xyz/file #{i}")}}
114
- flexmock(Ruber[:documents]).should_receive(:documents).once.and_return(docs)
115
- exp = [
116
- 'file:///xyz/file%200',
117
- 'file:///xyz/file%201',
118
- 'file:///xyz/file%202',
119
- 'file:///xyz/file%203',
120
- 'file:///xyz/file%204',
121
- ]
122
- @plug.send(:gather_settings).should have_entries(:open_documents => exp)
123
- end
124
-
125
- it 'stores nil in place of documents not associated with files' do
126
- docs = 5.times.map do |i|
127
- flexmock(i.to_s, :view => flexmock) do |m|
128
- m.should_receive(:url).and_return(i % 2 == 0 ? KDE::Url.new("file:///xyz/file #{i}") : KDE::Url.new)
129
- m.should_receive(:has_file?).and_return(i % 2 == 0)
130
- end
131
- end
132
- flexmock(Ruber[:documents]).should_receive(:documents).once.and_return(docs)
133
- exp = [
134
- 'file:///xyz/file%200',
135
- nil,
136
- 'file:///xyz/file%202',
137
- nil,
138
- 'file:///xyz/file%204',
139
- ]
140
- @plug.send(:gather_settings).should have_entries(:open_documents => exp)
141
- end
142
-
143
- it 'stores an empty array under the :open_files key if there are no open documents' do
144
- @plug.send(:gather_settings).should have_entries(:open_documents => [])
145
- end
146
-
147
- it 'stores a tree of the open editors for each tab under the tabs entry' do
148
- docs = [nil, __FILE__, File.join(File.dirname(__FILE__), 'common.rb'), nil].map! do |f|
149
- f ? Ruber[:documents].document(f) : Ruber[:documents].new_document
150
- end
151
- views = [
152
- docs[1].create_view,
153
- docs[0].create_view,
154
- docs[3].create_view,
155
- docs[2].create_view,
156
- docs[1].create_view,
157
- docs[0].create_view
158
- ]
159
- tab1 = Ruber::Pane.new views[0]
160
- tab1.split views[0], views[1], Qt::Vertical
161
- tab1.split views[0], views[2], Qt::Horizontal
162
- tab2 = Ruber::Pane.new views[3]
163
- tab2.split views[3], views[4], Qt::Horizontal
164
- tab3 = Ruber::Pane.new views[5]
165
- flexmock(Ruber[:main_window]).should_receive(:tabs).once.and_return [tab1, tab2, tab3]
166
- exp = [
167
- [Qt::Vertical, [Qt::Horizontal, 'file://' + __FILE__, 1], 0],
168
- [Qt::Horizontal, 'file://' + File.join(File.dirname(__FILE__), 'common.rb'), 'file://' + __FILE__],
169
- [0]
170
- ]
171
- @plug.send(:gather_settings)[:tabs].should == exp
172
- end
248
+ context 'when saving settings' do
173
249
 
174
- it 'uses arrays with a single element in the :tabs entry to represent tabs with a single view' do
175
- docs = [__FILE__, nil].map{|f| f ? Ruber[:documents].document(f) : Ruber[:documents].new_document}
176
- views = docs.reverse.map{|d| d.create_view}
177
- tabs = views.map{|v| Ruber::Pane.new v}
178
- flexmock(Ruber[:main_window]).should_receive(:tabs).once.and_return tabs
179
- exp = [[0], ['file://' + __FILE__]]
180
- @plug.send(:gather_settings)[:tabs].should == exp
250
+ before :all do
251
+ @keys = {
252
+ :tabs => :default_environment_tabs,
253
+ :active_view => :default_environment_active_view,
254
+ :cursor_positions => :default_environment_cursor_positions
255
+ }
181
256
  end
182
257
 
183
- it 'stores an empty array under the tabs entry if there aren\'t open editors' do
184
- docs = [
185
- Ruber[:documents].new_document,
186
- Ruber[:documents].document(__FILE__),
187
- ]
188
- @plug.send(:gather_settings)[:tabs].should == []
189
- end
190
-
191
- it 'stores the active view as an array of integers referring to the tabs entry in the active_view entry' do
192
- docs = [
193
- Ruber[:documents].new_document,
194
- Ruber[:documents].document(__FILE__),
195
- Ruber[:documents].document(File.join(File.dirname(__FILE__), 'common.rb')),
196
- Ruber[:documents].new_document,
197
- ]
198
- views = [
199
- docs[1].create_view,
200
- docs[0].create_view,
201
- docs[3].create_view,
202
- docs[2].create_view,
203
- docs[1].create_view,
204
- docs[0].create_view
205
- ]
206
- tab1 = Ruber::Pane.new views[0]
207
- tab1.split views[0], views[1], Qt::Vertical
208
- tab1.split views[0], views[2], Qt::Horizontal
209
- tab2 = Ruber::Pane.new views[3]
210
- tab2.split views[3], views[4], Qt::Horizontal
211
- tab3 = Ruber::Pane.new views[5]
212
- flexmock(Ruber[:main_window]).should_receive(:tabs).once.and_return [tab1, tab2, tab3]
213
- exp = [
214
- [Qt::Vertical, [Qt::Horizontal, 'file://' + __FILE__, 1], 0],
215
- [Qt::Horizontal, 'file://' + File.join(File.dirname(__FILE__), 'common.rb'), 'file://' + __FILE__],
216
- [0]
217
- ]
218
- flexmock(Ruber[:main_window]).should_receive(:active_editor).and_return(views[2])
219
- flexmock(Ruber[:main_window]).should_receive(:tab).with(views[2]).and_return tab1
220
- @plug.send(:gather_settings)[:active_view].should == [0,1]
221
- end
222
-
223
- it 'sets the active_view entry to nil if there isn\'t an active editor' do
224
- docs = [
225
- Ruber[:documents].new_document,
226
- Ruber[:documents].document(__FILE__),
227
- ]
228
- @plug.send(:gather_settings)[:active_view].should be_nil
229
- end
230
-
231
- it 'stores the cursor position for each view in each tab in the cursor_positions entry' do
232
- docs = [
233
- Ruber[:documents].new_document,
234
- Ruber[:documents].document(__FILE__),
235
- Ruber[:documents].document(File.join(File.dirname(__FILE__), 'common.rb')),
236
- Ruber[:documents].new_document,
237
- ]
238
- views = [
239
- docs[1].create_view,
240
- docs[0].create_view,
241
- docs[3].create_view,
242
- docs[2].create_view,
243
- docs[1].create_view,
244
- docs[0].create_view
245
- ]
246
- tab1 = Ruber::Pane.new views[0]
247
- tab1.split views[0], views[1], Qt::Vertical
248
- tab1.split views[1], views[2], Qt::Horizontal
249
- tab2 = Ruber::Pane.new views[3]
250
- tab2.split views[3], views[4], Qt::Horizontal
251
- tab3 = Ruber::Pane.new views[5]
252
- cursor_positions = [
253
- [[5, 1], [95,102], [1, 4]],
254
- [[0,0], [45,93]],
255
- [[12,42]]
256
- ]
257
- i = 0
258
- cursor_positions.each do |t|
259
- t.each do |pos|
260
- flexmock(views[i]).should_receive(:cursor_position).and_return(KTextEditor::Cursor.new(*pos))
261
- i += 1
262
- end
263
- end
264
- flexmock(Ruber[:main_window]).should_receive(:tabs).once.and_return [tab1, tab2, tab3]
265
- @plug.send(:gather_settings)[:cursor_positions].should == cursor_positions
266
- end
267
-
268
- end
269
-
270
- describe '#save_settings' do
271
-
272
- it 'stores the value corresponding to the :open_projects key in the hash returned by gather_settings in the state/open_projects setting' do
273
- flexmock(@plug).should_receive(:gather_settings).once.and_return(:open_projects => %w[x y z])
274
- flexmock(Ruber[:config]).should_receive(:[]=).with(:state, :open_projects, %w[x y z]).once
275
- flexmock(Ruber[:config]).should_receive(:[]=)
276
- @plug.save_settings
258
+ before do
259
+ @files = [nil, '/prj1.ruprj', '/prj2.ruprj']
260
+ @prjs = @files.map{|f| f ? flexmock(:project_file => f) : nil}
261
+ @envs = @prjs.map{|pr| flexmock :project => pr}
262
+ @state = @plug
263
+ @container = Ruber[:config]
264
+ @env = Ruber[:world].default_environment
277
265
  end
278
266
 
279
- it 'stores the value corresponding to the :open_documents key in the hash returned by gather_settings in the state/open_documents setting' do
280
- flexmock(@plug).should_receive(:gather_settings).once.and_return(:open_documents => %w[x y z])
281
- flexmock(Ruber[:config]).should_receive(:[]=).with(:state, :open_documents, %w[x y z]).once
282
- flexmock(Ruber[:config]).should_receive(:[]=)
267
+
268
+ it 'lists the active environment as first element under the state/last_state key' do
269
+ flexmock(Ruber[:world]).should_receive(:active_environment).and_return(@envs[1])
270
+ exp = [@files[1], @files[0], @files[2]]
271
+ flexmock(Ruber[:world]).should_receive(:environments).and_return @envs
283
272
  @plug.save_settings
273
+ Ruber[:config][:state, :last_state].should == exp
284
274
  end
285
275
 
286
- it 'stores the value corresponding to the :active_view key in the hash returned by gather_settings in the state/active_editor setting' do
287
- flexmock(@plug).should_receive(:gather_settings).once.and_return(:active_view => [1, 2])
288
- flexmock(Ruber[:config]).should_receive(:[]=).with(:state, :active_view, [1,2]).once
289
- flexmock(Ruber[:config]).should_receive(:[]=)
276
+ it 'puts the default environment as first element of the state/last_state entry if there\'s no active environment' do
277
+ flexmock(Ruber[:world]).should_receive(:active_environment).and_return(nil)
278
+ flexmock(Ruber[:world]).should_receive(:environments).and_return @envs
290
279
  @plug.save_settings
280
+ Ruber[:config][:state, :last_state].should == @files
291
281
  end
292
282
 
293
- it 'stores the value corresponding to the :tabs key of the has returned by gather_settings in the state/tabs setting' do
294
- flexmock(@plug).should_receive(:gather_settings).once.and_return(:tabs => [Qt::Horizontal, 'file://'+__FILE__, 0])
295
- flexmock(Ruber[:config]).should_receive(:[]=).with(:state, :tabs, [Qt::Horizontal, 'file://'+__FILE__, 0]).once
296
- flexmock(Ruber[:config]).should_receive(:[]=)
297
- @plug.save_settings
298
-
299
- end
283
+ it_behaves_like 'a component of the state plugin saving an environment'
300
284
 
301
285
  end
302
286
 
303
- describe '#restore_cursor_position?' do
304
-
305
- it 'returns the value of the state/restore_cursor_position config entry if the @force_restore_cursor_position instance variable is nil' do
306
- flexmock(Ruber[:config]).should_receive(:[]).with(:state, :restore_cursor_position).once.and_return(true)
307
- flexmock(Ruber[:config]).should_receive(:[]).with(:state, :restore_cursor_position).once.and_return(false)
308
- @plug.instance_variable_set :@force_restore_cursor_position, nil
309
- @plug.restore_cursor_position?.should == true
310
- @plug.restore_cursor_position?.should == false
311
- end
287
+ context 'when restoring an environment' do
312
288
 
313
- it 'returns the value of the @force_restore_cursor_position instance variable if it is not nil' do
314
- flexmock(Ruber[:config]).should_receive(:[]).with(:state, :restore_cursor_position).never
315
- @plug.instance_variable_set :@force_restore_cursor_position, true
316
- @plug.restore_cursor_position?.should == true
317
- @plug.instance_variable_set :@force_restore_cursor_position, false
318
- @plug.restore_cursor_position?.should == false
289
+ it 'closes all the editors in the environment' do
290
+ data = {
291
+ :tabs => [],
292
+ :cursor_positions => []
293
+ }
294
+ env = Ruber[:world].default_environment
295
+ env.editor_for! __FILE__
296
+ @plug.send :restore_environment, env, data
297
+ env.tabs.should be_empty
298
+ end
299
+
300
+ it 'recreates the tabs contained in the environment' do
301
+ data = {
302
+ :tabs => [
303
+ [Qt::Vertical, 0, 1, 'file://'+__FILE__],
304
+ [Qt::Horizontal, [Qt::Vertical, 1,0], 'file://'+__FILE__]
305
+ ],
306
+ :cursor_positions => []
307
+ }
308
+ env = Ruber[:world].default_environment
309
+ @plug.send :restore_environment, env, data
310
+ env.tabs.count.should == 2
311
+ env.tabs[0].panes.map{|pn| pn.view.document.path}.should == ['', '', __FILE__]
312
+ env.tabs[1].views.map{|v| v.document.path}.should == ['', '', __FILE__]
313
+ env.tabs[0].views[1].document.should == env.tabs[1].views[0].document
314
+ env.tabs[1].views[0].document.should == env.tabs[0].views[1].document
315
+ env.tabs[0].views[0].document.should_not == env.tabs[0].views[1].document
316
+ end
317
+
318
+ it 'creates empty documents for local files which do not exist' do
319
+ data = {
320
+ :tabs => [[Qt::Vertical, 0, 'file://'+__FILE__, 'file:///xyz.rb']],
321
+ :cursor_positions => [],
322
+ :active_view => [0,0]
323
+ }
324
+ env = Ruber[:world].default_environment
325
+ lambda{@plug.send :restore_environment, env, data}.should_not raise_error
326
+ env.views[2].document.should be_pristine
319
327
  end
320
328
 
321
- end
322
-
323
- describe '#restore_project_files?' do
324
-
325
- it 'returns the value of the state/restore_project_files config entry if the @force_restore_project_files instance variable is nil' do
326
- flexmock(Ruber[:config]).should_receive(:[]).with(:state, :restore_project_files).once.and_return(true)
327
- flexmock(Ruber[:config]).should_receive(:[]).with(:state, :restore_project_files).once.and_return(false)
328
- @plug.instance_variable_set :@force_restore_project_files, nil
329
- @plug.restore_project_files?.should == true
330
- @plug.restore_project_files?.should == false
329
+ it 'creates empty documents for remote files which do not exist' do
330
+ data = {
331
+ :tabs => [[Qt::Vertical, 0, 'file://'+__FILE__, 'http:///xyz.org/abc.txt']],
332
+ :cursor_positions => [],
333
+ :active_view => [0,0]
334
+ }
335
+ env = Ruber[:world].default_environment
336
+ lambda{@plug.send :restore_environment, env, data}.should_not raise_error
337
+ env.views[2].document.should be_pristine
331
338
  end
332
339
 
333
- it 'returns the value of the @force_restore_project_files instance variable if it is not nil' do
334
- flexmock(Ruber[:config]).should_receive(:[]).with(:state, :restore_project_files).never
335
- @plug.instance_variable_set :@force_restore_project_files, true
336
- @plug.restore_project_files?.should == true
337
- @plug.instance_variable_set :@force_restore_project_files, false
338
- @plug.restore_project_files?.should == false
340
+ it 'activates the view which was active last time' do
341
+ data = {
342
+ :tabs => [
343
+ [Qt::Vertical, 0, 1, 'file://'+__FILE__],
344
+ [Qt::Horizontal, [Qt::Vertical, 1,0], 'file://'+__FILE__]
345
+ ],
346
+ :cursor_positions => [],
347
+ :active_view => [1,2]
348
+ }
349
+ env = Ruber[:world].default_environment
350
+ @plug.send :restore_environment, env, data
351
+ env.views[0].should == env.tabs[1].panes[1].view
339
352
  end
340
353
 
341
- end
342
-
343
- describe 'session_data' do
344
-
345
- it 'returns a hash containing the hash returned by the gather_settings method under the "State" key' do
346
- hash = {
347
- :open_projects => %w[a b c],
348
- :open_documents => %w[x y z],
349
- :tabs => [Qt::Horizontal, 'file://'+__FILE__, 0],
350
- :active_view => [0,0]
351
- }
352
- flexmock(@plug).should_receive(:gather_settings).once.and_return hash
353
- res = @plug.session_data
354
- res['State'].should == hash
354
+ it 'moves the cursor of each view to the position it was last time' do
355
+ positions = [
356
+ [[10,5]],
357
+ [[78,12]]
358
+ ]
359
+ data = {
360
+ :tabs => [
361
+ [Qt::Vertical,'file://'+__FILE__],
362
+ [Qt::Horizontal, 'file://'+__FILE__]
363
+ ],
364
+ :cursor_positions => positions
365
+ }
366
+ doc = Ruber[:world].document __FILE__
367
+ views = Array.new(2){doc.create_view}
368
+ views.each do |v|
369
+ flexmock(doc).should_receive(:create_view).once.and_return v
370
+ end
371
+ flexmock(views[0]).should_receive(:go_to).once.with(*positions[0][0])
372
+ flexmock(views[1]).should_receive(:go_to).once.with(*positions[1][0])
373
+ @plug.send :restore_environment, Ruber[:world].default_environment, data
374
+ end
375
+
376
+ it 'gives focus to the active window' do
377
+ data = {
378
+ :tabs => [
379
+ [Qt::Vertical,'file://'+__FILE__],
380
+ [Qt::Horizontal, 'file://'+__FILE__]
381
+ ],
382
+ :cursor_positions => [],
383
+ :active_view => [1,0]
384
+ }
385
+ doc = Ruber[:world].document __FILE__
386
+ views = Array.new(2){doc.create_view}
387
+ views.each do |v|
388
+ flexmock(doc).should_receive(:create_view).once.and_return v
389
+ end
390
+ flexmock(views[1]).should_receive(:set_focus).at_least.once
391
+ @plug.send :restore_environment, Ruber[:world].default_environment, data
392
+
355
393
  end
356
394
 
357
- end
358
-
359
- describe '#restore_session' do
360
-
361
- it 'calls restore from within a with block with :restore_cursor_position and :restore_project_files set to true passing the hash contained in the State entry of the argument' do
362
- hash = {
363
- 'State' => {
364
- :open_projects => %w[a b c],
365
- :open_documents => %w[x y z],
366
- :tabs => [Qt::Horizontal, 'file://'+__FILE__, 0],
367
- :active_view => [0,0]
368
- }
369
- }
370
- exp_hash = {
371
- [:state, :open_projects] => %w[a b c],
372
- [:state, :open_documents] => %w[x y z],
373
- [:state, :active_view] => [0,0],
374
- [:state, :tabs] => [Qt::Horizontal, 'file://'+__FILE__, 0],
375
- }
376
- default = {:open_projects => [], :open_documents => [], :active_document => nil}
377
- flexmock(@plug).should_receive(:with).with({:restore_cursor_position => true, :restore_project_files => true, :force => true}, FlexMock.on{|a| a.call || a.is_a?(Proc)}).once
378
- flexmock(@plug).should_receive(:restore).with(FlexMock.on{|a| a == exp_hash and a[:state, :open_projects] == %w[a b c]}).once
379
- @plug.restore_session hash
395
+ it 'does nothing if there are no views' do
396
+ Ruber[:config][:state, :startup_behaviour] = [:default_environment]
397
+ Ruber[:config][:state, :default_environment_tabs] = []
398
+ Ruber[:config][:state, :default_environment_active_view] = nil
399
+ @plug.send :restore_environment, Ruber[:world].default_environment, :tabs => [], :cursor_positions => []
400
+ Ruber[:world].default_environment.tabs.should be_empty
380
401
  end
381
402
 
382
403
  end
383
404
 
384
- describe '#with' do
405
+ describe '#restore_last_state' do
385
406
 
386
- describe ', when the @force_restore_cursor_position instance variable is nil' do
407
+ context 'when called with no arguments' do
387
408
 
388
- it 'calls the given block after setting the @force_restore_project_files instance variable to the :restore_cursor_position entry if the entry is a true value' do
389
- restore_doc = nil
390
- @plug.with(:restore_cursor_position => 'x'){restore_doc = @plug.instance_variable_get(:@force_restore_cursor_position)}
391
- restore_doc.should == 'x'
392
- end
393
-
394
- it 'calls the given block after setting the @force_restore_project_files instance variable to false if the :restore_cursor_position entry is given and is a false value' do
395
- restore_doc = nil
396
- @plug.with(:restore_cursor_position => false){restore_doc = @plug.instance_variable_get(:@force_restore_cursor_position)}
397
- restore_doc.should == false
398
- restore_doc = nil
399
- @plug.instance_variable_set :@force_restore_cursor_position, nil
400
- @plug.with(:restore_cursor_position => nil){restore_doc = @plug.instance_variable_get(:@force_restore_cursor_position)}
401
- restore_doc.should == false
402
- end
403
-
404
- it 'calls the block without changing the @force_restore_cursor_position instance variable if the :restore_cursor_position entry isn\'t given' do
405
- restore_doc = true
406
- @plug.with({}){restore_doc = @plug.instance_variable_get(:@force_restore_cursor_position)}
407
- restore_doc.should be_nil
408
- end
409
-
410
- it 'sets the @force_restore_cursor_position back to nil after executing the block, even if the block raises an exception' do
411
- @plug.with(:restore_cursor_position => true){@plug.instance_variable_get(:@force_restore_cursor_position).should be_true}
412
- @plug.instance_variable_get(:@force_restore_cursor_position).should be_nil
413
- @plug.with(:restore_cursor_position => false){@plug.instance_variable_get(:@force_restore_cursor_position).should == false}
414
- @plug.instance_variable_get(:@force_restore_cursor_position).should be_nil
415
- begin @plug.with(:restore_cursor_position => true){raise Exception}
416
- rescue Exception
409
+ context 'if the state/startup_behaviour config option contains :default_environment' do
410
+
411
+ it 'restores the default environment' do
412
+ data = {
413
+ :tabs => [[Qt::Vertical, 0, 'file://'+__FILE__]],
414
+ :cursor_positions => [[2,3], [4,5]],
415
+ :active_view => [0,1]
416
+ }
417
+ cfg = Ruber[:config][:state]
418
+ cfg[:startup_behaviour] = [:default_environment]
419
+ cfg[:default_environment_tabs] = data[:tabs]
420
+ cfg[:default_environment_cursor_positions] = data[:cursor_positions]
421
+ cfg[:default_environment_active_view] = data[:active_view]
422
+ flexmock(@plug).should_receive(:restore_environment).with(Ruber[:world].default_environment, data).once
423
+ @plug.send(:restore_last_state)
417
424
  end
418
- @plug.instance_variable_get(:@force_restore_cursor_position).should be_nil
425
+
419
426
  end
420
427
 
421
- end
422
-
423
- describe ', when the @force_restore_cursor_position instance variable is not nil' do
424
-
425
- describe ' and the :force entry isn\'t true' do
426
-
427
- it 'calls the block without changing the value of the @force_restore_cursor_position instance variable' do
428
- restore = nil
429
- @plug.instance_variable_set(:@force_restore_cursor_position, 'x')
430
- @plug.with(:restore_cursor_position => 'y'){restore = @plug.instance_variable_get(:@force_restore_cursor_position)}
431
- restore.should == 'x'
428
+ context 'if the state/startup_behaviour config option doesn\'t contain :default_environment' do
429
+
430
+ it 'doesn\'t recreate the tabs in the default environment' do
431
+ Ruber[:config][:state, :startup_behaviour] = []
432
+ Ruber[:config][:state, :default_environment_tabs] = [
433
+ [Qt::Vertical, 0, 1, 'file://'+__FILE__],
434
+ [Qt::Horizontal, [Qt::Vertical, 1,0], 'file://'+__FILE__]
435
+ ]
436
+ @plug.send(:restore_last_state)
437
+ flexmock(@plug).should_receive(:restore_environment).never
432
438
  end
433
-
439
+
434
440
  end
435
441
 
436
- describe ' and the :force entry is true' do
442
+ context 'if the state/startup_behaviour config option contains :projects' do
437
443
 
438
444
  before do
439
- @plug.instance_variable_set :@force_restore_cursor_position, 'y'
445
+ @project_files = Array.new(3) do |i|
446
+ file = Tempfile.new ['', 'ruprj']
447
+ file.write YAML.dump(:general => {:project_name => "project #{i}"})
448
+ file.flush
449
+ file
450
+ end
440
451
  end
441
452
 
442
- it 'calls the given block after setting the @force_restore_project_files instance variable to the :restore_cursor_position entry if the entry is a true value' do
443
- restore_doc = nil
444
- @plug.with(:restore_cursor_position => 'x', :force => true){restore_doc = @plug.instance_variable_get(:@force_restore_cursor_position)}
445
- restore_doc.should == 'x'
453
+ after do
454
+ Ruber[:world].close_all(:projects, :discard)
446
455
  end
447
456
 
448
- it 'calls the given block after setting the @force_restore_project_files instance variable to false if the :restore_cursor_position entry is given and is a false value' do
449
- restore_doc = nil
450
- @plug.with(:restore_cursor_position => false, :force => true){restore_doc = @plug.instance_variable_get(:@force_restore_cursor_position)}
451
- restore_doc.should == false
452
- restore_doc = nil
453
- @plug.instance_variable_set :@force_restore_cursor_position, nil
454
- @plug.with(:restore_cursor_position => nil, :force => true){restore_doc = @plug.instance_variable_get(:@force_restore_cursor_position)}
455
- restore_doc.should == false
457
+ it 'opens the projects listed under the state/last_state config option' do
458
+ exp = @project_files.map &:path
459
+ Ruber[:config][:state, :startup_behaviour] = [:projects]
460
+ Ruber[:config][:state, :last_state] = exp
461
+ @plug.send :restore_last_state
462
+ Ruber[:world].projects.map(&:project_file).should == exp
456
463
  end
457
464
 
458
- it 'calls the block without changing the @force_restore_cursor_position instance variable if the :restore_cursor_position entry isn\'t given' do
459
- restore_doc = true
460
- @plug.with({:force => true}){restore_doc = @plug.instance_variable_get(:@force_restore_cursor_position)}
461
- restore_doc.should == 'y'
465
+ it 'ignores any project whose project file doesn\'t exist' do
466
+ files = @project_files.map &:path
467
+ @project_files[1].close!
468
+ Ruber[:config][:state, :startup_behaviour] = [:projects]
469
+ Ruber[:config][:state, :last_state] = files
470
+ exp = files.dup
471
+ exp.delete_at(1)
472
+ @plug.send :restore_last_state
473
+ Ruber[:world].projects.map(&:project_file).should == exp
462
474
  end
463
475
 
464
- it 'sets the @force_restore_cursor_position back to the original value after executing the block, even if the block raises an exception' do
465
- @plug.with(:restore_cursor_position => true, :force => true){@plug.instance_variable_get(:@force_restore_cursor_position).should be_true}
466
- @plug.instance_variable_get(:@force_restore_cursor_position).should == 'y'
467
- @plug.with(:restore_cursor_position => false, :force => true){@plug.instance_variable_get(:@force_restore_cursor_position).should == false}
468
- @plug.instance_variable_get(:@force_restore_cursor_position).should == 'y'
469
- begin @plug.with(:restore_cursor_position => true, :force => true){raise Exception}
470
- rescue Exception
471
- end
472
- @plug.instance_variable_get(:@force_restore_cursor_position).should == 'y'
473
- end
474
-
475
- end
476
-
477
- end
478
-
479
- describe ', when the @force_restore_cursor_position instance variable is nil' do
480
-
481
- it 'calls the given block after setting the @force_restore_project_files instance variable to the :restore_cursor_position entry if the entry is a true value' do
482
- restore_doc = nil
483
- @plug.with(:restore_cursor_position => 'x'){restore_doc = @plug.instance_variable_get(:@force_restore_cursor_position)}
484
- restore_doc.should == 'x'
485
- end
486
-
487
- it 'calls the given block after setting the @force_restore_project_files instance variable to false if the :restore_cursor_position entry is given and is a false value' do
488
- restore_doc = nil
489
- @plug.with(:restore_cursor_position => false){restore_doc = @plug.instance_variable_get(:@force_restore_cursor_position)}
490
- restore_doc.should == false
491
- restore_doc = nil
492
- @plug.instance_variable_set :@force_restore_cursor_position, nil
493
- @plug.with(:restore_cursor_position => nil){restore_doc = @plug.instance_variable_get(:@force_restore_cursor_position)}
494
- restore_doc.should == false
495
- end
496
-
497
- it 'calls the block without changing the @force_restore_cursor_position instance variable if the :restore_cursor_position entry isn\'t given' do
498
- restore_doc = true
499
- @plug.with({}){restore_doc = @plug.instance_variable_get(:@force_restore_cursor_position)}
500
- restore_doc.should be_nil
501
- end
502
-
503
- it 'sets the @force_restore_cursor_position back to nil after executing the block, even if the block raises an exception' do
504
- @plug.with(:restore_cursor_position => true){@plug.instance_variable_get(:@force_restore_cursor_position).should be_true}
505
- @plug.instance_variable_get(:@force_restore_cursor_position).should be_nil
506
- @plug.with(:restore_cursor_position => false){@plug.instance_variable_get(:@force_restore_cursor_position).should == false}
507
- @plug.instance_variable_get(:@force_restore_cursor_position).should be_nil
508
- begin @plug.with(:restore_cursor_position => true){raise Exception}
509
- rescue Exception
476
+ it 'ignores any project whose project file is invalid' do
477
+ @project_files[1] << "\n{"
478
+ @project_files[1].flush
479
+ files = @project_files.map &:path
480
+ Ruber[:config][:state, :startup_behaviour] = [:projects]
481
+ Ruber[:config][:state, :last_state] = files
482
+ exp = files.dup
483
+ exp.delete_at(1)
484
+ @plug.send :restore_last_state
485
+ Ruber[:world].projects.map(&:project_file).should == exp
510
486
  end
511
- @plug.instance_variable_get(:@force_restore_cursor_position).should be_nil
512
- end
513
-
514
- end
515
-
516
- describe ', when the @force_restore_project_files instance variable is not nil' do
517
-
518
- describe ' and the :force entry isn\'t true' do
519
-
520
- it 'calls the block without changing the value of the @force_restore_project_files instance variable' do
521
- restore = nil
522
- @plug.instance_variable_set(:@force_restore_project_files, 'x')
523
- @plug.with(:restore_project_files => 'y'){restore = @plug.instance_variable_get(:@force_restore_project_files)}
524
- restore.should == 'x'
525
- end
526
-
527
- end
528
-
529
- describe ' and the :force entry is true' do
530
487
 
531
- before do
532
- @plug.instance_variable_set :@force_restore_project_files, 'y'
488
+ it 'restores all opened projects' do
489
+ files = @project_files.map &:path
490
+ prjs = @project_files.map{|f| Ruber[:world].project(f.path)}
491
+ prjs.each do |prj|
492
+ flexmock(@plug).should_receive(:restore_environment).with( Ruber[:world].environment(prj), Hash).once
493
+ end
494
+ Ruber[:config][:state, :startup_behaviour] = [:projects]
495
+ Ruber[:config][:state, :last_state] = files
496
+ @plug.send :restore_last_state
533
497
  end
534
498
 
535
- it 'calls the given block after setting the @force_restore_project_files instance variable to the :restore_project_files entry if the entry is a true value' do
536
- restore_prj = nil
537
- @plug.with(:restore_project_files => 'x', :force => true){restore_prj = @plug.instance_variable_get(:@force_restore_project_files)}
538
- restore_prj.should == 'x'
499
+ it 'activates the project which is listed first in the state/last_state option' do
500
+ files = @project_files.map &:path
501
+ Ruber[:config][:state, :startup_behaviour] = [:projects]
502
+ Ruber[:config][:state, :last_state] = files
503
+ @plug.send :restore_last_state
504
+ Ruber[:world].active_project.should == Ruber[:world].project(files[0])
539
505
  end
540
506
 
541
- it 'calls the given block after setting the @force_restore_project_files instance variable to false if the :restore_project_files entry is given and is a false value' do
542
- restore_prj = nil
543
- @plug.with(:restore_project_files => false, :force => true){restore_prj = @plug.instance_variable_get(:@force_restore_project_files)}
544
- restore_prj.should == false
545
- restore_prj = nil
546
- @plug.instance_variable_set :@force_restore_project_files, nil
547
- @plug.with(:restore_project_files => nil, :force => true){restore_prj = @plug.instance_variable_get(:@force_restore_project_files)}
548
- restore_prj.should == false
507
+ it 'activates the default environment if the first entry of the state/last_state option is nil' do
508
+ files = @project_files.map(&:path).unshift nil
509
+ Ruber[:config][:state, :startup_behaviour] = [:projects]
510
+ Ruber[:config][:state, :last_state] = files
511
+ @plug.send :restore_last_state
512
+ Ruber[:world].active_project.should be_nil
549
513
  end
550
514
 
551
- it 'calls the block without changing the @force_restore_project_files instance variable if the :restore_project_files entry isn\'t given' do
552
- restore_prj = true
553
- @plug.with({:force => true}){restore_prj = @plug.instance_variable_get(:@force_restore_project_files)}
554
- restore_prj.should == 'y'
555
- end
515
+ end
516
+
517
+ context 'if the state/startup_behaviour config option doesn\'t contain :projects' do
556
518
 
557
- it 'sets the @force_restore_project_files back to the original value after executing the block, even if the block raises an exception' do
558
- @plug.with(:restore_project_files => true, :force => true){@plug.instance_variable_get(:@force_restore_project_files).should be_true}
559
- @plug.instance_variable_get(:@force_restore_project_files).should == 'y'
560
- @plug.with(:restore_project_files => false, :force => true){@plug.instance_variable_get(:@force_restore_project_files).should == false}
561
- @plug.instance_variable_get(:@force_restore_project_files).should == 'y'
562
- begin @plug.with(:restore_project_files => true, :force => true){raise Exception}
563
- rescue Exception
564
- end
565
- @plug.instance_variable_get(:@force_restore_project_files).should == 'y'
519
+ it 'doesn\'t attempt to open other projects' do
520
+ Ruber[:config][:state, :startup_behaviour] = []
521
+ flexmock(Ruber[:world]).should_receive(:project).never
522
+ @plug.send :restore_last_state
566
523
  end
567
524
 
568
525
  end
569
526
 
570
527
  end
571
528
 
572
- end
573
-
574
- describe '#restore_document' do
575
-
576
- it 'calls the document\'s state extension\'s restore method' do
577
- ext = flexmock('extension'){|m| m.should_receive(:restore).once}
578
- doc = flexmock('doc'){|m| m.should_receive(:extension).once.with(:state).and_return ext}
579
- @plug.restore_document doc
580
- end
581
-
582
- end
583
-
584
- describe '#restore_project' do
585
-
586
- it 'calls the project\'s state extension\'s restore method' do
587
- ext = flexmock('extension'){|m| m.should_receive(:restore).once}
588
- prj = flexmock('prj'){|m| m.should_receive(:extension).once.with(:state).and_return ext}
589
- @plug.restore_project prj
590
- end
591
-
592
- end
593
-
594
- describe '#restore_projects' do
595
-
596
- it 'closes all projects' do
597
- prjs = 3.times.map{|i| flexmock(i.to_s)}
598
- prjs.each{|pr| flexmock(Ruber[:projects]).should_receive(:close_project).with(pr).once}
599
- flexmock(Ruber[:projects]).should_receive(:to_a).once.and_return(prjs)
600
- @plug.restore_projects
601
- end
602
-
603
- it 'uses the safe_open_project method of the main window to open the first entry of the state/open_projects setting' do
604
- flexmock(Ruber[:config]).should_receive(:[]).with(:state, :open_projects).once.and_return %w[/x/y/z.ruprj /a/b/c.ruprj]
605
- prj = flexmock('project', :project_file => '/x/y/z.ruprj')
606
- flexmock(Ruber[:main_window]).should_receive(:safe_open_project).once.with('/x/y/z.ruprj').and_return prj
607
- flexmock(Ruber[:projects]).should_receive(:current_project=)
608
- @plug.restore_projects
609
- end
610
-
611
- it 'activates the project returned by safe_open_project' do
612
- flexmock(Ruber[:config]).should_receive(:[]).with(:state, :open_projects).once.and_return %w[/x/y/z.ruprj /a/b/c.ruprj]
613
- prj = flexmock('project')
614
- flexmock(Ruber[:main_window]).should_receive(:safe_open_project).once.with('/x/y/z.ruprj').and_return prj
615
- flexmock(Ruber[:projects]).should_receive(:current_project=).once.with(prj)
616
- @plug.restore_projects
617
- end
618
-
619
- it 'doesn\'t attempt to activate the project if safe_open_project returned nil' do
620
- flexmock(Ruber[:config]).should_receive(:[]).with(:state, :open_projects).once.and_return %w[/x/y/z.ruprj /a/b/c.ruprj]
621
- prj = flexmock('project')
622
- flexmock(Ruber[:main_window]).should_receive(:safe_open_project).once.with('/x/y/z.ruprj').and_return nil
623
- flexmock(Ruber[:projects]).should_receive(:current_project=).never
624
- lambda{@plug.restore_projects}.should_not raise_error
625
- end
626
-
627
- it 'does nothing if the state/open_projects setting is empty' do
628
- flexmock(Ruber[:config]).should_receive(:[]).with(:state, :open_projects).once.and_return []
629
- prj = flexmock('project')
630
- flexmock(Ruber[:projects]).should_receive(:project).never
631
- flexmock(Ruber[:projects]).should_receive(:current_project=).never
632
- @plug.restore_projects
633
- end
634
-
635
- it 'reads the settings from the argument, if given, rather than from the config object' do
636
- flexmock(Ruber[:config]).should_receive(:[]).never
637
- h = {[:state, :open_projects] => ['/x/y/z.ruprj']}
638
- def h.[] group, name
639
- super [group, name]
640
- end
641
- prj = flexmock('project')
642
- flexmock(Ruber[:main_window]).should_receive(:safe_open_project).once.with('/x/y/z.ruprj').and_return prj
643
- flexmock(Ruber[:projects]).should_receive(:current_project=).once.with(prj)
644
- @plug.restore_projects h
645
- end
646
-
647
- end
648
-
649
- describe '#restore_documents' do
650
-
651
- it 'closes all open documents' do
652
- flexmock(Ruber[:documents]).should_receive(:close_all).once.and_return true
653
- @plug.restore_documents
654
- end
655
-
656
- it 'does nothing if the user chooses to abort closing the documents' do
657
- flexmock(Ruber[:documents]).should_receive(:close_all).once.and_return false
658
- files = [__FILE__, File.join(File.dirname(__FILE__), 'common.rb'), File.join(File.dirname(__FILE__), 'framework.rb')].map{|f| "file://#{f}"}
659
- Ruber[:config][:state, :open_documents] = files
660
- flexmock(Ruber[:documents]).should_receive(:document).never
661
- @plug.restore_documents
662
- end
663
-
664
- it 'creates a new document for each entry in the state/open_documents' do
665
- files = [__FILE__, File.join(File.dirname(__FILE__), 'common.rb'), File.join(File.dirname(__FILE__), 'framework.rb')].map{|f| "file://#{f}"}
666
- Ruber[:config][:state, :open_documents] = files
667
- @plug.restore_documents
668
- Ruber[:documents].count.should == files.count
669
- Ruber[:documents].each_with_index do |doc, i|
670
- doc.url.url.should == files[i]
671
- end
672
- end
673
-
674
- it 'creates empty documents for numeric entries under the state/open_documents key' do
675
- files = [0, 'file:///x/y/f1.rb', 'file:///a/b/f2.rb', 2]
676
- Ruber[:config][:state, :open_documents] = files
677
- flexmock(Ruber[:documents]).should_receive(:new_document).once.ordered
678
- flexmock(Ruber[:documents]).should_receive(:document).once.with(KDE::Url.new(files[1])).ordered
679
- flexmock(Ruber[:documents]).should_receive(:document).once.with(KDE::Url.new(files[2])).ordered
680
- flexmock(Ruber[:documents]).should_receive(:new_document).once.ordered
681
- flexmock(Ruber[:main_window]).should_receive(:without_activating)
682
- @plug.restore_documents
683
- end
684
-
685
- it 'creates a tab for each array in the :tabs entry if all of them contain a single element' do
686
- docs = [nil, __FILE__, File.join(File.dirname(__FILE__), 'common.rb'), nil].map{|f| f ? 'file://' + f : nil}
687
- views = [[docs[1]], [1], [0]]
688
- Ruber[:config][:state, :open_documents] = docs
689
- Ruber[:config][:state, :tabs] = views
690
- @plug.restore_documents
691
- tabs = Ruber[:main_window].tabs
692
- tabs.count.should == 3
693
- tabs[0].view.document.path.should == __FILE__
694
- tabs[1].view.document.should == Ruber[:documents][3]
695
- tabs[2].view.document.should == Ruber[:documents][0]
696
- end
697
-
698
- it 'creates nested tabs for each element of the :tabs entry which is a nested array' do
699
- docs = [nil, __FILE__, File.join(File.dirname(__FILE__), 'common.rb'), nil].map{|f| f ? 'file://' + f : nil}
700
- views =[
701
- [Qt::Vertical, [Qt::Horizontal, 'file://' + __FILE__, 1], 0],
702
- [Qt::Horizontal, 'file://' + File.join(File.dirname(__FILE__), 'common.rb'), 'file://' + __FILE__],
703
- [0]
704
- ]
705
- Ruber[:config][:state, :open_documents] = docs
706
- Ruber[:config][:state, :tabs] = views
707
- @plug.restore_documents
708
- tabs = Ruber[:main_window].tabs
709
- tabs.count.should == 3
710
- tabs[0].orientation.should == Qt::Vertical
711
- child_pane = tabs[0].splitter.widget(0)
712
- child_pane.orientation.should == Qt::Horizontal
713
- view_list = child_pane.to_a
714
- view_list[0].document.path.should == __FILE__
715
- view_list[1].document.should == Ruber[:documents][-1]
716
- tabs[0].splitter.widget(1).view.document.should == Ruber[:documents][0]
717
- tabs[1].orientation.should == Qt::Horizontal
718
- view_list = tabs[1].to_a
719
- view_list[0].document.path.should == File.join(File.dirname(__FILE__), 'common.rb')
720
- view_list[1].document.path.should == __FILE__
721
- tabs[2].should be_single_view
722
- tabs[2].view.document.should == Ruber[:documents][0]
723
- end
724
-
725
- it 'moves the cursor position of each view according to the contents of the :cursor_positions entry' do
726
- docs = ['file://'+__FILE__, 'file://'+File.join(File.dirname(__FILE__), 'common.rb'), 'file://'+File.join(File.dirname(__FILE__), 'framework.rb')]
727
- views =[
728
- [Qt::Vertical, [Qt::Horizontal, docs[0], docs[1] ], docs[2]],
729
- [docs[1]]
730
- ]
731
- positions = [
732
- [[30, 16], [53,33], [1,2]],
733
- [[2,6]]
734
- ]
735
- Ruber[:config][:state, :open_documents] = docs
736
- Ruber[:config][:state, :tabs] = views
737
- Ruber[:config][:state, :cursor_positions] = positions
738
- @plug.restore_documents
739
- tabs = Ruber[:main_window].tabs
740
- tabs.each_with_index do |t, i|
741
- t.to_a.each_with_index do |v, j|
742
- c = v.cursor_position
743
- c.line.should == positions[i][j][0]
744
- c.column.should == positions[i][j][1]
529
+ context 'when called with :force as argument' do
530
+
531
+ before do
532
+ @project_files = Array.new(3) do |i|
533
+ file = Tempfile.new ['', 'ruprj']
534
+ file.write YAML.dump(:general => {:project_name => "project #{i}"})
535
+ file.flush
536
+ file
745
537
  end
746
538
  end
747
- end
748
-
749
- it 'doesn\'t attempt to change the cursor positions if the cursor_positions entry is empty' do
750
- docs = ['file://'+__FILE__, 'file://'+File.join(File.dirname(__FILE__), 'common.rb'), 'file://'+File.join(File.dirname(__FILE__), 'framework.rb')]
751
- views =[
752
- [Qt::Vertical, [Qt::Horizontal, docs[0], docs[1] ], docs[2]],
753
- [docs[1]]
754
- ]
755
- Ruber[:config][:state, :open_documents] = docs
756
- Ruber[:config][:state, :tabs] = views
757
- @plug.restore_documents
758
- tabs = Ruber[:main_window].tabs
759
- tabs.each_with_index do |t, i|
760
- t.to_a.each_with_index do |v, j|
761
- c = v.cursor_position
762
- c.line.should == 0
763
- c.column.should == 0
539
+
540
+ after do
541
+ Ruber[:world].close_all(:all, :discard)
542
+ end
543
+
544
+ it 'restores the default environment even if the state/startup_behaviour option doesn\'t contain :default_environment' do
545
+ data = {
546
+ :tabs => [[Qt::Vertical, 0, 'file://'+__FILE__]],
547
+ :cursor_positions => [[2,3], [4,5]],
548
+ :active_view => [0,1]
549
+ }
550
+ cfg = Ruber[:config][:state]
551
+ cfg[:startup_behaviour] = []
552
+ cfg[:default_environment_tabs] = data[:tabs]
553
+ cfg[:default_environment_cursor_positions] = data[:cursor_positions]
554
+ cfg[:default_environment_active_view] = data[:active_view]
555
+ flexmock(@plug).should_receive(:restore_environment).with(Ruber[:world].default_environment, data).once
556
+ @plug.send :restore_last_state, :force
557
+ end
558
+
559
+ it 'opens the projects listed under the state/last_state config option even
560
+ if the state/startup_behaviour option doesn\'t contain :projects' do
561
+ exp = @project_files.map &:path
562
+ Ruber[:config][:state, :startup_behaviour] = []
563
+ Ruber[:config][:state, :last_state] = exp
564
+ @plug.send :restore_last_state, :force
565
+ Ruber[:world].projects.map(&:project_file).should == exp
566
+ end
567
+
568
+ it 'restores all opened projects even if the state/startup_behaviour option doesn\'t contain :projects' do
569
+ files = @project_files.map &:path
570
+ prjs = @project_files.map{|f| Ruber[:world].project(f.path)}
571
+ prjs.each do |prj|
572
+ flexmock(@plug).should_receive(:restore_environment).with( Ruber[:world].environment(prj), Hash).once
764
573
  end
574
+ flexmock(@plug).should_receive(:restore_environment).with Ruber[:world].default_environment, Hash
575
+ Ruber[:config][:state, :startup_behaviour] = []
576
+ Ruber[:config][:state, :last_state] = files
577
+ @plug.send :restore_last_state, :force
765
578
  end
766
- end
767
-
768
- it 'gives focus to the editor corresponding to the value in the active_editor entry' do
769
- docs = [nil, __FILE__, File.join(File.dirname(__FILE__), 'common.rb'), nil].map{|f| f ? 'file://' + f : nil}
770
- views =[
771
- [Qt::Vertical, [Qt::Horizontal, 'file://' + __FILE__, 1], 0],
772
- [Qt::Horizontal, 'file://' + File.join(File.dirname(__FILE__), 'common.rb'), 'file://' + __FILE__],
773
- [0]
774
- ]
775
- Ruber[:config][:state, :open_documents] = docs
776
- Ruber[:config][:state, :tabs] = views
777
- Ruber[:config][:state, :active_view] = [1, 1]
778
- flexmock(Ruber[:main_window]).should_receive(:focus_on_editor).once.with(FlexMock.on{|v, h| v == Ruber[:main_window].tabs[1].to_a[1]})
779
- @plug.restore_documents
780
- end
781
-
782
- it 'doesn\'t attempt to give focus to an editor if the active_editor entry is nil' do
783
- docs = [nil, __FILE__, File.join(File.dirname(__FILE__), 'common.rb'), nil].map{|f| f ? 'file://' + f : nil}
784
- views =[
785
- [Qt::Vertical, [Qt::Horizontal, 'file://' + __FILE__, 1], 0],
786
- [Qt::Horizontal, 'file://' + File.join(File.dirname(__FILE__), 'common.rb'), 'file://' + __FILE__],
787
- [0]
788
- ]
789
- Ruber[:config][:state, :open_documents] = docs
790
- Ruber[:config][:state, :tabs] = views
791
- Ruber[:config][:state, :active_view] = nil
792
- flexmock(Ruber[:main_window]).should_receive(:focus_on_editor).never
793
- @plug.restore_documents
794
- end
795
-
796
- it 'uses the settings stored in the object passed as a argument instead of those in the global configuration object' do
797
- docs = [nil, 'file://'+__FILE__]
798
- conf = flexmock do |m|
799
- m.should_receive(:[]).with(:state, :open_documents).once.and_return docs
800
- m.should_receive(:[]).with(:state, :tabs).once.and_return []
801
- m.should_receive(:[]).with(:state, :active_view).once.and_return nil
802
- m.should_receive(:[]).with(:state, :cursor_positions).once.and_return []
579
+
580
+ it 'activates the project which is listed first in the state/last_state option even if the state/startup_behaviour option doesn\'t contain :projects' do
581
+ files = @project_files.map &:path
582
+ Ruber[:config][:state, :startup_behaviour] = []
583
+ Ruber[:config][:state, :last_state] = files
584
+ @plug.send :restore_last_state, :force
585
+ Ruber[:world].active_project.should == Ruber[:world].project(files[0])
803
586
  end
804
- flexmock(Ruber[:config]).should_receive(:[]).never
805
- @plug.restore_documents conf
806
- documents = Ruber[:documents].to_a
807
- documents.size.should == 2
808
- documents[0].should be_pristine
809
- documents[1].path.should == __FILE__
587
+
810
588
  end
811
589
 
812
590
  end
813
591
 
814
- describe 'restore' do
592
+ context 'when a project is created' do
815
593
 
816
- it 'calls the restore_projects method if the state/open_project setting is not empty' do
817
- flexmock(Ruber[:config]).should_receive(:[]).with(:state, :open_projects).and_return %w[/xyz/abc.ruprj]
818
- flexmock(@plug).should_receive(:restore_projects).once.with(Ruber[:config])
819
- @plug.restore
820
- end
821
-
822
- it 'calls the restore_documents method if the state/open_projects setting is empty' do
823
- flexmock(Ruber[:config]).should_receive(:[]).with(:state, :open_projects).and_return []
824
- flexmock(@plug).should_receive(:restore_documents).once.with(Ruber[:config])
825
- @plug.restore
826
- end
827
-
828
- it 'uses the argument, rather than the config object, if one is given' do
829
- flexmock(Ruber[:config]).should_receive(:[]).never
830
- h = {[:state, :open_projects] => %w[/xyz/abc.ruprj]}
831
- def h.[](group, name)
832
- super [group, name]
594
+ before do
595
+ @project_file = Tempfile.new ['', 'ruprj']
596
+ @project_file.write YAML.dump(:general => {:project_name => "project"})
597
+ @project_file.flush
833
598
  end
834
- flexmock(@plug).should_receive(:restore_projects).once.with(h)
835
- @plug.restore h
836
- h[[:state, :open_projects]] = []
837
- flexmock(@plug).should_receive(:restore_documents).once.with(h)
838
- @plug.restore h
839
- end
840
-
841
- end
842
-
843
- describe 'restore_last_state' do
844
-
845
- describe ', when the state/startup_behaviour option is :restore_all' do
846
599
 
847
- it 'calls the restore method' do
848
- flexmock(Ruber[:config]).should_receive(:[]).with(:state, :startup_behaviour).once.and_return :restore_all
849
- flexmock(@plug).should_receive(:restore).once
850
- @plug.restore_last_state
600
+ after do
601
+ Ruber[:world].close_all(:all, :discard)
851
602
  end
852
-
853
- end
603
+
854
604
 
855
- describe ', when the state/startup_behaviour option is :restore_projects_only' do
605
+ context 'if the state/restore_projects option is true' do
856
606
 
857
- it 'calls restore_project from within a with block with :restore_project_files set to false' do
858
- flexmock(Ruber[:config]).should_receive(:[]).with(:state, :startup_behaviour).once.and_return :restore_projects_only
859
- flexmock(@plug).should_receive(:restore_projects).once
860
- flexmock(@plug).should_receive(:with).once.with({:restore_project_files => false}, FlexMock.on{|a| a.call || a.is_a?(Proc)})
861
- @plug.restore_last_state
607
+ before do
608
+ Ruber[:config][:state, :restore_projects] = true
862
609
  end
863
610
 
864
- end
865
-
866
- describe ', when the state/startup_behaviour option is :restore_documents_only' do
611
+ it 'calls the restore_environment method passing the project\'s environment and the data associated with it as argument' do
612
+ flexmock(@plug).should_receive(:restore_environment).once.with(FlexMock.on{|env| env.project.project_file == @project_file.path}, Hash)
613
+ Ruber[:world].project @project_file.path
614
+ end
867
615
 
868
- it 'calls restore_documents' do
869
- flexmock(Ruber[:config]).should_receive(:[]).with(:state, :startup_behaviour).once.and_return :restore_documents_only
870
- flexmock(@plug).should_receive(:restore_documents).once
871
- @plug.restore_last_state
616
+ it 'doesn\'t call the restore_environment if the environment already contains views' do
617
+ prj = Ruber[:world].project @project_file.path
618
+ flexmock(@plug).should_receive(:restore_environment).never
619
+ Ruber[:world].environment(prj).editor_for! __FILE__
620
+ Ruber[:world].instance_eval{emit project_created(prj)}
872
621
  end
873
622
 
874
623
  end
875
624
 
876
- describe ', when the state/startup_behaviour option is :restore_nothing' do
625
+ context 'if the state/restore_projects option is true' do
877
626
 
878
- it 'does nothing' do
879
- flexmock(Ruber[:config]).should_receive(:[]).with(:state, :startup_behaviour).once.and_return :restore_nothing
880
- flexmock(@plug).should_receive(:with).never
881
- flexmock(@plug).should_receive(:restore_projects).never
882
- flexmock(@plug).should_receive(:restore_documents).never
883
- flexmock(@plug).should_receive(:restore).never
884
- @plug.restore_last_state
627
+ before do
628
+ Ruber[:config][:state, :restore_projects] = false
885
629
  end
886
630
 
631
+ it 'does nothing' do
632
+ flexmock(@plug).should_receive(:restore_environment).never
633
+ Ruber[:world].project @project_file.path
634
+ end
635
+
887
636
  end
888
637
 
889
638
  end
890
-
639
+
891
640
  end
892
641
 
893
642
  describe Ruber::State::DocumentExtension do
894
643
 
895
644
  before do
896
645
  Ruber[:components].load_plugin 'plugins/state/'
897
- Ruber[:documents].close_all(false)
646
+ Ruber[:world].documents.dup.each{|d| d.close false}
898
647
  @plug = Ruber[:components][:state]
899
- @doc = Ruber[:documents].document __FILE__
648
+ @doc = Ruber[:world].document __FILE__
900
649
  @prj = @doc.own_project
901
650
  @ext = @doc.own_project.extension(:state)
902
651
  end
903
652
 
904
653
  after do
905
- Ruber[:documents].close_all(false)
654
+ Ruber[:world].documents.dup.each{|d| d.close false}
906
655
  Ruber[:components].unload_plugin :state
907
656
  end
908
657
 
@@ -974,16 +723,16 @@ describe Ruber::State::DocumentExtension do
974
723
  @prj[:state, :cursor_position].should == [50,15]
975
724
  end
976
725
 
977
- # it 'keeps using the view which last got focus' do
978
- # views = 3.times.map{@doc.create_view}
979
- # views[1].instance_eval{emit focus_in(self)}
980
- # views[0].instance_eval{emit focus_in(self)}
981
- # flexmock(@ext).should_receive(:save_settings)
982
- # views[1].close
983
- # flexmock(@prj).should_receive(:[]).with(:state, :cursor_position).never
984
- # flexmock(views[0]).should_receive(:cursor_position).once.and_return(KTextEditor::Cursor.new(2,3))
985
- # @doc.create_view
986
- # end
726
+ it 'keeps using the view which last got focus' do
727
+ views = 3.times.map{@doc.create_view}
728
+ views[1].instance_eval{emit focus_in(self)}
729
+ views[0].instance_eval{emit focus_in(self)}
730
+ flexmock(@ext).should_receive(:save_settings)
731
+ views[1].close
732
+ flexmock(@prj).should_receive(:[]).with(:state, :cursor_position).never
733
+ flexmock(views[0]).should_receive(:cursor_position).once.and_return(KTextEditor::Cursor.new(2,3))
734
+ @doc.create_view
735
+ end
987
736
 
988
737
 
989
738
  it 'does nothing if none of the views associated with the document have received focus' do
@@ -999,11 +748,14 @@ describe Ruber::State::DocumentExtension do
999
748
 
1000
749
  describe 'auto_restore' do
1001
750
 
1002
- context 'if the state plugin wants the cursor position restored' do
1003
-
1004
- it 'calls the restore method if the State plugins wants the curesor position restored' do
751
+ context 'if the state/restore_cursor_position option is true' do
752
+
753
+ before do
754
+ Ruber[:config][:state, :restore_cursor_position] = true
755
+ end
756
+
757
+ it 'calls the restore method' do
1005
758
  view = @doc.create_view
1006
- flexmock(@plug).should_receive(:restore_cursor_position?).once.and_return true
1007
759
  flexmock(@ext).should_receive(:restore).once.with(view)
1008
760
  @ext.send :auto_restore, view
1009
761
  end
@@ -1011,10 +763,13 @@ describe Ruber::State::DocumentExtension do
1011
763
  end
1012
764
 
1013
765
  context 'if the state plugin doesn\'t want the cursor position restored' do
1014
-
766
+
767
+ before do
768
+ Ruber[:config][:state, :restore_cursor_position] = false
769
+ end
770
+
1015
771
  it 'does nothing' do
1016
772
  view = @doc.create_view
1017
- flexmock(@plug).should_receive(:restore_cursor_position?).once.and_return false
1018
773
  flexmock(@ext).should_receive(:restore).never
1019
774
  @ext.send :auto_restore, view
1020
775
  end
@@ -1038,7 +793,7 @@ describe Ruber::State::DocumentExtension do
1038
793
  flexmock(@ext).should_receive(:save_settings)
1039
794
  end
1040
795
 
1041
- it 'after behaves as if no other view had ever got focus' do
796
+ it 'behaves as if no other view had ever got focus' do
1042
797
  views = 3.times.map{@doc.create_view}
1043
798
  views[1].instance_eval{emit focus_in(self)}
1044
799
  views[0].instance_eval{emit focus_in(self)}
@@ -1052,7 +807,7 @@ describe Ruber::State::DocumentExtension do
1052
807
 
1053
808
  context 'and the view isn\'t the last one which got focus' do
1054
809
 
1055
- it 'does nothing if the view is not the last which got focus' do
810
+ it 'does nothing' do
1056
811
  views = 3.times.map{@doc.create_view}
1057
812
  views[1].instance_eval{emit focus_in(self)}
1058
813
  views[0].instance_eval{emit focus_in(self)}
@@ -1091,13 +846,14 @@ describe Ruber::State::ProjectExtension do
1091
846
  end
1092
847
 
1093
848
  before do
1094
- Ruber[:documents].close_all(false)
849
+ Ruber[:world].documents.dup.each{|doc| doc.close false}
1095
850
  Ruber[:components].load_plugin 'plugins/state/'
1096
851
  @plug = Ruber[:components][:state]
1097
852
  @dir = File.join Dir.tmpdir, random_string(10)
1098
853
  FileUtils.mkdir @dir
1099
- @prj = Ruber[:projects].new_project File.join(@dir, 'test.ruprj'), 'Test'
854
+ @prj = Ruber[:world].new_project File.join(@dir, 'test.ruprj'), 'Test'
1100
855
  @ext = @prj.extension :state
856
+ @env = Ruber[:world].environment @prj
1101
857
  end
1102
858
 
1103
859
  after do
@@ -1105,74 +861,15 @@ describe Ruber::State::ProjectExtension do
1105
861
  Ruber[:components].unload_plugin :state
1106
862
  end
1107
863
 
1108
- describe ', when created' do
1109
-
1110
- it 'connects the project\'s activated() signal to its auto_restore slot' do
1111
- flexmock(@ext).should_receive(:auto_restore).once
1112
- @prj.activate
1113
- end
1114
-
1115
- it 'connects the save_settings slot to the deactivated signal of the project' do
1116
- flexmock(@ext).should_receive(:save_settings).once
1117
- @prj.instance_eval{emit deactivated}
1118
- end
1119
-
1120
- end
1121
-
1122
- describe '#restore' do
1123
-
1124
- it 'calls the restore_documents method of the state plugin passing the project as argument' do
1125
- flexmock(Ruber[:state]).should_receive(:restore_documents).once.with(@prj)
1126
- @ext.restore
1127
- end
1128
-
1129
- end
1130
-
1131
864
  describe '#save_settings' do
1132
865
 
1133
- it 'stores the entries returned by the documents_state and tabs_state entries of the state plugin in the project' do
1134
- @prj.activate
1135
- docs_state = ['file://'+__FILE__, nil]
1136
- tabs_state = {
1137
- :tabs => [['file://'+__FILE__], [0]],
1138
- :cursor_positions => [],
1139
- :active_view => [[1,0]]
1140
- }
1141
- state = Ruber[:state]
1142
- flexmock(state).should_receive(:documents_state).once.and_return(docs_state)
1143
- flexmock(state).should_receive(:tabs_state).once.and_return(tabs_state)
1144
- @ext.save_settings
1145
- @prj[:state, :open_documents].should == docs_state
1146
- @prj[:state, :tabs].should == tabs_state[:tabs]
1147
- @prj[:state, :active_view].should == tabs_state[:active_view]
1148
- @prj[:state, :cursor_positions].should == tabs_state[:cursor_positions]
1149
- end
1150
-
1151
- end
1152
-
1153
- describe 'auto_restore' do
1154
-
1155
-
1156
- it 'disconnects the project\'s activated() signal from the extension' do
1157
- flexmock(Ruber[:state]).should_receive(:restore_project_files?).once.and_return false
1158
- @ext.send :auto_restore
1159
- flexmock(@ext).should_receive(:auto_restore).never
1160
- flexmock(@prj).instance_eval{emit activated}
1161
- end
1162
-
1163
- it 'calls the restore method if the State plugins wants the project files restored' do
1164
- flexmock(Ruber[:state]).should_receive(:restore_project_files?).once.and_return true
1165
- flexmock(@ext).should_receive(:restore).once
1166
- @ext.send :auto_restore
866
+ before do
867
+ @state = @ext
868
+ @container = @prj
1167
869
  end
1168
870
 
1169
- it 'does noting if the State plugins doesn\'t want the project_files restored' do
1170
- flexmock(Ruber[:state]).should_receive(:restore_project_files?).once.and_return false
1171
- flexmock(@ext).should_receive(:restore).never
1172
- @ext.send :auto_restore
1173
- end
1174
-
871
+ it_behaves_like 'a component of the state plugin saving an environment'
1175
872
 
1176
873
  end
1177
-
874
+
1178
875
  end