How to automate the testing of my Rails project via Ruby?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Brad Chin

    #1

    How to automate the testing of my Rails project via Ruby?

    Hi,

    I'm still new to Ruby on Rails, and I want to utilize
    ActiveRecord::O bserver. I got Observer working under the rails
    environment by putting my rb files under app/model and configuring
    config/environment.rb. However, I want to automate the testing of my
    site via command line. Is this possible?

    So, I have a foo.rb

    Code:
    (bchin ~/setup/rails/pratice/app/models)cat foo.rb
    class Foo < ActiveRecord::Base
    end
    and my foo_observer.rb

    Code:
    (bchin ~/setup/rails/pratice/app/models)cat foo_observer.rb
    class FooObserver < ActiveRecord::Observer
    
      def after_create(foo)
        puts foo.id
        Foo.find(foo.id)
      end
    
    end
    and I registered foo_observer under config/environment

    Code:
    (bchin ~/setup/rails/pratice/app/models)grep 'foo'
    ../../config/environment.rb
      config.active_record.observers = :foo_observer
    And, when I go to the console, everything works as expected

    Code:
    (bchin ~/setup/rails/pratice/script)./console
    Loading development environment (Rails 2.3.2)
    >> Foo.create
    2
    => #<Foo id: 2>
    >>
    How can I use ruby to test this? I tried creating a main.rb, which
    'require' foo and foo_observer, but that doesn't seem to work. What am I
    missing? Thanks for any help anyone can provide.
    Last edited by acoder; Oct 31 '12, 10:42 PM.
Working...