[Kde-bindings] problem with calling signals in block associated with Class.new and rspec
Richard Dale
rdale at foton.es
Mon Nov 24 18:11:15 UTC 2008
On Sunday 23 November 2008 14:51:22 Stefano Crocco wrote:
> I wanted to write a method which generates a Qt::Object-derived class which
> defines signals determined at runtime. The definition of the method is the
> following:
>
> def MyModule.create *sigs
> Class.new(Qt::Object) do
> signals( *sigs)
> end
> end
>
> This is called this way:
>
> MyModule.create 's1(QString)', 's2(QObject*, QPoint)'
>
> and returns a new class, derived from Qt::Object, which has the two signals
> passed as argument.
>
> When used by itself, this method works correctly, and returns a class
> which, has a 's1' and a 's2' method among its instance methods. The problem
> is that I want to test this code using RSpec. I do something like this:
>
> describe 'MyModule.create' do
> it 'should work' do
> cls = MyModule::Signaler.create 's1()', 's2(QString)', 's3(QObject*)'
> cls.instance_methods.should include('s1')
> cls.instance_methods.should include('s2')
> cls.instance_methods.should include('s3')
> end
> end
>
> but it doesn't work. Indeed, looking at the contents of
> cls.instance_methods, one can see that 's1', 's2' and 's3' aren't there.
> Now, I know it's very likely you won't know RSpec and its internals, but I
> was wandering if you know of some edge cases which can lead to the above
> behaviour. I tried to look at the source for the signals method in the
> qtruby4.rb file, but I couldn't find any hint on what may be failing.
It seems to work fine for me as long as I don't call create() more than once.
require 'Qt4'
require 'autotest/rspec'
module MyModule
def MyModule.create *sigs
Class.new(Qt::Object) do
signals(*sigs)
end
end
end
describe 'MyModule.create' do
it 'should work' do
cls = MyModule.create 's1()', 's2(QString)', 's3(QObject*)'
cls.instance_methods.should include('s1')
cls.instance_methods.should include('s2')
cls.instance_methods.should include('s3')
end
end
app = Qt::Application.new(ARGV)
# s = MyModule.create("sig1()", "sig2()")
# p s.superclass
# p s.instance_methods.sort
If I uncomment the s = MyModule.create("sig1()", "sig2()") line, the RSpec
test fails, otherwise it works.
-- Richard
More information about the Kde-bindings
mailing list