On Dec 4, 2011, at 7:48 AM, Ants Pants wrote:

> Hello everyone,
> 
> I am trying to do the following ....
> 
> before(:each) do
>     @valid_attributes = {:foo => 'bar'}
>     @event_type = event_category.event_types.build(@valid_attributes) 
>     $stderr.puts "**** #{@event_type.class} *****"
> end
> 
> let (:event_category) { mock_model(EventCategory).as_null_object }
> 
> and the problem I'm having is that @event_type is coming back as 
> EventCategory and not EventType.
> 
> Because of this problem, I thought, eh, I didn't know Rails did that!  So I 
> checked use of .build in the real code and it does return EventType.
> 
> I'm obviously doing something stupidly wrong in the test but I just can't 
> figure it out. 
> 
> Any pointers would be greatly appreciated, thank you.

event_category is a mock_model, not an EventCategory. Since it's declared 
as_null_object, when it receives :event_types, it returns itself, and then does 
the same for :build. So it's not really even an EventCategory: it's a the same 
mock_model object, which is designed to lie about it's class in order to be 
able to work with form builders.

HTH,
David
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to