ruber 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. data/CHANGES +42 -1
  2. data/lib/ruber/application/application.rb +25 -5
  3. data/lib/ruber/application/plugin.yaml +2 -10
  4. data/lib/ruber/component_manager.rb +2 -2
  5. data/lib/ruber/document_project.rb +5 -3
  6. data/lib/ruber/editor/document.rb +5 -4
  7. data/lib/ruber/editor/ktexteditor_wrapper.rb +1 -1
  8. data/lib/ruber/exception_widgets.rb +1 -1
  9. data/lib/ruber/main_window/main_window.rb +4 -3
  10. data/lib/ruber/main_window/main_window_actions.rb +2 -2
  11. data/lib/ruber/main_window/main_window_internal.rb +1 -1
  12. data/lib/ruber/output_widget.rb +17 -5
  13. data/lib/ruber/project.rb +34 -3
  14. data/lib/ruber/project_dir_scanner.rb +171 -0
  15. data/lib/ruber/settings_container.rb +7 -7
  16. data/lib/ruber/settings_dialog.rb +24 -24
  17. data/lib/ruber/version.rb +1 -1
  18. data/lib/ruber/world/environment.rb +1 -0
  19. data/lib/ruber/world/plugin.yaml +7 -2
  20. data/lib/ruber/{application → world}/project_files_widget.rb +0 -0
  21. data/lib/ruber/{application → world}/ui/project_files_rule_chooser_widget.rb +2 -2
  22. data/lib/ruber/{application → world}/ui/project_files_rule_chooser_widget.ui +0 -0
  23. data/lib/ruber/{application → world}/ui/project_files_widget.rb +2 -2
  24. data/lib/ruber/{application → world}/ui/project_files_widget.ui +0 -0
  25. data/plugins/auto_end/auto_end.rb +21 -18
  26. data/plugins/autosave/autosave.rb +1 -1
  27. data/plugins/find_in_files/find_in_files.rb +1 -1
  28. data/plugins/irb/irb.png +0 -0
  29. data/plugins/irb/irb.rb +142 -0
  30. data/plugins/irb/irb.svg +240 -0
  31. data/plugins/irb/irb_controller.rb +541 -0
  32. data/plugins/irb/irbrc.rb +21 -0
  33. data/plugins/irb/plugin.yaml +19 -0
  34. data/plugins/irb/ui/irb_config_widget.rb +151 -0
  35. data/plugins/irb/ui/irb_config_widget.ui +123 -0
  36. data/plugins/irb/ui/irb_tool_widget.rb +97 -0
  37. data/plugins/irb/ui/irb_tool_widget.ui +86 -0
  38. data/plugins/project_browser/project_browser.rb +1 -1
  39. data/plugins/rspec/plugin.yaml +6 -3
  40. data/plugins/rspec/rspec.rb +172 -473
  41. data/plugins/rspec/tool_widget.rb +462 -0
  42. data/plugins/rspec/ui/rspec_project_widget.rb +58 -38
  43. data/plugins/rspec/ui/rspec_project_widget.ui +68 -64
  44. data/plugins/ruberri/class_formatter.rb +126 -0
  45. data/plugins/ruberri/method_formatter.rb +90 -0
  46. data/plugins/ruberri/plugin.yaml +13 -0
  47. data/plugins/ruberri/ruberri.rb +226 -0
  48. data/plugins/ruberri/search.rb +111 -0
  49. data/plugins/ruberri/ui/tool_widget.rb +73 -0
  50. data/plugins/ruberri/ui/tool_widget.ui +49 -0
  51. data/plugins/ruby_runner/ruby_runner.rb +2 -2
  52. data/plugins/ruby_syntax_checker/plugin.yaml +11 -0
  53. data/plugins/ruby_syntax_checker/ruby_syntax_checker.rb +147 -0
  54. data/plugins/syntax_checker/plugin.yaml +10 -6
  55. data/plugins/syntax_checker/syntax_checker.rb +216 -520
  56. data/plugins/syntax_checker/ui/config_widget.rb +61 -0
  57. data/plugins/syntax_checker/ui/config_widget.ui +44 -0
  58. data/plugins/yaml_syntax_checker/plugin.yaml +11 -0
  59. data/plugins/yaml_syntax_checker/yaml_syntax_checker.rb +62 -0
  60. data/ruber.desktop +0 -0
  61. data/spec/auto_end_spec.rb +224 -186
  62. data/spec/document_project_spec.rb +9 -1
  63. data/spec/document_spec.rb +9 -0
  64. data/spec/environment_spec.rb +12 -0
  65. data/spec/output_widget_spec.rb +69 -2
  66. data/spec/project_dir_scanner_spec.rb +195 -0
  67. data/spec/project_spec.rb +43 -73
  68. data/spec/ruby_syntax_checker_spec.rb +361 -0
  69. data/spec/syntax_checker_spec.rb +1132 -0
  70. data/spec/yaml_syntax_checker_spec.rb +130 -0
  71. metadata +232 -225
  72. data/lib/ruber/application/project_files_list.rb +0 -320
  73. data/spec/project_files_list_spec.rb +0 -411
