2012-03-18 3 views
4

Ruby on Rails 3.2.2, cucumber-rails-1.3.0, rspec-rails-2.8.1 및 capybara-1.1.2를 사용하고 있습니다. 자바 스크립트를 테스트하기 위해 Selenium을 사용하고 싶지만, 내 터미널 창에서 cucumber 명령 줄을 실행할 때마다 test 데이터베이스 데이터를 삭제하지 않아도됩니다. 즉, 다음과 같은 기능을 말하면 :`test` 데이터베이스 데이터를 삭제하지 않고 JavaScripts를 테스트하는 방법은 무엇입니까?

Feature: ... 

    @javascript 
    Scenario: ... 

JavaScript가 제대로 테스트 된 것입니다. 그러나 테스트가 실행 된 후 test 데이터베이스 데이터가 삭제되고 새 테스트를 제대로 실행하려면 해당 데이터베이스를 다시 시드해야합니다.

ROOT_APP/features/support/env.rb 파일에있는 Official Documentation과 텍스트를 읽었습니다 (필요한 모든 Ruby 보석을 설치 한 것으로 보입니다 - 사용중인 Gemfile에 대한 자세한 내용은 아래 참조).하지만 피하는 방법을 이해하지 못했습니다. 데이터베이스 데이터를 삭제하고 Cucumber와 Capybara 보석을 구성하는 방법을 Selenium과 올바르게 작동하도록 설정하십시오.

어떻게해야합니까?

주 I : 나도 같은 test 데이터베이스 데이터 I "테스트"/ "실행"시나리오을하고 싶은 때문에이 (가) 위하고 싶다.

주 II : (내 응용 프로그램 데이터가 일 것을 필요)을 test 데이터베이스의 데이터를 시드하기 위해, 나는 RAILS_ROOT_PATH/lib/tasks/cucumber.rake 파일에 다음 코드를 추가하고 내가 터미널 창에서 rake db:test:prepare 명령 줄을 실행합니다. ROOT_APP/features/support/env.rb 파일에서

namespace :db do 
    namespace :test do 
    task :prepare => :environment do 
     Rake::Task["db:seed"].invoke 
    end 
    end 
end 

내가 다음 코드 블록 중 하나와 모두 주석을 제거하려고 (은 BTW : 그것은이다 그래서 나는 cucumber-rails 보석에 의해 자동으로 생성 된 원본 파일을 변경하지 기본값은 1), 테스트를 실행 한 후에도 test 데이터베이스 데이터가 삭제됩니다.

# Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do 
#  # { :except => [:widgets] } may not do what you expect here 
#  # as tCucumber::Rails::Database.javascript_strategy overrides 
#  # this setting. 
#  DatabaseCleaner.strategy = :truncation 
# end 
# 
# Before('[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]') do 
#  DatabaseCleaner.strategy = :transaction 
# end 

Gemfile 발췌 :

group :development, :test do 
    gem "rspec-rails" 
end 

group :test do 
    gem 'cucumber-rails' 
    gem 'database_cleaner' 
    gem 'capybara' 
end 

답변

3

나는이 같은 문제로 달리고,

Cucumber::Rails::Database.javascript_strategy = :truncation 
에서 ROOT_APP/features/support/env.rb

에 다음 줄을 변경하여 그것을 해결하기 위해 관리

Cucumber::Rails::Database.javascript_strategy = :transaction 

에 희망이 ...

하는 데 도움이
관련 문제