I''m a relative newbie to Ruby and Rails but have done a bit of test driven development and understand the concepts and importances of it. My experiences are with the .NET framework. Much of my development is ASP.NET which isn''t typically easy to do TDD with. I''m curious as to how TDD is done within Rails. What sorts of things are people testing and how? Sample code is greatly appreicated as I would like to start off on the right foot now. Kyle Heon kheon-Wuw85uim5zDR7s880joybQ@public.gmane.org _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
I highly recommend the book: http://www.pragmaticprogrammer.com/titles/rails/index.html Otherwise, check out the docs: http://manuals.rubyonrails.com/read/book/5 On 7/20/05, Kyle Heon <kheon-Wuw85uim5zDR7s880joybQ@public.gmane.org> wrote:> > > I''m a relative newbie to Ruby and Rails but have done a bit of test driven > development and understand the concepts and importances of it. > > My experiences are with the .NET framework. Much of my development is > ASP.NET which isn''t typically easy to do TDD with. > > > I''m curious as to how TDD is done within Rails. What sorts of things are > people testing and how? > > Sample code is greatly appreicated as I would like to start off on the right > foot now. > > Kyle Heon > kheon-Wuw85uim5zDR7s880joybQ@public.gmane.org > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
Thanks. I realized immediately after I sent this that I should have just looked in the Rails book. Of course, I would still be interested in hearing others experiences with TDD and Rails. Kyle Heon kheon-Wuw85uim5zDR7s880joybQ@public.gmane.org -----Original Message----- From: Cuong Tran [mailto:cuong.tran-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org] Sent: Wednesday, July 20, 2005 9:49 PM To: kheon-Wuw85uim5zDR7s880joybQ@public.gmane.org; rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails] Unit Testing in Rails I highly recommend the book: http://www.pragmaticprogrammer.com/titles/rails/index.html Otherwise, check out the docs: http://manuals.rubyonrails.com/read/book/5 On 7/20/05, Kyle Heon <kheon-Wuw85uim5zDR7s880joybQ@public.gmane.org> wrote:> > > I''m a relative newbie to Ruby and Rails but have done a bit of test > driven development and understand the concepts and importances of it. > > My experiences are with the .NET framework. Much of my development is > ASP.NET which isn''t typically easy to do TDD with. > > > I''m curious as to how TDD is done within Rails. What sorts of things > are people testing and how? > > Sample code is greatly appreicated as I would like to start off on the > right foot now. > > Kyle Heon > kheon-Wuw85uim5zDR7s880joybQ@public.gmane.org > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
On Thursday 21 July 2005 06:52 pm, Kyle Heon wrote:> Thanks. I realized immediately after I sent this that I should have just > looked in the Rails book. > > Of course, I would still be interested in hearing others experiences with > TDD and Rails. >1) Rails has very good support for writing automated tests using Test::Unit. 2) It has very poor support for writing "unit tests" by any conventional standard, though I''ve been able to work around it. One problem causing #2, is that NOTHING can happen without the database. Without DB access, there are no ''fields'' in the model objects.
On Saturday 23 July 2005 02:05, David Corbin wrote:> 2) [Rails] has very poor support for writing "unit tests" by any > conventional standard, though I''ve been able to work around it. > > One problem causing #2, is that NOTHING can happen without the > database. Without DB access, there are no ''fields'' in the model > objects.Well, it actually is possible to test without a database. It''s neither straightforward, easy, or pretty -- just possible. Below is an excerpt. Michael class OptimisticUpdateSupportTest < Test::Unit::TestCase include BoilerPlate::OptimisticUpdateSupport cattr_reader :date_format class MockConnection < ActiveRecord::ConnectionAdapters::AbstractAdapter include Test::Unit::Assertions def initialize super(nil) @handlers = {} end def columns(arg1, arg2) [ ActiveRecord::ConnectionAdapters::Column.new(''id'', 0, ''integer''), ActiveRecord::ConnectionAdapters::Column.new(''attrib1'', '''', ''varchar(255)''), ActiveRecord::ConnectionAdapters::Column.new(''attrib2'', '''', ''varchar(255)''), ActiveRecord::ConnectionAdapters::Column.new(''dateattrib'', '''', ''date''), ActiveRecord::ConnectionAdapters::Column.new(''dummy_id'', nil, ''integer''), ActiveRecord::ConnectionAdapters::Column.new(''lock_version'', 0, ''integer'') ] end def insert(*args) call_handler(:insert, *args) end def select_all(*args) call_handler(:select_all, *args) end def select_one(*args) call_handler(:select_one, *args) end def update(*args) call_handler(:update, *args) end def delete(*args) call_handler(:delete, *args) end def add_handler(handler_name, &block) @handlers[handler_name] ||= [] @handlers[handler_name] << block end def call_handler(handler_name, *args) if handler = @handlers[handler_name].shift handler.call(*args) else flunk("Unexpected call to \"#{handler_name}\"") end end def verify assert( @handlers.all? { |k| @handlers[k].nil? || @handlers[i].empty? } ) end end class Dummy < ActiveRecord::Base attr_accessor :is_valid cattr_accessor :instance def initialize(id, conn) @id = id @@connection = conn super(nil) end def self.find(*args) object = instance.dup attributes = object.attributes.dup if (args[0].kind_of?(Fixnum)) attributes[''id''] = args[0] end object.instance_variable_set(''@attributes'', attributes) object end def valid? result = super unless is_valid.nil? result = is_valid end result end def self.retrieve_connection @@connection end def unserializable_attribute?(attr_name, column) false end end def setup @params = HashWithIndifferentAccess.new @connection = MockConnection.new dummy = Dummy.new(1, @connection) dummy.attrib1 = ''value1'' dummy.attrib2 = ''value2'' dummy.dummy_id = nil @connection.add_handler(:insert) { } assert(dummy.save) Dummy.instance = dummy @dummy = Dummy.find(1) end -- Michael Schuerig The Fifth Rider of the Apocalypse mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org is a programmer. http://www.schuerig.de/michael/
On Friday 22 July 2005 08:36 pm, Michael Schuerig wrote:> On Saturday 23 July 2005 02:05, David Corbin wrote: > > 2) [Rails] has very poor support for writing "unit tests" by any > > conventional standard, though I''ve been able to work around it. > > > > One problem causing #2, is that NOTHING can happen without the > > database. Without DB access, there are no ''fields'' in the model > > objects. > > Well, it actually is possible to test without a database. It''s neither > straightforward, easy, or pretty -- just possible. Below is an excerpt.I''d actually considered writing an adapter at one point that would do this based on file, possibly generated from the SQL database. But I haven''t, and the idea slipped my mind. Thanks> > Michael > >