Rails 3 통합 테스트 플러그 인 Rails - Carrot (1)
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.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
새로운 UI의 Stripe Checkout을 Rails로 만들어 보았습니다.Stripe의 옛 디자인인 Stripe의 구현 기사는 많이 있습니다만, 지금 현재의 디자인에서의 도입 기사는 발견되지 않았기 때문에 투고합니다. Stripe의 체크아웃을 stripe의 문서라든지 stackoverfl...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.