@@ -0,0 +1,61 @@
1
+ =begin
2
+ ** Form generated from reading ui file 'config_widget.ui'
3
+ **
4
+ ** Created: ven lug 1 15:40:38 2011
5
+ ** by: Qt User Interface Compiler version 4.7.3
6
+ **
7
+ ** WARNING! All changes made in this file will be lost when recompiling ui file!
8
+ =end
9
+
10
+ class Ui_SyntaxCheckerConfigWidget
11
+ attr_reader :horizontalLayout
12
+ attr_reader :label
13
+ attr_reader :_syntax_checker__time_interval
14
+
15
+ def setupUi(syntaxCheckerConfigWidget)
16
+ if syntaxCheckerConfigWidget.objectName.nil?
17
+ syntaxCheckerConfigWidget.objectName = "syntaxCheckerConfigWidget"
18
+ end
19
+ syntaxCheckerConfigWidget.resize(400, 40)
20
+ @horizontalLayout = Qt::HBoxLayout.new(syntaxCheckerConfigWidget)
21
+ @horizontalLayout.objectName = "horizontalLayout"
22
+ @label = Qt::Label.new(syntaxCheckerConfigWidget)
23
+ @label.objectName = "label"
24
+
25
+ @horizontalLayout.addWidget(@label)
26
+
27
+ @_syntax_checker__time_interval = Qt::SpinBox.new(syntaxCheckerConfigWidget)
28
+ @_syntax_checker__time_interval.objectName = "_syntax_checker__time_interval"
29
+ @_syntax_checker__time_interval.maximum = 999
30
+ @_syntax_checker__time_interval.value = 1
31
+
32
+ @horizontalLayout.addWidget(@_syntax_checker__time_interval)
33
+
34
+ @label.buddy = @_syntax_checker__time_interval
35
+
36
+ retranslateUi(syntaxCheckerConfigWidget)
37
+
38
+ Qt::MetaObject.connectSlotsByName(syntaxCheckerConfigWidget)
39
+ end # setupUi
40
+
41
+ def setup_ui(syntaxCheckerConfigWidget)
42
+ setupUi(syntaxCheckerConfigWidget)
43
+ end
44
+
45
+ def retranslateUi(syntaxCheckerConfigWidget)
46
+ syntaxCheckerConfigWidget.windowTitle = Qt::Application.translate("SyntaxCheckerConfigWidget", "Syntax Checker", nil, Qt::Application::UnicodeUTF8)
47
+ @label.text = Qt::Application.translate("SyntaxCheckerConfigWidget", "&Inactivity time before checking syntax (s)", nil, Qt::Application::UnicodeUTF8)
48
+ @_syntax_checker__time_interval.specialValueText = Qt::Application.translate("SyntaxCheckerConfigWidget", "Disable timed syntax check", nil, Qt::Application::UnicodeUTF8)
49
+ end # retranslateUi
50
+
51
+ def retranslate_ui(syntaxCheckerConfigWidget)
52
+ retranslateUi(syntaxCheckerConfigWidget)
53
+ end
54
+
55
+ end
56
+
57
+ module Ui
58
+ class SyntaxCheckerConfigWidget < Ui_SyntaxCheckerConfigWidget
59
+ end
60
+ end # module Ui
61
+
@@ -0,0 +1,44 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <ui version="4.0">
3
+ <class>SyntaxCheckerConfigWidget</class>
4
+ <widget class="QWidget" name="SyntaxCheckerConfigWidget">
5
+ <property name="geometry">
6
+ <rect>
7
+ <x>0</x>
8
+ <y>0</y>
9
+ <width>400</width>
10
+ <height>40</height>
11
+ </rect>
12
+ </property>
13
+ <property name="windowTitle">
14
+ <string>Syntax Checker</string>
15
+ </property>
16
+ <layout class="QHBoxLayout" name="horizontalLayout">
17
+ <item>
18
+ <widget class="QLabel" name="label">
19
+ <property name="text">
20
+ <string>&amp;Inactivity time before checking syntax (s)</string>
21
+ </property>
22
+ <property name="buddy">
23
+ <cstring>_syntax_checker__time_interval</cstring>
24
+ </property>
25
+ </widget>
26
+ </item>
27
+ <item>
28
+ <widget class="QSpinBox" name="_syntax_checker__time_interval">
29
+ <property name="specialValueText">
30
+ <string>Disable timed syntax check</string>
31
+ </property>
32
+ <property name="maximum">
33
+ <number>999</number>
34
+ </property>
35
+ <property name="value">
36
+ <number>1</number>
37
+ </property>
38
+ </widget>
39
+ </item>
40
+ </layout>
41
+ </widget>
42
+ <resources/>
43
+ <connections/>
44
+ </ui>
@@ -0,0 +1,11 @@
1
+ name: yaml_syntax_checker
2
+ version: 0.0.1
3
+ about:
4
+ authors: [Stefano Crocco, stefano.crocco@alice.it]
5
+ license: :gpl
6
+ description: Syntax checker for YAML documents. Requires the syntax checker plugin
7
+ icon: tools-check-spelling
8
+ bug_address: http://github.com/stcrocco/ruber/issues
9
+ class: Ruber::YAMLSyntaxChecker::Plugin
10
+ require: yaml_syntax_checker
11
+ deps: syntax_checker
@@ -0,0 +1,62 @@
1
+ =begin
2
+ Copyright (C) 2010, 2011 by Stefano Crocco
3
+ stefano.crocco@alice.it
4
+
5
+ This program is free software; you can redistribute it andor modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation; either version 2 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program; if not, write to the
17
+ Free Software Foundation, Inc.,
18
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
+ =end
20
+
21
+ require 'yaml'
22
+
23
+ module Ruber
24
+
25
+ module YAMLSyntaxChecker
26
+
27
+ SyntaxError = Struct.new :line, :column, :message, :formatted_message
28
+
29
+ class Plugin < Ruber::Plugin
30
+
31
+ def initialize psf
32
+ super
33
+ Ruber[:syntax_checker].register_syntax_checker YAMLSyntaxChecker::Checker,
34
+ [], ['*.yaml']
35
+ end
36
+
37
+ def unload
38
+ Ruber[:syntax_checker].remove_syntax_checker YAMLSyntaxChecker::Checker
39
+ end
40
+
41
+ end
42
+
43
+ class Checker
44
+
45
+ def check_syntax str, format
46
+ begin
47
+ YAML.parse str
48
+ nil
49
+ rescue ArgumentError => e
50
+ match = e.message.match %r{syntax error on line\s+(-?\d+),\s+col\s+(-?\d+)}i
51
+ return [] unless match
52
+ line = [match[1].to_i, 0].max
53
+ col = [match[2].to_i, 0].max
54
+ [SyntaxError.new(line, col, 'Syntax error', 'Syntax error')]
55
+ end
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+
62
+ end
File without changes
@@ -5,7 +5,114 @@ require 'tempfile'
5
5
 
