Rails3集成测试插件Rails-Carrot(一)

Rails-Carrot部分参考Capybara,支持原生的测试Gem驱动,主要是供喜欢用Celerity或者原生浏览器测试Driver。

 

支持远程,本地,本地外部ruby运行服务器 进行集成测试。

 

插件地址: http://github.com/sloanwu/carrot

 

简要介绍,以集成Celerity(需要使用JRuby)为例



You can use carrot with celerity, or another driver.

1. Rails Gemfile 
gem 'rails-carrot', :require => 'carrot'

2. add a celerity_helper
/spec/celerity_helper.rb

3. Add some code in celerity_helper
require 'database_cleaner' 
require 'celerity' # You can change driver
require 'carrot'

ENV["RAILS_ENV"] = 'celerity' # You can change it with your environment.
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'



4. Three test styles

If you don't use JRuby, you just can use Remote and Local.

a) Remote
Carrot.configure do |config|
  config.run_server = false
  config.app_host = "www.google.com"
end
Carrot.register_driver(Celerity::Browser.new)

b) Local 
Carrot.configure do |config|
  config.run_server = true
end
Carrot.register_driver(Celerity::Browser.new)

c) Local, server with external ruby, You should use jruby to run RSpec. 
Carrot.configure do |config|
  config.run_server = true
  config.external_ruby = true
  config.rails_command = "~/.rvm/gems/ruby-1.9.2-p0/bin/rails s -e celerity -p 3001"
  config.project_path = "#{Rails.root}"
  config.server_port = 3001
  # config.server_debug = true
end
Carrot.register_driver(Celerity::Browser.new)

RSpec.configure do |config|
   DatabaseCleaner.strategy = :truncation 
  
   config.before :each do 
     @browser = Carrot.driver   # get native driver
     DatabaseCleaner.clean 
   end

   config.after :all do
     DatabaseCleaner.clean 
   end
 
   config.use_transactional_fixtures = false

end

5 Test
a) get url 
Carrot.url(path)
eg:
Carrot.url('/')        =>   http://host/
Carrot.url('/hello')   =>   http://host/hello

b) get native browser driver 
Carrot.driver

6 FAQ
a) Does Carrot support server with external ruby? 
Yes, but it just supports jruby run rspec and run server using external ruby. I use jruby to create native java process to run server using external ruby.

If you want to use ruby to run rspec and run server using external ruby, you can create a new server class to support it or wait for my upgrade. 



 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值