<br><br><div class="gmail_quote">On Nov 22, 2007 8:31 AM, aslak hellesoy <<a href="mailto:aslak.hellesoy@gmail.com">aslak.hellesoy@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="Wj3C7c">On Nov 21, 2007 10:22 PM, David Chelimsky <<a href="mailto:dchelimsky@gmail.com">dchelimsky@gmail.com</a>> wrote:<br>><br>> On Nov 21, 2007 3:14 PM, Daniel N <<a href="mailto:has.sox@gmail.com">
has.sox@gmail.com</a>> wrote:<br>> > Hi,<br>> ><br>> > I want to be able to get at the described class in my shared behaviour. I'm<br>> > sure an example will say it better than my words<br>
> ><br>> > describe "my shared", :shared => true do<br>> ><br>> > it "should tell me what the class is its describing" do<br>> > how_do_i_get_the_user_class_here<br>
> > end<br>> ><br>> > end<br>> ><br>> > describe User do<br>> > it_should_behave_like "my shared"<br>> ><br>> > #...<br>> > end<br>> ><br>> > So in my shared behaviour, how do I get access to the User class?
<br>><br>> There's no way to do this implicitly. i.e. rspec does not expose the<br>> class. You'd have to have a method like described_class or something:<br>><br>> describe "my shared", :shared => true do
<br>><br>> it "should tell me what the class is its describing" do<br>> described_class.should do_something_I_care_about<br>> end<br>><br>> end<br>><br>> describe User do<br>> def described_class
<br>> User<br>> end<br>> ...<br>> end<br>><br>><br><br></div></div>However, if you do this:<br><br>describe MyModule do # MyModule has a #hello method<br> it "should be polite" do<br>
hello.should == 'How do you do'<br> end<br>end<br><br>Modules are automatically mixed into your examples<br><font color="#888888"><br>Aslak<br></font><div><div></div><div class="Wj3C7c">><br>><br>><br>> >
<br>> > Cheers<br>> > Daniel<br>> ><a href="http://rubyforge.org/mailman/listinfo/rspec-users" target="_blank"></a></div></div></blockquote><div><br>Aslak<br><br>Thanx. I was aware of that behaviour, but this module is being mixed into AR classes and relies on there being methods available to AR models. I really want to implemnet these specs as a shared behaviour on each implementing model.
<br><br>That way I can check to make sure that the model has the correct attributes for the mixin to function properly etc.<br><br>Thanx again.<br>Daniel<br></div></div><br>