6
6
  module InsertionChecker
7
7
 
8
- def it_should_insert_end cond, text, initial_text, exp_text, cursor_pos = [2, 0]
8
+ def it_checks_for_syntax_errors_when cond, inserted_text, existing_text = ''
9
+ lines = existing_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 ||= [existing_text.each_line.count, 0]
16
+ insert_pos = KTextEditor::Cursor.new *insert_pos
17
+
18
+ context "when #{cond}" do
19
+
20
+ context 'and the document is active' do
21
+
22
+ before do
23
+ @doc.activate
24
+ @view = @doc.create_view
25
+ @doc.text = ''
26
+ flexmock(@doc).should_receive(:active_view).and_return @view
27
+ @doc.block_signals true
28
+ @doc.text= existing_text.sub '%', ''
29
+ @doc.block_signals false
30
+ #avoid messing up the text with indentation
31
+ flexmock(@view).should_receive(:execute_action).with('tools_align').by_default
32
+ end
33
+
34
+ it 'checks the syntax of the document' do
35
+ flexmock(@doc.extension(:syntax_checker)).should_receive(:check_syntax).with(:format => false, :update => false).once.and_return :errors => []
36
+ @doc.insert_text insert_pos, inserted_text
37
+ end
38
+
39
+ end
40
+
41
+ context 'and the active view is not associated with the document' do
42
+
43
+ before do
44
+ @doc.deactivate
45
+ flexmock(@doc.extension(:syntax_checker)).should_receive(:check_syntax).never
46
+ end
47
+
48
+ it 'does nothing' do
49
+ flexmock(@doc).should_receive(:active_view).and_return nil
50
+ old_text = @doc.text
51
+ @doc.insert_text insert_pos, inserted_text
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+
58
+ end
59
+
60
+ def it_doesnt_check_for_syntax_errors_when cond, line, existing_text = ''
61
+
62
+ lines = existing_text.split "\n"
63
+ insert_pos = lines.find_and_map do |l|
64
+ if l.include? '%'
65
+ [lines.index(l), l.index('%')]
66
+ end
67
+ end
68
+ insert_pos ||= [existing_text.each_line.count, 0]
69
+ insert_pos = KTextEditor::Cursor.new *insert_pos
70
+
71
+ context "when #{cond}" do
72
+
73
+ context "and the view is active" do
74
+
75
+ before do
76
+ @doc.activate
77
+ @view = @doc.create_view
78
+ @doc.text = ''
79
+ flexmock(@doc).should_receive(:active_view).and_return @view
80
+ @doc.block_signals true
81
+ @doc.text= existing_text.sub '%', ''
82
+ @doc.block_signals false
83
+ #avoid messing up the text with indentation
84
+ flexmock(@view).should_receive(:execute_action).with('tools_align').by_default
85
+ end
86
+
87
+ it 'doesn\'t check the syntax of the document' do
88
+ flexmock(@doc.extension(:syntax_checker)).should_receive(:check_syntax).never
89
+ @doc.insert_text insert_pos, line
90
+ end
91
+
92
+ end
93
+
94
+ context 'and the active view is not associated with the document' do
95
+
96
+ before do
97
+ @doc.deactivate
98
+ flexmock(@doc.extension(:syntax_checker)).should_receive(:check_syntax).never
99
+ end
100
+
101
+ it 'does nothing' do
102
+ flexmock(@doc).should_receive(:active_view).and_return nil
103
+ old_text = @doc.text
104
+ @doc.insert_text insert_pos, line
105
+ end
106
+
107
+ end
108
+
109
+
110
+ end
111
+
112
+
113
+ end
114
+
115
+ def it_should_insert_end cond, text, initial_text, exp_text, error_type, cursor_pos = [2, 0], error_message = ''
9
116
  lines = initial_text.split "\n"
