查看完整版本: CruiseControl RB(aka CCRB) and Rspec

blackanger 2008-3-3 23:41

CruiseControl RB(aka CCRB) and Rspec

[b]此文章是公司CEO Kevin Yang 给新项目做持续集成的时候碰到的问题,然后写在blog上的文章,转贴自此。[/b]


[u]CruiseControl RB(简称CCRB) 和 Rspec[/u]


先说一下原理, CCRB其实是一个Rails项目。
当ccrb启动的时候, 会有一个daemon进程,每隔30秒,去检查svn是否有更新。 如果有更新,就会运行一个rake任务,从而激发一系列的测试代码被执行。
当测试失败的时候,会根据配置文件发送邮件提醒。


如果你使用rspec的话, 需要改写ccrb的一些任务,才能支持rspec

desc ‘Custom curise task for RSpec’  
task :cruise do  
      ENV[‘RAILS_ENV’] = ‘test’  
  
      if File.exists?(Dir.pwd + "/config/database.yml")  
        if Dir[Dir.pwd + "/db/migrate/*.rb"].empty?  
          raise "No migration scripts found in db/migrate/ but database.yml exists, " +  
                "CruiseControl won’t be able to build the latest test database. Build aborted."  
        end  
  
        # perform standard Rails database cleanup/preparation tasks if they are defined in project  
        # this is necessary because there is no up-to-date development database on a continuous integration box  
        if Rake.application.lookup(‘db:test:purge’)
          CruiseControl::invoke_rake_task ‘db:test:purge’
        end

        if Rake.application.lookup(‘db:migrate’)
          CruiseControl::reconnect
          CruiseControl::invoke_rake_task ‘db:migrate’
        end
      end

      CruiseControl::invoke_rake_task ‘spec’  
end

需要注意的是,
对Rspec的支持,稍有不同。 Autotest的环境初始化机制,与Rake Spec的机制不同, 会造成test数据库中的数据不同,从而导致autotest能全部通过, 在服务器上调用rake spec的时候,却出现错误。


解决的办法是:  在所有的Spec文件中,
describe Account do
  
  fixtures :all
  
end
确保运行所有的测试时候,都初始化到相同的test数据环境中。
这样一来, 就能确保测试结果,不受测试工具(autotest或者rake spec)的影响。

当要启动ccrb的时候,  ./cruise start -p 8006 -d
就能以服务器状态Daemon启动


每个project,都有自己的配置文件。
举例说明:     ./projects/foo/cruise_config.rb

Project.configure do |project|

  project.email_notifier.emails = [‘[email]kevin@nibirutech.com[/email]’]
  project.email_notifier.from = ‘[email]no-reply@nibirutech.com[/email]’

end

这样就能在测试失败的时候收到邮件

yudi 2008-3-26 04:25

想为多个 ruby project 做 CI, 有机会玩玩?
页: [1]
查看完整版本: CruiseControl RB(aka CCRB) and Rspec