Forum: RSpec rspec testing inheritance

78e7109f5fd74ae07678541288f0a417?d=identicon&s=25 slavix tube (slavix)
on 2011-09-07 07:31
(Received via mailing list)
Hello,
Is there any way to test model inheritance in spec?

something like..
 it { ChildModel.should < ParentModel }

thanks.
1df9fc8ddf084661265bbae74a8d0b43?d=identicon&s=25 Justin Ko (Guest)
on 2011-09-07 07:42
(Received via mailing list)
On Tue, Sep 6, 2011 at 9:40 PM, slavix <mikerin.slava@gmail.com> wrote:

> http://rubyforge.org/mailman/listinfo/rspec-users
>

specify { ChildModel.should be < ParentModel }
7bb0d7e74198c735783b8a65cd14989c?d=identicon&s=25 Sidu Ponnappa (kaiwren)
on 2011-09-07 09:01
(Received via mailing list)
Wouldn't this be an implementation bound spec?

Best,
Sidu.
http://c42.in
Cdf378de2284d8acf137122e541caa28?d=identicon&s=25 Matt Wynne (mattwynne)
on 2011-09-07 14:48
(Received via mailing list)
On 7 Sep 2011, at 07:53, Sidu Ponnappa wrote:

>>>  it { ChildModel.should < ParentModel }
>>>
>>> thanks.

> Wouldn't this be an implementation bound spec?

+1

Test the behaviour, not the implementation. You could look at using a
shared example group if you want to specify that the subclass shared
behaviour with the superclass.

--
Freelance programmer & coach
Author, http://pragprog.com/book/hwcuc/the-cucumber-book (with Aslak
Hellesy)
Founder, http://relishapp.com
+44(0)7974430184 | http://twitter.com/mattwynne
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2011-09-07 16:01
(Received via mailing list)
On Sep 7, 2011, at 7:03 AM, Matt Wynne wrote:

>>>> it { ChildModel.should < ParentModel }
>>>>
>>>> thanks.
>
>> Wouldn't this be an implementation bound spec?
>
> +1
>
> Test the behaviour, not the implementation. You could look at using a shared
example group if you want to specify that the subclass shared behaviour with the
superclass.

+1

It might not surprise you that I prefer to focus on behavior over
implementation (though it might surprise some people who think I like to
mock too much! ;)), however ...

-1

... there are absolutely valid cases for focusing on type. In
rspec-rails, for example, mock_models need to lie about their type to
Rails' internals in order for things to run smoothly. There are,
therefore, examples like:

  mock_model("User").should be_a(User)

Any sort of factory that might generate objects of different types in
different contexts would warrant this as well.

That said, I'll guess that @slavix's motivation here is that there are
ParentModel specs and he doesn't want to duplicate them for ChildModel.
If that's true, then a shared group is definitely a better option for a
number of reasons. The most obvious one is that ChildModel is free to
override behavior defined in ParentModel, so the fact that ChildModel <
ParentModel is no guarantee that they behave the same way.

HTH,
David
This topic is locked and can not be replied to.