10
117
  insert_pos = lines.find_and_map do |l|
11
118
  if l.include? '%'
@@ -21,12 +128,15 @@ module InsertionChecker
21
128
 
22
129
  before do
23
130
  @view = @doc.create_view
131
+ @doc.text = ''
24
132
  flexmock(@doc).should_receive(:active_view).and_return @view
25
133
  @doc.block_signals true
26
134
  @doc.text= initial_text.sub '%', ''
27
135
  @doc.block_signals false
28
136
  #avoid messing up the text with indentation
29
137
  flexmock(@view).should_receive(:execute_action).with('tools_align').by_default
138
+ error = {:errors => [OpenStruct.new(:error_type => error_type, :error_message => error_message)]}
139
+ flexmock(@doc.extension(:syntax_checker)).should_receive(:check_syntax).with(:format => false, :update => false).once.and_return error
30
140
  end
31
141
 
32
142
  it "inserts an an empty line followed by and end keyword" do
@@ -49,6 +159,10 @@ module InsertionChecker
49
159
 
50
160
  context 'and the active view is not associated with the document' do
51
161
 
162
+ before do
163
+ flexmock(@doc.extension(:syntax_checker)).should_receive(:check_syntax).never
164
+ end
165
+
52
166
  it 'does nothing' do
53
167
  flexmock(@doc).should_receive(:active_view).and_return nil
