h-lame (owner)

Revisions

gist: 210792 Download_button fork
public
Description:
Run all cucumber features and collect failed ones, then run just those failed ones.
Public Clone URL: git://gist.github.com/210792.git
Embed All Files: show embed
cucumber.rake #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
$LOAD_PATH.unshift(Rails.root + '/vendor/plugins/cucumber/lib') if File.directory?(Rails.root + '/vendor/plugins/cucumber/lib')
CUCUMBER_FAILED_LOG = Rails.root + "log/cucumber_failed"
touch(CUCUMBER_FAILED_LOG) unless File.exist?(CUCUMBER_FAILED_LOG)
 
begin
  require 'cucumber/rake/task'
  require "cucumber_rerun_task"
 
  namespace :features do
    Cucumber::Rake::Task.new(:active) do |t|
      t.cucumber_opts = "-f pretty -f rerun -o #{CUCUMBER_FAILED_LOG} --tags ~@pending --require features"
    end
    task :active => 'db:test:prepare'
 
    Cucumber::Rake::RerunTask.new(:failed, File.open(CUCUMBER_FAILED_LOG)) do |t|
      t.cucumber_opts = "-f pretty -f rerun -o #{CUCUMBER_FAILED_LOG} --tags ~@pending --require features"
    end
    task :failed => 'db:test:prepare'
 
  end
 
  desc "Run all features"
  task :features => ["features:pending", "features:active"]
 
rescue LoadError
  desc 'Cucumber rake task not available'
  task :features do
    abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
  end
end
 
cucumber_rerun_task.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module Cucumber
  module Rake
    class DummyRunner
      def run
      end
    end
 
    class RerunTask < Task
      def initialize(task_name, rerun_output, desc = "Run Cucumber features by file and line from the output of -f rerun")
        @rerun_output = rerun_output
        super(task_name, desc)
      end
 
      def runner(task_args = nil)
        if feature_files.any?
          super
        else
          DummyRunner.new
        end
      end
 
      def feature_files(*ignored)
        @feature_files ||= if @rerun_output.respond_to?(:read)
          @rerun_output.read
        else
          @rerun_output
        end.strip.split(/ /)
      end
    end
  end
end