ruber 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/CHANGES +54 -0
  2. data/bin/ruber +12 -1
  3. data/data/share/apps/ruber/ruberui.rc +5 -0
  4. data/data/share/icons/pin.png +0 -0
  5. data/lib/ruber/application/application.rb +1 -1
  6. data/lib/ruber/documents/document_list.rb +1 -1
  7. data/lib/ruber/editor/document.rb +26 -6
  8. data/lib/ruber/editor/editor_view.rb +21 -2
  9. data/lib/ruber/filtered_output_widget.rb +1 -1
  10. data/lib/ruber/ktexteditor_sugar.rb +124 -0
  11. data/lib/ruber/main_window/main_window.rb +34 -16
  12. data/lib/ruber/main_window/main_window_actions.rb +98 -5
  13. data/lib/ruber/main_window/main_window_internal.rb +1 -1
  14. data/lib/ruber/main_window/plugin.yaml +5 -0
  15. data/lib/ruber/main_window/ui/choose_plugins_widget.rb +2 -2
  16. data/lib/ruber/main_window/ui/main_window_settings_widget.rb +67 -34
  17. data/lib/ruber/main_window/ui/main_window_settings_widget.ui +77 -30
  18. data/lib/ruber/main_window/ui/new_project_widget.rb +2 -2
  19. data/lib/ruber/main_window/ui/open_file_in_project_dlg.rb +2 -2
  20. data/lib/ruber/main_window/ui/output_color_widget.rb +2 -2
  21. data/lib/ruber/main_window/ui/workspace_settings_widget.rb +1 -1
  22. data/lib/ruber/main_window/view_manager.rb +14 -1
  23. data/lib/ruber/output_widget.rb +409 -288
  24. data/lib/ruber/pane.rb +22 -0
  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/qt_sugar.rb +11 -0
  28. data/lib/ruber/version.rb +1 -1
  29. data/plugins/auto_end/auto_end.rb +122 -0
  30. data/plugins/auto_end/plugin.yaml +11 -0
  31. data/plugins/autosave/ui/autosave_config_widget.rb +2 -2
  32. data/plugins/command/command.rb +71 -12
  33. data/plugins/command/output.rb +592 -0
  34. data/plugins/command/ui/tool_widget.rb +143 -0
  35. data/plugins/command/ui/tool_widget.ui +147 -0
  36. data/plugins/find_in_files/ui/config_widget.rb +2 -2
  37. data/plugins/find_in_files/ui/find_in_files_widget.rb +2 -2
  38. data/plugins/rake/ui/add_quick_task_widget.rb +2 -2
  39. data/plugins/rake/ui/choose_task_widget.rb +2 -2
  40. data/plugins/rake/ui/config_widget.rb +2 -2
  41. data/plugins/rake/ui/project_widget.rb +2 -2
  42. data/plugins/rspec/plugin.yaml +7 -2
  43. data/plugins/rspec/rspec.rb +178 -53
  44. data/plugins/rspec/rspecui.rc +2 -3
  45. data/plugins/rspec/ui/config_widget.rb +79 -0
  46. data/plugins/rspec/ui/config_widget.ui +89 -0
  47. data/plugins/rspec/ui/rspec_project_widget.rb +2 -2
  48. data/plugins/ruby_development/ruby_development.rb +1 -1
  49. data/plugins/ruby_development/ui/config_widget.rb +1 -1
  50. data/plugins/ruby_development/ui/project_widget.rb +2 -2
  51. data/plugins/ruby_runner/ruby_runner.rb +13 -12
  52. data/plugins/ruby_runner/ui/config_widget.rb +2 -2
  53. data/plugins/ruby_runner/ui/project_widget.rb +2 -2
  54. data/plugins/ruby_runner/ui/ruby_runnner_plugin_option_widget.rb +2 -2
  55. data/plugins/state/ui/config_widget.rb +2 -2
  56. data/plugins/syntax_checker/syntax_checker.rb +1 -1
  57. data/spec/auto_end_spec.rb +272 -0
  58. data/spec/common.rb +1 -0
  59. data/spec/document_spec.rb +83 -0
  60. data/spec/editor_view_spec.rb +41 -0
  61. data/spec/filtered_output_widget_spec.rb +2 -2
  62. data/spec/ktexteditor_sugar_spec.rb +190 -0
  63. data/spec/output_widget_spec.rb +120 -11
  64. data/spec/pane_spec.rb +1 -1
  65. data/spec/qt_sugar_spec.rb +14 -0
  66. data/spec/state_spec.rb +0 -26
  67. metadata +14 -3
