Christopher J. Bottaro
2011-Aug-05 17:55 UTC
[rspec-users] named context or calling include_context with block?
Hello, I''m playing around with Rspec again after going from test/unit to rspec then back to test/unit... :) Right off the bat, I find myself wanting to do something like this: https://gist.github.com/1128091 Basically, I want to name a context, then call it later by name, passing a block to it. Or in other words... what is the best way to DRY this code? https://gist.github.com/1128108 Is that possible in Rspec 2.6? If not, can anyone provide a monkey patch for me? Thanks!
David Chelimsky
2011-Aug-06 12:56 UTC
[rspec-users] named context or calling include_context with block?
On Aug 5, 2011, at 1:55 PM, Christopher J. Bottaro wrote:> Hello, > > I''m playing around with Rspec again after going from test/unit to > rspec then back to test/unit... :) Right off the bat, I find myself > wanting to do something like this: https://gist.github.com/1128091 > > Basically, I want to name a context, then call it later by name, > passing a block to it. > > Or in other words... what is the best way to DRY this code? > https://gist.github.com/1128108 > > Is that possible in Rspec 2.6?Yes! Take a look at http://relishapp.com/rspec/rspec-core/dir/example-groups/shared-examples for some different options.> If not, can anyone provide a monkey > patch for me? Thanks!
Christopher J. Bottaro
2011-Aug-06 14:05 UTC
[rspec-users] named context or calling include_context with block?
Hey, Maybe I''m reading that wrong, but that''s not exactly what I want to do. In my example, when I call the shared context, I''m passing it a block. Neither include_context or include_examples take a block when called. Thanks. On Aug 6, 8:56?am, David Chelimsky <dchelim... at gmail.com> wrote:> On Aug 5, 2011, at 1:55 PM, Christopher J. Bottaro wrote: > > > Hello, > > > I''m playing around with Rspec again after going from test/unit to > > rspec then back to test/unit... :) ?Right off the bat, I find myself > > wanting to do something like this: ?https://gist.github.com/1128091 > > > Basically, I want to name a context, then call it later by name, > > passing a block to it. > > > Or in other words... what is the best way to DRY this code? > >https://gist.github.com/1128108 > > > Is that possible in Rspec 2.6? > > Yes! Take a look athttp://relishapp.com/rspec/rspec-core/dir/example-groups/shared-examplesfor some different options. > > > If not, can anyone provide a monkey > > patch for me? ?Thanks! > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
David Chelimsky
2011-Aug-06 15:57 UTC
[rspec-users] named context or calling include_context with block?
On Aug 6, 2011, at 10:05 AM, Christopher J. Bottaro wrote:> On Aug 6, 8:56 am, David Chelimsky <dchelim... at gmail.com> wrote: >> On Aug 5, 2011, at 1:55 PM, Christopher J. Bottaro wrote: >> >>> Hello, >> >>> I''m playing around with Rspec again after going from test/unit to >>> rspec then back to test/unit... :) Right off the bat, I find myself >>> wanting to do something like this: https://gist.github.com/1128091 >> >>> Basically, I want to name a context, then call it later by name, >>> passing a block to it. >> >>> Or in other words... what is the best way to DRY this code? >>> https://gist.github.com/1128108 >> >>> Is that possible in Rspec 2.6? >> >> Yes! Take a look athttp://relishapp.com/rspec/rspec-core/dir/example-groups/shared-examplesfor some different options.> Hey, > > Maybe I''m reading that wrong, but that''s not exactly what I want to > do. In my example, when I call the shared context, I''m passing it a > block. Neither include_context or include_examples take a block when > called. > > Thanks.it_behaves_like does, and it can be aliased, so you could so something like https://gist.github.com/1129417. HTH, David ps - I moved your reply inline. Please post inline or at the bottom, especially if the conversation is already structured that way. See http://idallen.com/topposting.html for rationale.>>> If not, can anyone provide a monkey >>> patch for me? Thanks!
Christopher J. Bottaro
2011-Aug-07 17:17 UTC
[rspec-users] named context or calling include_context with block?
On Aug 6, 11:57?am, David Chelimsky <dchelim... at gmail.com> wrote:> On Aug 6, 2011, at 10:05 AM, Christopher J. Bottaro wrote: > > > > > > > > > > > On Aug 6, 8:56 am, David Chelimsky <dchelim... at gmail.com> wrote: > >> On Aug 5, 2011, at 1:55 PM, Christopher J. Bottaro wrote: > > >>> Hello, > > >>> I''m playing around with Rspec again after going from test/unit to > >>> rspec then back to test/unit... :) ?Right off the bat, I find myself > >>> wanting to do something like this: ?https://gist.github.com/1128091 > > >>> Basically, I want to name a context, then call it later by name, > >>> passing a block to it. > > >>> Or in other words... what is the best way to DRY this code? > >>>https://gist.github.com/1128108 > > >>> Is that possible in Rspec 2.6? > > >> Yes! Take a look athttp://relishapp.com/rspec/rspec-core/dir/example-groups/shared-examp...some different options. > > Hey, > > > Maybe I''m reading that wrong, but that''s not exactly what I want to > > do. ?In my example, when I call the shared context, I''m passing it a > > block. ?Neither include_context or include_examples take a block when > > called. > > > Thanks. > > it_behaves_like does, and it can be aliased, so you could so something like https://gist.github.com/1129417 .Awesome, that''s exactly what I''m looking for! I guess I was confused with the examples on relishapp because I thought it would just print out "it behaves like Module" instead of printing out each individual example. One quick thing though... I couldn''t use the constant MyModule with shared_examples and alias to it_should_behave_like. I had to change it to a string "MyModule" then everything worked. I''m using RSpec 2.6.4. Thank you, -- C> HTH, > David > > ps - I moved your reply inline. Please post inline or at the bottom, especially if the conversation is already structured that way. Seehttp://idallen.com/topposting.htmlfor rationale. > > >>> If not, can anyone provide a monkey > >>> patch for me? ?Thanks! > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
David Chelimsky
2011-Aug-07 21:16 UTC
[rspec-users] named context or calling include_context with block?
On Aug 7, 2011, at 12:17 PM, Christopher J. Bottaro wrote:> One quick thing though... I couldn''t use the constant MyModule with > shared_examples and alias to it_should_behave_like. I had to change > it to a string "MyModule" then everything worked. I''m using RSpec > 2.6.4.That''s fixed in git, will be released in rspec 2.7.0. Cheers, David