ruber 0.0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING +339 -0
- data/INSTALL +137 -0
- data/LICENSE +8 -0
- data/bin/ruber +65 -0
- data/data/share/apps/ruber/core_components.yaml +31 -0
- data/data/share/apps/ruber/ruberui.rc +109 -0
- data/data/share/icons/ruber.png +0 -0
- data/data/share/pixmaps/ruby.png +0 -0
- data/icons/ruber-16.png +0 -0
- data/icons/ruber-32.png +0 -0
- data/icons/ruber-48.png +0 -0
- data/icons/ruber-8.png +0 -0
- data/lib/ruber/application/application.rb +288 -0
- data/lib/ruber/application/plugin.yaml +11 -0
- data/lib/ruber/component_manager.rb +899 -0
- data/lib/ruber/config/config.rb +82 -0
- data/lib/ruber/config/plugin.yaml +3 -0
- data/lib/ruber/document_project.rb +209 -0
- data/lib/ruber/documents/document_list.rb +416 -0
- data/lib/ruber/documents/plugin.yaml +4 -0
- data/lib/ruber/editor/document.rb +506 -0
- data/lib/ruber/editor/editor_view.rb +167 -0
- data/lib/ruber/editor/ktexteditor_wrapper.rb +202 -0
- data/lib/ruber/exception_widgets.rb +245 -0
- data/lib/ruber/external_program_plugin.rb +397 -0
- data/lib/ruber/filtered_output_widget.rb +342 -0
- data/lib/ruber/gui_states_handler.rb +231 -0
- data/lib/ruber/kde_config_option_backend.rb +167 -0
- data/lib/ruber/kde_sugar.rb +249 -0
- data/lib/ruber/main_window/choose_plugins_dlg.rb +353 -0
- data/lib/ruber/main_window/main_window.rb +524 -0
- data/lib/ruber/main_window/main_window_actions.rb +537 -0
- data/lib/ruber/main_window/main_window_internal.rb +239 -0
- data/lib/ruber/main_window/open_file_in_project_dlg.rb +212 -0
- data/lib/ruber/main_window/output_color_widget.rb +35 -0
- data/lib/ruber/main_window/plugin.yaml +58 -0
- data/lib/ruber/main_window/save_modified_files_dlg.rb +89 -0
- data/lib/ruber/main_window/status_bar.rb +156 -0
- data/lib/ruber/main_window/ui/choose_plugins_widget.rb +90 -0
- data/lib/ruber/main_window/ui/choose_plugins_widget.ui +77 -0
- data/lib/ruber/main_window/ui/main_window_settings_widget.rb +108 -0
- data/lib/ruber/main_window/ui/main_window_settings_widget.ui +89 -0
- data/lib/ruber/main_window/ui/new_project_widget.rb +119 -0
- data/lib/ruber/main_window/ui/new_project_widget.ui +178 -0
- data/lib/ruber/main_window/ui/open_file_in_project_dlg.rb +109 -0
- data/lib/ruber/main_window/ui/open_file_in_project_dlg.ui +168 -0
- data/lib/ruber/main_window/ui/output_color_widget.rb +241 -0
- data/lib/ruber/main_window/ui/output_color_widget.ui +204 -0
- data/lib/ruber/main_window/workspace.rb +442 -0
- data/lib/ruber/output_widget.rb +1093 -0
- data/lib/ruber/plugin.rb +264 -0
- data/lib/ruber/plugin_like.rb +589 -0
- data/lib/ruber/plugin_specification.rb +106 -0
- data/lib/ruber/plugin_specification_reader.rb +451 -0
- data/lib/ruber/project.rb +493 -0
- data/lib/ruber/project_backend.rb +105 -0
- data/lib/ruber/projects/plugin.yaml +11 -0
- data/lib/ruber/projects/project_files_list.rb +314 -0
- data/lib/ruber/projects/project_files_widget.rb +301 -0
- data/lib/ruber/projects/project_list.rb +314 -0
- data/lib/ruber/projects/ui/project_files_rule_chooser_widget.rb +74 -0
- data/lib/ruber/projects/ui/project_files_rule_chooser_widget.ui +61 -0
- data/lib/ruber/projects/ui/project_files_widget.rb +117 -0
- data/lib/ruber/projects/ui/project_files_widget.ui +123 -0
- data/lib/ruber/qt_sugar.rb +673 -0
- data/lib/ruber/settings_container.rb +515 -0
- data/lib/ruber/settings_dialog.rb +244 -0
- data/lib/ruber/settings_dialog_manager.rb +503 -0
- data/lib/ruber/utils.rb +414 -0
- data/lib/ruber/yaml_option_backend.rb +159 -0
- data/outsider_files +15 -0
- data/plugins/autosave/autosave.rb +404 -0
- data/plugins/autosave/plugin.yaml +16 -0
- data/plugins/autosave/ui/autosave_config_widget.rb +83 -0
- data/plugins/autosave/ui/autosave_config_widget.ui +68 -0
- data/plugins/command/command.png +0 -0
- data/plugins/command/command.rb +74 -0
- data/plugins/command/plugin.yaml +11 -0
- data/plugins/find_in_files/find_in_files.rb +337 -0
- data/plugins/find_in_files/find_in_files_dlg.rb +411 -0
- data/plugins/find_in_files/find_in_files_ui.rc +11 -0
- data/plugins/find_in_files/find_in_files_widgets.rb +485 -0
- data/plugins/find_in_files/plugin.yaml +23 -0
- data/plugins/find_in_files/ui/config_widget.rb +58 -0
- data/plugins/find_in_files/ui/config_widget.ui +41 -0
- data/plugins/find_in_files/ui/find_in_files_widget.rb +260 -0
- data/plugins/find_in_files/ui/find_in_files_widget.ui +324 -0
- data/plugins/project_browser/plugin.yaml +10 -0
- data/plugins/project_browser/project_browser.rb +245 -0
- data/plugins/rake/plugin.yaml +39 -0
- data/plugins/rake/rake.png +0 -0
- data/plugins/rake/rake.rb +567 -0
- data/plugins/rake/rake_extension.rb +153 -0
- data/plugins/rake/rake_widgets.rb +615 -0
- data/plugins/rake/rakeui.rc +27 -0
- data/plugins/rake/ui/add_quick_task_widget.rb +71 -0
- data/plugins/rake/ui/add_quick_task_widget.ui +59 -0
- data/plugins/rake/ui/choose_task_widget.rb +77 -0
- data/plugins/rake/ui/choose_task_widget.ui +72 -0
- data/plugins/rake/ui/config_widget.rb +127 -0
- data/plugins/rake/ui/config_widget.ui +123 -0
- data/plugins/rake/ui/project_widget.rb +217 -0
- data/plugins/rake/ui/project_widget.ui +246 -0
- data/plugins/rspec/plugin.yaml +30 -0
- data/plugins/rspec/rspec.png +0 -0
- data/plugins/rspec/rspec.rb +945 -0
- data/plugins/rspec/rspec.svg +90 -0
- data/plugins/rspec/rspecui.rc +20 -0
- data/plugins/rspec/ruber_rspec_formatter.rb +312 -0
- data/plugins/rspec/ui/rspec_project_widget.rb +170 -0
- data/plugins/rspec/ui/rspec_project_widget.ui +193 -0
- data/plugins/ruby_development/plugin.yaml +27 -0
- data/plugins/ruby_development/ruby_development.png +0 -0
- data/plugins/ruby_development/ruby_development.rb +453 -0
- data/plugins/ruby_development/ruby_developmentui.rc +19 -0
- data/plugins/ruby_development/ui/project_widget.rb +112 -0
- data/plugins/ruby_development/ui/project_widget.ui +108 -0
- data/plugins/ruby_runner/config_widget.rb +116 -0
- data/plugins/ruby_runner/plugin.yaml +26 -0
- data/plugins/ruby_runner/project_widget.rb +62 -0
- data/plugins/ruby_runner/ruby.png +0 -0
- data/plugins/ruby_runner/ruby_interpretersui.rc +26 -0
- data/plugins/ruby_runner/ruby_runner.rb +411 -0
- data/plugins/ruby_runner/ui/config_widget.rb +92 -0
- data/plugins/ruby_runner/ui/config_widget.ui +91 -0
- data/plugins/ruby_runner/ui/project_widget.rb +60 -0
- data/plugins/ruby_runner/ui/project_widget.ui +48 -0
- data/plugins/ruby_runner/ui/ruby_runnner_plugin_option_widget.rb +59 -0
- data/plugins/ruby_runner/ui/ruby_runnner_plugin_option_widget.ui +44 -0
- data/plugins/state/plugin.yaml +28 -0
- data/plugins/state/state.rb +520 -0
- data/plugins/state/ui/config_widget.rb +92 -0
- data/plugins/state/ui/config_widget.ui +89 -0
- data/plugins/syntax_checker/plugin.yaml +18 -0
- data/plugins/syntax_checker/syntax_checker.rb +662 -0
- data/ruber.desktop +10 -0
- data/spec/annotation_model_spec.rb +174 -0
- data/spec/common.rb +119 -0
- data/spec/component_manager_spec.rb +1259 -0
- data/spec/document_list_spec.rb +626 -0
- data/spec/document_project_spec.rb +373 -0
- data/spec/document_spec.rb +779 -0
- data/spec/editor_view_spec.rb +167 -0
- data/spec/external_program_plugin_spec.rb +676 -0
- data/spec/filtered_output_widget_spec.rb +642 -0
- data/spec/gui_states_handler_spec.rb +304 -0
- data/spec/kde_config_option_backend_spec.rb +214 -0
- data/spec/kde_sugar_spec.rb +101 -0
- data/spec/ktexteditor_wrapper_spec.rb +305 -0
- data/spec/output_widget_spec.rb +1703 -0
- data/spec/plugin_spec.rb +1393 -0
- data/spec/plugin_specification_reader_spec.rb +1765 -0
- data/spec/plugin_specification_spec.rb +401 -0
- data/spec/project_backend_spec.rb +172 -0
- data/spec/project_files_list_spec.rb +401 -0
- data/spec/project_list_spec.rb +511 -0
- data/spec/project_spec.rb +990 -0
- data/spec/qt_sugar_spec.rb +328 -0
- data/spec/settings_container_spec.rb +617 -0
- data/spec/settings_dialog_manager_spec.rb +773 -0
- data/spec/settings_dialog_spec.rb +419 -0
- data/spec/state_spec.rb +991 -0
- data/spec/utils_spec.rb +406 -0
- data/spec/workspace_spec.rb +869 -0
- data/spec/yaml_option_backend_spec.rb +246 -0
- metadata +284 -0
data/spec/plugin_spec.rb
ADDED
|
@@ -0,0 +1,1393 @@
|
|
|
1
|
+
require 'spec/common'
|
|
2
|
+
|
|
3
|
+
require 'ruber/plugin'
|
|
4
|
+
require 'ruber/plugin_specification'
|
|
5
|
+
require 'ruber/project'
|
|
6
|
+
require 'ruber/settings_container'
|
|
7
|
+
require 'ruber/kde_config_option_backend'
|
|
8
|
+
require 'ruber/editor/document'
|
|
9
|
+
require 'ruber/plugin_specification_reader'
|
|
10
|
+
|
|
11
|
+
module PluginSpec
|
|
12
|
+
|
|
13
|
+
class FakeConfig < Qt::Object
|
|
14
|
+
signals 'settings_changed()'
|
|
15
|
+
|
|
16
|
+
include Ruber::SettingsContainer
|
|
17
|
+
|
|
18
|
+
def initialize
|
|
19
|
+
super
|
|
20
|
+
setup_container(Ruber::KDEConfigSettingsBackend.new)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def add_option *args; end
|
|
24
|
+
|
|
25
|
+
def remove_option *args;end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class MyWidget < Qt::Widget
|
|
29
|
+
|
|
30
|
+
slots 'load_settings()'
|
|
31
|
+
|
|
32
|
+
def load_settings
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe 'Ruber::Plugin, when created' do
|
|
40
|
+
|
|
41
|
+
before do
|
|
42
|
+
@app = Qt::Object.new
|
|
43
|
+
@data = {:name => :test, :class => 'Ruber::Plugin'}
|
|
44
|
+
@manager = flexmock{|m| m.should_ignore_missing}
|
|
45
|
+
@config = PluginSpec::FakeConfig.new
|
|
46
|
+
@mw = flexmock("main_window"){|m| m.should_ignore_missing}
|
|
47
|
+
flexmock(Ruber).should_receive(:[]).with(:app).and_return(@app).by_default
|
|
48
|
+
flexmock(Ruber).should_receive(:[]).with(:components).and_return(@manager).by_default
|
|
49
|
+
flexmock(Ruber).should_receive(:[]).with(:config).and_return(@config).by_default
|
|
50
|
+
flexmock(Ruber).should_receive(:[]).with(:main_window).and_return(@mw).by_default
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'should call super passing the application object as argument' do
|
|
54
|
+
plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
55
|
+
plug.parent.should equal(@app)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it 'should store the argument passed to the constructor int the plugin_description attribute' do
|
|
59
|
+
pdf = Ruber::PluginSpecification.full( @data )
|
|
60
|
+
plug = Ruber::Plugin.new pdf
|
|
61
|
+
plug.plugin_description.should equal( pdf )
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'should store itself in the component manager' do
|
|
65
|
+
@manager = flexmock('manager'){|m| m.should_receive(:add).once .with(Ruber::Plugin)}
|
|
66
|
+
flexmock(Ruber).should_receive(:[]).with(:components).and_return(@manager)
|
|
67
|
+
flexmock(Ruber).should_receive(:[]).with(:app).and_return(@app)
|
|
68
|
+
flexmock(Ruber).should_receive(:[]).with(:config).and_return(@config)
|
|
69
|
+
Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it 'should set the plugin name to be equal to the name contained in the pdf' do
|
|
73
|
+
plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
74
|
+
plug.plugin_name.should == :test
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it 'should connect its "load_settings()" slot to the configuration manager\'s "settings_changed()" signal' do
|
|
78
|
+
plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
79
|
+
flexmock(plug).should_receive(:load_settings).once
|
|
80
|
+
@config.instance_eval{emit settings_changed}
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it 'should register its options, if any, with the config object, if it exists (converting each Option object to an OpenStruct)' do
|
|
84
|
+
@data[:config_options]= {
|
|
85
|
+
:General=> {
|
|
86
|
+
:o1 => {:default => '"#{\'a\'.capitalize}"'},
|
|
87
|
+
:o2 => {:default => 3},
|
|
88
|
+
:o3 => {:default => "Array"},
|
|
89
|
+
:o4 => {:default => 'y', :eval_default => false}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
flexmock(@config) do |m|
|
|
93
|
+
m.should_receive(:add_option).once.with(OS.new(:name => :o1, :group => :General, :default => 'A', :relative_path => false, :eval_default => true, :order => nil))
|
|
94
|
+
m.should_receive(:add_option).once.with(OS.new({:name => :o2, :group => :General, :default => 3, :relative_path => false, :eval_default => true, :order => nil}))
|
|
95
|
+
m.should_receive(:add_option).once.with(OS.new({:name => :o3, :group => :General, :default => Array, :relative_path => false, :eval_default => true, :order => nil}))
|
|
96
|
+
m.should_receive(:add_option).once.with(OS.new({:name => :o4, :group => :General, :default => 'y', :relative_path => false, :eval_default => false, :order => nil}))
|
|
97
|
+
end
|
|
98
|
+
plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it 'register options which have a lower "order" attribute before those with a higher value' do
|
|
102
|
+
@data[:config_options]= {
|
|
103
|
+
:General=> {
|
|
104
|
+
:o1 => {:default => '"#{\'a\'.capitalize}"', :order => 1},
|
|
105
|
+
:o2 => {:default => 3, :order => 0},
|
|
106
|
+
:o3 => {:default => "Array", :order => 0},
|
|
107
|
+
:o4 => {:default => 'y', :eval_default => false, :order => 1}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
flexmock(@config) do |m|
|
|
111
|
+
m.should_receive(:add_option).once.with(OS.new({:name => :o2, :group => :General, :default => 3, :relative_path => false, :eval_default => true, :order => 0})).ordered('first')
|
|
112
|
+
m.should_receive(:add_option).once.with(OS.new({:name => :o3, :group => :General, :default => Array, :relative_path => false, :eval_default => true, :order => 0})).ordered('first')
|
|
113
|
+
m.should_receive(:add_option).once.with(OS.new(:name => :o1, :group => :General, :default => 'A', :relative_path => false, :eval_default => true, :order => 1)).ordered('second')
|
|
114
|
+
m.should_receive(:add_option).once.with(OS.new({:name => :o4, :group => :General, :default => 'y', :relative_path => false, :eval_default => false, :order => 1})).ordered('second')
|
|
115
|
+
end
|
|
116
|
+
plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
it 'register options don\'t have an "order" attribute at an arbitrary time' do
|
|
120
|
+
@data[:config_options]= {
|
|
121
|
+
:General=> {
|
|
122
|
+
:o1 => {:default => '"#{\'a\'.capitalize}"', :order => 1},
|
|
123
|
+
:o2 => {:default => 3},
|
|
124
|
+
:o3 => {:default => "Array", :order => 0},
|
|
125
|
+
:o4 => {:default => 'y', :eval_default => false}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
flexmock(@config) do |m|
|
|
129
|
+
m.should_receive(:add_option).once.with(OS.new({:name => :o2, :group => :General, :default => 3, :relative_path => false, :eval_default => true, :order => nil}))
|
|
130
|
+
m.should_receive(:add_option).once.with(OS.new({:name => :o3, :group => :General, :default => Array, :relative_path => false, :eval_default => true, :order => 0})).ordered('first')
|
|
131
|
+
m.should_receive(:add_option).once.with(OS.new(:name => :o1, :group => :General, :default => 'A', :relative_path => false, :eval_default => true, :order => 1)).ordered('second')
|
|
132
|
+
m.should_receive(:add_option).once.with(OS.new({:name => :o4, :group => :General, :default => 'y', :relative_path => false, :eval_default => false, :order => nil}))
|
|
133
|
+
end
|
|
134
|
+
plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
it 'should use the plugin\'s binding to evaluate the options\' default value' do
|
|
139
|
+
class Ruber::Plugin
|
|
140
|
+
def test_value
|
|
141
|
+
7
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
@data[:config_options] = {
|
|
145
|
+
:G => {
|
|
146
|
+
:o1 => {:default => 'test_value'}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
flexmock(@config){|m| m.should_receive(:add_option).once.with(OS.new(:name => :o1, :group => :G, :default => 7, :relative_path => false, :eval_default => true, :order => nil))}
|
|
150
|
+
plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
151
|
+
class Ruber::Plugin
|
|
152
|
+
undef_method :test_value
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it 'should not attempt to register its options if the config component doesn\'t exist' do
|
|
157
|
+
flexmock(Ruber).should_receive(:[]).with(:config).and_return nil
|
|
158
|
+
flexmock(Ruber).should_receive(:[]).with(:components).and_return(@manager)
|
|
159
|
+
flexmock(Ruber).should_receive(:[]).with(:app).and_return(@app)
|
|
160
|
+
@data[:config_options]= { :General=> { :o1 => {:type => 'string', :default => '"#{\'a\'.capitalize}"'} }}
|
|
161
|
+
lambda{Ruber::Plugin.new Ruber::PluginSpecification.full(@data)}.should_not raise_error
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
it 'should add all the config widgets it provides, if any, to the config manager' do
|
|
165
|
+
@data[:config_widgets] = [
|
|
166
|
+
{:class => Qt::CheckBox, :caption => 'C1'},
|
|
167
|
+
{:class => Qt::PushButton, :caption => 'C2'}
|
|
168
|
+
]
|
|
169
|
+
Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
170
|
+
mw = Qt::Widget.new
|
|
171
|
+
flexmock(Ruber).should_receive(:[]).with(:app).and_return(@app)
|
|
172
|
+
flexmock(Ruber).should_receive(:[]).with(:components).and_return(@manager)
|
|
173
|
+
flexmock(Ruber).should_receive(:[]).with(:config).and_return(@config)
|
|
174
|
+
flexmock(Ruber).should_receive(:[]).with(:main_window).and_return(mw)
|
|
175
|
+
widgets = @config.dialog.widgets
|
|
176
|
+
widgets.size.should == 2
|
|
177
|
+
widgets.any?{|w| w.is_a?(Qt::CheckBox)}.should_not be_nil
|
|
178
|
+
widgets.any?{|w| w.is_a?(Qt::PushButton)}.should_not be_nil
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
it 'should call the "load_settings" method, if the configuration manager exists' do
|
|
182
|
+
Ruber::Plugin.class_eval do
|
|
183
|
+
alias :old_load_settings :load_settings
|
|
184
|
+
def load_settings
|
|
185
|
+
@called = true
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
@data[:config_options]= { :General=> { :o1 => {:type => 'string', :default => '"#{\'a\'.capitalize}"'} } }
|
|
189
|
+
flexmock(@config).should_receive(:add_option)
|
|
190
|
+
plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
191
|
+
plug.instance_variable_get(:@called).should be_true
|
|
192
|
+
Ruber::Plugin.class_eval{alias :load_settings :old_load_settings}
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
it 'shouldn\'t call the "load_settings" method, if the configuration manager doesn\'t exist' do
|
|
196
|
+
Ruber::Plugin.class_eval do
|
|
197
|
+
alias :old_load_settings :load_settings
|
|
198
|
+
def load_settings
|
|
199
|
+
@called = true
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
flexmock(Ruber).should_receive(:[]).with(:config).and_return nil
|
|
203
|
+
flexmock(Ruber).should_receive(:[]).with(:components).and_return(@manager)
|
|
204
|
+
flexmock(Ruber).should_receive(:[]).with(:app).and_return(@app)
|
|
205
|
+
@data[:config_options]= { :General=> { :o1 => {:type => 'string', :default => '"#{\'a\'.capitalize}"'} } }
|
|
206
|
+
plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
207
|
+
plug.instance_variable_get(:@called).should be_nil
|
|
208
|
+
Ruber::Plugin.class_eval{alias :load_settings :old_load_settings}
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
it 'should create the tool widgets mentioned in the PDF' do
|
|
212
|
+
@data[:tool_widgets] = [
|
|
213
|
+
{:class => Qt::CheckBox, :caption => 'w1', :pixmap => 'xyz.png'},
|
|
214
|
+
{:class => Qt::LineEdit, :position => :left, :caption => 'w2', :pixmap => 'abc.png'},
|
|
215
|
+
]
|
|
216
|
+
pix1 = flexmock('xyz.png')
|
|
217
|
+
pix2 = flexmock('abc.png')
|
|
218
|
+
flexmock(Qt::Pixmap).should_receive(:new).once.with('xyz.png').and_return pix1
|
|
219
|
+
flexmock(Qt::Pixmap).should_receive(:new).once.with('abc.png').and_return pix2
|
|
220
|
+
pdf = Ruber::PluginSpecification.full(@data)
|
|
221
|
+
pdf.tool_widgets[0].pixmap = 'xyz.png'
|
|
222
|
+
pdf.tool_widgets[1].pixmap = 'abc.png'
|
|
223
|
+
@mw.should_receive(:add_tool).with(:bottom, Qt::CheckBox, pix1, 'w1').once
|
|
224
|
+
@mw.should_receive(:add_tool).with(:left, Qt::LineEdit, pix2, 'w2').once
|
|
225
|
+
Ruber::Plugin.new pdf
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
it 'should give the tool widgets the names specified in the :name entry, if given' do
|
|
229
|
+
@data[:tool_widgets] = [
|
|
230
|
+
{:class => Qt::CheckBox, :caption => 'w1', :pixmap => 'xyz.png', :name => 'W1'},
|
|
231
|
+
{:class => Qt::LineEdit, :position => :left, :caption => 'w2', :pixmap => 'abc.png', :name => 'W2'},
|
|
232
|
+
]
|
|
233
|
+
w1 = Qt::CheckBox.new
|
|
234
|
+
w2 = Qt::LineEdit.new
|
|
235
|
+
flexmock(Qt::CheckBox).should_receive(:new).once.and_return(w1)
|
|
236
|
+
flexmock(Qt::LineEdit).should_receive(:new).once.and_return(w2)
|
|
237
|
+
Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
238
|
+
w1.object_name.should == 'W1'
|
|
239
|
+
w2.object_name.should == 'W2'
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
it 'should store the tool widgets in instance variables, according to the :var_name entry' do
|
|
243
|
+
@data[:tool_widgets] = [
|
|
244
|
+
{:class => Qt::CheckBox, :caption => 'w1', :pixmap => 'xyz.png', :var_name => 'w1'},
|
|
245
|
+
{:class => Qt::LineEdit, :position => :left, :caption => 'w2', :pixmap => 'abc.png'},
|
|
246
|
+
{:class => Qt::PushButton, :position => :right, :caption => 'w3', :pixmap => 'jkl.png', :var_name => nil},
|
|
247
|
+
]
|
|
248
|
+
w1 = Qt::CheckBox.new
|
|
249
|
+
w2 = Qt::LineEdit.new
|
|
250
|
+
flexmock(Qt::CheckBox).should_receive(:new).once.and_return(w1)
|
|
251
|
+
flexmock(Qt::LineEdit).should_receive(:new).once.and_return(w2)
|
|
252
|
+
plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
253
|
+
plug.instance_variable_get(:@w1).should equal(w1)
|
|
254
|
+
plug.instance_variable_get(:@widget).should equal(w2)
|
|
255
|
+
# the map part is needed because instance_variables returns strings in ruby
|
|
256
|
+
# 1.8 and symbols in ruby 1.9
|
|
257
|
+
plug.instance_variables.map{|v| v.to_s}.should =~ ['@plugin_description', '@w1', '@widget']
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
it 'should connect the tool widgets\' "load_settings" method to the application, if the application exists and the tool widgets provide a load_settings method' do
|
|
261
|
+
Object.class_eval <<-EOS
|
|
262
|
+
class W1 < Qt::Widget
|
|
263
|
+
slots 'load_settings()'
|
|
264
|
+
def load_settings;end
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
class W2 < Qt::Widget
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
class W3 < Qt::Widget
|
|
271
|
+
slots 'load_settings()'
|
|
272
|
+
def load_settings;end
|
|
273
|
+
end
|
|
274
|
+
EOS
|
|
275
|
+
@data[:tool_widgets] = [
|
|
276
|
+
{:class => W1, :caption => 'w1', :pixmap => 'xyz.png', :var_name => 'w1'},
|
|
277
|
+
{:class => W2, :position => :left, :caption => 'w2', :pixmap => 'abc.png'},
|
|
278
|
+
{:class => W3, :position => :right, :caption => 'w3', :pixmap => 'jkl.png', :var_name => nil},
|
|
279
|
+
]
|
|
280
|
+
w1 = W1.new
|
|
281
|
+
w2 = W2.new
|
|
282
|
+
w3 = W3.new
|
|
283
|
+
flexmock(W1).should_receive(:new).once.and_return(w1)
|
|
284
|
+
flexmock(W2).should_receive(:new).once.and_return(w2)
|
|
285
|
+
flexmock(W3).should_receive(:new).once.and_return(w3)
|
|
286
|
+
plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
287
|
+
flexmock(w2).should_receive(:load_settings).never
|
|
288
|
+
flexmock(w1).should_receive(:load_settings).once
|
|
289
|
+
flexmock(w3).should_receive(:load_settings).once
|
|
290
|
+
@config.instance_eval{emit settings_changed}
|
|
291
|
+
Object.send(:remove_const, :W1)
|
|
292
|
+
Object.send(:remove_const, :W2)
|
|
293
|
+
Object.send(:remove_const, :W3)
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
it 'should call the "load_settings" method of each tool widget which provides it, if the configuration manager exists' do
|
|
297
|
+
Object.class_eval <<-EOS
|
|
298
|
+
class W1b < Qt::Widget
|
|
299
|
+
slots 'load_settings()'
|
|
300
|
+
def load_settings;end
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
class W2b < Qt::Widget
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
class W3b < Qt::Widget
|
|
307
|
+
slots 'load_settings()'
|
|
308
|
+
def load_settings;end
|
|
309
|
+
end
|
|
310
|
+
EOS
|
|
311
|
+
@data[:tool_widgets] = [
|
|
312
|
+
{:class => W1b, :caption => 'w1', :pixmap => 'xyz.png', :var_name => 'w1'},
|
|
313
|
+
{:class => W2b, :position => :left, :caption => 'w2', :pixmap => 'abc.png'},
|
|
314
|
+
{:class => W3b, :position => :right, :caption => 'w3', :pixmap => 'jkl.png', :var_name => nil},
|
|
315
|
+
]
|
|
316
|
+
w1 = W1b.new
|
|
317
|
+
w2 = W2b.new
|
|
318
|
+
w3 = W3b.new
|
|
319
|
+
flexmock(W1b).should_receive(:new).once.and_return(w1)
|
|
320
|
+
flexmock(W2b).should_receive(:new).once.and_return(w2)
|
|
321
|
+
flexmock(W3b).should_receive(:new).once.and_return(w3)
|
|
322
|
+
flexmock(w1).should_receive(:load_settings).once
|
|
323
|
+
flexmock(w3).should_receive(:load_settings).once
|
|
324
|
+
plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
325
|
+
Object.send(:remove_const, :W1b)
|
|
326
|
+
Object.send(:remove_const, :W2b)
|
|
327
|
+
Object.send(:remove_const, :W3b)
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
describe 'Ruber::Plugin#unload' do
|
|
333
|
+
|
|
334
|
+
before do
|
|
335
|
+
@app = Qt::Object.new
|
|
336
|
+
@data = {:name => :test, :class => 'Ruber::Plugin'}
|
|
337
|
+
@manager = flexmock{|m| m.should_ignore_missing}
|
|
338
|
+
@config = PluginSpec::FakeConfig.new
|
|
339
|
+
@mw = flexmock('main window'){|m| m.should_ignore_missing}
|
|
340
|
+
flexmock(Ruber).should_receive(:[]).with(:app).and_return(@app).by_default
|
|
341
|
+
flexmock(Ruber).should_receive(:[]).with(:components).and_return(@manager).by_default
|
|
342
|
+
flexmock(Ruber).should_receive(:[]).with(:config).and_return(@config).by_default
|
|
343
|
+
flexmock(Ruber).should_receive(:[]).with(:main_window).and_return(@mw).by_default
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
it 'calls the shutdown method' do
|
|
347
|
+
plugin = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
348
|
+
flexmock(plugin).should_receive(:shutdown).once
|
|
349
|
+
plugin.unload
|
|
350
|
+
end
|
|
351
|
+
|
|
352
|
+
it 'should disconnect itself from the application\'s settings_changed signal' do
|
|
353
|
+
plugin = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
354
|
+
flexmock(plugin).should_receive(:load_settings).never
|
|
355
|
+
plugin.unload
|
|
356
|
+
@config.instance_eval{emit settings_changed}
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
it 'should remove all tool widgets from the main window' do
|
|
360
|
+
@data[:tool_widgets] = [
|
|
361
|
+
{:class => Qt::CheckBox, :caption => 'W1', :pixmap => 'xyz.png', :name => 'w1'},
|
|
362
|
+
{:class => Qt::LineEdit, :position => :left, :caption => 'W2', :name => 'w2', :pixmap => 'xab.png'},
|
|
363
|
+
{:class => Qt::PushButton, :position => :right, :caption => 'w3', :pixmap => 'jkl.png'},
|
|
364
|
+
]
|
|
365
|
+
w1 = Qt::CheckBox.new
|
|
366
|
+
w2 = Qt::LineEdit.new
|
|
367
|
+
w3 = Qt::PushButton.new
|
|
368
|
+
flexmock(Qt::CheckBox).should_receive(:new).once.and_return(w1)
|
|
369
|
+
flexmock(Qt::LineEdit).should_receive(:new).once.and_return(w2)
|
|
370
|
+
flexmock(Qt::PushButton).should_receive(:new).once.and_return(w3)
|
|
371
|
+
@mw.should_receive(:remove_tool).once.with('w1')
|
|
372
|
+
@mw.should_receive(:remove_tool).once.with('w2')
|
|
373
|
+
@mw.should_receive(:remove_tool).once.with('w3')
|
|
374
|
+
plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
375
|
+
plug.unload
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
it 'should remove all configuration options from the configuration manager, if it exists' do
|
|
379
|
+
@data[:config_options] = {:x => {:a => {:default => 3}, :b => {:default => 'string'}}, :y => {:c => {:default => true}}}
|
|
380
|
+
flexmock(@config) do |mk|
|
|
381
|
+
mk.should_receive(:remove_option).with(:x, :a).once
|
|
382
|
+
mk.should_receive(:remove_option).with(:x, :b).once
|
|
383
|
+
mk.should_receive(:remove_option).with(:y, :c).once
|
|
384
|
+
end
|
|
385
|
+
plugin = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
386
|
+
plugin.unload
|
|
387
|
+
end
|
|
388
|
+
|
|
389
|
+
it 'shouldn\'t attempt tp remove the configuration options from the configuration manager, if it doesn\'t exist' do
|
|
390
|
+
@data[:config_options] = {:x => {:a => {:default => 3}, :b => {:default => 'string'}}, :y => {:c => {:default => true}}}
|
|
391
|
+
plugin = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
392
|
+
lambda{plugin.unload}.should_not raise_error
|
|
393
|
+
end
|
|
394
|
+
|
|
395
|
+
end
|
|
396
|
+
|
|
397
|
+
describe 'Ruber::Plugin' do
|
|
398
|
+
|
|
399
|
+
before do
|
|
400
|
+
@data = {:name => 'test', :class => 'Ruber::Plugin'}
|
|
401
|
+
@app = Qt::Object.new
|
|
402
|
+
flexmock(Ruber).should_receive(:[]).with(:app).and_return(@app).by_default
|
|
403
|
+
@projects = Qt::Object.new
|
|
404
|
+
flexmock(Ruber).should_receive(:[]).with(:projects).and_return(@projects).by_default
|
|
405
|
+
@manager = flexmock{|m| m.should_ignore_missing}
|
|
406
|
+
flexmock(Ruber).should_receive(:[]).with(:components).and_return(@manager).by_default
|
|
407
|
+
flexmock(Ruber).should_receive(:[]).with(:config).and_return(nil).by_default
|
|
408
|
+
@plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
409
|
+
end
|
|
410
|
+
|
|
411
|
+
it 'should have a "load_settings" private method' do
|
|
412
|
+
@plug.respond_to?(:load_settings, true).should be_true
|
|
413
|
+
@plug.respond_to?(:load_settings).should be_false
|
|
414
|
+
end
|
|
415
|
+
|
|
416
|
+
it 'should have a save_settings method' do
|
|
417
|
+
@plug.should respond_to(:save_settings)
|
|
418
|
+
end
|
|
419
|
+
|
|
420
|
+
it 'should have a query_close method which returns true' do
|
|
421
|
+
@plug.query_close.should == true
|
|
422
|
+
end
|
|
423
|
+
|
|
424
|
+
describe '#add_options_to_project' do
|
|
425
|
+
|
|
426
|
+
before do
|
|
427
|
+
@data[:project_options] = {
|
|
428
|
+
:g1 => {:o1 => {:default => 7, :scope => :global}, :o2 => {:default => 'abc', :scope => :document}},
|
|
429
|
+
:g2 => {:o1 => {:default => %w[a b c]}, :o3 => {:default => :xyz}}
|
|
430
|
+
}
|
|
431
|
+
@projects = Qt::Object.new
|
|
432
|
+
flexmock(Ruber).should_receive(:[]).with(:projects).and_return(@projects).by_default
|
|
433
|
+
@plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
434
|
+
@prj = Ruber::Project.new('test.ruprj', 'Test')
|
|
435
|
+
end
|
|
436
|
+
|
|
437
|
+
it 'adds the options for which the project\'s match_rule? returns true to the project' do
|
|
438
|
+
desc = @plug.plugin_description
|
|
439
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.project_options[[:g1, :o1]]).and_return true
|
|
440
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.project_options[[:g1, :o2]]).and_return false
|
|
441
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.project_options[[:g2, :o1]]).and_return false
|
|
442
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.project_options[[:g2, :o3]]).and_return true
|
|
443
|
+
@plug.add_options_to_project @prj
|
|
444
|
+
opts = @prj.instance_variable_get(:@known_options)
|
|
445
|
+
opts[[:g1,:o1]].default.should == 7
|
|
446
|
+
opts[[:g1,:o2]].should be_nil
|
|
447
|
+
opts[[:g2,:o1]].should be_nil
|
|
448
|
+
opts[[:g2,:o3]].default.should == :xyz
|
|
449
|
+
end
|
|
450
|
+
|
|
451
|
+
it 'uses the project\'s binding to evaluate the default values of the options' do
|
|
452
|
+
@prj.instance_variable_set(:@xyz, 5)
|
|
453
|
+
@plug.plugin_description.project_options[[:g1,:o1]].default = '2*@xyz'
|
|
454
|
+
@plug.add_options_to_project @prj
|
|
455
|
+
opts = @prj.instance_variable_get(:@known_options)
|
|
456
|
+
opts[[:g1,:o1]].default.should == 10
|
|
457
|
+
end
|
|
458
|
+
|
|
459
|
+
it 'adds first options whose "order" attribure is lower' do
|
|
460
|
+
desc = @plug.plugin_description.project_options
|
|
461
|
+
desc[[:g1, :o1]].order = 1
|
|
462
|
+
desc[[:g1, :o2]].order = 0
|
|
463
|
+
desc[[:g2, :o1]].order = 0
|
|
464
|
+
desc[[:g2, :o3]].order = 1
|
|
465
|
+
flexmock(@prj).should_receive(:match_rule?).and_return true
|
|
466
|
+
flexmock(@prj).should_receive(:add_option).once.with(desc[[:g1,:o2]]).ordered('first')
|
|
467
|
+
flexmock(@prj).should_receive(:add_option).once.with(desc[[:g2,:o1]]).ordered('first')
|
|
468
|
+
flexmock(@prj).should_receive(:add_option).once.with(desc[[:g1,:o1]]).ordered('second')
|
|
469
|
+
flexmock(@prj).should_receive(:add_option).once.with(desc[[:g2,:o3]]).ordered('second')
|
|
470
|
+
@plug.add_options_to_project @prj
|
|
471
|
+
end
|
|
472
|
+
|
|
473
|
+
it 'adds options with an "order" attribute of nil at any time' do
|
|
474
|
+
desc = @plug.plugin_description.project_options
|
|
475
|
+
desc[[:g1, :o1]].order = 1
|
|
476
|
+
desc[[:g1, :o2]].order = nil
|
|
477
|
+
desc[[:g2, :o1]].order = 0
|
|
478
|
+
desc[[:g2, :o3]].order = nil
|
|
479
|
+
flexmock(@prj).should_receive(:match_rule?).and_return true
|
|
480
|
+
flexmock(@prj).should_receive(:add_option).once.with(desc[[:g1,:o2]])
|
|
481
|
+
flexmock(@prj).should_receive(:add_option).once.with(desc[[:g2,:o1]]).ordered('first')
|
|
482
|
+
flexmock(@prj).should_receive(:add_option).once.with(desc[[:g1,:o1]]).ordered('second')
|
|
483
|
+
flexmock(@prj).should_receive(:add_option).once.with(desc[[:g2,:o3]])
|
|
484
|
+
@plug.add_options_to_project @prj
|
|
485
|
+
end
|
|
486
|
+
|
|
487
|
+
it 'ignores any option which has already been added if the second parameter is false' do
|
|
488
|
+
desc = @plug.plugin_description
|
|
489
|
+
|
|
490
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.project_options[[:g1, :o1]]).and_return true
|
|
491
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.project_options[[:g1, :o2]]).and_return true
|
|
492
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.project_options[[:g2, :o1]]).and_return true
|
|
493
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.project_options[[:g2, :o3]]).and_return true
|
|
494
|
+
|
|
495
|
+
flexmock(@prj).should_receive(:add_option).once.with(desc.project_options[[:g1, :o1]])
|
|
496
|
+
flexmock(@prj).should_receive(:add_option).once.with(desc.project_options[[:g1, :o2]]).and_raise(ArgumentError)
|
|
497
|
+
flexmock(@prj).should_receive(:add_option).once.with(desc.project_options[[:g2, :o1]])
|
|
498
|
+
flexmock(@prj).should_receive(:add_option).once.with(desc.project_options[[:g2, :o3]])
|
|
499
|
+
|
|
500
|
+
@plug.add_options_to_project @prj, false
|
|
501
|
+
end
|
|
502
|
+
|
|
503
|
+
it 'doesn\'t ignore exceptions due to options having already been added if the second argument is true' do
|
|
504
|
+
desc = @plug.plugin_description
|
|
505
|
+
|
|
506
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.project_options[[:g1, :o1]]).and_return true
|
|
507
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.project_options[[:g1, :o2]]).and_return true
|
|
508
|
+
flexmock(@prj).should_receive(:match_rule?).never.with(desc.project_options[[:g2, :o1]]).and_return true
|
|
509
|
+
flexmock(@prj).should_receive(:match_rule?).never.with(desc.project_options[[:g2, :o3]]).and_return true
|
|
510
|
+
|
|
511
|
+
flexmock(@prj).should_receive(:add_option).once.with(desc.project_options[[:g1, :o1]])
|
|
512
|
+
flexmock(@prj).should_receive(:add_option).once.with(desc.project_options[[:g1, :o2]]).and_raise(ArgumentError)
|
|
513
|
+
flexmock(@prj).should_receive(:add_option).never.with(desc.project_options[[:g2, :o1]])
|
|
514
|
+
flexmock(@prj).should_receive(:add_option).never.with(desc.project_options[[:g2, :o3]])
|
|
515
|
+
|
|
516
|
+
lambda{@plug.add_options_to_project @prj, true}.should raise_error(ArgumentError)
|
|
517
|
+
end
|
|
518
|
+
|
|
519
|
+
end
|
|
520
|
+
|
|
521
|
+
describe '#add_widgets_to_project' do
|
|
522
|
+
|
|
523
|
+
before do
|
|
524
|
+
@data[:project_widgets] = [
|
|
525
|
+
{:class => 'Qt::ComboBox', :caption => 'C1', :scope => :document},
|
|
526
|
+
{:class => 'Qt::LineEdit', :caption => 'C1', :scope => :global},
|
|
527
|
+
{:class => 'Qt::CheckBox', :caption => 'C2'},
|
|
528
|
+
]
|
|
529
|
+
@mw = Qt::Widget.new
|
|
530
|
+
flexmock(Ruber).should_receive(:[]).with(:main_window).and_return(@mw).by_default
|
|
531
|
+
@projects = Qt::Object.new
|
|
532
|
+
flexmock(Ruber).should_receive(:[]).with(:projects).and_return(@projects).by_default
|
|
533
|
+
@plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
534
|
+
@prj = Ruber::Project.new('test.ruprj', 'Test')
|
|
535
|
+
end
|
|
536
|
+
|
|
537
|
+
it 'adds the widgets for which the project\'s match_rule? method returns true to the project' do
|
|
538
|
+
desc = @plug.plugin_description
|
|
539
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.project_widgets[0]).and_return false
|
|
540
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.project_widgets[1]).and_return true
|
|
541
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.project_widgets[2]).and_return true
|
|
542
|
+
@plug.register_with_project @prj
|
|
543
|
+
le = Qt::LineEdit.new
|
|
544
|
+
cb = Qt::CheckBox.new
|
|
545
|
+
flexmock(Qt::LineEdit).should_receive(:new).once.and_return(le)
|
|
546
|
+
flexmock(Qt::CheckBox).should_receive(:new).once.and_return(cb)
|
|
547
|
+
widgets = @prj.dialog.widgets
|
|
548
|
+
widgets.size.should == 2
|
|
549
|
+
widgets.find{|w| w.is_a? Qt::ComboBox}.should be_nil
|
|
550
|
+
widgets.find{|w| w.is_a? Qt::LineEdit}.should_not be_nil
|
|
551
|
+
widgets.find{|w| w.is_a? Qt::CheckBox}.should_not be_nil
|
|
552
|
+
end
|
|
553
|
+
|
|
554
|
+
end
|
|
555
|
+
|
|
556
|
+
describe '#add_extensions_to_project' do
|
|
557
|
+
|
|
558
|
+
class Ext < Qt::Object
|
|
559
|
+
include Ruber::Extension
|
|
560
|
+
end
|
|
561
|
+
|
|
562
|
+
before do
|
|
563
|
+
@cls_name = self.class.const_get(:Ext).name
|
|
564
|
+
@data[:extensions] = {
|
|
565
|
+
:ext1 => {:class => @cls_name},
|
|
566
|
+
:ext2 => {:class => 'Qt::Object', :scope => :document}
|
|
567
|
+
}
|
|
568
|
+
@projects = Qt::Object.new
|
|
569
|
+
flexmock(Ruber).should_receive(:[]).with(:projects).and_return(@projects).by_default
|
|
570
|
+
@plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
571
|
+
@prj = Ruber::Project.new('test.ruprj', 'Test')
|
|
572
|
+
end
|
|
573
|
+
|
|
574
|
+
it 'adds each extension for which the project\'s match_rule? method returns true to the project' do
|
|
575
|
+
desc = @plug.plugin_description
|
|
576
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.extensions[:ext1]).and_return true
|
|
577
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.extensions[:ext2]).and_return false
|
|
578
|
+
@plug.add_extensions_to_project @prj
|
|
579
|
+
exts = @prj.instance_variable_get(:@project_extensions)
|
|
580
|
+
exts[:ext1].parent.should equal(@prj)
|
|
581
|
+
exts[:ext2].should be_nil
|
|
582
|
+
end
|
|
583
|
+
|
|
584
|
+
it 'adds only the first extension matching the project in a list of extensions' do
|
|
585
|
+
@data[:extensions] = {
|
|
586
|
+
:e => [
|
|
587
|
+
{:class => 'String', :scope => :global},
|
|
588
|
+
{:class => 'Qt::Widget', :scope => :document},
|
|
589
|
+
{:class => 'Qt::Object', :scope => [:globl, :document]}
|
|
590
|
+
]
|
|
591
|
+
}
|
|
592
|
+
@plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
593
|
+
@prj = Ruber::Project.new('test.ruprj', 'Test')
|
|
594
|
+
w = Qt::Widget.new{extend Ruber::Extension}
|
|
595
|
+
flexmock(Qt::Widget).should_receive(:new).once.with(@prj).and_return w
|
|
596
|
+
desc = @plug.plugin_description
|
|
597
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.extensions[:e][0]).and_return false
|
|
598
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.extensions[:e][1]).and_return true
|
|
599
|
+
flexmock(@prj).should_receive(:match_rule?).never.with(desc.extensions[:e][2])
|
|
600
|
+
@plug.add_extensions_to_project @prj
|
|
601
|
+
exts = @prj.instance_variable_get(:@project_extensions)
|
|
602
|
+
exts[:e].should be_a(Qt::Widget)
|
|
603
|
+
end
|
|
604
|
+
|
|
605
|
+
it 'sets the plugin attribute of the extension to itself' do
|
|
606
|
+
@data[:extensions][:ext3] = [
|
|
607
|
+
{:class => 'String', :scope => :global},
|
|
608
|
+
{:class => 'Qt::Widget', :scope => :document},
|
|
609
|
+
{:class => 'Qt::Object', :scope => [:globl, :document]}
|
|
610
|
+
]
|
|
611
|
+
@plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
612
|
+
@prj = Ruber::Project.new('test.ruprj', 'Test')
|
|
613
|
+
wid = Qt::Widget.new{extend Ruber::Extension}
|
|
614
|
+
flexmock(Qt::Widget).should_receive(:new).once.with(@prj).and_return(wid)
|
|
615
|
+
desc = @plug.plugin_description
|
|
616
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.extensions[:ext1]).and_return true
|
|
617
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.extensions[:ext2]).and_return false
|
|
618
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.extensions[:ext3][0]).and_return false
|
|
619
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.extensions[:ext3][1]).and_return true
|
|
620
|
+
@plug.add_extensions_to_project @prj
|
|
621
|
+
wid.plugin.should be_the_same_as(@plug)
|
|
622
|
+
@prj.extension(:ext1).plugin.should be_the_same_as(@plug)
|
|
623
|
+
end
|
|
624
|
+
|
|
625
|
+
it 'doesn\'t attempt to add any extension from a list if no one matches' do
|
|
626
|
+
@data[:extensions] = {
|
|
627
|
+
:e => [
|
|
628
|
+
{:class => 'String', :scope => :global},
|
|
629
|
+
{:class => 'Qt::Widget', :scope => :document},
|
|
630
|
+
{:class => 'Qt::Object', :scope => [:globl, :document]}
|
|
631
|
+
]
|
|
632
|
+
}
|
|
633
|
+
@plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
634
|
+
@prj = Ruber::Project.new('test.ruprj', 'Test')
|
|
635
|
+
desc = @plug.plugin_description
|
|
636
|
+
desc.extensions[:e].each{|d| flexmock(@prj).should_receive(:match_rule?).once.with(d).once.and_return false}
|
|
637
|
+
lambda{@plug.add_extensions_to_project @prj}.should_not raise_error
|
|
638
|
+
exts = @prj.instance_variable_get(:@project_extensions)
|
|
639
|
+
exts.should_not have_key(:e)
|
|
640
|
+
end
|
|
641
|
+
|
|
642
|
+
it 'doesn\'t attempt to add an extension which has already been added if the second argument is false' do
|
|
643
|
+
desc = @plug.plugin_description
|
|
644
|
+
old = Qt::Object.new Qt::Object.new
|
|
645
|
+
flexmock(@prj).should_receive(:match_rule?).with(desc.extensions[:ext1]).and_return true
|
|
646
|
+
flexmock(@prj).should_receive(:match_rule?).with(desc.extensions[:ext2]).and_return false
|
|
647
|
+
flexmock(@prj).should_receive(:extension).with(:ext1).once.and_return(old)
|
|
648
|
+
flexmock(@prj).should_receive(:extension).with(:ext2).once.and_return(nil)
|
|
649
|
+
flexmock(Qt::Object).should_receive(:new).never
|
|
650
|
+
flexmock(@prj).should_receive(:add_extension).never
|
|
651
|
+
@plug.add_extensions_to_project @prj, false
|
|
652
|
+
end
|
|
653
|
+
|
|
654
|
+
it 'doesn\'t check whether the extension already exists if the second argument is true' do
|
|
655
|
+
desc = @plug.plugin_description
|
|
656
|
+
new = Ext.new
|
|
657
|
+
flexmock(@prj).should_receive(:match_rule?).with(desc.extensions[:ext1]).and_return true
|
|
658
|
+
flexmock(@prj).should_receive(:match_rule?).with(desc.extensions[:ext2]).and_return false
|
|
659
|
+
flexmock(@prj).should_receive(:extension).never
|
|
660
|
+
flexmock(Ext).should_receive(:new).once.with(@prj).and_return new
|
|
661
|
+
flexmock(@prj).should_receive(:add_extension).once.with :ext1, new
|
|
662
|
+
@plug.add_extensions_to_project @prj, true
|
|
663
|
+
end
|
|
664
|
+
|
|
665
|
+
it 'emits the extension_added(QString, QObject*) signal for each added_extension, passing the extension name and the project as arguments' do
|
|
666
|
+
@data[:extensions][:ext3] = {:class => @cls_name, :scope => :global}
|
|
667
|
+
@data[:extensions][:ext4] = [
|
|
668
|
+
{:class => 'Qt::Widget', :scope => :global},
|
|
669
|
+
{:class => @cls_name, :scope => :global},
|
|
670
|
+
]
|
|
671
|
+
@plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
672
|
+
desc = @plug.plugin_description
|
|
673
|
+
@prj = Ruber::Project.new('test.ruprj', 'Test')
|
|
674
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.extensions[:ext1]).and_return true
|
|
675
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.extensions[:ext2]).and_return false
|
|
676
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.extensions[:ext3]).and_return true
|
|
677
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.extensions[:ext4][0]).and_return false
|
|
678
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.extensions[:ext4][1]).and_return true
|
|
679
|
+
m = flexmock do |mk|
|
|
680
|
+
mk.should_receive(:test).with('ext1', @prj).once.ordered
|
|
681
|
+
mk.should_receive(:test).with('ext2', @prj).never
|
|
682
|
+
mk.should_receive(:test).with('ext3', @prj).once.ordered
|
|
683
|
+
mk.should_receive(:test).with('ext4', @prj).once.ordered
|
|
684
|
+
end
|
|
685
|
+
@plug.connect(SIGNAL('extension_added(QString, QObject*)')){|s, o| m.test s, o}
|
|
686
|
+
@plug.add_extensions_to_project @prj
|
|
687
|
+
end
|
|
688
|
+
|
|
689
|
+
it 'doesn\'t attempt to emit the extension_added signal if it doesn\'t have it' do
|
|
690
|
+
desc = @plug.plugin_description
|
|
691
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.extensions[:ext1]).and_return true
|
|
692
|
+
flexmock(@prj).should_receive(:match_rule?).once.with(desc.extensions[:ext2]).and_return false
|
|
693
|
+
class << @plug
|
|
694
|
+
undef_method :extension_added
|
|
695
|
+
end
|
|
696
|
+
lambda{@plug.add_extensions_to_project @prj}.should_not raise_error
|
|
697
|
+
end
|
|
698
|
+
|
|
699
|
+
end
|
|
700
|
+
|
|
701
|
+
describe '#remove_options_from_project' do
|
|
702
|
+
|
|
703
|
+
before do
|
|
704
|
+
@data[:project_options] = {
|
|
705
|
+
:g1 => {:o1 => {:default => 7, :scope => :global}, :o2 => {:default => 'abc', :scope => :document}},
|
|
706
|
+
:g2 => {:o1 => {:default => %w[a b c]}, :o3 => {:default => :xyz}}
|
|
707
|
+
}
|
|
708
|
+
@projects = Qt::Object.new
|
|
709
|
+
flexmock(Ruber).should_receive(:[]).with(:projects).and_return(@projects).by_default
|
|
710
|
+
@plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
711
|
+
@manager.should_receive(:each_component).once.and_yield(@plug)
|
|
712
|
+
@prj = Ruber::Project.new('test.ruprj', 'Test')
|
|
713
|
+
end
|
|
714
|
+
|
|
715
|
+
it 'removes all options belonging to the plugin for which the project\'s match_rule? method returns true if the second argument is true' do
|
|
716
|
+
desc = @plug.plugin_description
|
|
717
|
+
@prj.add_option OS.new({:group => :g1, :name => :opt1, :default => nil})
|
|
718
|
+
@prj.add_option OS.new({:group => :g2, :name => :opt2, :default => (1..2)})
|
|
719
|
+
@prj.add_option OS.new({:group => :g3, :name => :opt3, :default => /a/})
|
|
720
|
+
@prj.add_option OS.new({:group => :g1, :name => :o2, :default => 7})
|
|
721
|
+
flexmock(@prj).should_receive(:match_rule?).with(desc.project_options[[:g1, :o1]]).once.and_return true
|
|
722
|
+
flexmock(@prj).should_receive(:match_rule?).with(desc.project_options[[:g1, :o2]]).once.and_return false
|
|
723
|
+
flexmock(@prj).should_receive(:match_rule?).with(desc.project_options[[:g2, :o1]]).once.and_return true
|
|
724
|
+
flexmock(@prj).should_receive(:match_rule?).with(desc.project_options[[:g2, :o3]]).once.and_return true
|
|
725
|
+
flexmock(@prj).should_receive(:remove_option).with(:g1, :o1).once
|
|
726
|
+
flexmock(@prj).should_receive(:remove_option).with(:g1, :o2).never
|
|
727
|
+
flexmock(@prj).should_receive(:remove_option).with(:g2, :o1).once
|
|
728
|
+
flexmock(@prj).should_receive(:remove_option).with(:g2, :o3).once
|
|
729
|
+
@plug.remove_options_from_project @prj, true
|
|
730
|
+
end
|
|
731
|
+
|
|
732
|
+
it 'removes all options belonging to the plugin and previously added to the project for which the project\'s match_rule? method returns false if the second argument is false' do
|
|
733
|
+
desc = @plug.plugin_description
|
|
734
|
+
@prj.add_option OS.new({:group => :g1, :name => :opt1, :default => nil})
|
|
735
|
+
@prj.add_option OS.new({:group => :g2, :name => :opt2, :default => (1..2)})
|
|
736
|
+
@prj.add_option OS.new({:group => :g3, :name => :opt3, :default => /a/})
|
|
737
|
+
flexmock(@prj).should_receive(:match_rule?).with(desc.project_options[[:g1, :o1]]).once.and_return true
|
|
738
|
+
flexmock(@prj).should_receive(:match_rule?).with(desc.project_options[[:g1, :o2]]).never
|
|
739
|
+
flexmock(@prj).should_receive(:match_rule?).with(desc.project_options[[:g2, :o1]]).once.and_return false
|
|
740
|
+
flexmock(@prj).should_receive(:match_rule?).with(desc.project_options[[:g2, :o3]]).once.and_return true
|
|
741
|
+
flexmock(@prj).should_receive(:remove_option).with(:g1, :o1).never
|
|
742
|
+
flexmock(@prj).should_receive(:remove_option).with(:g1, :o2).never
|
|
743
|
+
flexmock(@prj).should_receive(:remove_option).with(:g2, :o1).once
|
|
744
|
+
flexmock(@prj).should_receive(:remove_option).with(:g2, :o3).never
|
|
745
|
+
@plug.remove_options_from_project @prj, false
|
|
746
|
+
end
|
|
747
|
+
|
|
748
|
+
end
|
|
749
|
+
|
|
750
|
+
describe '#remove_widgets_from_project' do
|
|
751
|
+
|
|
752
|
+
before do
|
|
753
|
+
@data[:project_widgets] = [
|
|
754
|
+
{:class => 'Qt::ComboBox', :caption => 'C1', :scope => :document},
|
|
755
|
+
{:class => 'Qt::LineEdit', :caption => 'C1', :scope => :global},
|
|
756
|
+
{:class => 'Qt::CheckBox', :caption => 'C2'},
|
|
757
|
+
]
|
|
758
|
+
@mw = Qt::Widget.new
|
|
759
|
+
flexmock(Ruber).should_receive(:[]).with(:main_window).and_return(@mw).by_default
|
|
760
|
+
@projects = Qt::Object.new
|
|
761
|
+
flexmock(Ruber).should_receive(:[]).with(:projects).and_return(@projects).by_default
|
|
762
|
+
@plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
763
|
+
@manager.should_receive(:each_component).once.and_yield @plug
|
|
764
|
+
@prj = Ruber::Project.new('test.ruprj', 'Test')
|
|
765
|
+
end
|
|
766
|
+
|
|
767
|
+
it 'removes all widgets belonging to the plugin from the project' do
|
|
768
|
+
desc = @plug.plugin_description
|
|
769
|
+
flexmock(@prj).should_receive(:remove_widget).once.with desc.project_widgets[0]
|
|
770
|
+
flexmock(@prj).should_receive(:remove_widget).once.with desc.project_widgets[1]
|
|
771
|
+
flexmock(@prj).should_receive(:remove_widget).once.with desc.project_widgets[2]
|
|
772
|
+
@plug.remove_widgets_from_project @prj
|
|
773
|
+
end
|
|
774
|
+
|
|
775
|
+
end
|
|
776
|
+
|
|
777
|
+
describe '#remove_extensions_from_project' do
|
|
778
|
+
|
|
779
|
+
class Ext < Qt::Object
|
|
780
|
+
include Ruber::Extension
|
|
781
|
+
end
|
|
782
|
+
|
|
783
|
+
before do
|
|
784
|
+
@cls_name = self.class.const_get(:Ext).name
|
|
785
|
+
@data[:extensions] = {
|
|
786
|
+
:ext1 => {:class => @cls_name},
|
|
787
|
+
:ext2 => {:class => 'Qt::Object', :scope => :document},
|
|
788
|
+
:ext3 => {:class => @cls_name}
|
|
789
|
+
}
|
|
790
|
+
@projects = Qt::Object.new
|
|
791
|
+
flexmock(Ruber).should_receive(:[]).with(:projects).and_return(@projects).by_default
|
|
792
|
+
@plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
793
|
+
@manager.should_receive(:each_component).and_yield(@plug)
|
|
794
|
+
other_data = {
|
|
795
|
+
:name => :plug1,
|
|
796
|
+
:class => 'Ruber::Plugin',
|
|
797
|
+
:extensions => {
|
|
798
|
+
:e1 => {:class => @cls_name, :scope => :global},
|
|
799
|
+
:e2 => {:class => @cls_name, :scope => :global},
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
@other_plug = Ruber::Plugin.new Ruber::PluginSpecification.full(other_data)
|
|
803
|
+
@prj = Ruber::Project.new('test.ruprj', 'Test')
|
|
804
|
+
@other_plug.add_extensions_to_project @prj
|
|
805
|
+
end
|
|
806
|
+
|
|
807
|
+
describe ', when the second argument is true' do
|
|
808
|
+
|
|
809
|
+
it 'removes all extensions provided by the plugin for which the project\'s match_rule? method returns true' do
|
|
810
|
+
@prj.extensions.keys.sort.should == [:e1, :e2, :ext1, :ext3]
|
|
811
|
+
@plug.remove_extensions_from_project @prj, true
|
|
812
|
+
@prj.extensions.keys.sort.should == [:e1, :e2]
|
|
813
|
+
end
|
|
814
|
+
|
|
815
|
+
it 'removes a multiple extension from the project if one of the entries\' rule matches the project\'s, when the second argument is true' do
|
|
816
|
+
desc = @plug.plugin_description
|
|
817
|
+
desc.extensions[:ext4] = [
|
|
818
|
+
OS.new(:class_obj => String, :scope => [:document]),
|
|
819
|
+
OS.new(:class_obj => Ext, :scope => [:global])
|
|
820
|
+
]
|
|
821
|
+
@prj.add_extension :ext4, Ext.new(@prj)
|
|
822
|
+
@prj.extension(:ext4).plugin = @plug
|
|
823
|
+
@plug.remove_extensions_from_project @prj, true
|
|
824
|
+
@prj.extensions.keys.sort.should == [:e1, :e2]
|
|
825
|
+
end
|
|
826
|
+
|
|
827
|
+
it 'emits the removing_extension(QString, QObject*) signal for each existing extension which is being removed passing the extension name and the project as arguments' do
|
|
828
|
+
desc = @plug.plugin_description
|
|
829
|
+
desc.extensions[:ext4] = [
|
|
830
|
+
OS.new(:class_obj => String, :scope => [:document]),
|
|
831
|
+
OS.new(:class_obj => Ext, :scope => [:global])
|
|
832
|
+
]
|
|
833
|
+
@prj.add_extension :ext4, Ext.new(@prj)
|
|
834
|
+
@prj.extension(:ext4).plugin = @plug
|
|
835
|
+
m = flexmock do |mk|
|
|
836
|
+
mk.should_receive(:test).once.with('ext1', @prj)
|
|
837
|
+
mk.should_receive(:test).once.with('ext3', @prj)
|
|
838
|
+
mk.should_receive(:test).once.with('ext4', @prj)
|
|
839
|
+
end
|
|
840
|
+
@plug.connect(SIGNAL('removing_extension(QString, QObject*)')){|s, o| m.test s, o}
|
|
841
|
+
@plug.remove_extensions_from_project @prj, true
|
|
842
|
+
end
|
|
843
|
+
|
|
844
|
+
it 'emits the extension_removed(QString, QObject*) signal for each existing extension which has been removed passing the extension name and the project as arguments after removing it' do
|
|
845
|
+
desc = @plug.plugin_description
|
|
846
|
+
desc.extensions[:ext4] = [
|
|
847
|
+
OS.new(:class_obj => String, :scope => [:document]),
|
|
848
|
+
OS.new(:class_obj => Ext, :scope => [:global])
|
|
849
|
+
]
|
|
850
|
+
@prj.add_extension :ext4, Ext.new(@prj)
|
|
851
|
+
@prj.extension(:ext4).plugin = @plug
|
|
852
|
+
m = flexmock
|
|
853
|
+
flexmock(@prj).should_receive(:remove_extension).once.with(:ext1).ordered('1')
|
|
854
|
+
m.should_receive(:test).once.with('ext1', @prj).ordered('1')
|
|
855
|
+
flexmock(@prj).should_receive(:remove_extension).once.with(:ext3).ordered('3')
|
|
856
|
+
m.should_receive(:test).once.with('ext3', @prj).ordered('3')
|
|
857
|
+
flexmock(@prj).should_receive(:remove_extension).once.with(:ext4).ordered('4')
|
|
858
|
+
m.should_receive(:test).once.with('ext4', @prj).ordered('4')
|
|
859
|
+
@plug.connect(SIGNAL('extension_removed(QString, QObject*)')){|s, o| m.test s, o}
|
|
860
|
+
@plug.remove_extensions_from_project @prj, true
|
|
861
|
+
end
|
|
862
|
+
|
|
863
|
+
it 'doesn\'t attempt to emit the removing_extension signal if the plugin doesn\'t define it' do
|
|
864
|
+
class << @plug
|
|
865
|
+
undef_method :removing_extension
|
|
866
|
+
end
|
|
867
|
+
lambda{@plug.remove_extensions_from_project @prj, true}.should_not raise_error
|
|
868
|
+
end
|
|
869
|
+
|
|
870
|
+
it 'doesn\'t attempt to emit the extension_removed signal if the plugin doesn\'t define it' do
|
|
871
|
+
class << @plug
|
|
872
|
+
undef_method :extension_removed
|
|
873
|
+
end
|
|
874
|
+
lambda{@plug.remove_extensions_from_project @prj, true}.should_not raise_error
|
|
875
|
+
end
|
|
876
|
+
|
|
877
|
+
end
|
|
878
|
+
|
|
879
|
+
describe ', when the second argument is false' do
|
|
880
|
+
|
|
881
|
+
it 'removes the existing extensions provided by the plugin for which the project\'s match_rule? method returns false' do
|
|
882
|
+
desc = @plug.plugin_description
|
|
883
|
+
desc.extensions[:ext4] = OS.new(:class => @cls_name, :scope => [:document])
|
|
884
|
+
ext = Ext.new
|
|
885
|
+
ext.plugin = @plug
|
|
886
|
+
@prj.add_extension :ext4, ext
|
|
887
|
+
@plug.remove_extensions_from_project @prj, false
|
|
888
|
+
@prj.extensions.keys.sort.should == [:e1, :e2, :ext1, :ext3]
|
|
889
|
+
end
|
|
890
|
+
|
|
891
|
+
it 'removes a multiple extension only if the class of the existing extension corresponds to the one specified by the entry for which the project\'s match_rule? fails' do
|
|
892
|
+
desc = @plug.plugin_description
|
|
893
|
+
desc.extensions[:ext4] = [
|
|
894
|
+
OS.new(:class_obj => String, :scope => [:document]),
|
|
895
|
+
OS.new(:class_obj => Ext, :scope => [:global])
|
|
896
|
+
]
|
|
897
|
+
desc.extensions[:ext5] = [
|
|
898
|
+
OS.new(:class_obj => Qt::Object, :scope => [:global]),
|
|
899
|
+
OS.new(:class_obj => Ext, :scope => [:document])
|
|
900
|
+
]
|
|
901
|
+
@prj.add_extension :ext4, Ext.new(@prj)
|
|
902
|
+
@prj.add_extension :ext5, Ext.new(@prj)
|
|
903
|
+
@prj.extension(:ext4).plugin = @plug
|
|
904
|
+
@prj.extension(:ext5).plugin = @plug
|
|
905
|
+
@plug.remove_extensions_from_project @prj, false
|
|
906
|
+
@prj.extensions.keys.should =~ [:e1, :e2, :ext1, :ext3, :ext4]
|
|
907
|
+
end
|
|
908
|
+
|
|
909
|
+
it 'emits the removing_extension(QString, QObject*) signal for each removed extension' do
|
|
910
|
+
desc = @plug.plugin_description
|
|
911
|
+
desc.extensions[:ext4] = OS.new(:class => @cls_name, :scope => [:document])
|
|
912
|
+
desc.extensions[:ext5] = [
|
|
913
|
+
OS.new(:class_obj => Qt::Object, :scope => [:global]),
|
|
914
|
+
OS.new(:class_obj => Ext, :scope => [:document])
|
|
915
|
+
]
|
|
916
|
+
@prj.add_extension :ext4, Ext.new(@prj)
|
|
917
|
+
@prj.add_extension :ext5, Ext.new(@prj)
|
|
918
|
+
@prj.extension(:ext4).plugin = @plug
|
|
919
|
+
@prj.extension(:ext5).plugin = @plug
|
|
920
|
+
m = flexmock do |mk|
|
|
921
|
+
mk.should_receive(:test).once.with('ext4', @prj)
|
|
922
|
+
mk.should_receive(:test).once.with('ext5', @prj)
|
|
923
|
+
end
|
|
924
|
+
@plug.connect(SIGNAL('removing_extension(QString, QObject*)')){|s, o| m.test s, o}
|
|
925
|
+
@plug.remove_extensions_from_project @prj, false
|
|
926
|
+
end
|
|
927
|
+
|
|
928
|
+
it 'emits the extension(QString, QObject*) signal for each removed extension after removing it' do
|
|
929
|
+
desc = @plug.plugin_description
|
|
930
|
+
desc.extensions[:ext4] = OS.new(:class => @cls_name, :scope => [:document])
|
|
931
|
+
desc.extensions[:ext5] = [
|
|
932
|
+
OS.new(:class_obj => Qt::Object, :scope => [:global]),
|
|
933
|
+
OS.new(:class_obj => Ext, :scope => [:document])
|
|
934
|
+
]
|
|
935
|
+
@prj.add_extension :ext4, Ext.new(@prj)
|
|
936
|
+
@prj.add_extension :ext5, Ext.new(@prj)
|
|
937
|
+
@prj.extension(:ext4).plugin = @plug
|
|
938
|
+
@prj.extension(:ext5).plugin = @plug
|
|
939
|
+
m = flexmock
|
|
940
|
+
flexmock(@prj).should_receive(:remove_extension).with(:ext4).once.ordered('4')
|
|
941
|
+
m.should_receive(:test).once.with('ext4', @prj).once.ordered('4')
|
|
942
|
+
flexmock(@prj).should_receive(:remove_extension).with(:ext5).once.ordered('5')
|
|
943
|
+
m.should_receive(:test).once.with('ext5', @prj).once.ordered('5')
|
|
944
|
+
@plug.connect(SIGNAL('extension_removed(QString, QObject*)')){|s, o| m.test s, o}
|
|
945
|
+
@plug.remove_extensions_from_project @prj, false
|
|
946
|
+
end
|
|
947
|
+
|
|
948
|
+
it 'doesn\'t attempt to emit the removing_extension signal if the plugin doesn\'t define it' do
|
|
949
|
+
desc = @plug.plugin_description
|
|
950
|
+
desc.extensions[:ext4] = OS.new(:class => @cls_name, :scope => [:document])
|
|
951
|
+
desc.extensions[:ext5] = [
|
|
952
|
+
OS.new(:class_obj => Qt::Object, :scope => [:global]),
|
|
953
|
+
OS.new(:class_obj => Ext, :scope => [:document])
|
|
954
|
+
]
|
|
955
|
+
@prj.add_extension :ext4, Ext.new(@prj)
|
|
956
|
+
@prj.add_extension :ext5, Ext.new(@prj)
|
|
957
|
+
@prj.extension(:ext4).plugin = @plug
|
|
958
|
+
@prj.extension(:ext5).plugin = @plug
|
|
959
|
+
class << @plug
|
|
960
|
+
undef_method :removing_extension
|
|
961
|
+
end
|
|
962
|
+
lambda{@plug.remove_extensions_from_project @prj, false}.should_not raise_error
|
|
963
|
+
end
|
|
964
|
+
|
|
965
|
+
it 'doesn\'t attempt to emit the extension_removed signal if the plugin doesn\'t define it' do
|
|
966
|
+
desc = @plug.plugin_description
|
|
967
|
+
desc.extensions[:ext4] = OS.new(:class => @cls_name, :scope => [:document])
|
|
968
|
+
desc.extensions[:ext5] = [
|
|
969
|
+
OS.new(:class_obj => Qt::Object, :scope => [:global]),
|
|
970
|
+
OS.new(:class_obj => Ext, :scope => [:document])
|
|
971
|
+
]
|
|
972
|
+
@prj.add_extension :ext4, Ext.new(@prj)
|
|
973
|
+
@prj.add_extension :ext5, Ext.new(@prj)
|
|
974
|
+
@prj.extension(:ext4).plugin = @plug
|
|
975
|
+
@prj.extension(:ext5).plugin = @plug
|
|
976
|
+
class << @plug
|
|
977
|
+
undef_method :extension_removed
|
|
978
|
+
end
|
|
979
|
+
lambda{@plug.remove_extensions_from_project @prj, false}.should_not raise_error
|
|
980
|
+
end
|
|
981
|
+
|
|
982
|
+
|
|
983
|
+
end
|
|
984
|
+
|
|
985
|
+
end
|
|
986
|
+
|
|
987
|
+
end
|
|
988
|
+
|
|
989
|
+
describe 'Ruber::Plugin#register_with_project' do
|
|
990
|
+
|
|
991
|
+
include FlexMock::ArgumentTypes
|
|
992
|
+
|
|
993
|
+
before do
|
|
994
|
+
@data = {:name => 'test', :class => 'Ruber::Plugin'}
|
|
995
|
+
@app = Qt::Object.new
|
|
996
|
+
flexmock(Ruber).should_receive(:[]).with(:app).and_return(@app).by_default
|
|
997
|
+
@manager = flexmock{|m| m.should_ignore_missing}
|
|
998
|
+
flexmock(Ruber).should_receive(:[]).with(:components).and_return(@manager).by_default
|
|
999
|
+
flexmock(Ruber).should_receive(:[]).with(:config).and_return(nil).by_default
|
|
1000
|
+
@mw = Qt::Widget.new
|
|
1001
|
+
flexmock(Ruber).should_receive(:[]).with(:main_window).and_return(@mw).by_default
|
|
1002
|
+
@projects = Qt::Object.new
|
|
1003
|
+
flexmock(Ruber).should_receive(:[]).with(:projects).and_return(@projects).by_default
|
|
1004
|
+
@plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
1005
|
+
@prj = Ruber::Project.new('test.ruprj', 'Test')
|
|
1006
|
+
end
|
|
1007
|
+
|
|
1008
|
+
it 'calls add_options_to_project passing true as second argument' do
|
|
1009
|
+
flexmock(@plug).should_receive(:add_options_to_project).once.with(@prj, true)
|
|
1010
|
+
@plug.register_with_project @prj
|
|
1011
|
+
end
|
|
1012
|
+
|
|
1013
|
+
it 'calls add_widgets_to_project' do
|
|
1014
|
+
flexmock(@plug).should_receive(:add_widgets_to_project).once.with(@prj)
|
|
1015
|
+
@plug.register_with_project @prj
|
|
1016
|
+
end
|
|
1017
|
+
|
|
1018
|
+
it 'calls add_extensions_to_project' do
|
|
1019
|
+
flexmock(@plug).should_receive(:add_extensions_to_project).once.with(@prj, true)
|
|
1020
|
+
@plug.register_with_project @prj
|
|
1021
|
+
end
|
|
1022
|
+
|
|
1023
|
+
end
|
|
1024
|
+
|
|
1025
|
+
describe 'Ruber::Plugin#remove_from_project' do
|
|
1026
|
+
|
|
1027
|
+
before do
|
|
1028
|
+
@data = {:name => 'test', :class => 'Ruber::Plugin'}
|
|
1029
|
+
@app = Qt::Object.new
|
|
1030
|
+
flexmock(Ruber).should_receive(:[]).with(:app).and_return(@app).by_default
|
|
1031
|
+
@manager = flexmock{|m| m.should_ignore_missing}
|
|
1032
|
+
flexmock(Ruber).should_receive(:[]).with(:components).and_return(@manager).by_default
|
|
1033
|
+
flexmock(Ruber).should_receive(:[]).with(:config).and_return(nil).by_default
|
|
1034
|
+
@mw = Qt::Widget.new
|
|
1035
|
+
flexmock(Ruber).should_receive(:[]).with(:main_window).and_return(@mw).by_default
|
|
1036
|
+
@projects = Qt::Object.new
|
|
1037
|
+
flexmock(Ruber).should_receive(:[]).with(:projects).and_return(@projects).by_default
|
|
1038
|
+
@plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
1039
|
+
@prj = Ruber::Project.new('test.ruprj', 'Test')
|
|
1040
|
+
@plug.register_with_project @prj
|
|
1041
|
+
end
|
|
1042
|
+
|
|
1043
|
+
it 'calls remove_options_from_project passing true as second argument' do
|
|
1044
|
+
flexmock(@plug).should_receive(:remove_options_from_project).once.with(@prj, true)
|
|
1045
|
+
@plug.remove_from_project @prj
|
|
1046
|
+
end
|
|
1047
|
+
|
|
1048
|
+
it 'calls remove_widgets_from_project' do
|
|
1049
|
+
flexmock(@plug).should_receive(:remove_widgets_from_project).once.with(@prj)
|
|
1050
|
+
@plug.remove_from_project @prj
|
|
1051
|
+
end
|
|
1052
|
+
|
|
1053
|
+
it 'calls remove_extensions_from_project passing true as second argument' do
|
|
1054
|
+
flexmock(@plug).should_receive(:remove_extensions_from_project).once.with(@prj, true)
|
|
1055
|
+
@plug.remove_from_project @prj
|
|
1056
|
+
end
|
|
1057
|
+
|
|
1058
|
+
end
|
|
1059
|
+
|
|
1060
|
+
describe 'Ruber::Plugin#update_project' do
|
|
1061
|
+
|
|
1062
|
+
before do
|
|
1063
|
+
@data = {:name => 'test', :class => 'Ruber::Plugin'}
|
|
1064
|
+
@app = Qt::Object.new
|
|
1065
|
+
flexmock(Ruber).should_receive(:[]).with(:app).and_return(@app).by_default
|
|
1066
|
+
@manager = flexmock{|m| m.should_ignore_missing}
|
|
1067
|
+
@projects = Qt::Object.new
|
|
1068
|
+
flexmock(Ruber).should_receive(:[]).with(:projects).and_return(@projects).by_default
|
|
1069
|
+
flexmock(Ruber).should_receive(:[]).with(:components).and_return(@manager).by_default
|
|
1070
|
+
flexmock(Ruber).should_receive(:[]).with(:config).and_return(nil).by_default
|
|
1071
|
+
@plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
1072
|
+
@prj = Ruber::Project.new 'test.ruprj', 'Test'
|
|
1073
|
+
@plug.register_with_project @prj
|
|
1074
|
+
@doc = Ruber::Document.new nil, __FILE__
|
|
1075
|
+
end
|
|
1076
|
+
|
|
1077
|
+
it 'calls remove_options_from_project passing false as second argument' do
|
|
1078
|
+
flexmock(@plug).should_receive(:remove_options_from_project).once.with(@prj, false)
|
|
1079
|
+
@plug.update_project @prj
|
|
1080
|
+
end
|
|
1081
|
+
|
|
1082
|
+
it 'calls add_options_to_project passing false as second argument' do
|
|
1083
|
+
flexmock(@plug).should_receive(:add_options_to_project).once.with(@prj, false)
|
|
1084
|
+
@plug.update_project @prj
|
|
1085
|
+
end
|
|
1086
|
+
|
|
1087
|
+
it 'calls remove_widgets_from_project passing false as second argument' do
|
|
1088
|
+
flexmock(@plug).should_receive(:remove_widgets_from_project).once.with(@prj)
|
|
1089
|
+
@plug.update_project @prj
|
|
1090
|
+
end
|
|
1091
|
+
|
|
1092
|
+
it 'calls add_widgets_to_project passing false as second argument' do
|
|
1093
|
+
flexmock(@plug).should_receive(:add_widgets_to_project).once.with(@prj)
|
|
1094
|
+
@plug.update_project @prj
|
|
1095
|
+
end
|
|
1096
|
+
|
|
1097
|
+
it 'calls remove_extensions_from_project passing false as second argument' do
|
|
1098
|
+
flexmock(@plug).should_receive(:remove_extensions_from_project).once.with(@prj, false)
|
|
1099
|
+
@plug.update_project @prj
|
|
1100
|
+
end
|
|
1101
|
+
|
|
1102
|
+
it 'calls add_extensions_to_project passing false as second argument' do
|
|
1103
|
+
flexmock(@plug).should_receive(:add_extensions_to_project).once.with(@prj, false)
|
|
1104
|
+
@plug.update_project @prj
|
|
1105
|
+
end
|
|
1106
|
+
|
|
1107
|
+
end
|
|
1108
|
+
|
|
1109
|
+
describe Ruber::Plugin do
|
|
1110
|
+
|
|
1111
|
+
it 'has a restore_session method which takes one argument' do
|
|
1112
|
+
Ruber::Plugin.instance_method(:restore_session).arity.should == 1
|
|
1113
|
+
end
|
|
1114
|
+
|
|
1115
|
+
it 'has a private delayed_initialize method' do
|
|
1116
|
+
Ruber::Plugin.private_instance_methods.should include(:delayed_initialize)
|
|
1117
|
+
end
|
|
1118
|
+
|
|
1119
|
+
describe '#session_data' do
|
|
1120
|
+
|
|
1121
|
+
it 'returns an empty hash' do
|
|
1122
|
+
data = {:name => 'test', :class => 'Ruber::Plugin'}
|
|
1123
|
+
app = Qt::Object.new
|
|
1124
|
+
flexmock(Ruber).should_receive(:[]).with(:app).and_return(app).by_default
|
|
1125
|
+
manager = flexmock{|m| m.should_ignore_missing}
|
|
1126
|
+
flexmock(Ruber).should_receive(:[]).with(:components).and_return(manager).by_default
|
|
1127
|
+
flexmock(Ruber).should_receive(:[]).with(:config).and_return(nil).by_default
|
|
1128
|
+
plug = Ruber::Plugin.new Ruber::PluginSpecification.full(data)
|
|
1129
|
+
plug.session_data.should == {}
|
|
1130
|
+
end
|
|
1131
|
+
|
|
1132
|
+
end
|
|
1133
|
+
|
|
1134
|
+
describe '#setup_action' do
|
|
1135
|
+
|
|
1136
|
+
before do
|
|
1137
|
+
@app = KDE::Application.instance
|
|
1138
|
+
@components = flexmock('components'){|m| m.should_ignore_missing}
|
|
1139
|
+
@main_window = flexmock('main_window'){|m| m.should_ignore_missing}
|
|
1140
|
+
flexmock(Ruber).should_receive(:[]).with(:app).and_return(@app).by_default
|
|
1141
|
+
flexmock(Ruber).should_receive(:[]).with(:components).and_return(@components).by_default
|
|
1142
|
+
flexmock(Ruber).should_receive(:[]).with(:main_window).and_return(@main_window).by_default
|
|
1143
|
+
flexmock(Ruber).should_receive(:[]).with(:config).and_return(nil).by_default
|
|
1144
|
+
data = { :name => 'test', :actions => {'a1' => {} } }
|
|
1145
|
+
pdf = Ruber::PluginSpecification.full(data)
|
|
1146
|
+
@action = pdf.actions['a1']
|
|
1147
|
+
@plug = Ruber::Plugin.new pdf
|
|
1148
|
+
@coll = KDE::XMLGUIClient.new.action_collection
|
|
1149
|
+
end
|
|
1150
|
+
|
|
1151
|
+
it 'should call the method given in the standard_action entry of the KDE::StandardAction class, if the standard_action entry isn\'t nil' do
|
|
1152
|
+
@action.standard_action = :open_new
|
|
1153
|
+
@action.action_class = nil
|
|
1154
|
+
action = KDE::Action.new @coll
|
|
1155
|
+
flexmock(KDE::StandardAction).should_receive(:open_new).once.with(nil, '', KDE::ActionCollection).and_return action
|
|
1156
|
+
@plug.send(:setup_action, @action, @coll)
|
|
1157
|
+
end
|
|
1158
|
+
|
|
1159
|
+
it 'should create a new action of the given class, passing the gui action_collection as argument if the standard_action entry of the data is nil' do
|
|
1160
|
+
@action.action_class = KDE::ToggleAction
|
|
1161
|
+
action = KDE::Action.new @coll
|
|
1162
|
+
flexmock(KDE::ToggleAction).should_receive(:new).with(KDE::ActionCollection).once.and_return action
|
|
1163
|
+
@plug.send(:setup_action, @action, @coll)
|
|
1164
|
+
end
|
|
1165
|
+
|
|
1166
|
+
it 'should return the new action' do
|
|
1167
|
+
action = KDE::Action.new @coll
|
|
1168
|
+
flexmock(KDE::Action).should_receive(:new).and_return(action).once
|
|
1169
|
+
@plug.send(:setup_action, @action, @coll).should equal(action)
|
|
1170
|
+
end
|
|
1171
|
+
|
|
1172
|
+
it 'should set the text of the action to the value stored in the data if the latter is not empty' do
|
|
1173
|
+
@action.text = 'xyz'
|
|
1174
|
+
@plug.send(:setup_action, @action, @coll).text.should == 'xyz'
|
|
1175
|
+
end
|
|
1176
|
+
|
|
1177
|
+
it 'should not set the text of the action to the value stored in the data if the latter is empty' do
|
|
1178
|
+
action = KDE::Action.new @coll
|
|
1179
|
+
flexmock(action).should_receive(:text=).never
|
|
1180
|
+
flexmock(KDE::Action).should_receive(:new).with(KDE::ActionCollection).and_return action
|
|
1181
|
+
@plug.send(:setup_action, @action, @coll)
|
|
1182
|
+
end
|
|
1183
|
+
|
|
1184
|
+
it 'should set the icon of the action to the value stored in the data if the latter is not empty' do
|
|
1185
|
+
@action.icon = KDE::IconLoader.global.iconPath 'document-new', KDE::IconLoader::Small
|
|
1186
|
+
icon = Qt::Icon.new @action.icon
|
|
1187
|
+
flexmock(Qt::Icon).should_receive(:new).with(@action.icon).once.and_return icon
|
|
1188
|
+
@plug.send(:setup_action, @action, @coll).icon.should_not be_null
|
|
1189
|
+
end
|
|
1190
|
+
|
|
1191
|
+
it 'should not set the icon of the action to the value stored in the data if the latter is not empty' do
|
|
1192
|
+
action = KDE::Action.new @coll
|
|
1193
|
+
flexmock(action).should_receive(:icon=).never
|
|
1194
|
+
flexmock(KDE::Action).should_receive(:new).with(KDE::ActionCollection).and_return action
|
|
1195
|
+
@plug.send :setup_action, @action, @coll
|
|
1196
|
+
end
|
|
1197
|
+
|
|
1198
|
+
it 'should set the help text of the action to the value stored in the data if the latter is not empty' do
|
|
1199
|
+
@action.help = 'xyz'
|
|
1200
|
+
@plug.send(:setup_action, @action, @coll).tool_tip.should == 'xyz'
|
|
1201
|
+
end
|
|
1202
|
+
|
|
1203
|
+
it 'should not set the help text of the action to the value stored in the data if the latter is empty' do
|
|
1204
|
+
action = KDE::Action.new @coll
|
|
1205
|
+
flexmock(action).should_receive(:help_text=).never
|
|
1206
|
+
flexmock(KDE::Action).should_receive(:new).with(KDE::ActionCollection).and_return action
|
|
1207
|
+
@plug.send(:setup_action, @action, @coll)
|
|
1208
|
+
end
|
|
1209
|
+
|
|
1210
|
+
it 'should set the shortcut of the action to the value stored in the data, if the latter isn\'t nil' do
|
|
1211
|
+
@action.shortcut = KDE::Shortcut.new 'Ctrl+S'
|
|
1212
|
+
@plug.send(:setup_action, @action, @coll).shortcut.to_string.should == 'Ctrl+S'
|
|
1213
|
+
end
|
|
1214
|
+
|
|
1215
|
+
it 'should not set the shortcut of the action to the value stored in the data if the latter is nil' do
|
|
1216
|
+
action = KDE::Action.new @coll
|
|
1217
|
+
flexmock(action).should_receive(:shortcut=).never
|
|
1218
|
+
flexmock(KDE::Action).should_receive(:new).with(KDE::ActionCollection).and_return action
|
|
1219
|
+
@plug.send(:setup_action, @action, @coll)
|
|
1220
|
+
end
|
|
1221
|
+
|
|
1222
|
+
it 'should connect the signal stored in the data with the slot stored in the data of the receiver obtained by calling instance_eval on self with the recevier stored in the data as argument if the slot is not nil' do
|
|
1223
|
+
@action.slot = 'action_triggered(bool)'
|
|
1224
|
+
@action.receiver = '@obj'
|
|
1225
|
+
obj = Qt::Object.new @plug
|
|
1226
|
+
@plug.instance_variable_set(:@obj, obj)
|
|
1227
|
+
def @plug.connect *args
|
|
1228
|
+
end
|
|
1229
|
+
action = KDE::Action.new @coll
|
|
1230
|
+
flexmock(@plug).should_receive(:connect).with(action, SIGNAL('triggered(bool)'), obj, SLOT('action_triggered(bool)')).once
|
|
1231
|
+
flexmock(KDE::Action).should_receive(:new).with(KDE::ActionCollection).and_return action
|
|
1232
|
+
@plug.send(:setup_action, @action, @coll)
|
|
1233
|
+
end
|
|
1234
|
+
|
|
1235
|
+
it 'should not attempt to connect a signal of the action if the slot method of the data returns nil' do
|
|
1236
|
+
def @plug.connect *args
|
|
1237
|
+
end
|
|
1238
|
+
action = KDE::Action.new @coll
|
|
1239
|
+
flexmock(@plug).should_receive(:connect).never
|
|
1240
|
+
flexmock(KDE::Action).should_receive(:new).with(KDE::ActionCollection).and_return action
|
|
1241
|
+
@plug.send(:setup_action, @action, @coll)
|
|
1242
|
+
end
|
|
1243
|
+
|
|
1244
|
+
it 'should register an ui state handler for the action if the state entry of the data is not nil' do
|
|
1245
|
+
flexmock(Ruber).should_receive(:[]).with(:app).and_return(@app)
|
|
1246
|
+
flexmock(Ruber).should_receive(:[]).with(:components).and_return(@components)
|
|
1247
|
+
flexmock(Ruber).should_receive(:[]).with(:config).and_return(nil)
|
|
1248
|
+
action = KDE::Action.new @coll
|
|
1249
|
+
flexmock(KDE::Action).should_receive(:new).with(KDE::ActionCollection).and_return action
|
|
1250
|
+
mw = flexmock('main_window') do |m|
|
|
1251
|
+
m.should_receive(:register_action_handler).with(action,'s1', :extra_id => @plug).once
|
|
1252
|
+
end
|
|
1253
|
+
flexmock(Ruber).should_receive(:[]).with(:main_window).and_return mw
|
|
1254
|
+
@action.state = 's1'
|
|
1255
|
+
@plug.send(:setup_action, @action, @coll)
|
|
1256
|
+
end
|
|
1257
|
+
|
|
1258
|
+
it 'should not attempt to register an ui state handler if the state entry of the data is nil' do
|
|
1259
|
+
flexmock(Ruber).should_receive(:[]).with(:app).and_return(@app)
|
|
1260
|
+
flexmock(Ruber).should_receive(:[]).with(:components).and_return(@components)
|
|
1261
|
+
flexmock(Ruber).should_receive(:[]).with(:config).and_return(nil)
|
|
1262
|
+
action = KDE::Action.new @coll
|
|
1263
|
+
flexmock(KDE::Action).should_receive(:new).with(KDE::ActionCollection).and_return action
|
|
1264
|
+
mw = flexmock('main_window') do |m|
|
|
1265
|
+
m.should_receive(:register_action_handler).never
|
|
1266
|
+
end
|
|
1267
|
+
flexmock(Ruber).should_receive(:[]).with(:main_window).and_return mw
|
|
1268
|
+
@plug.send(:setup_action, @action, @coll)
|
|
1269
|
+
end
|
|
1270
|
+
|
|
1271
|
+
end
|
|
1272
|
+
|
|
1273
|
+
describe '#setup_actions' do
|
|
1274
|
+
|
|
1275
|
+
before do
|
|
1276
|
+
@app = KDE::Application.instance
|
|
1277
|
+
@components = flexmock('components'){|m| m.should_ignore_missing}
|
|
1278
|
+
@main_window = flexmock('main_window'){|m| m.should_ignore_missing}
|
|
1279
|
+
flexmock(Ruber).should_receive(:[]).with(:app).and_return(@app).by_default
|
|
1280
|
+
flexmock(Ruber).should_receive(:[]).with(:components).and_return(@components).by_default
|
|
1281
|
+
flexmock(Ruber).should_receive(:[]).with(:main_window).and_return(@main_window).by_default
|
|
1282
|
+
flexmock(Ruber).should_receive(:[]).with(:config).and_return(nil).by_default
|
|
1283
|
+
data = { :name => 'test', :actions => {'a1' => {:text => '1'}, 'a2' => {:text => '2'}, 'a3' => {:text => '3'} } }
|
|
1284
|
+
@pdf = Ruber::PluginSpecification.full(data)
|
|
1285
|
+
@plug = Ruber::Plugin.new @pdf
|
|
1286
|
+
@gui = KDE::XMLGUIClient.new
|
|
1287
|
+
end
|
|
1288
|
+
|
|
1289
|
+
it 'should call the setup_action method for each action in the plugin description' do
|
|
1290
|
+
coll = @gui.action_collection
|
|
1291
|
+
@pdf.actions.each_value do |a|
|
|
1292
|
+
flexmock(@plug).should_receive(:setup_action).with(a, KDE::ActionCollection).once.and_return KDE::Action.new(coll)
|
|
1293
|
+
end
|
|
1294
|
+
@plug.send :setup_actions, coll
|
|
1295
|
+
end
|
|
1296
|
+
|
|
1297
|
+
it 'should add each action to the action collection' do
|
|
1298
|
+
coll = @gui.action_collection
|
|
1299
|
+
@plug.send :setup_actions, coll
|
|
1300
|
+
@pdf.actions.each_value do |a|
|
|
1301
|
+
coll.action(a.name).text.should == a.text
|
|
1302
|
+
end
|
|
1303
|
+
end
|
|
1304
|
+
|
|
1305
|
+
end
|
|
1306
|
+
|
|
1307
|
+
describe '#about_data' do
|
|
1308
|
+
|
|
1309
|
+
before do
|
|
1310
|
+
@data = {:name => :test_plugin, :class => 'Ruber::Plugin'}
|
|
1311
|
+
@app = Qt::Object.new
|
|
1312
|
+
flexmock(Ruber).should_receive(:[]).with(:app).and_return(@app).by_default
|
|
1313
|
+
@manager = flexmock{|m| m.should_ignore_missing}
|
|
1314
|
+
flexmock(Ruber).should_receive(:[]).with(:components).and_return(@manager).by_default
|
|
1315
|
+
flexmock(Ruber).should_receive(:[]).with(:config).and_return(nil).by_default
|
|
1316
|
+
@plug = Ruber::Plugin.new Ruber::PluginSpecification.full(@data)
|
|
1317
|
+
@desc = @plug.plugin_description
|
|
1318
|
+
end
|
|
1319
|
+
|
|
1320
|
+
it 'should return an instance of KDE::AboutData' do
|
|
1321
|
+
@plug.about_data.should be_a(KDE::AboutData)
|
|
1322
|
+
end
|
|
1323
|
+
|
|
1324
|
+
it 'should set the app name of the returned object to the plugin name' do
|
|
1325
|
+
@plug.about_data.app_name.should == 'test_plugin'
|
|
1326
|
+
end
|
|
1327
|
+
|
|
1328
|
+
it 'should set the program name of the returned object to human name of the plugin' do
|
|
1329
|
+
@desc.about.human_name = 'XyZ'
|
|
1330
|
+
@plug.about_data.program_name.should == 'XyZ'
|
|
1331
|
+
end
|
|
1332
|
+
|
|
1333
|
+
it 'should set the version of the returned object to the version of the plugin' do
|
|
1334
|
+
@desc.version = '2.6.4'
|
|
1335
|
+
@plug.about_data.version.should == '2.6.4'
|
|
1336
|
+
end
|
|
1337
|
+
|
|
1338
|
+
it 'should set the license of the returned object to the license of the plugin if the latter is a symbol' do
|
|
1339
|
+
Ruber::Plugin::LICENSES.each_pair do |sym, val|
|
|
1340
|
+
@desc.about.license = sym
|
|
1341
|
+
@plug.about_data.licenses[0].key.should == val
|
|
1342
|
+
end
|
|
1343
|
+
end
|
|
1344
|
+
|
|
1345
|
+
it 'should set the license to Custom and the license text to the license of the plugin if the latter is a string' do
|
|
1346
|
+
@desc.about.license = 'My License'
|
|
1347
|
+
data = @plug.about_data
|
|
1348
|
+
data.licenses[0].key.should == KDE::AboutData::License_Custom
|
|
1349
|
+
data.licenses[0].text.should == 'My License'
|
|
1350
|
+
end
|
|
1351
|
+
|
|
1352
|
+
it 'should add an author (with the respective e-mail, if given) for each of the plugin authors' do
|
|
1353
|
+
@desc.about.authors = [['A1', 'a1@something.com'], ['A2']]
|
|
1354
|
+
authors = @plug.about_data.authors
|
|
1355
|
+
authors.size.should == 2
|
|
1356
|
+
authors[0].name.should == 'A1'
|
|
1357
|
+
authors[0].email_address.should == 'a1@something.com'
|
|
1358
|
+
authors[1].name.should == 'A2'
|
|
1359
|
+
authors[1].email_address.should be_empty
|
|
1360
|
+
end
|
|
1361
|
+
|
|
1362
|
+
it 'should set the short description of the returned object to the description of the plugin' do
|
|
1363
|
+
@desc.about.description = 'A pluging which does something'
|
|
1364
|
+
@plug.about_data.short_description.should == @desc.about.description
|
|
1365
|
+
end
|
|
1366
|
+
|
|
1367
|
+
it 'should set the bug address, if given' do
|
|
1368
|
+
@plug.about_data.bug_address.should == "submit@bugs.kde.org"
|
|
1369
|
+
@desc.about.bug_address = 'xyz@abc.org'
|
|
1370
|
+
@plug.about_data.bug_address.should == 'xyz@abc.org'
|
|
1371
|
+
end
|
|
1372
|
+
|
|
1373
|
+
it 'should set the copyright text of the plugin, if given' do
|
|
1374
|
+
@plug.about_data.copyright_statement.should be_nil
|
|
1375
|
+
@desc.about.copyright = 'copyright text'
|
|
1376
|
+
@plug.about_data.copyright_statement.should == 'copyright text'
|
|
1377
|
+
end
|
|
1378
|
+
|
|
1379
|
+
it 'should set the homepage, if given' do
|
|
1380
|
+
@plug.about_data.homepage.should == ''
|
|
1381
|
+
@desc.about.homepage = 'http://something.com'
|
|
1382
|
+
@plug.about_data.homepage.should == 'http://something.com'
|
|
1383
|
+
end
|
|
1384
|
+
|
|
1385
|
+
it 'should set the plugin icon, if given' do
|
|
1386
|
+
@plug.about_data.program_icon_name.should == 'test_plugin'
|
|
1387
|
+
@desc.about.icon = '/usr/test.png'
|
|
1388
|
+
@plug.about_data.program_icon_name.should == '/usr/test.png'
|
|
1389
|
+
end
|
|
1390
|
+
|
|
1391
|
+
end
|
|
1392
|
+
|
|
1393
|
+
end
|