@@ -1,13 +1,12 @@
1
1
  <!DOCTYPE kpartgui SYSTEM 'kpartgui.dtd'>
2
- <kpartgui version="1" name="ruber-rspec_plugin" >
2
+ <kpartgui version="2" name="ruber-rspec_plugin" >
3
3
  <MenuBar>
4
4
  <Menu noMerge="1" name="ruby" >
5
5
  <text>&amp;Ruby</text>
6
6
  <Separator/>
7
7
  <Menu noMerge="1" name="rspec">
8
8
  <text>&amp;Tests</text>
9
- <Action name="rspec-go_to_spec"/>
10
- <Action name="rspec-go_to_file"/>
9
+ <Action name="rspec-switch"/>
11
10
  <Separator/>
12
11
  <Action name="rspec-run_all" />
13
12
  <Action name="rspec-run_current"/>
@@ -0,0 +1,79 @@
1
+ =begin
2
+ ** Form generated from reading ui file 'config_widget.ui'
3
+ **
4
+ ** Created: dom gen 30 12:01:53 2011
5
+ ** by: Qt User Interface Compiler version 4.7.1
6
+ **
7
+ ** WARNING! All changes made in this file will be lost when recompiling ui file!
8
+ =end
9
+
10
+ class Ui_RSpecConfigWidget
11
+ attr_reader :gridLayout
12
+ attr_reader :label
13
+ attr_reader :_rspec__switch_behaviour
14
+ attr_reader :label_2
15
+ attr_reader :_rspec__auto_expand
16
+
17
+ def setupUi(rSpecConfigWidget)
18
+ if rSpecConfigWidget.objectName.nil?
19
+ rSpecConfigWidget.objectName = "rSpecConfigWidget"
20
+ end
21
+ rSpecConfigWidget.resize(400, 49)
22
+ @gridLayout = Qt::GridLayout.new(rSpecConfigWidget)
23
+ @gridLayout.objectName = "gridLayout"
24
+ @label = Qt::Label.new(rSpecConfigWidget)
25
+ @label.objectName = "label"
26
+
27
+ @gridLayout.addWidget(@label, 0, 0, 1, 1)
28
+
29
+ @_rspec__switch_behaviour = KDE::ComboBox.new(rSpecConfigWidget)
30
+ @_rspec__switch_behaviour.objectName = "_rspec__switch_behaviour"
31
+
32
+ @gridLayout.addWidget(@_rspec__switch_behaviour, 0, 1, 1, 1)
33
+
34
+ @label_2 = Qt::Label.new(rSpecConfigWidget)
35
+ @label_2.objectName = "label_2"
36
+
37
+ @gridLayout.addWidget(@label_2, 1, 0, 1, 1)
38
+
39
+ @_rspec__auto_expand = KDE::ComboBox.new(rSpecConfigWidget)
40
+ @_rspec__auto_expand.objectName = "_rspec__auto_expand"
41
+
42
+ @gridLayout.addWidget(@_rspec__auto_expand, 1, 1, 1, 1)
43
+
44
+ @label.buddy = @_rspec__switch_behaviour
45
+ @label_2.buddy = @_rspec__auto_expand
46
+
47
+ retranslateUi(rSpecConfigWidget)
48
+
49
+ Qt::MetaObject.connectSlotsByName(rSpecConfigWidget)
50
+ end # setupUi
51
+
52
+ def setup_ui(rSpecConfigWidget)
53
+ setupUi(rSpecConfigWidget)
54
+ end
55
+
56
+ def retranslateUi(rSpecConfigWidget)
57
+ rSpecConfigWidget.windowTitle = Qt::Application.translate("RSpecConfigWidget", "Form", nil, Qt::Application::UnicodeUTF8)
58
+ @label.text = Qt::Application.translate("RSpecConfigWidget", "&Open spec/code file", nil, Qt::Application::UnicodeUTF8)
59
+ @_rspec__switch_behaviour.insertItems(0, [Qt::Application.translate("RSpecConfigWidget", "In a new tab", nil, Qt::Application::UnicodeUTF8),
60
+ Qt::Application.translate("RSpecConfigWidget", "Splitting horizontally the current tab", nil, Qt::Application::UnicodeUTF8),
61
+ Qt::Application.translate("RSpecConfigWidget", "Splitting vertically the current tab", nil, Qt::Application::UnicodeUTF8)])
62
+ @label_2.text = Qt::Application.translate("RSpecConfigWidget", "&After running rspec", nil, Qt::Application::UnicodeUTF8)
63
+ @_rspec__auto_expand.insertItems(0, [Qt::Application.translate("RSpecConfigWidget", "Collapse all examples", nil, Qt::Application::UnicodeUTF8),
64
+ Qt::Application.translate("RSpecConfigWidget", "Expand first failed or pending example", nil, Qt::Application::UnicodeUTF8),
65
+ Qt::Application.translate("RSpecConfigWidget", "Expand all failed or pending examples (slow)", nil, Qt::Application::UnicodeUTF8)])
66
+ @_rspec__auto_expand.setProperty("access", Qt::Variant.new(Qt::Application.translate("RSpecConfigWidget", "$auto_expand", nil, Qt::Application::UnicodeUTF8)))
67
+ end # retranslateUi
68
+
69
+ def retranslate_ui(rSpecConfigWidget)
70
+ retranslateUi(rSpecConfigWidget)
71
+ end
72
+
73
+ end
74
+
75
+ module Ui
76
+ class RSpecConfigWidget < Ui_RSpecConfigWidget
77
+ end
78
+ end # module Ui
79
+
@@ -0,0 +1,89 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <ui version="4.0">
3
+ <class>RSpecConfigWidget</class>
4
+ <widget class="QWidget" name="RSpecConfigWidget">
5
+ <property name="geometry">
6
+ <rect>
7
+ <x>0</x>
8
+ <y>0</y>
9
+ <width>400</width>
10
+ <height>49</height>
11
+ </rect>
12
+ </property>
13
+ <property name="windowTitle">
14
+ <string>Form</string>
15
+ </property>
16
+ <layout class="QGridLayout" name="gridLayout">
17
+ <item row="0" column="0">
18
+ <widget class="QLabel" name="label">
19
+ <property name="text">
20
+ <string>&amp;Open spec/code file</string>
21
+ </property>
22
+ <property name="buddy">
23
+ <cstring>_rspec__switch_behaviour</cstring>
24
+ </property>
25
+ </widget>
26
+ </item>
27
+ <item row="0" column="1">
28
+ <widget class="KComboBox" name="_rspec__switch_behaviour">
29
+ <item>
30
+ <property name="text">
31
+ <string>In a new tab</string>
32
+ </property>
33
+ </item>
34
+ <item>
35
+ <property name="text">
36
+ <string>Splitting horizontally the current tab</string>
37
+ </property>
38
+ </item>
39
+ <item>
40
+ <property name="text">
41
+ <string>Splitting vertically the current tab</string>
42
+ </property>
43
+ </item>
44
+ </widget>
45
+ </item>
46
+ <item row="1" column="0">
47
+ <widget class="QLabel" name="label_2">
48
+ <property name="text">
49
+ <string>&amp;After running rspec</string>
50
+ </property>
51
+ <property name="buddy">
52
+ <cstring>_rspec__auto_expand</cstring>
53
+ </property>
54
+ </widget>
55
+ </item>
56
+ <item row="1" column="1">
57
+ <widget class="KComboBox" name="_rspec__auto_expand">
58
+ <property name="access" stdset="0">
59
+ <string>$auto_expand</string>
60
+ </property>
61
+ <item>
62
+ <property name="text">
63
+ <string>Collapse all examples</string>
64
+ </property>
65
+ </item>
66
+ <item>
67
+ <property name="text">
68
+ <string>Expand first failed or pending example</string>
69
+ </property>
70
+ </item>
71
+ <item>
72
+ <property name="text">
73
+ <string>Expand all failed or pending examples (slow)</string>
74
+ </property>
75
+ </item>
76
+ </widget>
77
+ </item>
78
+ </layout>
79
+ </widget>
80
+ <customwidgets>
81
+ <customwidget>
82
+ <class>KComboBox</class>
83
+ <extends>QComboBox</extends>
84
+ <header>kcombobox.h</header>
85
+ </customwidget>
86
+ </customwidgets>
87
+ <resources/>
88
+ <connections/>
89
+ </ui>
@@ -1,8 +1,8 @@
1
1
  =begin