54
168
  old_text = @doc.text
@@ -68,6 +182,14 @@ describe Ruber::AutoEnd::Extension do
68
182
 
69
183
  extend InsertionChecker
70
184
 
185
+ before :all do
186
+ Ruber[:components].load_plugin 'plugins/autosave'
187
+ Ruber[:components].load_plugin 'plugins/ruby_runner'
188
+ Ruber[:components].load_plugin 'plugins/ruby_development'
189
+ Ruber[:components].load_plugin 'plugins/syntax_checker'
190
+ Ruber[:components].load_plugin 'plugins/ruby_syntax_checker'
191
+ end
192
+
71
193
  before do
72
194
  Ruber[:components].load_plugin 'plugins/auto_end/'
73
195
  @file = Tempfile.new ['auto_end_test', '.rb']
@@ -80,6 +202,14 @@ describe Ruber::AutoEnd::Extension do
80
202
  @file.close true
81
203
  end
82
204
 
205
+ after :all do
206
+ Ruber[:components].unload_plugin :ruby_syntax_checker
207
+ Ruber[:components].unload_plugin :syntax_checker
208
+ Ruber[:components].unload_plugin :ruby_development
209
+ Ruber[:components].unload_plugin :autosave
210
+ Ruber[:components].unload_plugin :ruby_runner
211
+ end
212
+
83
213
  it 'includes the Extension module' do
84
214
  Ruber::AutoEnd::Extension.should include(Ruber::Extension)
85
215
  end
@@ -110,195 +240,114 @@ describe Ruber::AutoEnd::Extension do
110
240
 
111
241
  context 'when a piece of text ending with a newline is inserted' do
112
242
 
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
243
+ it_checks_for_syntax_errors_when 'the line contains the word "module"', "abc module xyz\n"
130
244
 
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
245
+ it_checks_for_syntax_errors_when 'the line contains the word "class"', "abc class xyz\n"
142
246
 
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
247
+ it_checks_for_syntax_errors_when 'the line contains the word "if" preceded only by whitespaces', " if abc\n"
150
248
 
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
249
+ it_checks_for_syntax_errors_when 'the line contains the word "if" preceded by an equal sign whitespaces', "a = if abc\n"
163
250
 
164
- context "and the last line contains a for followed by an identifier, and in and some other characters" do
165
-
166
- it_should_insert_end "if the for is at the beginning of the line", "for kkk in abc\n", "class X\n%\nend", "class X\nfor kkk in abc\n\nend\nend", [2, 0]
167
-
168
- it_should_insert_end "if the for is preceded only by whitespaces", " for kkk in abc\n", "class X\n%\nend", "class X\n for kkk in abc\n\nend\nend", [2, 0]
169
-
170
- it_should_insert_end 'if the for is preceded by an =', "x =for kkk in abc\n",
171
- "class X\n%\nend", "class X\nx =for kkk in abc\n\nend\nend"
172
-
173
- it_should_insert_end 'if the for is preceded by an = followed by spaces', "x = for kkk in abc\n", "class X\n%\nend", "class X\nx = for kkk in abc\n\nend\nend"
174
-
175
- end
176
-
177
- context "and the last line contains an unless" do
178
-
179
- it_should_insert_end "if the unless is at the beginning of the line", "unless kkk\n", "class X\n%\nend", "class X\nunless kkk\n\nend\nend", [2, 0]
180
-
181
- it_should_insert_end "if the unless is preceded only by whitespaces", " unless kkk\n", "class X\n%\nend", "class X\n unless kkk\n\nend\nend", [2, 0]
182
-
183
- it_should_insert_end 'if the unless is preceded by an =', "x =unless kkk\n",
184
- "class X\n%\nend", "class X\nx =unless kkk\n\nend\nend"
185
-
186
- it_should_insert_end 'if the unless is preceded by an = followed by spaces', "x = unless kkk\n", "class X\n%\nend", "class X\nx = unless kkk\n\nend\nend"
187
-
188
- end
251
+ it_doesnt_check_for_syntax_errors_when 'the line contains the word "if" preceded by anything other than an equal sign and/or spaces', "abc if xyz\n"
189
252
 
