2013-10-21 16 views
1

我已經設置了一個rake任務來在生成服務器上運行無頭茉莉花測試,並以junit格式輸出結果。這裏的任務:在rails中運行無頭茉莉花測試時出現錯誤

namespace :jasmine do                    
    desc "Runs Jasmine tests headlessly and writes out junit xml."         
    task :headless_junit do |t, args|                
    run_jasmine_tests(Dir.pwd)                  
    end                        
end                        

def run_jasmine_tests(output_dir)                 
    require 'headless'                    
    require 'jasmine'                    
    require 'rspec'                     
    require 'rspec/core/rake_task'                 

    output_file = "#{output_dir}/jasmine_results.xml"            

    Headless.ly do                     
    RSpec::Core::RakeTask.new(:jasmine_continuous_integration_runner) do |t|      
     t.rspec_opts = ['--format', 'RspecJunitFormatter', '--out', output_file ]     
     t.verbose = true                    
     t.rspec_opts += ["-r #{File.expand_path(File.join(::Rails.root, 'config', 'environment'))}"] 
     t.pattern = [Jasmine.runner_filepath]              
    end                       

    Rake::Task['jasmine_continuous_integration_runner'].invoke          
    end                        

end                        

當我運行此我得到這個錯誤:

TypeError: jasmine.getEnv(...).currentSpec is null in http://localhost:34002/assets/jquery.js?body=true (line 1129) 
[email protected]://localhost:34002/assets/jquery.js?body=true:1129              
@http://localhost:34002/__spec__/activity_catalog_search_filters_spec.js:15           
[email protected]://localhost:34002/__jasmine__/jasmine.js:1064         
[email protected]://localhost:34002/__jasmine__/jasmine.js:2096 
jasmine.Queue.prototype.next_/onComplete/<@http://localhost:34002/__jasmine__/jasmine.js:2086 
... LOTS MORE ... 

我使用的軌道3.2.13,茉莉1.3.2,1.0.1無頭,rspec的2.14。 1和茉莉的jQuery 1.5.8

我認爲這可能是類似這樣的傢伙有問題: TypeError: jasmine.getEnv().currentSpec is null

回答

1

原來的問題是一個測試WA s使用jQuery.get將url加載到dom中。一個空字符串被作爲url傳遞下來(因爲測試編寫者並不在乎我猜的是什麼),但是這導致jQuery獲取當前頁面(茉莉花測試自己)並將其加載到dom中。大規模的混亂隨之而來。

更有趣的事情(也許更有幫助)是我們如何計算出來的。原來那個奇特的耙子任務不是問題。這只是無頭測試使用Firefox,我通常手動加載他們在鉻,這種錯誤似乎沒有發生。一個我在Firefox中重現錯誤,很容易找到調試器的原因。

因此,底線是,如果你是ci測試失敗,你不能再現它,嘗試在Firefox中手動加載它們。