Class: Henry::Task::CucumberTask

Inherits:
RakeTask show all
Defined in:
lib/henry/task/cucumber_task.rb

Overview

The Henry Task implementation for Cucumber

Constant Summary collapse

OUT_PATH =

The temporary output file path for the RspecTask execution.

'cucumber.out'
DEFAULT_OUTPUT_BASE_DIR =

Default base output directory

'.output'
REPORTS_DIR =

The reports path template.

'reports/${FORMAT}'
TIME_FORMAT =

Default time format to be used in the reports filepath.

'%Y-%m-%dT%H%M%S'
APPLICATION_NAME =

The Cucumber Rake Application name.

Returns:

  • (String)

    the rake application name.

'cucumber'

Instance Attribute Summary collapse

Attributes inherited from Henry::Task

#data, #enabled, #name, #timeout

Instance Method Summary collapse

Methods inherited from Henry::Task

#before_execute, create, #disable!, #disabled?, #enable!, #enabled?, #execution, #execution=, #export_config, #export_params, #initialize, #logger, #report

Constructor Details

This class inherits a constructor from Henry::Task

Instance Attribute Details

#generated_reportsObject

Returns the value of attribute generated_reports.



11
12
13
# File 'lib/henry/task/cucumber_task.rb', line 11

def generated_reports
  @generated_reports
end

#report_recipientsObject

Returns the value of attribute report_recipients.



11
12
13
# File 'lib/henry/task/cucumber_task.rb', line 11

def report_recipients
  @report_recipients
end

Instance Method Details

#after_executeObject



46
47
48
# File 'lib/henry/task/cucumber_task.rb', line 46

def after_execute
  super
end

#application_nameObject



30
31
32
# File 'lib/henry/task/cucumber_task.rb', line 30

def application_name
  APPLICATION_NAME
end

#base_output_pathString

Returns output base path

Returns:

  • (String)

    the base output path.



53
54
55
# File 'lib/henry/task/cucumber_task.rb', line 53

def base_output_path
  @base_output_path ||= (self.data.system[:output_directory] ? "#{self.data.system[:output_directory]}/output" : DEFAULT_OUTPUT_BASE_PATH)
end

#configure(params, extended_context = {}) ⇒ Object

Configures the Task.

Parameters:

  • params (Hash)

    the task params.

  • extended_context (Hash) (defaults to: {})

    task extended context.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/henry/task/cucumber_task.rb', line 61

def configure(params, extended_context={})
  File.open(OUT_PATH, 'w') { |f| }

  # Makes available the cucumber rake task.
  Rake.application.clear
  Cucumber::Rake::Task.new do |t|
    if self.data.options
      t.cucumber_opts = self.custom_options(extended_context['options']||{})
    else
      t.cucumber_opts = self.default_options()
    end
  end
  
  super
end

#custom_options(extended_options = {}) ⇒ String

Returns the custom cucumber_opts that user may have passed.

Parameters:

  • extended_options (Hash) (defaults to: {})

    set of extended options.

Returns:

  • (String)


81
82
83
# File 'lib/henry/task/cucumber_task.rb', line 81

def custom_options(extended_options={})
  "#{self.format_options} #{self.tags_options(extended_options)} #{self.report_options(extended_options)} #{self.rerun_options} #{self.misc_options}" 
end

#default_optionsString

Returns the default cucumber_opts.

Returns:

  • (String)


100
101
102
# File 'lib/henry/task/cucumber_task.rb', line 100

def default_options
  "--format pretty --format pretty --out #{OUT_PATH}"
end

#executeObject



38
39
40
41
42
43
44
# File 'lib/henry/task/cucumber_task.rb', line 38

