[rspec-users] stubs which yield and return
dchelimsky at gmail.com
Tue Aug 7 12:54:45 EDT 2007
On 8/7/07, Scott Taylor <mailing_lists at railsnewbie.com> wrote:
> Is there any reason why a stub couldn't both yield and return?
Yes. Nobody ever asked for it :)
> looking for a way to mock out a class I've made named "AnonymousClass":
> class AnonymousClass
> def initialize(&blk)
> @klass = Class.new
> @klass.instance_eval(&blk) if block_given?
> def new
> def evaluate(&blk)
> attr_reader :klass
> alias_method :class, :klass
> One of the behaviours of the AnonymousClass is that new can take a
> block, and eval the block in the anonymous class, represented by the
> @klass instance_variable:
> ac = AnonymousClass.new do
> include Enumerable
> So is there a way to stub AnonymousClass.new such that it yield an
> AnonymousClass mock, as well as yielding to the block given? What
> are the technical challenges involved in implementing this in the
> mocking framework? Or is it a matter of clean syntax?
Again - this simply hasn't come up. Please add an RFE and feel free to
submit a patch.
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users