Gudleik Rasch
2010-Aug-05 14:32 UTC
[rspec-users] Macros and accessing block-variables (rspec2)
Hi, I''m trying to create an rspec macro (for rspec2) but it cannot access variables defined in a before-block. Am I missing something or is it supposed to be like that? Here''s a full example: http://gist.github.com/509802 -- gudleik
Myron Marston
2010-Aug-06 00:24 UTC
[rspec-users] Macros and accessing block-variables (rspec2)
The before block and the macro declaration get run in different contexts. In the before block, self is an instance of the example group. Your macro declaration runs with self set to the example group itself. It''s the difference between an instance variable of a Class instance (since Classes are objects, too), and an instance variable of an instance of a class. Myron On Aug 5, 7:32?am, Gudleik Rasch <gudl... at gmail.com> wrote:> Hi, > > I''m trying to create an rspec macro (for rspec2) but it cannot access > variables defined in a before-block. > Am I missing something or is it supposed to be like that? > > Here''s a full example:http://gist.github.com/509802 > > -- > gudleik > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
Ashley Moran
2010-Aug-06 09:27 UTC
[rspec-users] Macros and accessing block-variables (rspec2)
On Aug 06, 2010, at 1:24 am, Myron Marston wrote:> It''s the difference between an instance variable of a Class instance > (since Classes are objects, too), and an instance variable of an > instance of a class.I talked a .Net dev friend of mine through instance ivar + class ivar + class variables last weekend. His response was something along the lines of "Woah!" :) Gudleik - the simplest, readable change I can think of is to make the answer a constant[1]. The answer is really a property of the spec, not of the examples, so it doesn''t belong in the `before` block. But I suspect the example you''ve given is a simplified version of something more complex, so real-world solution may be different. HTH Ash [1] http://gist.github.com/511087 -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran