【问题标题】:Getting an error when running headless jasmine tests in rails在 Rails 中运行无头 jasmine 测试时出错
【发布时间】:2013-10-30 13:01:22
【问题描述】:

我设置了一个 rake 任务,用于在构建服务器上运行无头 jasmine 测试并以 junit 格式输出结果。任务如下:

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)
expect@http://localhost:34002/assets/jquery.js?body=true:1129                                                      
@http://localhost:34002/__spec__/activity_catalog_search_filters_spec.js:15                                        
jasmine.Block.prototype.execute@http://localhost:34002/__jasmine__/jasmine.js:1064                                 
jasmine.Queue.prototype.next_@http://localhost:34002/__jasmine__/jasmine.js:2096
jasmine.Queue.prototype.next_/onComplete/<@http://localhost:34002/__jasmine__/jasmine.js:2086
... LOTS MORE ...

我正在使用 rails 3.2.13、jasmine 1.3.2、headless 1.0.1、rspec 2.14.1 和 Jasmine-jQuery 1.5.8

我认为这可能类似于这个人遇到的问题: TypeError: jasmine.getEnv().currentSpec is null

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3.2 jasmine jasmine-jquery


    【解决方案1】:

    原来问题出在使用 jQuery.get 将 url 加载到 dom 的测试中。一个空字符串作为 url 被传递(因为测试作者并不真正关心加载了什么我猜)但这导致 jQuery 获取当前页面(茉莉花测试本身)并将其加载到 dom 中。随之而来的是大混乱。

    更有趣(也许更有帮助)的是我们是如何解决这个问题的。原来花哨的 rake 任务不是问题。只是无头测试使用Firefox,我通常在chrome中手动加载它们,似乎没有发生这个错误。一个我在 Firefox 中重现了该错误,使用调试器很容易找到原因。

    所以底线是,如果您的 ci 测试失败并且您无法重现它,请尝试在 Firefox 中手动加载它们。

    【讨论】:

      猜你喜欢
      • 2018-04-13
      • 2021-01-01
      • 1970-01-01
      • 2016-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-01
      • 2014-09-02
      相关资源
      最近更新 更多