190
- context "and the last line contains a while" do
191
-
192
- it_should_insert_end "if the while is at the beginning of the line", "while kkk\n", "class X\n%\nend", "class X\nwhile kkk\n\nend\nend", [2, 0]
193
-
194
- it_should_insert_end "if the while is preceded only by whitespaces", " while kkk\n", "class X\n%\nend", "class X\n while kkk\n\nend\nend", [2, 0]
195
-
196
- end
253
+ it_checks_for_syntax_errors_when 'the line contains the word "unless" at the beginning of the line, maybe preceded only by spaces', " unless xyz\n"
197
254
 
198
- context "and the last line contains a until" do
199
-
200
- it_should_insert_end "if the until is at the beginning of the line", "until kkk\n", "class X\n%\nend", "class X\nuntil kkk\n\nend\nend", [2, 0]
201
-
202
- it_should_insert_end "if the until is preceded only by whitespaces", " until kkk\n", "class X\n%\nend", "class X\n until kkk\n\nend\nend", [2, 0]
203
-
204
- end
255
+ it_checks_for_syntax_errors_when 'the line contains the word "unless" preceded by an equal sign and maybe by spaces', " abc = unless xyz\n"
205
256
 
206
- context "and the line contains a do" do
207
-
208
- 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]
209
-
210
- 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]
211
-
212
- 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]
213
-
214
- it 'does nothing if the first character of the line is a #' do
215
- @doc.block_signals true
216
- @doc.text = "def x\n\nend"
217
- @doc.block_signals false
218
- @doc.insert_text KTextEditor::Cursor.new(1,0), "# a.each do\n"
219
- @doc.text.should == "def x\n# a.each do\n\nend"
220
- end
221
-
222
- it 'does nothing if the line starts with spaces followed by a #' do
223
- @doc.block_signals true
224
- @doc.text = "def x\n\nend"
225
- @doc.block_signals false
226
- @doc.insert_text KTextEditor::Cursor.new(1,0), " # a.each do\n"
227
- @doc.text.should == "def x\n # a.each do\n\nend"
228
- end
229
-
230
- end
257
+ it_doesnt_check_for_syntax_errors_when 'the line contains the "unless" word, but not at the beginning of line or preceded by an equal sign', " abc unless xyz"
231
258
 
