Forum: IronRuby Building expressions

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1e39a948a58f4569c53d971c2e120920?d=identicon&s=25 Ivan Porto carrero (casualjim)
on 2009-05-03 12:20
(Received via mailing list)
Hi

I'm trying to get some Moq mockery going in IronRuby but Moq expects
Expression<Func<MyObject, TReturn>> in his methods.
Is there a way to make a RubyProc/lambda return an expression or convert
it
to an expression?

---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Author of IronRuby in Action (http://manning.com/carrero)

Steve Martin
<http://www.brainyquote.com/quotes/authors/s/steve_...
- "I've got to keep breathing. It'll be my worst business mistake if I
don't."
Aea6cfe04952626ab630bde47ff82f89?d=identicon&s=25 Shri Borde (Guest)
on 2009-05-03 23:37
(Received via mailing list)
It cannot be done. Even if you could get to the ExpressionTree of a Ruby
lambda, the ExpressionTree would be loosely-bound as Ruby uses
duck-typing, whereas Moq expects a strongly-typed ExpressionTree so that
it can figure out the exact method that you are trying to associate some
expectation with.

FWIW, Mark had also been playing with mocking, and in our discussions,
we said that the easiest mocking approach would be to use Ruby features
like method_missing, monkey-patching, etc (like rspec does). Ie.
something like this:

def mock(clrInterface):
  class ClrMock < clrInterface
    # monkey-patch all of “clrInterface.methods" here, and redirect to
the mocking framework
  end
  return ClrMock.new
end

From: ironruby-core-bounces@rubyforge.org
[mailto:ironruby-core-bounces@rubyforge.org] On Behalf Of Ivan Porto
Carrero
Sent: Sunday, May 03, 2009 3:18 AM
To: ironruby-core
Subject: [Ironruby-core] Building expressions

Hi

I'm trying to get some Moq mockery going in IronRuby but Moq expects
Expression<Func<MyObject, TReturn>> in his methods.
Is there a way to make a RubyProc/lambda return an expression or convert
it to an expression?

---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Author of IronRuby in Action (http://manning.com/carrero)

Steve
Martin<http://www.brainyquote.com/quotes/authors/s/steve_...  -
"I've got to keep breathing. It'll be my worst business mistake if I
don't."
99b1f0c67bec23747d007e27d000487b?d=identicon&s=25 Ryan Riley (Guest)
on 2009-05-05 16:26
(Received via mailing list)
Ivan,

You may want to try Jeremy Mcanally's
stump<http://github.com/jeremymcanally/stump/tree/master...
framework. I haven't used it much, so I can't give any additional
info on it. It may not be what you are wanting, but if you just need
mocks,
it may be worth a shot.


Ryan Riley
ryan.riley@panesofglass.org
http://panesofglass.org/
http://wizardsofsmart.net/
1e39a948a58f4569c53d971c2e120920?d=identicon&s=25 Ivan Porto carrero (casualjim)
on 2009-05-05 16:47
(Received via mailing list)
Yes
I have since changed my approach. I've also talked with Mark about
approaching this.

The approach I take now is to generate a proxy to the
object/class/interface
that will record method calls.
After recording you can then run verifications on those method calls.
The
way I generate the proxy for an interface came out of my talk with Mark.

http://github.com/casualjim/caricature/blob/922bdc...

But the deeper implication is then that when a library uses
Expression<Func<,>> as parameters you cannot use it from ironruby at
all?
Not even by building the expression tree yourself?


(I forgot to hit send apparently :))
---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
GSM: +32.486.787.582
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

Emo Philips
<http://www.brainyquote.com/quotes/authors/e/emo_ph...
- "I got some new underwear the other day. Well, new to me."
F983f0c990cba2fe743ef62a975ec99c?d=identicon&s=25 Curt Hagenlocher (Guest)
on 2009-05-05 17:11
(Received via mailing list)
Of course you should be able to build the expression tree manually –
though even here, you may have trouble under .NET 3.5 as a result of the
duplicated namespace. (That issue goes away with .NET 4.)

From: ironruby-core-bounces@rubyforge.org
[mailto:ironruby-core-bounces@rubyforge.org] On Behalf Of Ivan Porto
Carrero
Sent: Tuesday, May 05, 2009 7:46 AM
To: ironruby-core@rubyforge.org
Subject: Re: [Ironruby-core] Building expressions

Yes
I have since changed my approach. I've also talked with Mark about
approaching this.

The approach I take now is to generate a proxy to the
object/class/interface that will record method calls.
After recording you can then run verifications on those method calls.
The way I generate the proxy for an interface came out of my talk with
Mark.

http://github.com/casualjim/caricature/blob/922bdc...

But the deeper implication is then that when a library uses
Expression<Func<,>> as parameters you cannot use it from ironruby at
all?  Not even by building the expression tree yourself?


(I forgot to hit send apparently :))
---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
GSM: +32.486.787.582
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

Emo
Philips<http://www.brainyquote.com/quotes/authors/e/emo_ph...  -
"I got some new underwear the other day. Well, new to me."
On Sun, May 3, 2009 at 11:37 PM, Shri Borde
<Shri.Borde@microsoft.com<mailto:Shri.Borde@microsoft.com>> wrote:

It cannot be done. Even if you could get to the ExpressionTree of a Ruby
lambda, the ExpressionTree would be loosely-bound as Ruby uses
duck-typing, whereas Moq expects a strongly-typed ExpressionTree so that
it can figure out the exact method that you are trying to associate some
expectation with.



FWIW, Mark had also been playing with mocking, and in our discussions,
we said that the easiest mocking approach would be to use Ruby features
like method_missing, monkey-patching, etc (like rspec does). Ie.
something like this:



def mock(clrInterface):

  class ClrMock < clrInterface

    # monkey-patch all of “clrInterface.methods" here, and redirect to
the mocking framework

  end

  return ClrMock.new

end



From:
ironruby-core-bounces@rubyforge.org<mailto:ironruby-core-bounces@rubyforge.org>
[mailto:ironruby-core-bounces@rubyforge.org<mailto:ironruby-core-bounces@rubyforge.org>]
On Behalf Of Ivan Porto Carrero
Sent: Sunday, May 03, 2009 3:18 AM
To: ironruby-core
Subject: [Ironruby-core] Building expressions



Hi

I'm trying to get some Moq mockery going in IronRuby but Moq expects
Expression<Func<MyObject, TReturn>> in his methods.
Is there a way to make a RubyProc/lambda return an expression or convert
it to an expression?

---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Author of IronRuby in Action (http://manning.com/carrero)

Steve
Martin<http://www.brainyquote.com/quotes/authors/s/steve_...  -
"I've got to keep breathing. It'll be my worst business mistake if I
don't."

_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org<mailto:Ironruby-core@rubyforge.org>
http://rubyforge.org/mailman/listinfo/ironruby-core
This topic is locked and can not be replied to.