Hi, What's the purpose of test/mocks? I couldn't quite complete the Wiki entry on this because all the information I _could_ find was in the readme. - Rowan -- Morality is usually taught by the immoral. _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
As an example, let''s say you have a model called Order. Order has a method called authorize which when you run in production mode actually calls PayPal or some other credit agencies. But in development mode you want to mock this process. What you should do is to place order.rb file into your test/mocks/development directory and provide a mock implementation of the authorize method. For example: require_dependency ''models/order'' class Order def authorize set_success(@total > 500.dollars) end end Kent. On Dec 27, 2005, at 2:17 PM, BigSmoke wrote:> Hi, > > What''s the purpose of test/mocks? I couldn''t quite complete the Wiki > entry on this because all the information I _could_ find was in the > readme. > > - Rowan > > -- > Morality is usually taught by the immoral. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Thank you for clearing this up for me. Which mock library is mostly used for developing with Rails? I'm assuming http://raa.ruby-lang.org/project/test-unit-mock, since that seems to be used by LoginGenerator, but since there are others, ... - Rowan On 12/27/05, Kent Sibilev <ksruby@gmail.com> wrote:> As an example, let's say you have a model called Order. Order has a > method called authorize which when you run in production mode > actually calls PayPal or some other credit agencies. But in > development mode you want to mock this process. What you should do is > to place order.rb file into your test/mocks/development directory and > provide a mock implementation of the authorize method. For example: > > require_dependency 'models/order' > class Order > def authorize > set_success(@total > 500.dollars) > end > end > > > Kent. > > On Dec 27, 2005, at 2:17 PM, BigSmoke wrote: > > > Hi, > > > > What's the purpose of test/mocks? I couldn't quite complete the Wiki > > entry on this because all the information I _could_ find was in the > > readme. > > > > - Rowan-- Morality is usually taught by the immoral. _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Rails doesn''t use a mock library as such - it just arranges for source under test/mocks/ to be at the top of require()s search path. If you look at the code below, first the main Order class is loaded, then you just redefine the method you want to change (that''s the nice thing about Rubys open classes). On 27/12/05, BigSmoke <bigsmoke-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Which mock library is mostly used for developing with Rails? I''m > assuming http://raa.ruby-lang.org/project/test-unit-mock, since that > seems to be used by LoginGenerator, but since there are others, ...> On 12/27/05, Kent Sibilev <ksruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > require_dependency ''models/order'' > > class Order > > def authorize > > set_success(@total > 500.dollars) > > end > > end-- Rasputin :: Jack of All Trades - Master of Nuns http://number9.hellooperator.net/
> Rails doesn''t use a mock library as such - it just arranges for > source under test/mocks/ to be at the top of require()s search path.Defining a dummy class in test/mocks/ doesn''t make it a mock. It means you''ve defined a stub in a poorly named directory. FWIW, I enjoy using FlexMock in Rails. Install the gem, or copy flexmock.rb to lib/ -Steven.> If you look at the code below, first the main Order class is loaded, then > you just redefine the method you want to change (that''s the nice thing about > Rubys open classes). > > On 27/12/05, BigSmoke <bigsmoke-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Which mock library is mostly used for developing with Rails? I''m > > assuming http://raa.ruby-lang.org/project/test-unit-mock, since that > > seems to be used by LoginGenerator, but since there are others, ... > > > On 12/27/05, Kent Sibilev <ksruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > require_dependency ''models/order'' > > > class Order > > > def authorize > > > set_success(@total > 500.dollars) > > > end > > > end > > > > -- > Rasputin :: Jack of All Trades - Master of Nuns > http://number9.hellooperator.net/ > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Possibly Parallel Threads
- Repost - Do dynamic finders work with legacy schemas?
- [Prototype] Why doesn''t calling submit() on a form result in the execution of the onsubmit event handler?
- Checking the existance of a NOT NULL constraint from Active Record
- SwitchTower and Subversion branches
- Are migrations executed within a transaction?