2
2
  ** Form generated from reading ui file 'rspec_project_widget.ui'
3
3
  **
4
- ** Created: mar nov 16 11:52:49 2010
5
- ** by: Qt User Interface Compiler version 4.7.0
4
+ ** Created: mer gen 12 12:12:11 2011
5
+ ** by: Qt User Interface Compiler version 4.7.1
6
6
  **
7
7
  ** WARNING! All changes made in this file will be lost when recompiling ui file!
8
8
  =end
@@ -270,7 +270,7 @@ was started. If the user pressed the Cancel button of the dialog, *nil* is retur
270
270
  @fake_file = FakeFileInfo.new Tempfile.new('ruby_development'), url
271
271
  downloaded = KIO::NetAccess.download url, @fake_file.file.path, Ruber[:main_window]
272
272
  unless downloaded
273
- KDE::MessageBox.sorry Ruber[:main_window], KDE::NetAccess.last_error_string
273
+ KDE::MessageBox.sorry Ruber[:main_window], KIO::NetAccess.last_error_string
274
274
  return
275
275
  end
276
276
  file = @fake_file.file.path
@@ -1,7 +1,7 @@
1
1
  =begin
2
2
  ** Form generated from reading ui file 'config_widget.ui'
3
3
  **
4
- ** Created: mar gen 11 14:57:22 2011
4
+ ** Created: mer gen 12 12:12:11 2011
5
5
  ** by: Qt User Interface Compiler version 4.7.1
