[rspec-users] RSpec - Testing ActiveRecord addins

Pat Nakajima patnakajima at gmail.com
Fri Jan 30 11:31:52 EST 2009


So, in acts_as_fu, I actually set the ActiveRecord logger to just log
to a StringIO that you can inspect by calling ActsAsFu.log. That's not
going to fly for your project though, so let me give the ability to
set your own. It'll be committed soon.

- Pat

On Jan 30, 11:10 am, James Byrne <li... at ruby-forum.com> wrote:
> Pat Nakajima wrote:
> > If you want an easy way to test ActiveRecord extensions, check out
> > acts_as_fu:http://github.com/nakajima/acts_as_fu. It makes generating
> > ActiveRecord models dead simple.
>
> This seems to work very well.  However, I am causing myself a problem
> with the logger and I could use some clarification on what is happening
> so that I can fix it.
>
> I created a custom logger to format the log output into syslog style.
> So, in environment.rb I have this:
>
>   # Customize logger - 'require "syslog_formatter"'
>   config.logger = RAILS_DEFAULT_LOGGER = Logger.new(config.log_path)
>   config.logger.formatter = SyslogFormatter.new
>   config.logger.level     = Logger::INFO # DEBUG, WARN, ERROR, FATAL
>
> and lib/syslog_formatter.rb has this:
>
> # Configure custom logger used in all environments
>
> class SyslogFormatter
>   def call(level, time, program, message)
>     l_time    = time.strftime("%b %d %H:%M:%S")
>     l_process = "rails[#{$PID}]"
>     l_host    = Socket.gethostname.split('.')[0]
>     l_user    = @current_user if defined?(@current_user)
>     l_text    = (String === message ?  message :
> message.inspect).gsub(/\n/, '').strip
>     "#{l_time} #{l_host} #{l_process} #{l_text} #{l_user}\n"
>   end
> end
>
> and when I run rake spec I see this:
>
> NameError in 'Role should create a new instance given valid attributes'
> undefined local variable or method `logger' for
> #<Spec::Rails::Example::ModelExampleGroup::Subclass_4:0x2ad081fa0998>
> /usr/lib64/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/test_p rocess.rb:471:in
> `method_missing'
> /home/byrnejb/Software/Development/Projects/proforma.git/spec/spec_helper.r b:25:
>
> Which is explicitly related to this code in spec_helper.rb:
>
> # Custom Logger
>
>   config.before(:each) do
>     full_example_description = "#{self.class.description}
> #{@method_name}"
>     logger.info(
>       "\n\n#{full_example_description}\n#{'-' *
>           (full_example_description.length)}")
>   end
>
> Do I just comment this out or is there something else I should do, short
> of disabling my own custom logger, to get this to work?
>
> --
> Posted viahttp://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users


More information about the rspec-users mailing list