232
- context "and the last line contains a begin" do
259
+ it_checks_for_syntax_errors_when 'the line contains the word "do" followed by optional spaces the end of line', "abc do\n"
260
+
261
+ it_checks_for_syntax_errors_when 'the line contains the word "do" followed by optional spaces and the pipe character', "abc do |xyz| \n"
262
+
263
+ it_doesnt_check_for_syntax_errors_when 'the line contains "do" but not as a standalone word', "abcdo\n"
264
+
265
+ it_doesnt_check_for_syntax_errors_when 'the line contains the word do but it is followed by something other than the end of line or a pipe character', "abc do xyz"
266
+
267
+ it_checks_for_syntax_errors_when 'the line contains the word "def" at the begining of line (optionally preceded by spaces) and followed by a space', " def \n"
268
+
269
+ it_doesnt_check_for_syntax_errors_when 'the line contains the word "def" but not at the beginning of the line (optionally preceded by spaces)', "abc def \n"
270
+
271
+ it_doesnt_check_for_syntax_errors_when 'the line contains the string "def" but not followed by spaces', " defx \n"
272
+
273
+ it_checks_for_syntax_errors_when 'the line contains the word "case" at the beginning of the line, maybe preceded only by spaces', " case xyz\n"
274
+
275
+ it_checks_for_syntax_errors_when 'the line contains the word "case" preceded by an equal sign and maybe by spaces', " abc = case xyz\n"
276
+
277
+ it_doesnt_check_for_syntax_errors_when 'the line contains the "case" word, but not at the beginning of line or preceded by an equal sign', " abc case xyz"
278
+
279
+ it_checks_for_syntax_errors_when 'the line contains the word "while" at the beginning of the line, maybe preceded only by spaces', " while xyz\n"
280
+
281
+ it_doesnt_check_for_syntax_errors_when 'the line contains the "while" word, but not at the beginning of line or preceded by an equal sign', " abc while xyz"
282
+
283
+ it_checks_for_syntax_errors_when 'the line contains the word "until" at the beginning of the line, maybe preceded only by spaces', " until xyz\n"
284
+
285
+ it_doesnt_check_for_syntax_errors_when 'the line contains the "until" word, but not at the beginning of line or preceded by an equal sign', " abc until xyz"
286
+
287
+ it_checks_for_syntax_errors_when 'the line contains the word "for" at the beginning of the line, maybe preceded only by spaces', " for xyz\n"
288
+
289
+ it_checks_for_syntax_errors_when 'the line contains the word "for" preceded by an equal sign and maybe by spaces', " abc = for xyz\n"
290
+
291
+ it_doesnt_check_for_syntax_errors_when 'the line contains the "for" word, but not at the beginning of line or preceded by an equal sign', " abc for xyz"
292
+
293
+ it_checks_for_syntax_errors_when 'the line contains the word "begin" at the beginning of the line, maybe preceded by spaces', " begin xyz\n"
294
+
295
+ it_checks_for_syntax_errors_when 'the line contains the word "begin" preceded by an equal sign and optionally by space', " a = begin xyz\n"
296
+
297
+ context ', the syntax check returns errors' do
298
+
299
+ before do
300
+ @view = @doc.create_view
301
+ @doc.text = ''
302
+ flexmock(@doc).should_receive(:active_view).and_return @view
303
+ #avoid messing up the text with indentation
304
+ flexmock(@view).should_receive(:execute_action).with('tools_align').by_default
305
+ @doc.activate
306
+ end
233
307
 
234
- 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]
308
+ context 'and the last error is of type :missing_end' do
309
+
310
+ before do
311
+ errors = {:errors => [OpenStruct.new(:error_type => :xyz, :error_message => ''), OpenStruct.new(:error_type => :missing_end, :error_message => 'missing kEND')]}
312
+ flexmock(@doc.extension(:syntax_checker)).should_receive(:check_syntax).with(:format => false, :update => false).once.and_return errors
235
313
 
236
- 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]
237
-
238
- it_should_insert_end 'if the begin is preceded by an =', "x =begin kkk\n",
239
- "class X\n%\nend", "class X\nx =begin kkk\n\nend\nend"
240
-
241
- 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"
314
+ end
315
+
316
+ it "inserts an an empty line followed by an =end if the line starts with =begin" do
317
+ @doc.insert_text KTextEditor::Cursor.new, "abc\n=begin xyz\n"
318
+ @doc.text.should == "abc\n=begin xyz\n\n=end"
319
+ end
320
+
321
+ it 'inserts an empty line followed by an end keyword if the line starts with something other than =begin' do
322
+ @doc.insert_text KTextEditor::Cursor.new, "abc\ndef xyz\n"
323
+ @doc.text.should == "abc\ndef xyz\n\nend"
324
+ end
325
+
326
+ it 'indents the text' do
327
+ flexmock(@view).should_receive(:execute_action).with('tools_align').once
328
+ @doc.insert_text KTextEditor::Cursor.new, "def xyz\n"
329
+ end
330
+
331
+ it 'moves the cursor to the line before the end' do
332
+ @doc.insert_text KTextEditor::Cursor.new, "def xyz\n"
333
+ @view.cursor_position.should == KTextEditor::Cursor.new(1,0)
334
+ end
335
+
336
+ end
242
337
 