6
6
  **
7
7
  ** WARNING! All changes made in this file will be lost when recompiling ui file!
@@ -1,8 +1,8 @@
1
1
  =begin
2
2
  ** Form generated from reading ui file 'project_widget.ui'
3
3
  **
4
- ** Created: mar nov 16 11:52:49 2010
5
- ** by: Qt User Interface Compiler version 4.7.0
4
+ ** Created: mer gen 12 12:12:11 2011
5
+ ** by: Qt User Interface Compiler version 4.7.1
6
6
  **
7
7
  ** WARNING! All changes made in this file will be lost when recompiling ui file!
8
8
  =end
@@ -197,6 +197,19 @@ be used.
197
197
  chosen_interpreter
198
198
  end
199
199
 
200
+ =begin rdoc
201
+ Override of {PluginLike#unload}
202
+
203
+ Besides doing the same as the base class method, it also removes the @Ruber::RubyRunner::RubyRunnerPlugin@
204
+ constant, so that other plugins may reimplement it using another base class.
205
+ @return [nil]
206
+ =end
207
+ def unload
208
+ Ruber::RubyRunner.send :remove_const, :RubyRunnerPlugin
209
+ super
210
+ end
211
+
212
+
200
213
  private
201
214
 
202
215
  =begin rdoc
@@ -243,19 +256,7 @@ default entry is selected.
243
256
  end
244
257
  nil
245
258
  end
246
-
247
- =begin rdoc
248
- Override of {PluginLike#unload}
249
259
 
250
- Besides doing the same as the base class method, it also removes the @Ruber::RubyRunner::RubyRunnerPlugin@
251
- constant, so that other plugins may reimplement it using another base class.
252
- @return [nil]
253
- =end
254
- def unload
255
- Ruber::RubyRunner.send :remove_const, :RubyRunnerPlugin
256
- super
257
- end
258
-
259
260
  end
260
261
 
261
262
  =begin
@@ -1,8 +1,8 @@
1
1
  =begin
2
2
  ** Form generated from reading ui file 'config_widget.ui'
3
3
  **
4
- ** Created: mar nov 16 11:52:49 2010
5
- ** by: Qt User Interface Compiler version 4.7.0
4
+ ** Created: mer gen 12 12:12:11 2011
5
+ ** by: Qt User Interface Compiler version 4.7.1
6
6
  **
7
7
  ** WARNING! All changes made in this file will be lost when recompiling ui file!
8
8
  =end
@@ -1,8 +1,8 @@
1
1
  =begin
2
2
  ** Form generated from reading ui file 'project_widget.ui'
3
3
  **
4
- ** Created: mar nov 16 11:52:49 2010
5
- ** by: Qt User Interface Compiler version 4.7.0
4
+ ** Created: mer gen 12 12:12:11 2011
5
+ ** by: Qt User Interface Compiler version 4.7.1
6
6
  **
7
7
  ** WARNING! All changes made in this file will be lost when recompiling ui file!
8
8
  =end
@@ -1,8 +1,8 @@
1
1
  =begin
2
2
  ** Form generated from reading ui file 'ruby_runnner_plugin_option_widget.ui'
3
3
  **
4
- ** Created: mar nov 16 11:52:49 2010
5
- ** by: Qt User Interface Compiler version 4.7.0
4
+ ** Created: mer gen 12 12:12:11 2011
5
+ ** by: Qt User Interface Compiler version 4.7.1
6
6
  **
7
7
  ** WARNING! All changes made in this file will be lost when recompiling ui file!
8
8
  =end
@@ -1,8 +1,8 @@
1
1
  =begin
2
2
  ** Form generated from reading ui file 'config_widget.ui'
3
3
  **
4
- ** Created: mar nov 16 11:52:49 2010
5
- ** by: Qt User Interface Compiler version 4.7.0
4
+ ** Created: mer gen 12 12:12:11 2011
5
+ ** by: Qt User Interface Compiler version 4.7.1
6
6
  **
7
7
  ** WARNING! All changes made in this file will be lost when recompiling ui file!
8
8
  =end
@@ -203,7 +203,7 @@ registered
203
203
  def remove_syntax_checker cls
204
204
  res = @availlable_syntax_checkers.delete cls
205
205
  res.to_bool
206
- end
206
+ end
207
207
 
208
208
  =begin rdoc
209
209
  Prepares the plugin for application shutdown
@@ -0,0 +1,272 @@
1
+ require './spec/framework'
2
+ require './spec/common'
3
+ require 'plugins/auto_end/auto_end'
4
+ require 'tempfile'
5
+
6
+ module InsertionChecker
7
+
8
+ def it_should_insert_end cond, text, initial_text, exp_text, cursor_pos = [2, 0]
9
+ lines = initial_text.split "\n"
10
+ insert_pos = lines.find_and_map do |l|
11
+ if l.include? '%'
12
+ [lines.index(l), l.index('%')]
13
+ end
14
+ end
15
+ insert_pos ||= [initial_text.each_line.count, 0]
16
+ insert_pos = KTextEditor::Cursor.new *insert_pos
17
+
18
+ context cond do
19
+
20
+ context "and the active view is associated with the document" do
21
+
22
+ before do
23
+ @view = @doc.create_view
24
+ flexmock(@doc).should_receive(:active_view).and_return @view
25
+ @doc.block_signals true
26
+ @doc.text= initial_text.sub '%', ''
27
+ @doc.block_signals false
28
+ #avoid messing up the text with indentation
29
+ flexmock(@view).should_receive(:execute_action).with('tools_align').by_default
30
+ end
31
+
32
+ it "inserts an an empty line followed by and end keyword" do
33
+ lines = text.split
34
+ @doc.insert_text insert_pos, text
35
+ @doc.text.should == exp_text
36
+ end
37
+
38
+ it 'indents the text' do
39
+ flexmock(@view).should_receive(:execute_action).with('tools_align').once
40
+ @doc.insert_text insert_pos, text
41
+ end
42
+
43
+ it 'moves the cursor to the line before the end' do
44
+ @doc.insert_text insert_pos, text
45
+ @view.cursor_position.should == KTextEditor::Cursor.new(*cursor_pos)
46
+ end
47
+
48
+ end
49
+
50
+ context 'and the active view is not associated with the document' do
51
+
52
+ it 'does nothing' do
53
+ flexmock(@doc).should_receive(:active_view).and_return nil
54
+ old_text = @doc.text
55
+ @doc.insert_text insert_pos, text
56
+ @doc.text.should == old_text
57
+ end
58
+
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+
65
+ end
66
+
67
+ describe Ruber::AutoEnd::Extension do
68
+
69
+ extend InsertionChecker
70
+
71
+ before do
72
+ Ruber[:components].load_plugin 'plugins/auto_end/'
73
+ @file = Tempfile.new ['auto_end_test', '.rb']
74
+ @doc = Ruber[:documents].document @file.path
75
+ @ext = @doc.extension(:auto_end)
76
+ end
77
+
78
+ after do
79
+ Ruber[:components].unload_plugin :auto_end
80
+ @file.close true
81
+ end
82
+
83
+ it 'includes the Extension module' do
84
+ Ruber::AutoEnd::Extension.should include(Ruber::Extension)
85
+ end
86
+
87
+ it 'inherits Qt::Object' do
88
+ Ruber::AutoEnd::Extension.ancestors.should include(Qt::Object)
89
+ end
90
+
91
+ context 'when created' do
92
+
93
+ it 'connects the text_inserted(KTextEditor::Range, QObject*) signal of the document with the text_inserted(KTextEditor::Range) slot' do
94
+ range = KTextEditor::Range.new 2, 3, 5, 6
95
+ flexmock(@ext).should_receive(:text_inserted).once.with range
96
+ @doc.instance_eval{emit text_inserted(range, self)}
97
+ end
98
+
99
+ end
100
+
101
+ context 'when a piece of text not ending in a newline is inserted' do
102
+
103
+ it 'does nothing' do
104
+ @doc.text = "xyz\nabc"
105
+ @doc.insert_text KTextEditor::Cursor.new(1,2), 'X'
106
+ @doc.text.should == "xyz\nabXc"
107
+ end
108
+
109
+ end
110
+
111
+ context 'when a piece of text ending with a newline is inserted' do
112
+
113
+ context 'and the last line contains a module' do
114
+
115
+ it_should_insert_end "if the module is at the beginning of the line and followed by spaces, an identifier, possible spaces and end of line", "module xY_12a\n", "module X\n%\nend", "module X\nmodule xY_12a\n\nend\nend"
116
+
117
+ it_should_insert_end "if the module is at the beginning of the line, preceded only by spaces and followed by spaces, an identifier, possible spaces and end of line", " module xY_12a \n", "module X\n%\nend", "module X\n module xY_12a \n\nend\nend"
118
+
119
+ it 'does not insert an end keyword if the identifier is followed by anything but spaces or other identifers separated by ::' do
120
+ @doc.block_signals true
121
+ @doc.text = "module X\n\nend"
122
+ @doc.block_signals false
123
+ @doc.insert_text KTextEditor::Cursor.new(1,0), 'module Y a.b'
124
+ @doc.text.should == "module X\nmodule Y a.b\nend"
125
+ end
126
+
127
+ it_should_insert_end "if the module is at the beginning of the line and followed by spaces, a sequence of identifiers separated by ::, possible spaces and end of line", "module xY_12a::Ac::By\n", "module X\n%\nend", "module X\nmodule xY_12a::Ac::By\n\nend\nend"
128
+
129
+ end
130
+
131
+ context 'and the last line contains a class' do
132
+
133
+ it_should_insert_end "if the class is at the beginning of the line and followed by spaces, an identifier, possible spaces and end of line", "class xY_12a\n", "module X\n%\nend", "module X\nclass xY_12a\n\nend\nend"
134
+
135
+ it_should_insert_end "if the class is at the beginning of the line and followed by spaces, an identifier, a <, another identifier, possible spaces and end of line", "class xY_12a < Ba6_1\n", "module X\n%\nend", "module X\nclass xY_12a < Ba6_1\n\nend\nend"
136
+
137
+ it_should_insert_end "if the class is at the beginning of the line and followed by spaces, an identifier, a <<, another identifier, possible spaces and end of line", "class xY_12a << Ba6_1\n", "module X\n%\nend", "module X\nclass xY_12a << Ba6_1\n\nend\nend"
138
+
139
+ it_should_insert_end "in all the previous cases if there are more than one identifier separated by :: instead of a single identifier", "class A::B < C::D\n", "module X\n%\nend", "module X\nclass A::B < C::D\n\nend\nend"
140
+
141
+ end
142
+
143
+ context "and the last line contains a def" do
144
+
145
+ it_should_insert_end "if the def is at the beginning of the line", "def xyz a, b\n", "class X\n%\nend", "class X\ndef xyz a, b\n\nend\nend"
146
+
147
+ it_should_insert_end 'if the def is preceded only by spaces', " def xyz a, b\n", "class X\n%\nend", "class X\n def xyz a, b\n\nend\nend"
148
+
149
+ end
150
+
151
+ context "and the last line contains an if " do
152
+
153
+ it_should_insert_end "if the if is at the beginning of the line", "if kkk\n", "class X\n%\nend", "class X\nif kkk\n\nend\nend", [2, 0]
154
+
155
+ it_should_insert_end "if the if is preceded only by whitespaces", " if kkk\n", "class X\n%\nend", "class X\n if kkk\n\nend\nend", [2, 0]
156
+
157
+ it_should_insert_end 'if the if is preceded by an =', "x =if kkk\n",
158
+ "class X\n%\nend", "class X\nx =if kkk\n\nend\nend"
159
+
160
+ it_should_insert_end 'if the if is preceded by an = followed by spaces', "x = if kkk\n", "class X\n%\nend", "class X\nx = if kkk\n\nend\nend"
161
+
162
+ end
163
+
164
+ context "and the line contains a do" do
165
+
166
+ it_should_insert_end "if the do is at the end of the line", "x.each do\n", "def y x\n%\nend", "def y x\nx.each do\n\nend\nend", [2, 0]
167
+
168
+ it_should_insert_end "if the do is only followed by whitespaces", " x.each do\n", "def y x\n%\nend", "def y x\n x.each do\n\nend\nend", [2, 0]
169
+
170
+ it_should_insert_end "if the do is followed by spaces and a pipe char", " x.each do |a|\n", "def y x\n%\nend", "def y x\n x.each do |a|\n\nend\nend", [2, 0]
171
+
172
+ it 'does nothing if the first character of the line is a #' do
173
+ @doc.block_signals true
174
+ @doc.text = "def x\n\nend"
175
+ @doc.block_signals false
176
+ @doc.insert_text KTextEditor::Cursor.new(1,0), "# a.each do\n"
177
+ @doc.text.should == "def x\n# a.each do\n\nend"
178
+ end
179
+
180
+ it 'does nothing if the line starts with spaces followed by a #' do
181
+ @doc.block_signals true
182
+ @doc.text = "def x\n\nend"
183
+ @doc.block_signals false
184
+ @doc.insert_text KTextEditor::Cursor.new(1,0), " # a.each do\n"
185
+ @doc.text.should == "def x\n # a.each do\n\nend"
186
+ end
187
+
188
+ end
189
+
190
+ context "and the last line contains a begin" do
191
+
192
+ it_should_insert_end "if the begin is at the beginning of the line", "begin kkk\n", "class X\n%\nend", "class X\nbegin kkk\n\nend\nend", [2, 0]
193
+
194
+ it_should_insert_end "if the begin is preceded only by whitespaces", " begin kkk\n", "class X\n%\nend", "class X\n begin kkk\n\nend\nend", [2, 0]
195
+
196
+ it_should_insert_end 'if the begin is preceded by an =', "x =begin kkk\n",
197
+ "class X\n%\nend", "class X\nx =begin kkk\n\nend\nend"
198
+
199
+ it_should_insert_end 'if the begin is preceded by an = followed by spaces', "x = begin kkk\n", "class X\n%\nend", "class X\nx = begin kkk\n\nend\nend"
200
+
201
+ end
202
+
203
+ context "and the last line starts with =begin" do
204
+
205
+ context "and the active view is associated with the document" do
206
+
207
+ before do
208
+ @view = @doc.create_view
209
+ flexmock(@doc).should_receive(:active_view).and_return @view
210
+ @doc.block_signals true
211
+ @doc.text= "abc\n"
212
+ @doc.block_signals false
213
+ @insert_pos = KTextEditor::Cursor.new(1,0)
214
+ #avoid messing up the text with indentation
215
+ flexmock(@view).should_receive(:execute_action).with('tools_align').by_default
216
+ end
217
+
218
+ it "inserts an an empty line followed by a =end" do
219
+ @doc.insert_text @insert_pos, "=begin xyz\n"
220
+ @doc.text.should == "abc\n=begin xyz\n\n=end"
221
+ end
222
+
223
+ it 'indents the text' do
224
+ flexmock(@view).should_receive(:execute_action).with('tools_align').once
225
+ @doc.insert_text @insert_pos, "=begin xyz\n"
226
+ end
227
+
228
+ it 'moves the cursor to the line before the end' do
229
+ @doc.insert_text @insert_pos, "=begin xyz\n"
230
+ @view.cursor_position.should == KTextEditor::Cursor.new(2,0)
231
+ end
232
+
233
+ end
234
+
235
+ context 'and the active view is not associated with the document' do
236
+
237
+ it 'does nothing' do
238
+ flexmock(@doc).should_receive(:active_view).and_return nil
239
+ @doc.block_signals true
240
+ old_text = "abc\n"
241
+ @doc.text = old_text
242
+ @doc.block_signals false
243
+ @doc.insert_text KTextEditor::Cursor.new(1,0), "=begin xyz\n"
244
+ @doc.text.should == "abc\n=begin xyz\n"
245
+ end
246
+
247
+ end
248
+
249
+ end
250
+
251
+ end
252
+
253
+ it 'doesn\'t insert end keywords in the middle of a multi-line text' do
254
+ view = @doc.create_view
255
+ flexmock(@doc).should_receive(:active_view).and_return view
256
+ text = "class X\ndef y\n\nend\nend"
257
+ @doc.insert_text KTextEditor::Cursor.new(0,0), text
258
+ @doc.text.should == text
259
+ end
260
+
261
+ it 'doesn\'t insert an end keyword if the following line is more indented than the current one' do
262
+ view = @doc.create_view
263
+ flexmock(@doc).should_receive(:active_view).and_return view
264
+ text = "class X\n def y\n abc"
265
+ @doc.block_signals true
266
+ @doc.insert_text KTextEditor::Cursor.new(0,0), text
267
+ @doc.block_signals false
268
+ @doc.insert_text KTextEditor::Cursor.new(1,8), "\nY"
269
+ @doc.text.should == "class X\n def y\nY\n abc"
270
+ end
271
+
272
+ end