【问题标题】:How can I cleanly deploy RSpec & Cucumber HTML results with my Rails app?如何使用我的 Rails 应用程序清理部署 RSpec 和 Cucumber HTML 结果?
【发布时间】:2011-08-25 16:13:04
【问题描述】:

我与技术较少的利益相关者和测试人员一起制作 Rails 3.1 应用程序,他们从看到我的 Cucumber 和 RSpec 测试呈现的 HTML 输出中受益匪浅。

我想要一种在部署时将此输出与应用程序捆绑在一起的方法,但我正在努力寻找最简洁的方法来执行此操作。该 repo 在 Github 上,我们使用 Capistrano 进行部署。我强烈希望将此不受版本控制。

还有其他人这样做吗?谢谢!

【问题讨论】:

    标签: ruby-on-rails rspec cucumber capistrano bdd


    【解决方案1】:

    cukes 更容易一些...添加一个 rake 任务:

    desc "runs cucumber features and outputs them to doc/cucumber as html"
    task :html do 
      Dir.glob("features/*.feature").each do |story|
        system("cucumber", 
               "#{story}", 
               "--format=html", 
               "-o", 
               "doc/cucumber/#{story.gsub(/features\/(\w*).feature/, '\1.html')}")
      end
    end
    

    【讨论】:

    • 感谢您的建议!我应该提到我已经有一个类似于你的 rake 任务......我没有得到的主要部分是如何保持它的清洁和不受源代码控制。我在下面的答案是我决定的,利用 gitignore、scp 和 capistrano
    【解决方案2】:

    我不知道为什么我之前没有想到明显的解决方案:gitignore doc 文件并添加部署任务以将文件直接 scp 到应用程序的公共目录中。

    .gitignore

    public/doc
    

    lib/tasks/doc.rake

    namespace :doc do
    
      desc "run features and specs then generate pages accessible in public/doc"
      task :html do
        # Delete old files
        puts "Clearing out old html files..."
        system("rm -rf public/doc/")
        system("mkdir public/doc/")
    
        # Generate the feature html files
        puts "Generating Cucumber html files..."
        system("mkdir public/doc/features")
        Dir.glob("features/**/*.feature").each do |story|
          system("bundle exec cucumber #{story} --drb --format=html -o public/doc/#{story.gsub(/(\w*).feature/, '\1.html')}")
          puts "public/doc/#{story}"
        end
    
        # Generate RSpec html files
        puts "Generating RSpec html files..."
        system("mkdir public/doc/spec/")
        Dir.glob("spec/**/*_spec.rb").each do |spec|
          system("bundle exec rspec #{spec} --drb --format html -o public/doc/#{spec.gsub(/(\w*).rb/, '\1.html')}")
        end
    
        # Generate the index file
        puts "Writing index file..."
        system("echo \"<html><head><title>Doc</title></head><body>\" > public/doc/index.html")
    
        # Write test report navigation
        Dir.glob("public/doc/**/*.html").each do |file|
          unless file == 'public/doc/index.html'
            file.gsub!(/\public\/doc\//, '')
            system("echo \"<p><a href='#{file}'>#{file.gsub('.html', '')}</a></p>\" >> public/doc/index.html")
          end
        end
    
        # Close index.html file
        system("echo \"</body></html>\" >> public/doc/index.html")
        puts "Done!"
      end
    end
    

    config/deploy.rb

    desc "Generate Cucumber & RSpec HTML docs"
    task :generate_docs, :roles => :app do
      system("bundle exec rake doc:html")
    end
    
    desc "Copy Cucumber & RSpec HTML docs outside of version control with scp"
    task :copy_docs, :roles => :app do
      system("tar -zcvf tmp/doc.tar.gz public/doc && rm -rf public/doc")
      system("scp -r -i ~/myKey.pem tmp/doc.tar.gz #{user}@#{hostname}:#{deploy_to}/current/public/doc.tar.gz && rm tmp/doc.tar.gz")
      run "cd #{release_path}; tar -zxvf public/doc.tar.gz && rm public/doc.tar.gz"
    end
    
    after 'deploy', 'docs:generate_docs', 'docs:copy_docs'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-12
      • 2016-01-11
      • 2011-08-25
      • 1970-01-01
      • 2010-10-31
      • 1970-01-01
      • 2012-01-14
      相关资源
      最近更新 更多