Has anyone else run into a problem with trying to use mock_model in spec/lib ? For some reason, I can take the same spec, put it in spec/models, have it run fine, but put it in spec/lib, and have it complain about not being able to find #mock_model Thanks, Edward
On 8/30/07, Edward Ocampo-Gooding <edward.og at gmail.com> wrote:> Has anyone else run into a problem with trying to use mock_model in spec/lib ? > For some reason, I can take the same spec, put it in spec/models, have it run > fine, but put it in spec/lib, and have it complain about not being able to find > #mock_modelmock_model is not supported outside of model, view, controller and helper specs. Feel free to submit a feature request if you think it should be.> > Thanks, > Edward > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
David Chelimsky wrote:> On 8/30/07, Edward Ocampo-Gooding <edward.og at gmail.com> wrote: >> Has anyone else run into a problem with trying to use mock_model in spec/lib ? >> For some reason, I can take the same spec, put it in spec/models, have it run >> fine, but put it in spec/lib, and have it complain about not being able to find >> #mock_model > > mock_model is not supported outside of model, view, controller and > helper specs. Feel free to submit a feature request if you think it > should be.I can kind of understand why it''s not, but it''d be good to have an error message that pops informing the user saying as such. Edward
Edward Ocampo-Gooding wrote:> Has anyone else run into a problem with trying to use mock_model in spec/lib ? > For some reason, I can take the same spec, put it in spec/models, have it run > fine, but put it in spec/lib, and have it complain about not being able to find > #mock_modelInteresting. At first glance, at least, it looks like all of the controller/view/model behaviour includes base.rb''s EvalContext, but if you''re not in any of those behaviours, you don''t get the base behaviour either - "general" specs don''t get EvalBehaviour. I''m not positive, because I can''t find the bit that loads (dir_name)Behaviours at the moment, but I think that''s what''s happening. I''m not sure if this is a bug or an enhancement request, and if the right behaviour is to have all Rails specs get EvalBehaviour if they don''t live in a special-case dir, or if it would be better for lib to be another special case. Jay Levitt
Edward Ocampo-Gooding wrote:> David Chelimsky wrote: >> On 8/30/07, Edward Ocampo-Gooding <edward.og at gmail.com> wrote: >>> Has anyone else run into a problem with trying to use mock_model in spec/lib ? >>> For some reason, I can take the same spec, put it in spec/models, have it run >>> fine, but put it in spec/lib, and have it complain about not being able to find >>> #mock_model >> mock_model is not supported outside of model, view, controller and >> helper specs. Feel free to submit a feature request if you think it >> should be. > > I can kind of understand why it''s not, but it''d be good to have an error message > that pops informing the user saying as such.Also note that in trunk, you can work around this with describe my_lib_function, :behaviour_type => :controller (or model, or helper, or view) which is very useful for lib functions that are used in one of those contexts. Jay
On 8/30/07, Jay Levitt <lists-rspec at shopwatch.org> wrote:> Edward Ocampo-Gooding wrote: > > David Chelimsky wrote: > >> On 8/30/07, Edward Ocampo-Gooding <edward.og at gmail.com> wrote: > >>> Has anyone else run into a problem with trying to use mock_model in spec/lib ? > >>> For some reason, I can take the same spec, put it in spec/models, have it run > >>> fine, but put it in spec/lib, and have it complain about not being able to find > >>> #mock_model > >> mock_model is not supported outside of model, view, controller and > >> helper specs. Feel free to submit a feature request if you think it > >> should be. > > > > I can kind of understand why it''s not, but it''d be good to have an error message > > that pops informing the user saying as such. > > Also note that in trunk, you can work around this with > > describe my_lib_function, :behaviour_type => :controller (or model, or > helper, or view) > > which is very useful for lib functions that are used in one of those > contexts.Correct - that is the correct usage. the lib directory is for stuff not related specifically to rails, in my view> > Jay > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
David Chelimsky wrote:> On 8/30/07, Jay Levitt <lists-rspec at shopwatch.org> wrote: >> Edward Ocampo-Gooding wrote: >>> David Chelimsky wrote: >>>> On 8/30/07, Edward Ocampo-Gooding <edward.og at gmail.com> wrote: >>>>> Has anyone else run into a problem with trying to use mock_model in spec/lib ? >>>>> For some reason, I can take the same spec, put it in spec/models, have it run >>>>> fine, but put it in spec/lib, and have it complain about not being able to find >>>>> #mock_model >>>> mock_model is not supported outside of model, view, controller and >>>> helper specs. Feel free to submit a feature request if you think it >>>> should be. >>> I can kind of understand why it''s not, but it''d be good to have an error message >>> that pops informing the user saying as such. >> Also note that in trunk, you can work around this with >> >> describe my_lib_function, :behaviour_type => :controller (or model, or >> helper, or view) >> >> which is very useful for lib functions that are used in one of those >> contexts. > > Correct - that is the correct usage. > > the lib directory is for stuff not related specifically to rails, in my viewI don''t know how common that view is, though - in general, I think Rails folks use lib/ for classes that aren''t part of a model (be it an ActiveRecord model or a "fake" model like a shopping cart). They''re often non-Rails-specific, but f''rinstance I have an enum object that interacts with ActiveRecord, but isn''t itself a model. Eventually might be a plugin, but for now it''s only used in one app, so it lives in lib/. I created an enhancement request, but I can make a patch if you can remind me where on earth the directories are special-cased - I couldn''t find it for the life of me. Jay
Jay Levitt wrote:> David Chelimsky wrote: >> On 8/30/07, Jay Levitt <lists-rspec at shopwatch.org> wrote: >>> Edward Ocampo-Gooding wrote: >>>> David Chelimsky wrote: >>>>> On 8/30/07, Edward Ocampo-Gooding <edward.og at gmail.com> wrote: >>>>>> Has anyone else run into a problem with trying to use mock_model in spec/lib ? >>>>>> For some reason, I can take the same spec, put it in spec/models, have it run >>>>>> fine, but put it in spec/lib, and have it complain about not being able to find >>>>>> #mock_model >>>>> mock_model is not supported outside of model, view, controller and >>>>> helper specs. Feel free to submit a feature request if you think it >>>>> should be. >>>> I can kind of understand why it''s not, but it''d be good to have an error message >>>> that pops informing the user saying as such. >>> Also note that in trunk, you can work around this with >>> >>> describe my_lib_function, :behaviour_type => :controller (or model, or >>> helper, or view) >>> >>> which is very useful for lib functions that are used in one of those >>> contexts. >> Correct - that is the correct usage. >> >> the lib directory is for stuff not related specifically to rails, in my view > > I don''t know how common that view is, though - in general, I think Rails > folks use lib/ for classes that aren''t part of a model (be it an > ActiveRecord model or a "fake" model like a shopping cart). They''re > often non-Rails-specific, but f''rinstance I have an enum object that > interacts with ActiveRecord, but isn''t itself a model. Eventually might > be a plugin, but for now it''s only used in one app, so it lives in lib/.Yep, I happen to be one of those folks who use lib/ for classes that aren''t models.> I created an enhancement request, but I can make a patch if you can > remind me where on earth the directories are special-cased - I couldn''t > find it for the life of me.Thanks Jay. It sounds like we''d make a new DSL module for Libs with the same behaviour as Models. Edward