ruber 0.0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +339 -0
- data/INSTALL +137 -0
- data/LICENSE +8 -0
- data/bin/ruber +65 -0
- data/data/share/apps/ruber/core_components.yaml +31 -0
- data/data/share/apps/ruber/ruberui.rc +109 -0
- data/data/share/icons/ruber.png +0 -0
- data/data/share/pixmaps/ruby.png +0 -0
- data/icons/ruber-16.png +0 -0
- data/icons/ruber-32.png +0 -0
- data/icons/ruber-48.png +0 -0
- data/icons/ruber-8.png +0 -0
- data/lib/ruber/application/application.rb +288 -0
- data/lib/ruber/application/plugin.yaml +11 -0
- data/lib/ruber/component_manager.rb +899 -0
- data/lib/ruber/config/config.rb +82 -0
- data/lib/ruber/config/plugin.yaml +3 -0
- data/lib/ruber/document_project.rb +209 -0
- data/lib/ruber/documents/document_list.rb +416 -0
- data/lib/ruber/documents/plugin.yaml +4 -0
- data/lib/ruber/editor/document.rb +506 -0
- data/lib/ruber/editor/editor_view.rb +167 -0
- data/lib/ruber/editor/ktexteditor_wrapper.rb +202 -0
- data/lib/ruber/exception_widgets.rb +245 -0
- data/lib/ruber/external_program_plugin.rb +397 -0
- data/lib/ruber/filtered_output_widget.rb +342 -0
- data/lib/ruber/gui_states_handler.rb +231 -0
- data/lib/ruber/kde_config_option_backend.rb +167 -0
- data/lib/ruber/kde_sugar.rb +249 -0
- data/lib/ruber/main_window/choose_plugins_dlg.rb +353 -0
- data/lib/ruber/main_window/main_window.rb +524 -0
- data/lib/ruber/main_window/main_window_actions.rb +537 -0
- data/lib/ruber/main_window/main_window_internal.rb +239 -0
- data/lib/ruber/main_window/open_file_in_project_dlg.rb +212 -0
- data/lib/ruber/main_window/output_color_widget.rb +35 -0
- data/lib/ruber/main_window/plugin.yaml +58 -0
- data/lib/ruber/main_window/save_modified_files_dlg.rb +89 -0
- data/lib/ruber/main_window/status_bar.rb +156 -0
- data/lib/ruber/main_window/ui/choose_plugins_widget.rb +90 -0
- data/lib/ruber/main_window/ui/choose_plugins_widget.ui +77 -0
- data/lib/ruber/main_window/ui/main_window_settings_widget.rb +108 -0
- data/lib/ruber/main_window/ui/main_window_settings_widget.ui +89 -0
- data/lib/ruber/main_window/ui/new_project_widget.rb +119 -0
- data/lib/ruber/main_window/ui/new_project_widget.ui +178 -0
- data/lib/ruber/main_window/ui/open_file_in_project_dlg.rb +109 -0
- data/lib/ruber/main_window/ui/open_file_in_project_dlg.ui +168 -0
- data/lib/ruber/main_window/ui/output_color_widget.rb +241 -0
- data/lib/ruber/main_window/ui/output_color_widget.ui +204 -0
- data/lib/ruber/main_window/workspace.rb +442 -0
- data/lib/ruber/output_widget.rb +1093 -0
- data/lib/ruber/plugin.rb +264 -0
- data/lib/ruber/plugin_like.rb +589 -0
- data/lib/ruber/plugin_specification.rb +106 -0
- data/lib/ruber/plugin_specification_reader.rb +451 -0
- data/lib/ruber/project.rb +493 -0
- data/lib/ruber/project_backend.rb +105 -0
- data/lib/ruber/projects/plugin.yaml +11 -0
- data/lib/ruber/projects/project_files_list.rb +314 -0
- data/lib/ruber/projects/project_files_widget.rb +301 -0
- data/lib/ruber/projects/project_list.rb +314 -0
- data/lib/ruber/projects/ui/project_files_rule_chooser_widget.rb +74 -0
- data/lib/ruber/projects/ui/project_files_rule_chooser_widget.ui +61 -0
- data/lib/ruber/projects/ui/project_files_widget.rb +117 -0
- data/lib/ruber/projects/ui/project_files_widget.ui +123 -0
- data/lib/ruber/qt_sugar.rb +673 -0
- data/lib/ruber/settings_container.rb +515 -0
- data/lib/ruber/settings_dialog.rb +244 -0
- data/lib/ruber/settings_dialog_manager.rb +503 -0
- data/lib/ruber/utils.rb +414 -0
- data/lib/ruber/yaml_option_backend.rb +159 -0
- data/outsider_files +15 -0
- data/plugins/autosave/autosave.rb +404 -0
- data/plugins/autosave/plugin.yaml +16 -0
- data/plugins/autosave/ui/autosave_config_widget.rb +83 -0
- data/plugins/autosave/ui/autosave_config_widget.ui +68 -0
- data/plugins/command/command.png +0 -0
- data/plugins/command/command.rb +74 -0
- data/plugins/command/plugin.yaml +11 -0
- data/plugins/find_in_files/find_in_files.rb +337 -0
- data/plugins/find_in_files/find_in_files_dlg.rb +411 -0
- data/plugins/find_in_files/find_in_files_ui.rc +11 -0
- data/plugins/find_in_files/find_in_files_widgets.rb +485 -0
- data/plugins/find_in_files/plugin.yaml +23 -0
- data/plugins/find_in_files/ui/config_widget.rb +58 -0
- data/plugins/find_in_files/ui/config_widget.ui +41 -0
- data/plugins/find_in_files/ui/find_in_files_widget.rb +260 -0
- data/plugins/find_in_files/ui/find_in_files_widget.ui +324 -0
- data/plugins/project_browser/plugin.yaml +10 -0
- data/plugins/project_browser/project_browser.rb +245 -0
- data/plugins/rake/plugin.yaml +39 -0
- data/plugins/rake/rake.png +0 -0
- data/plugins/rake/rake.rb +567 -0
- data/plugins/rake/rake_extension.rb +153 -0
- data/plugins/rake/rake_widgets.rb +615 -0
- data/plugins/rake/rakeui.rc +27 -0
- data/plugins/rake/ui/add_quick_task_widget.rb +71 -0
- data/plugins/rake/ui/add_quick_task_widget.ui +59 -0
- data/plugins/rake/ui/choose_task_widget.rb +77 -0
- data/plugins/rake/ui/choose_task_widget.ui +72 -0
- data/plugins/rake/ui/config_widget.rb +127 -0
- data/plugins/rake/ui/config_widget.ui +123 -0
- data/plugins/rake/ui/project_widget.rb +217 -0
- data/plugins/rake/ui/project_widget.ui +246 -0
- data/plugins/rspec/plugin.yaml +30 -0
- data/plugins/rspec/rspec.png +0 -0
- data/plugins/rspec/rspec.rb +945 -0
- data/plugins/rspec/rspec.svg +90 -0
- data/plugins/rspec/rspecui.rc +20 -0
- data/plugins/rspec/ruber_rspec_formatter.rb +312 -0
- data/plugins/rspec/ui/rspec_project_widget.rb +170 -0
- data/plugins/rspec/ui/rspec_project_widget.ui +193 -0
- data/plugins/ruby_development/plugin.yaml +27 -0
- data/plugins/ruby_development/ruby_development.png +0 -0
- data/plugins/ruby_development/ruby_development.rb +453 -0
- data/plugins/ruby_development/ruby_developmentui.rc +19 -0
- data/plugins/ruby_development/ui/project_widget.rb +112 -0
- data/plugins/ruby_development/ui/project_widget.ui +108 -0
- data/plugins/ruby_runner/config_widget.rb +116 -0
- data/plugins/ruby_runner/plugin.yaml +26 -0
- data/plugins/ruby_runner/project_widget.rb +62 -0
- data/plugins/ruby_runner/ruby.png +0 -0
- data/plugins/ruby_runner/ruby_interpretersui.rc +26 -0
- data/plugins/ruby_runner/ruby_runner.rb +411 -0
- data/plugins/ruby_runner/ui/config_widget.rb +92 -0
- data/plugins/ruby_runner/ui/config_widget.ui +91 -0
- data/plugins/ruby_runner/ui/project_widget.rb +60 -0
- data/plugins/ruby_runner/ui/project_widget.ui +48 -0
- data/plugins/ruby_runner/ui/ruby_runnner_plugin_option_widget.rb +59 -0
- data/plugins/ruby_runner/ui/ruby_runnner_plugin_option_widget.ui +44 -0
- data/plugins/state/plugin.yaml +28 -0
- data/plugins/state/state.rb +520 -0
- data/plugins/state/ui/config_widget.rb +92 -0
- data/plugins/state/ui/config_widget.ui +89 -0
- data/plugins/syntax_checker/plugin.yaml +18 -0
- data/plugins/syntax_checker/syntax_checker.rb +662 -0
- data/ruber.desktop +10 -0
- data/spec/annotation_model_spec.rb +174 -0
- data/spec/common.rb +119 -0
- data/spec/component_manager_spec.rb +1259 -0
- data/spec/document_list_spec.rb +626 -0
- data/spec/document_project_spec.rb +373 -0
- data/spec/document_spec.rb +779 -0
- data/spec/editor_view_spec.rb +167 -0
- data/spec/external_program_plugin_spec.rb +676 -0
- data/spec/filtered_output_widget_spec.rb +642 -0
- data/spec/gui_states_handler_spec.rb +304 -0
- data/spec/kde_config_option_backend_spec.rb +214 -0
- data/spec/kde_sugar_spec.rb +101 -0
- data/spec/ktexteditor_wrapper_spec.rb +305 -0
- data/spec/output_widget_spec.rb +1703 -0
- data/spec/plugin_spec.rb +1393 -0
- data/spec/plugin_specification_reader_spec.rb +1765 -0
- data/spec/plugin_specification_spec.rb +401 -0
- data/spec/project_backend_spec.rb +172 -0
- data/spec/project_files_list_spec.rb +401 -0
- data/spec/project_list_spec.rb +511 -0
- data/spec/project_spec.rb +990 -0
- data/spec/qt_sugar_spec.rb +328 -0
- data/spec/settings_container_spec.rb +617 -0
- data/spec/settings_dialog_manager_spec.rb +773 -0
- data/spec/settings_dialog_spec.rb +419 -0
- data/spec/state_spec.rb +991 -0
- data/spec/utils_spec.rb +406 -0
- data/spec/workspace_spec.rb +869 -0
- data/spec/yaml_option_backend_spec.rb +246 -0
- metadata +284 -0
@@ -0,0 +1,167 @@
|
|
1
|
+
require 'spec/common'
|
2
|
+
|
3
|
+
require 'tempfile'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'flexmock/argument_types'
|
6
|
+
require 'facets/string/camelcase'
|
7
|
+
|
8
|
+
require 'ruber/editor/editor_view'
|
9
|
+
require 'ruber/editor/document'
|
10
|
+
|
11
|
+
describe Ruber::EditorView do
|
12
|
+
|
13
|
+
def self.test_auto_signal s, signal_args = [], pending_info = nil
|
14
|
+
signal_args = [signal_args] unless signal_args.is_a? Array
|
15
|
+
sig = s.sub('@', 'QWidget*')
|
16
|
+
s_args = s.match(/\((.*)\)/)[0].split(/\s*,\s*/)
|
17
|
+
s_args.map! do |a|
|
18
|
+
case a
|
19
|
+
when 'QString' then String
|
20
|
+
when 'QList' then Array
|
21
|
+
when 'QHash' then Hash
|
22
|
+
when /^Q/ then Qt.const_get(a[1..-1])
|
23
|
+
when /^KTextEditor/ then KTextEditor.const_get(a.sub(/^KTextEditor::/,''))
|
24
|
+
when /u?int/ then Integer
|
25
|
+
when 'double' then Double
|
26
|
+
else nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
has_view_arg = s.match(/@/)
|
30
|
+
o_sig = s.camelcase(false).sub(/\((.*?)(?:,\s+)?(@)\)/) do |s|
|
31
|
+
res = '('
|
32
|
+
res += 'KTextEditor::View*' + (!$1.empty? ? ', ' : '') if $2
|
33
|
+
res += ($1 || '')+')'
|
34
|
+
res
|
35
|
+
end
|
36
|
+
it "should emit the \"#{sig}\" signal in response to the underlying KTextEditor::View #{o_sig} signal" do
|
37
|
+
prc = lambda do
|
38
|
+
mock = flexmock('mock')
|
39
|
+
if has_view_arg
|
40
|
+
mock.should_receive(:test).once.with(@view.object_id)
|
41
|
+
else mock.should_receive(:test).once.with_no_args
|
42
|
+
end
|
43
|
+
signal_args.unshift 'self' if has_view_arg
|
44
|
+
@view.connect(SIGNAL(sig)) do |*args|
|
45
|
+
v = args.pop if has_view_arg
|
46
|
+
s_args.each_with_index do |a, i|
|
47
|
+
args[i].should be_kind_of a if a
|
48
|
+
end
|
49
|
+
has_view_arg ? mock.test(@view.object_id) : mock.test
|
50
|
+
end
|
51
|
+
v = @view.instance_variable_get :@view
|
52
|
+
code = "b = binding; emit #{o_sig[/[^(]*/]}(#{signal_args.map{|a| "eval( '#{a}', b)"}.join(',')})"
|
53
|
+
v.instance_eval code
|
54
|
+
end
|
55
|
+
if pending_info and pending_info[:no_block]
|
56
|
+
pending pending_info[:msg]
|
57
|
+
prc.call
|
58
|
+
elsif pending_info
|
59
|
+
pending(pending_info[:msg]){prc.call}
|
60
|
+
else prc.call
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
before do
|
66
|
+
@app = KDE::Application.instance
|
67
|
+
@w = Qt::Widget.new
|
68
|
+
@comp = Qt::Object.new
|
69
|
+
flexmock(@comp).should_receive(:each_component)
|
70
|
+
flexmock(Ruber).should_receive(:[]).with(:components).and_return @comp
|
71
|
+
@doc = Ruber::Document.new @app
|
72
|
+
@view = @doc.create_view @w
|
73
|
+
end
|
74
|
+
|
75
|
+
after do
|
76
|
+
@view.disconnect
|
77
|
+
end
|
78
|
+
|
79
|
+
test_auto_signal 'context_menu_about_to_show(QMenu*, @)', 'Qt::Menu.new'
|
80
|
+
test_auto_signal 'focus_in(@)'
|
81
|
+
test_auto_signal 'focus_out(@)'
|
82
|
+
test_auto_signal 'horizontal_scroll_position_changed(@)'
|
83
|
+
test_auto_signal 'information_message(QString, @)', '"test_string"'
|
84
|
+
test_auto_signal 'cursor_position_changed(KTextEditor::Cursor, @)', 'KTextEditor::Cursor.new()'
|
85
|
+
test_auto_signal 'mouse_position_changed(KTextEditor::Cursor, @)', 'KTextEditor::Cursor.new()'
|
86
|
+
test_auto_signal 'selection_changed(@)'
|
87
|
+
test_auto_signal 'text_inserted(KTextEditor::Cursor, QString, @)', ['KTextEditor::Cursor.new(0,0)', '"test text"']
|
88
|
+
test_auto_signal 'vertical_scroll_position_changed(KTextEditor::Cursor, @)', 'KTextEditor::Cursor.new()'
|
89
|
+
|
90
|
+
it "should emit the \"selection_mode_changed(bool, QWidget*)\" signal when the selection mode changes" do
|
91
|
+
mock = flexmock('mock')
|
92
|
+
mock.should_receive(:block_mode_on).globally.ordered.once.with(@view.object_id)
|
93
|
+
mock.should_receive(:block_mode_off).globally.ordered.once.with(@view.object_id)
|
94
|
+
@view.connect(SIGNAL('selection_mode_changed(bool, QWidget*)')) do |m, v|
|
95
|
+
mock.send( (m ? :block_mode_on : :block_mode_off), v.object_id)
|
96
|
+
end
|
97
|
+
@view.block_selection = true
|
98
|
+
@view.block_selection = false
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should emit the \"edit_mode_changed(KTextEditor::View::EditoMode, QWidget*)\" signal in response to the underlying KTextEditor::View viewEditModeChanged(KTextEditor::View, KTextEditor::View::EditMode) signal" do
|
102
|
+
mock = flexmock('mock')
|
103
|
+
mock.should_receive(:test).globally.ordered.once.with(1, @view.object_id)
|
104
|
+
mock.should_receive(:test).globally.ordered.once.with(0, @view.object_id)
|
105
|
+
@view.connect(SIGNAL('edit_mode_changed(KTextEditor::View::EditMode, QWidget*)')) do |m, v|
|
106
|
+
mock.test m, v.object_id
|
107
|
+
end
|
108
|
+
v = @view.instance_variable_get(:@view)
|
109
|
+
v.instance_eval{emit viewEditModeChanged(self, KTextEditor::View::EditOverwrite)}
|
110
|
+
v.instance_eval{emit viewEditModeChanged(self, KTextEditor::View::EditInsert)}
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should emit the \"view_mode_changed(QString, QWidget*)\" signal in response to the underlying KTextEditor::View viewModeChanged(KTextEditor::View*) signal" do
|
114
|
+
mock = flexmock('mock')
|
115
|
+
mock.should_receive(:test).once.with("INS", @view.object_id)
|
116
|
+
@view.connect(SIGNAL('view_mode_changed(QString, QWidget*)')) do |m, v|
|
117
|
+
mock.test m, v.object_id
|
118
|
+
end
|
119
|
+
v = @view.instance_variable_get(:@view)
|
120
|
+
v.instance_eval{emit viewModeChanged(self)}
|
121
|
+
end
|
122
|
+
|
123
|
+
describe '#internal' do
|
124
|
+
|
125
|
+
it 'returns the underlying KTextEditor::View object' do
|
126
|
+
@view.send(:internal).should be_a(KTextEditor::View)
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
describe 'Ruber::EditorView#execute_action' do
|
134
|
+
|
135
|
+
before do
|
136
|
+
@app = KDE::Application.instance
|
137
|
+
@w = Qt::Widget.new
|
138
|
+
@comp = Qt::Object.new
|
139
|
+
flexmock(@comp).should_receive(:each_component)
|
140
|
+
flexmock(Ruber).should_receive(:[]).with(:components).and_return @comp
|
141
|
+
@doc = Ruber::Document.new @app
|
142
|
+
@view = @doc.create_view @w
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'should make the action emit the "triggered()" signal' do
|
146
|
+
a = @view.action_collection.action 'edit_select_all'
|
147
|
+
mk = flexmock('test'){|m| m.should_receive(:triggered).once}
|
148
|
+
a.connect(SIGNAL(:triggered)){mk.triggered}
|
149
|
+
@view.execute_action 'edit_select_all'
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'should make the action emit the "toggled(bool)" signal if it is a KDE::ToggleAction' do
|
153
|
+
a = @view.action_collection.action 'view_vi_input_mode'
|
154
|
+
mk = flexmock('test'){|m| m.should_receive(:toggled).once.with true}
|
155
|
+
a.connect(SIGNAL('toggled(bool)')){|b| mk.toggled b}
|
156
|
+
@view.execute_action 'view_vi_input_mode', true
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'should return true if the action is found' do
|
160
|
+
@view.execute_action('edit_select_all').should be_true
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'should do nothing and return false if the action doesn\'t exist' do
|
164
|
+
lambda{@view.execute_action( 'inexistant_action').should be_false}.should_not raise_error
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
@@ -0,0 +1,676 @@
|
|
1
|
+
require 'spec/common'
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
require 'ruber/external_program_plugin'
|
6
|
+
require 'ruber/plugin_specification'
|
7
|
+
require 'ruber/output_widget'
|
8
|
+
|
9
|
+
describe Ruber::ExternalProgramPlugin do
|
10
|
+
|
11
|
+
before do
|
12
|
+
ui_file = random_string
|
13
|
+
`touch #{ui_file}`
|
14
|
+
@pdf = Ruber::PluginSpecification.full({:name => 'test', :ui_file => ui_file})
|
15
|
+
flexmock(Ruber).should_receive(:[]).with(:app).and_return(KDE::Application.instance)
|
16
|
+
@components = flexmock{|m| m.should_ignore_missing}
|
17
|
+
@mw = KParts::MainWindow.new nil, 0
|
18
|
+
@mw.send(:create_shell_GUI)
|
19
|
+
flexmock(Ruber).should_receive(:[]).with(:components).and_return(@components)
|
20
|
+
flexmock(Ruber).should_receive(:[]).with(:config).and_return(nil)
|
21
|
+
flexmock(Ruber).should_receive(:[]).with(:main_window).and_return(@mw)
|
22
|
+
end
|
23
|
+
|
24
|
+
after do
|
25
|
+
FileUtils.rm @pdf.ui_file
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'inherits from Ruber::GuiPlugin' do
|
29
|
+
Ruber::ExternalProgramPlugin.ancestors.should include(Ruber::GuiPlugin)
|
30
|
+
end
|
31
|
+
|
32
|
+
describe ', when created' do
|
33
|
+
|
34
|
+
it 'takes one or two arguments' do
|
35
|
+
lambda{Ruber::ExternalProgramPlugin.new @pdf, true}.should_not raise_error
|
36
|
+
lambda{Ruber::ExternalProgramPlugin.new @pdf}.should_not raise_error
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'creates a new process' do
|
40
|
+
plug = Ruber::ExternalProgramPlugin.new @pdf
|
41
|
+
plug.process.should be_a(KDE::Process)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'sets the value of the @line_buffered instance variable to the second argument' do
|
45
|
+
plug = Ruber::ExternalProgramPlugin.new @pdf
|
46
|
+
plug.instance_variable_get(:@line_buffered).should be_true
|
47
|
+
plug = Ruber::ExternalProgramPlugin.new @pdf, false
|
48
|
+
plug.instance_variable_get(:@line_buffered).should be_false
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'sets the @buffer instance variable to nil' do
|
52
|
+
plug = Ruber::ExternalProgramPlugin.new @pdf
|
53
|
+
plug.instance_variables.should include(:@buffer)
|
54
|
+
plug.instance_variable_get(:@buffer).should be_nil
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'sets the @buffer_content_channel instance variable to nil' do
|
58
|
+
plug = Ruber::ExternalProgramPlugin.new @pdf
|
59
|
+
plug.instance_variables.should include(:@buffer_content_channel)
|
60
|
+
plug.instance_variable_get(:@buffer_content_channel).should be_nil
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'sets the @output_widget instance variable to nil, if it doesn\'t exist' do
|
64
|
+
plug = Ruber::ExternalProgramPlugin.new @pdf
|
65
|
+
plug.instance_variables.should include(:@output_widget)
|
66
|
+
plug.instance_variable_get(:@output_widget).should be_nil
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'doesn\'t set the @output_widget instance variable to nil if it already exists' do
|
70
|
+
plug = Ruber::ExternalProgramPlugin.new(@pdf){@output_widget = 'test'}
|
71
|
+
plug.instance_variables.should include(:@output_widget)
|
72
|
+
plug.instance_variable_get(:@output_widget).should == 'test'
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'sets the process\'s process channel mode to Qt::Process::SeparateChannels' do
|
76
|
+
plug = Ruber::ExternalProgramPlugin.new @pdf
|
77
|
+
plug.process.process_channel_mode.should == Qt::Process::SeparateChannels
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'connects the process\'s readyReadStandardOutput() signal to a block which reads the contents of standard output, converts them to a string and calls do_stdout' do
|
81
|
+
plug = Ruber::ExternalProgramPlugin.new @pdf
|
82
|
+
data = Qt::ByteArray.new('xyz')
|
83
|
+
flexmock(data).should_receive(:to_s).once.and_return 'xyz'
|
84
|
+
flexmock(plug.process).should_receive(:read_all_standard_output).once.and_return(data)
|
85
|
+
flexmock(plug).should_receive(:do_stdout).once.with('xyz')
|
86
|
+
plug.process.instance_eval{emit readyReadStandardOutput}
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'connects the process\'s readyReadStandardError() signal to a block which reads the contents of standard error, converts them to a string and calls do_stderr' do
|
90
|
+
plug = Ruber::ExternalProgramPlugin.new @pdf
|
91
|
+
data = Qt::ByteArray.new('xyz')
|
92
|
+
flexmock(data).should_receive(:to_s).once.and_return 'xyz'
|
93
|
+
flexmock(plug.process).should_receive(:read_all_standard_error).once.and_return(data)
|
94
|
+
flexmock(plug).should_receive(:do_stderr).once.with('xyz')
|
95
|
+
plug.process.instance_eval{emit readyReadStandardError}
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'connects the process\'s finished(int, QProcess::ExitStatus) signal with its slot_process_finished(int, QProcess::ExitStatus) slot' do
|
99
|
+
plug = Ruber::ExternalProgramPlugin.new @pdf
|
100
|
+
flexmock(plug).should_receive(:slot_process_finished).once.with(1, Qt::Process::CrashExit)
|
101
|
+
plug.process.instance_eval{emit finished(1, Qt::Process::CrashExit)}
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'connects the process\'s started() signal with its process_started() signal' do
|
105
|
+
plug = Ruber::ExternalProgramPlugin.new @pdf
|
106
|
+
m = flexmock{|mk| mk.should_receive(:started).once}
|
107
|
+
plug.connect(SIGNAL('process_started()')){m.started}
|
108
|
+
plug.process.instance_eval{emit started}
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'connects the process\'s error(QProcess::ProcessError) signal to a block which calls failed_to_start if the argument is Qt::Process::FailedToStart' do
|
112
|
+
plug = Ruber::ExternalProgramPlugin.new @pdf
|
113
|
+
flexmock(plug).should_receive(:failed_to_start).once
|
114
|
+
plug.process.instance_eval{emit error Qt::Process::FailedToStart}
|
115
|
+
plug.process.instance_eval{emit error Qt::Process::Crashed}
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'connects its process_finished(int, QString) signal to its display_exit_message(int, QString) slot' do
|
119
|
+
plug = Ruber::ExternalProgramPlugin.new @pdf
|
120
|
+
flexmock(plug).should_receive(:display_exit_message).once.with(5, 'crash')
|
121
|
+
plug.instance_eval{emit process_finished(5, 'crash')}
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
describe '#shutdown' do
|
127
|
+
|
128
|
+
before do
|
129
|
+
@plug = Ruber::ExternalProgramPlugin.new @pdf
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'blocks the process\'s signals' do
|
133
|
+
flexmock(@plug.process).should_receive(:block_signals).once.with(true)
|
134
|
+
@plug.send :shutdown
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'kills the process' do
|
138
|
+
flexmock(@plug.process).should_receive(:kill).once
|
139
|
+
@plug.send :shutdown
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
describe '#do_stdout' do
|
145
|
+
|
146
|
+
before do
|
147
|
+
@plug = Ruber::ExternalProgramPlugin.new @pdf
|
148
|
+
end
|
149
|
+
|
150
|
+
describe 'if the plugin is not line buffered' do
|
151
|
+
|
152
|
+
before do
|
153
|
+
@plug.instance_variable_set(:@line_buffered, false)
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'calls the process_standard_output passing it the argument split into lines' do
|
157
|
+
flexmock(@plug).should_receive(:process_standard_output).twice.with %w[a b c]
|
158
|
+
@plug.send :do_stdout, "a\nb\nc\n"
|
159
|
+
@plug.send :do_stdout, "a\nb\nc"
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'does nothing if the string is empty or made only of newlines' do
|
163
|
+
flexmock(@plug).should_receive(:process_standard_output).never
|
164
|
+
@plug.send :do_stdout, ""
|
165
|
+
@plug.send :do_stdout, "\n"
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
describe ', if the plugin is line buffered' do
|
171
|
+
|
172
|
+
describe ' and the buffer is empty' do
|
173
|
+
|
174
|
+
it 'calls the process_standard_output method passing it the string divided into lines, if the string ends in a newline' do
|
175
|
+
flexmock(@plug).should_receive(:process_standard_output).once.with %w[a b c]
|
176
|
+
@plug.send :do_stdout, "a\nb\nc\n"
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'calls the process_standard_output method passing it the string divided into lines except for the last one if the string doesn\'t end in a newline' do
|
180
|
+
flexmock(@plug).should_receive(:process_standard_output).once.with %w[a b]
|
181
|
+
@plug.send :do_stdout, "a\nb\nc"
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'puts the last line in the buffer and sets the buffer_content_channel to :stdout if the string doesn\'t end in a newline' do
|
185
|
+
@plug.send :do_stdout, "a\nb\nc"
|
186
|
+
@plug.instance_variable_get(:@buffer).should == 'c'
|
187
|
+
@plug.instance_variable_get(:@buffer_content_channel).should == :stdout
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'puts the only line in the buffer, sets the buffer_content_channel to :stdout and does nothing else if there\'s only one string and it doesn\'t end in a newline' do
|
191
|
+
flexmock(@plug).should_receive(:process_standard_output).never
|
192
|
+
lambda{@plug.send :do_stdout, ''}.should_not raise_error
|
193
|
+
@plug.send :do_stdout, "a"
|
194
|
+
@plug.instance_variable_get(:@buffer).should == 'a'
|
195
|
+
@plug.instance_variable_get(:@buffer_content_channel).should == :stdout
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'does nothing if the string is empty or made only of newlines' do
|
199
|
+
flexmock(@plug).should_receive(:process_standard_output).never
|
200
|
+
lambda{@plug.send :do_stdout, ''}.should_not raise_error
|
201
|
+
lambda{@plug.send :do_stdout, "\n"}.should_not raise_error
|
202
|
+
end
|
203
|
+
|
204
|
+
end
|
205
|
+
|
206
|
+
describe ', the buffer is not empty and its channel is stdout' do
|
207
|
+
|
208
|
+
before do
|
209
|
+
@plug.instance_variable_set(:@buffer, 'x')
|
210
|
+
@plug.instance_variable_set(:@buffer_content_channel, :stdout)
|
211
|
+
class << @plug
|
212
|
+
alias :do_stdout_needed_for_test :do_stdout
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'adds the buffer to the beginning of the string, clears the buffer and calls itself with the new string' do
|
217
|
+
flexmock(@plug).should_receive(:do_stdout).once.with("xa\nb\nc\n")
|
218
|
+
@plug.send :do_stdout_needed_for_test, "a\nb\nc\n"
|
219
|
+
@plug.instance_variable_get(:@buffer).should be_nil
|
220
|
+
@plug.instance_variable_get(:@buffer_content_channel).should be_nil
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'does nothing if the string is empty' do
|
224
|
+
flexmock(@plug).should_receive(:process_standard_output).never
|
225
|
+
lambda{@plug.send :do_stdout, ''}.should_not raise_error
|
226
|
+
@plug.instance_variable_get(:@buffer).should == 'x'
|
227
|
+
@plug.instance_variable_get(:@buffer_content_channel).should == :stdout
|
228
|
+
end
|
229
|
+
|
230
|
+
it 'adds the buffer to the beginning of the string, clears the buffer and calls itself with the new string even if the string only contains newlines' do
|
231
|
+
flexmock(@plug).should_receive(:do_stdout).once.with("x\n\n")
|
232
|
+
@plug.send :do_stdout_needed_for_test, "\n\n"
|
233
|
+
@plug.instance_variable_get(:@buffer).should be_nil
|
234
|
+
@plug.instance_variable_get(:@buffer_content_channel).should be_nil
|
235
|
+
end
|
236
|
+
|
237
|
+
it 'doesn\'t call process_standard_output a second time' do
|
238
|
+
flexmock(@plug).should_receive(:process_standard_output).once
|
239
|
+
@plug.send :do_stdout, "a\nb\nc\n"
|
240
|
+
end
|
241
|
+
|
242
|
+
end
|
243
|
+
|
244
|
+
describe ', the buffer is not empty and its channel is stderr' do
|
245
|
+
|
246
|
+
before do
|
247
|
+
@plug.instance_variable_set(:@buffer, 'x')
|
248
|
+
@plug.instance_variable_set(:@buffer_content_channel, :stderr)
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'clears the buffer and calls process_standard_error passing the an array containing the buffer as argument before going on' do
|
252
|
+
flexmock(@plug).should_receive(:process_standard_error).once.with(["x"]).ordered
|
253
|
+
flexmock(@plug).should_receive(:process_standard_output).once.with(%w[a b c]).ordered
|
254
|
+
@plug.send :do_stdout, "a\nb\nc\n"
|
255
|
+
@plug.instance_variable_get(:@buffer).should be_nil
|
256
|
+
@plug.instance_variable_get(:@buffer_content_channel).should be_nil
|
257
|
+
end
|
258
|
+
|
259
|
+
it 'does nothing if the string is empty' do
|
260
|
+
flexmock(@plug).should_receive(:process_standard_output).never
|
261
|
+
flexmock(@plug).should_receive(:do_stderr).never
|
262
|
+
lambda{@plug.send :do_stdout, ''}.should_not raise_error
|
263
|
+
@plug.instance_variable_get(:@buffer).should == 'x'
|
264
|
+
@plug.instance_variable_get(:@buffer_content_channel).should == :stderr
|
265
|
+
end
|
266
|
+
|
267
|
+
it 'clears the buffer, calls do_stderr passing the buffer and does nothing else if the string only contains newlines' do
|
268
|
+
flexmock(@plug).should_receive(:process_standard_error).once.with(["x"]).ordered
|
269
|
+
flexmock(@plug).should_receive(:process_standard_output).never
|
270
|
+
@plug.send :do_stdout, "\n\n"
|
271
|
+
@plug.instance_variable_get(:@buffer).should be_nil
|
272
|
+
@plug.instance_variable_get(:@buffer_content_channel).should be_nil
|
273
|
+
end
|
274
|
+
|
275
|
+
end
|
276
|
+
|
277
|
+
end
|
278
|
+
|
279
|
+
end
|
280
|
+
|
281
|
+
describe '#do_stderr' do
|
282
|
+
|
283
|
+
before do
|
284
|
+
@plug = Ruber::ExternalProgramPlugin.new @pdf
|
285
|
+
end
|
286
|
+
|
287
|
+
describe 'if the plugin is not line buffered' do
|
288
|
+
|
289
|
+
before do
|
290
|
+
@plug.instance_variable_set(:@line_buffered, false)
|
291
|
+
end
|
292
|
+
|
293
|
+
it 'calls the process_standard_error passing it the argument split into lines' do
|
294
|
+
flexmock(@plug).should_receive(:process_standard_error).twice.with %w[a b c]
|
295
|
+
@plug.send :do_stderr, "a\nb\nc\n"
|
296
|
+
@plug.send :do_stderr, "a\nb\nc"
|
297
|
+
end
|
298
|
+
|
299
|
+
it 'does nothing if the string is empty or made only of newlines' do
|
300
|
+
flexmock(@plug).should_receive(:process_standard_error).never
|
301
|
+
@plug.send :do_stderr, ""
|
302
|
+
@plug.send :do_stderr, "\n"
|
303
|
+
end
|
304
|
+
|
305
|
+
end
|
306
|
+
|
307
|
+
describe ', if the plugin is line buffered' do
|
308
|
+
|
309
|
+
describe ' and the buffer is empty' do
|
310
|
+
|
311
|
+
it 'calls the process_standard_error method passing it the string divided into lines, if the string ends in a newline' do
|
312
|
+
flexmock(@plug).should_receive(:process_standard_error).once.with %w[a b c]
|
313
|
+
@plug.send :do_stderr, "a\nb\nc\n"
|
314
|
+
end
|
315
|
+
|
316
|
+
it 'calls the process_standard_error method passing it the string divided into lines except for the last one if the string doesn\'t end in a newline' do
|
317
|
+
flexmock(@plug).should_receive(:process_standard_error).once.with %w[a b]
|
318
|
+
@plug.send :do_stderr, "a\nb\nc"
|
319
|
+
end
|
320
|
+
|
321
|
+
it 'puts the last line in the buffer and sets the buffer_content_channel to :stderr if the string doesn\'t end in a newline' do
|
322
|
+
@plug.send :do_stderr, "a\nb\nc"
|
323
|
+
@plug.instance_variable_get(:@buffer).should == 'c'
|
324
|
+
@plug.instance_variable_get(:@buffer_content_channel).should == :stderr
|
325
|
+
end
|
326
|
+
|
327
|
+
it 'puts the only line in the buffer, sets the buffer_content_channel to :stderr and does nothing else if there\'s only one string and it doesn\'t end in a newline' do
|
328
|
+
flexmock(@plug).should_receive(:process_standard_error).never
|
329
|
+
lambda{@plug.send :do_stderr, ''}.should_not raise_error
|
330
|
+
@plug.send :do_stderr, "a"
|
331
|
+
@plug.instance_variable_get(:@buffer).should == 'a'
|
332
|
+
@plug.instance_variable_get(:@buffer_content_channel).should == :stderr
|
333
|
+
end
|
334
|
+
|
335
|
+
it 'does nothing if the string is empty or made only of newlines' do
|
336
|
+
flexmock(@plug).should_receive(:process_standard_error).never
|
337
|
+
lambda{@plug.send :do_stderr, ''}.should_not raise_error
|
338
|
+
lambda{@plug.send :do_stderr, "\n"}.should_not raise_error
|
339
|
+
end
|
340
|
+
|
341
|
+
end
|
342
|
+
|
343
|
+
describe ', the buffer is not empty and its channel is stderr' do
|
344
|
+
|
345
|
+
before do
|
346
|
+
@plug.instance_variable_set(:@buffer, 'x')
|
347
|
+
@plug.instance_variable_set(:@buffer_content_channel, :stderr)
|
348
|
+
class << @plug
|
349
|
+
alias :do_stderr_needed_for_test :do_stderr
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
it 'adds the buffer to the beginning of the string, clears the buffer and calls itself with the new string' do
|
354
|
+
flexmock(@plug).should_receive(:do_stderr).once.with("xa\nb\nc\n")
|
355
|
+
@plug.send :do_stderr_needed_for_test, "a\nb\nc\n"
|
356
|
+
@plug.instance_variable_get(:@buffer).should be_nil
|
357
|
+
@plug.instance_variable_get(:@buffer_content_channel).should be_nil
|
358
|
+
end
|
359
|
+
|
360
|
+
it 'does nothing if the string is empty' do
|
361
|
+
flexmock(@plug).should_receive(:process_standard_error).never
|
362
|
+
lambda{@plug.send :do_stderr, ''}.should_not raise_error
|
363
|
+
@plug.instance_variable_get(:@buffer).should == 'x'
|
364
|
+
@plug.instance_variable_get(:@buffer_content_channel).should == :stderr
|
365
|
+
end
|
366
|
+
|
367
|
+
it 'adds the buffer to the beginning of the string, clears the buffer and calls itself with the new string even if the string only contains newlines' do
|
368
|
+
flexmock(@plug).should_receive(:do_stderr).once.with("x\n\n")
|
369
|
+
@plug.send :do_stderr_needed_for_test, "\n\n"
|
370
|
+
@plug.instance_variable_get(:@buffer).should be_nil
|
371
|
+
@plug.instance_variable_get(:@buffer_content_channel).should be_nil
|
372
|
+
end
|
373
|
+
|
374
|
+
it 'doesn\'t call process_standard_error a second time' do
|
375
|
+
flexmock(@plug).should_receive(:process_standard_error).once
|
376
|
+
@plug.send :do_stderr, "a\nb\nc\n"
|
377
|
+
end
|
378
|
+
|
379
|
+
|
380
|
+
end
|
381
|
+
|
382
|
+
describe ', the buffer is not empty and its channel is stdout' do
|
383
|
+
|
384
|
+
before do
|
385
|
+
@plug.instance_variable_set(:@buffer, 'x')
|
386
|
+
@plug.instance_variable_set(:@buffer_content_channel, :stdout)
|
387
|
+
end
|
388
|
+
|
389
|
+
it 'clears the buffer and calls process_standard_output passing an array containing the buffer as argument before going on' do
|
390
|
+
flexmock(@plug).should_receive(:process_standard_output).once.with(["x"]).ordered
|
391
|
+
flexmock(@plug).should_receive(:process_standard_error).once.with(%w[a b c]).ordered
|
392
|
+
@plug.send :do_stderr, "a\nb\nc\n"
|
393
|
+
@plug.instance_variable_get(:@buffer).should be_nil
|
394
|
+
@plug.instance_variable_get(:@buffer_content_channel).should be_nil
|
395
|
+
end
|
396
|
+
|
397
|
+
it 'does nothing if the string is empty' do
|
398
|
+
flexmock(@plug).should_receive(:process_standard_error).never
|
399
|
+
flexmock(@plug).should_receive(:do_stdout).never
|
400
|
+
lambda{@plug.send :do_stderr, ''}.should_not raise_error
|
401
|
+
@plug.instance_variable_get(:@buffer).should == 'x'
|
402
|
+
@plug.instance_variable_get(:@buffer_content_channel).should == :stdout
|
403
|
+
end
|
404
|
+
|
405
|
+
it 'clears the buffer, calls process_standard_output passing an array containing the buffer and does nothing else if the string only contains newlines' do
|
406
|
+
flexmock(@plug).should_receive(:process_standard_output).once.with(["x"]).ordered
|
407
|
+
flexmock(@plug).should_receive(:process_standard_error).never
|
408
|
+
@plug.send :do_stderr, "\n\n"
|
409
|
+
@plug.instance_variable_get(:@buffer).should be_nil
|
410
|
+
@plug.instance_variable_get(:@buffer_content_channel).should be_nil
|
411
|
+
end
|
412
|
+
|
413
|
+
end
|
414
|
+
|
415
|
+
end
|
416
|
+
|
417
|
+
end
|
418
|
+
|
419
|
+
describe '#process_standard_output' do
|
420
|
+
|
421
|
+
before do
|
422
|
+
@plug = Ruber::ExternalProgramPlugin.new @pdf
|
423
|
+
end
|
424
|
+
|
425
|
+
it 'does nothing if the @output_widget instance variable is nil' do
|
426
|
+
lambda{@plug.send :process_standard_output, %w[a b]}.should_not raise_error
|
427
|
+
end
|
428
|
+
|
429
|
+
it 'inserts the entries of the array in the model associated to the @output_widget instance variable and set their output type to output if the @output_widget instance variable is not nil' do
|
430
|
+
ow = Ruber::OutputWidget.new
|
431
|
+
ow.set_color_for(:output, Qt::Color.new(0,0,0))
|
432
|
+
mod = ow.model
|
433
|
+
3.times{|i| mod.append_row Qt::StandardItem.new(i.to_s)}
|
434
|
+
@plug.instance_variable_set :@output_widget, ow
|
435
|
+
@plug.send :process_standard_output, %w[a b]
|
436
|
+
mod.row_count.should == 5
|
437
|
+
mod.column_count.should == 1
|
438
|
+
mod.item(3,0).text.should == 'a'
|
439
|
+
mod.item(3,0).data(Ruber::OutputWidget::OutputTypeRole).to_string.should == 'output'
|
440
|
+
mod.item(4,0).text.should == 'b'
|
441
|
+
mod.item(4,0).data(Ruber::OutputWidget::OutputTypeRole).to_string.should == 'output'
|
442
|
+
end
|
443
|
+
|
444
|
+
end
|
445
|
+
|
446
|
+
describe '#process_standard_error' do
|
447
|
+
|
448
|
+
before do
|
449
|
+
@plug = Ruber::ExternalProgramPlugin.new @pdf
|
450
|
+
end
|
451
|
+
|
452
|
+
it 'does nothing if the @error_widget instance variable is nil' do
|
453
|
+
lambda{@plug.send :process_standard_error, %w[a b]}.should_not raise_error
|
454
|
+
end
|
455
|
+
|
456
|
+
it 'inserts the entries of the array in the model associated to the @error_widget instance variable and set their error type to error if the @error_widget instance variable is not nil' do
|
457
|
+
ow = Ruber::OutputWidget.new
|
458
|
+
ow.set_color_for(:error, Qt::Color.new(0,0,0))
|
459
|
+
mod = ow.model
|
460
|
+
3.times{|i| mod.append_row Qt::StandardItem.new(i.to_s)}
|
461
|
+
@plug.instance_variable_set :@output_widget, ow
|
462
|
+
@plug.send :process_standard_error, %w[a b]
|
463
|
+
mod.row_count.should == 5
|
464
|
+
mod.column_count.should == 1
|
465
|
+
mod.item(3,0).text.should == 'a'
|
466
|
+
mod.item(3,0).data(Ruber::OutputWidget::OutputTypeRole).to_string.should == 'error'
|
467
|
+
mod.item(4,0).text.should == 'b'
|
468
|
+
mod.item(4,0).data(Ruber::OutputWidget::OutputTypeRole).to_string.should == 'error'
|
469
|
+
end
|
470
|
+
|
471
|
+
end
|
472
|
+
|
473
|
+
describe '#slot_process_finished' do
|
474
|
+
|
475
|
+
before do
|
476
|
+
@plug = Ruber::ExternalProgramPlugin.new @pdf
|
477
|
+
end
|
478
|
+
|
479
|
+
it 'reads from standard output and standard error and calls the do_stdout and do_stderr methods (appending a newline if necessary)' do
|
480
|
+
flexmock(@plug.process).should_receive(:read_all_standard_output).once.and_return(Qt::ByteArray.new('xyz'))
|
481
|
+
flexmock(@plug.process).should_receive(:read_all_standard_output).once.and_return(Qt::ByteArray.new("xyz\n"))
|
482
|
+
flexmock(@plug.process).should_receive(:read_all_standard_error).once.and_return(Qt::ByteArray.new('abc'))
|
483
|
+
flexmock(@plug.process).should_receive(:read_all_standard_error).once.and_return(Qt::ByteArray.new("abc\n"))
|
484
|
+
flexmock(@plug).should_receive(:do_stdout).twice.with("xyz\n")
|
485
|
+
flexmock(@plug).should_receive(:do_stderr).twice.with("abc\n")
|
486
|
+
@plug.send :slot_process_finished, 1, Qt::Process::NormalExit
|
487
|
+
@plug.send :slot_process_finished, 1, Qt::Process::NormalExit
|
488
|
+
end
|
489
|
+
|
490
|
+
it 'emits the process_finished(int, QString) with "killed" as second argument if status is Qt::Process::CrashExit and code is 0' do
|
491
|
+
m = flexmock{|mk| mk.should_receive(:test).once.with(0, 'killed')}
|
492
|
+
@plug.connect(SIGNAL('process_finished(int, QString)')){|i, s| m.test i, s}
|
493
|
+
@plug.process.instance_eval{emit finished(0, Qt::Process::CrashExit)}
|
494
|
+
end
|
495
|
+
|
496
|
+
it 'emits the process_finished(int, QString) with "crash" as second argument if status is Qt::Process::CrashExit and code is not 0' do
|
497
|
+
m = flexmock{|mk| mk.should_receive(:test).once.with(5, 'crash')}
|
498
|
+
@plug.connect(SIGNAL('process_finished(int, QString)')){|i, s| m.test i, s}
|
499
|
+
@plug.process.instance_eval{emit finished(5, Qt::Process::CrashExit)}
|
500
|
+
end
|
501
|
+
|
502
|
+
it 'emits the process_finished(int, QString) with "" as second argument if status is Qt::Process::NormalExit' do
|
503
|
+
m = flexmock{|mk| mk.should_receive(:test).once.with(0, '')}
|
504
|
+
@plug.connect(SIGNAL('process_finished(int, QString)')){|i, s| m.test i, s}
|
505
|
+
@plug.process.instance_eval{emit finished(0, Qt::Process::NormalExit)}
|
506
|
+
end
|
507
|
+
|
508
|
+
end
|
509
|
+
|
510
|
+
describe '#failed_to_start' do
|
511
|
+
|
512
|
+
before do
|
513
|
+
@plug = Ruber::ExternalProgramPlugin.new @pdf
|
514
|
+
end
|
515
|
+
|
516
|
+
it 'emits the process_failed_to_start signal' do
|
517
|
+
m = flexmock{|mk| mk.should_receive(:test).once}
|
518
|
+
@plug.connect(SIGNAL(:process_failed_to_start)){m.test}
|
519
|
+
@plug.send :failed_to_start
|
520
|
+
end
|
521
|
+
|
522
|
+
it 'displays a message of type error1 in the output widget @output_widget, if @output_widget is not nil' do
|
523
|
+
ow = Ruber::OutputWidget.new
|
524
|
+
ow.set_color_for :error1, Qt::Color.new(255,0,0)
|
525
|
+
mod = ow.model
|
526
|
+
3.times{|i| mod.append_row Qt::StandardItem.new(i.to_s)}
|
527
|
+
@plug.instance_variable_set :@output_widget, ow
|
528
|
+
@plug.process.set_program '/usr/bin/xyz', %w[-a --bc d]
|
529
|
+
@plug.send :failed_to_start
|
530
|
+
mod.row_count.should == 4
|
531
|
+
mod.item(3,0).text.should == "/usr/bin/xyz failed to start. The command line was /usr/bin/xyz -a --bc d"
|
532
|
+
mod.item(3,0).data(Ruber::OutputWidget::OutputTypeRole).to_string.should == 'error1'
|
533
|
+
end
|
534
|
+
|
535
|
+
it 'doesn\'t attempt to display the error message if @output_widget is nil' do
|
536
|
+
lambda{@plug.send :failed_to_start}.should_not raise_error
|
537
|
+
end
|
538
|
+
|
539
|
+
end
|
540
|
+
|
541
|
+
describe '#run_process' do
|
542
|
+
|
543
|
+
before do
|
544
|
+
@plug = Ruber::ExternalProgramPlugin.new @pdf
|
545
|
+
flexmock(@plug.process).should_receive(:start).by_default
|
546
|
+
end
|
547
|
+
|
548
|
+
it 'sets the working directory of the proces' do
|
549
|
+
@plug.run_process '/usr/bin/xyz', ENV['HOME'], %w[a b c]
|
550
|
+
@plug.process.working_directory.should == ENV['HOME']
|
551
|
+
end
|
552
|
+
|
553
|
+
it 'clears the program and argument list' do
|
554
|
+
flexmock(@plug).process.should_receive(:clear_program).once
|
555
|
+
@plug.run_process '/usr/bin/xyz', ENV['HOME'], %w[a b c]
|
556
|
+
end
|
557
|
+
|
558
|
+
it 'sets the program and argument list' do
|
559
|
+
@plug.run_process '/usr/bin/xyz', ENV['HOME'], %w[a b c]
|
560
|
+
@plug.process.program.should == %w[/usr/bin/xyz a b c]
|
561
|
+
end
|
562
|
+
|
563
|
+
it 'starts the program, after having set all the parameters' do
|
564
|
+
flexmock(@plug.process).should_receive(:clear_program).once.ordered
|
565
|
+
flexmock(@plug.process).should_receive(:working_directory=).once.ordered
|
566
|
+
flexmock(@plug.process).should_receive(:program=).once.ordered
|
567
|
+
flexmock(@plug.process).should_receive(:start).once.ordered
|
568
|
+
@plug.run_process '/usr/bin/xyz', ENV['HOME'], %w[a b c]
|
569
|
+
end
|
570
|
+
|
571
|
+
describe 'if the @output_widget instance variable is not nil' do
|
572
|
+
|
573
|
+
before do
|
574
|
+
@ow = Ruber::OutputWidget.new
|
575
|
+
@plug.instance_variable_set :@output_widget, @ow
|
576
|
+
end
|
577
|
+
|
578
|
+
it 'sets the title of the output widget to the command line before starting the program if the fourth parameter is an empty string' do
|
579
|
+
flexmock(@ow).should_receive(:title=).with('/usr/bin/xyz a b c').once.ordered
|
580
|
+
flexmock(@plug.process).should_receive(:start).once.ordered
|
581
|
+
@plug.run_process '/usr/bin/xyz', ENV['HOME'], %w[a b c], ''
|
582
|
+
end
|
583
|
+
|
584
|
+
it 'uses the fourth argument as title for the output widget if it\'s a non-empty string' do
|
585
|
+
flexmock(@ow).should_receive(:title=).with('TITLE').once.ordered
|
586
|
+
flexmock(@plug.process).should_receive(:start).once.ordered
|
587
|
+
@plug.run_process '/usr/bin/xyz', ENV['HOME'], %w[a b c], 'TITLE'
|
588
|
+
end
|
589
|
+
|
590
|
+
it 'doesn\'t attempt to set the output widget title if the fourth argument is nil or false' do
|
591
|
+
flexmock(@ow).should_receive(:title=).never
|
592
|
+
flexmock(@plug.process).should_receive(:start).twice
|
593
|
+
@plug.run_process '/usr/bin/xyz', ENV['HOME'], %w[a b c], false
|
594
|
+
@plug.run_process '/usr/bin/xyz', ENV['HOME'], %w[a b c], nil
|
595
|
+
end
|
596
|
+
|
597
|
+
end
|
598
|
+
|
599
|
+
it 'doesn\'t attempt to set the output widget title if the @output_widget instance variable is nil' do
|
600
|
+
lambda{@plug.run_process '/usr/bin/xyz', ENV['HOME'], %w[a b c], ''}.should_not raise_error
|
601
|
+
end
|
602
|
+
|
603
|
+
end
|
604
|
+
|
605
|
+
describe '#stop process' do
|
606
|
+
|
607
|
+
it 'kills the process' do
|
608
|
+
plug = Ruber::ExternalProgramPlugin.new @pdf
|
609
|
+
flexmock(plug.process).should_receive(:kill).once
|
610
|
+
plug.stop_process
|
611
|
+
end
|
612
|
+
|
613
|
+
end
|
614
|
+
|
615
|
+
describe '#display_exit_ message' do
|
616
|
+
|
617
|
+
before do
|
618
|
+
@plug = Ruber::ExternalProgramPlugin.new @pdf
|
619
|
+
end
|
620
|
+
|
621
|
+
describe ', if the @output_widget instance variable is not nil' do
|
622
|
+
|
623
|
+
before do
|
624
|
+
@ow = Ruber::OutputWidget.new
|
625
|
+
@ow.set_color_for :message, Qt::Color.new(255,0,0)
|
626
|
+
@ow.set_color_for :message_bad, Qt::Color.new(255,0,0)
|
627
|
+
@plug.instance_variable_set :@output_widget, @ow
|
628
|
+
@mod = @ow.model
|
629
|
+
5.times{|i| @mod.append_row Qt::StandardItem.new(i.to_s)}
|
630
|
+
end
|
631
|
+
|
632
|
+
it 'appends a line with output type message and text "Process exited normally" if the second argument is empty and code is 0' do
|
633
|
+
@plug.process.program = %w[/usr/bin/xyz -a --bc d]
|
634
|
+
@plug.send :display_exit_message, 0, ''
|
635
|
+
@mod.row_count.should == 6
|
636
|
+
@mod.item(5,0).text.should == 'Process exited normally'
|
637
|
+
@mod.item(5,0).data(Ruber::OutputWidget::OutputTypeRole).to_string.should == 'message'
|
638
|
+
end
|
639
|
+
|
640
|
+
it 'appends a line with output type message_bad and text "Process exited with code code" if the second argument is empty and code is not' do
|
641
|
+
@plug.process.program = %w[/usr/bin/xyz -a --bc d]
|
642
|
+
@plug.send :display_exit_message, 5, ''
|
643
|
+
@mod.row_count.should == 6
|
644
|
+
@mod.item(5,0).text.should == 'Process exited with code 5'
|
645
|
+
@mod.item(5,0).data(Ruber::OutputWidget::OutputTypeRole).to_string.should == 'message_bad'
|
646
|
+
end
|
647
|
+
|
648
|
+
it 'appends a line with output type message and text "Process killed" if the second argument is "killed"' do
|
649
|
+
@plug.process.program = %w[/usr/bin/xyz -a --bc d]
|
650
|
+
@plug.send :display_exit_message, 0, 'killed'
|
651
|
+
@mod.row_count.should == 6
|
652
|
+
@mod.item(5,0).text.should == 'Process killed'
|
653
|
+
@mod.item(5,0).data(Ruber::OutputWidget::OutputTypeRole).to_string.should == 'message'
|
654
|
+
end
|
655
|
+
|
656
|
+
it 'appends a line with output type message_bad and text "Process crashed with code code" if the second argument is "crash"' do
|
657
|
+
@plug.process.program = %w[/usr/bin/xyz -a --bc d]
|
658
|
+
@plug.send :display_exit_message, 5, 'crash'
|
659
|
+
@mod.row_count.should == 6
|
660
|
+
@mod.item(5,0).text.should == 'Process crashed with code 5'
|
661
|
+
@mod.item(5,0).data(Ruber::OutputWidget::OutputTypeRole).to_string.should == 'message_bad'
|
662
|
+
end
|
663
|
+
|
664
|
+
end
|
665
|
+
|
666
|
+
describe ', if the @output_widget instance variable is nil' do
|
667
|
+
|
668
|
+
it 'does nothing' do
|
669
|
+
lambda{@plug.send :display_exit_message, 0, ''}.should_not raise_error
|
670
|
+
end
|
671
|
+
|
672
|
+
end
|
673
|
+
|
674
|
+
end
|
675
|
+
|
676
|
+
end
|