Edward Ocampo-Gooding
2007-Aug-19 20:33 UTC
[rspec-users] describing a mock_model as being an instance
Is there a built-in way of describing a mock_model as being an instance, beyond stubbing the eval("Object.methods - Object.new.methods") methods to throw NoMethodErrors? Edward
David Chelimsky
2007-Aug-20 00:00 UTC
[rspec-users] describing a mock_model as being an instance
On 8/19/07, Edward Ocampo-Gooding <edward.og at gmail.com> wrote:> Is there a built-in way of describing a mock_model as being an instance, beyond > stubbing the eval("Object.methods - Object.new.methods") methods to throw > NoMethodErrors?Huh? Can you give an example of what you are trying to achieve?> > Edward > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Edward Ocampo-Gooding
2007-Aug-20 01:22 UTC
[rspec-users] describing a mock_model as being an instance
David Chelimsky wrote:> On 8/19/07, Edward Ocampo-Gooding <edward.og at gmail.com> wrote: >> Is there a built-in way of describing a mock_model as being an instance, beyond >> stubbing the eval("Object.methods - Object.new.methods") methods to throw >> NoMethodErrors? > > Huh? Can you give an example of what you are trying to achieve?I''m writing a method that involves deciding if an object is a class or an instance of a class. Right now I''m creating a mock_model and setting up an expectation on respond_to? :new but I''ve got a feeling that this isn''t the way to go. The current mock_model returns an object that looks more like a class based on the methods it has (I should actually go look now and check if it''s got the typical instantiated Object methods too...), and I''m wondering if there''s a clean way of creating a mock_model instance that has typical instantiated Object methods and no Object class methods. Edward
Courtenay
2007-Aug-20 05:00 UTC
[rspec-users] describing a mock_model as being an instance
On 8/19/07, Edward Ocampo-Gooding <edward.og at gmail.com> wrote:> David Chelimsky wrote: > > On 8/19/07, Edward Ocampo-Gooding <edward.og at gmail.com> wrote: > >> Is there a built-in way of describing a mock_model as being an instance, beyond > >> stubbing the eval("Object.methods - Object.new.methods") methods to throw > >> NoMethodErrors? > > > > Huh? Can you give an example of what you are trying to achieve? > > I''m writing a method that involves deciding if an object is a class or an > instance of a class. Right now I''m creating a mock_model and setting up an > expectation on respond_to? :new but I''ve got a feeling that this isn''t the way > to go. > > The current mock_model returns an object that looks more like a class based on > the methods it has (I should actually go look now and check if it''s got the > typical instantiated Object methods too...), and I''m wondering if there''s a > clean way of creating a mock_model instance that has typical instantiated Object > methods and no Object class methods. > > Edward > >Is there a reason it needs to be more complicated than this? class Foo end Foo.is_a?(Class) => true Foo.new.is_a?(Class) => false
Edward Ocampo-Gooding
2007-Aug-21 16:54 UTC
[rspec-users] describing a mock_model as being an instance
Courtenay wrote:> Is there a reason it needs to be more complicated than this? > > class Foo > end > > Foo.is_a?(Class) > => true > > Foo.new.is_a?(Class) > => falseYou can do that? Whoaaaaa... That totally makes sense. I also found out about Object#instance_of? yesterday. Thanks for the tip! Edward