def execute
  super

  if self.execution.code == 'OK'
    self.execution.code = 'ERROR' if self.execution.output =~ /\d+ scenarios? \([^\(]*\d+ failed[^\(]*\)/
  end
end

#format_optionsString

Returns the cucumber_opts related with formatting.

Returns:

  • (String)


107
108
109
# File 'lib/henry/task/cucumber_task.rb', line 107

def format_options
  "--format #{self.data.options['format'] || 'pretty'} --format #{self.data.options['format'] || 'pretty'} --out #{OUT_PATH}"
end

#misc_optionsString

Returns the miscellaneous cucumber_opts.

Returns:

  • (String)


88
89
90
91
92
93
94
95
# File 'lib/henry/task/cucumber_task.rb', line 88

def misc_options
  options = []
  options << '--expand' if self.data.options['expand']
  options << "--require features #{self.data.options['pattern']}" if self.data.options['pattern']
  options << '--no-source' if self.data.options['no-source']

  return options.join(' ')
end

#out_pathObject



34
35
36
# File 'lib/henry/task/cucumber_task.rb', line 34

def out_path
  OUT_PATH
end

#report_file_name(file_name, extended_options = {}) ⇒ Object

Interpolates and returns the report file name.

Parameters:

  • file_name (String)

    the report file name.



177
178
179
# File 'lib/henry/task/cucumber_task.rb', line 177

def report_file_name(file_name,extended_options={})
  file_name.gsub(/\${[A-Z_]+}/, '${TASK_NAME}' => self.name, '${DATE}' => DateTime.now.strftime(TIME_FORMAT), '${TAGS}' => ((self.data.options['tags']||[])+(extended_options['tags']||[])).join(' ')).gsub(' ', '_')
end

#report_file_path(format, file_name, extended_options = {}) ⇒ String

Returns the report file path for the given format and file name.

Parameters:

  • format (String)

    the rspec formatter name.

  • file_name (String)

    the report file name template.

Returns:

  • (String)

    the report file path.



169
170
171
# File 'lib/henry/task/cucumber_task.rb', line 169

def report_file_path(format, file_name, extended_options={})
  "#{self.reports_dir(format)}/#{self.report_file_name(file_name,extended_options)}"
end

#report_options(extended_options = {}) ⇒ String

Returns the cucumber_opts related with report paaths and formats.

Returns:

  • (String)


126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/henry/task/cucumber_task.rb', line 126

def report_options(extended_options={})
  self.generated_reports = []
  self.report_recipients = []

  return '' if self.data.reports.nil?

  self.data.reports.collect do |report_options|
    report_options['name'] ||= "${DATE}_${TASK_NAME}.#{report_options['format']}"

    self.generated_reports << self.report_file_path(report_options['format'], report_options['name'], extended_options)
    self.report_recipients += (report_options['recipients'] || [])

    FileUtils.mkdir_p(self.reports_dir(report_options['format']))

    "--format #{report_options['format']} --out #{self.report_file_path(report_options['format'], report_options['name'], extended_options)}"
  end.join(' ')
end

#reports_dir(format) ⇒ Stiring

Interpolates and returns the reports directory for the given format.

Parameters:

  • format (String)

    the formatter name.

Returns:

  • (Stiring)

    the reports directory.



185
186
187
# File 'lib/henry/task/cucumber_task.rb', line 185

def reports_dir(format)
  "#{self.base_output_path}/#{REPORTS_DIR}".gsub(/\${[A-Z_]+}/, '${FORMAT}' => format).gsub(' ', '_')
end

#rerun?True, False

Returns true whenever rerun is set and the reties counter is still positive.

Returns:

  • (True, False)


160
161
162
# File 'lib/henry/task/cucumber_task.rb', line 160

def rerun?
  self.data.options['rerun'] && self.data.options['rerun'] >= 0
end

#rerun_optionsString

Returns the cucumber_opts related with the rerun usage.

Returns:

  • (String)


147
148
149
150
151
152
153
154
155
# File 'lib/henry/task/cucumber_task.rb', line 147

def rerun_options
  return ''

  return ''  if self.data.options['rerun'].nil?
  
  self.data.options['rerun'] -= 1

  "---format rerun --out tmp/rerun"
end

#tags_options(extended_options = {}) ⇒ String

Returns the cucumber_opts related with tags to be run.

Returns:

  • (String)


115
116
117
118
119
120
121
# File 'lib/henry/task/cucumber_task.rb', line 115

def tags_options(extended_options={})
  return '' if self.data.options['tags'].nil? && extended_options['tags'].nil?

  ((self.data.options['tags']||[])+(extended_options['tags']||[])).collect do |tag|
    "--tags #{tag.gsub(/(,?~?)(\w+)/, '\1@\2')}"
  end.join(' ')
end