243
- it 'does nothing if the line starts with =begin ' do
244
- @doc.block_signals true
245
- @doc.text = "def x\n\nend"
246
- @doc.block_signals false
247
- @doc.insert_text KTextEditor::Cursor.new(1,0), "=begin \n"
248
- @doc.text.should == "def x\n=begin \n\nend"
338
+ context 'and the last error is not of type :missing_end' do
339
+
340
+ it 'doesn\'t alter the text' do
341
+ errors = {:errors => [OpenStruct.new(:error_type => :xyz, :error_message => ''), OpenStruct.new(:error_type => :abc, :error_message => '')]}
342
+ flexmock(@doc.extension(:syntax_checker)).should_receive(:check_syntax).with(:format => false, :update => false).once.and_return errors
343
+ @doc.insert_text KTextEditor::Cursor.new, "def a\nxyz)"
344
+ @doc.text.should == "def a\nxyz)"
345
+ end
346
+
249
347
  end
250
-
251
348
 
252
349
  end
253
350
 
254
- context "and the last line starts with =begin" do
255
- pending
256
- # context "and the active view is associated with the document" do
257
- #
258
- # before do
259
- # @view = @doc.create_view
260
- # flexmock(@doc).should_receive(:active_view).and_return @view
261
- # @doc.block_signals true
262
- # @doc.text= "abc\n"
263
- # @doc.block_signals false
264
- # @insert_pos = KTextEditor::Cursor.new(1,0)
265
- # #avoid messing up the text with indentation
266
- # flexmock(@view).should_receive(:execute_action).with('tools_align').by_default
267
- # end
268
- #
269
- # it "inserts an an empty line followed by a =end" do
270
- # @doc.insert_text @insert_pos, "=begin xyz\n"
271
- # @doc.text.should == "abc\n=begin xyz\n\n=end"
272
- # end
273
- #
274
- # it 'indents the text' do
275
- # flexmock(@view).should_receive(:execute_action).with('tools_align').once
276
- # @doc.insert_text @insert_pos, "=begin xyz\n"
277
- # end
278
- #
279
- # it 'moves the cursor to the line before the end' do
280
- # @doc.insert_text @insert_pos, "=begin xyz\n"
281
- # @view.cursor_position.should == KTextEditor::Cursor.new(2,0)
282
- # end
283
- #
284
- # end
285
- #
286
- # context 'and the active view is not associated with the document' do
287
- #
288
- # it 'does nothing' do
289
- # flexmock(@doc).should_receive(:active_view).and_return nil
290
- # @doc.block_signals true
291
- # old_text = "abc\n"
292
- # @doc.text = old_text
293
- # @doc.block_signals false
294
- # @doc.insert_text KTextEditor::Cursor.new(1,0), "=begin xyz\n"
295
- # @doc.text.should == "abc\n=begin xyz\n"
296
- # end
297
- #
298
- # end
299
- #
300
- end
301
-
302
351
  end
303
352
 
304
353
  it 'doesn\'t insert end keywords in the middle of a multi-line text' do
@@ -309,15 +358,4 @@ describe Ruber::AutoEnd::Extension do
309
358
  @doc.text.should == text
310
359
  end
311
360
 
312
- it 'doesn\'t insert an end keyword if the following line is more indented than the current one' do
313
- view = @doc.create_view
314
- flexmock(@doc).should_receive(:active_view).and_return view
315
- text = "class X\n def y\n abc"
316
- @doc.block_signals true
317
- @doc.insert_text KTextEditor::Cursor.new(0,0), text
318
- @doc.block_signals false
319
- @doc.insert_text KTextEditor::Cursor.new(1,8), "\nY"
320
- @doc.text.should == "class X\n def y\nY\n abc"
321
- end
322
-
323
361
  end