Forum: RSpec described_type

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.
Cdf378de2284d8acf137122e541caa28?d=identicon&s=25 Matt Wynne (mattwynne)
on 2008-10-31 10:46
(Received via mailing list)
I heard somebody mention described_type the other day, so I thought
I'd give it a spin.

It doesn't seem to behave as I'm expecting though.

I have a method which generates examples to verify AR associations:

         def it_should_have_many(klass, association, opts = {})
           it "should relate to #{association}" do
             klass.reflect_on_association(association).should_not be_nil
           end

           it "should have many #{association}" do
             klass.reflect_on_association(association).macro.should
== :has_many
           end

           if opts[:as]
             it "should relate to #{association} as :subject" do

klass.reflect_on_association(association).options[:as].should ==
opts[:as]
             end
           end
         end

So at the moment, I have to call it like this:

  it_should_have_many Post, :attachments, :as => :comments

Which is a bit ugly. I figured I could use described_type instead of
klass in the example-generating method, but it doesn't work:

  undefined local variable or method `described_type' for
#<
Spec
::Rails
::Example
::ModelExampleGroup::Subclass_1::Subclass_1::Subclass_1:0x21518bc>

What dumb thing am I doing wrong?

cheers,
Matt
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2008-10-31 12:07
(Received via mailing list)
Matt Wynne <matt@mattwynne.net> writes:

> I figured I could use described_type instead of
> klass in the example-generating method, but it doesn't work:
>
>   undefined local variable or method `described_type' for  #<
> Spec ::Rails ::Example
> ::ModelExampleGroup::Subclass_1::Subclass_1::Subclass_1:0x21518bc>
>
> What dumb thing am I doing wrong?

self.class.described_type

Pat
This topic is locked and can not be replied to.