Module: FlavoredGherkin

Defined in:
lib/flavored_gherkin.rb,
lib/flavored_gherkin/flavour.rb,
lib/flavored_gherkin/pdf_flavour.rb,
lib/flavored_gherkin/html_flavour.rb

Overview

Flavored Gherkin

Defined Under Namespace

Classes: Flavour, HtmlFlavour, PdfFlavour

Class Method Summary collapse

Class Method Details

.build(options = {}) ⇒ Object

Build Flavored Gherkin

Examples:

FlavoredGherkin.build

FlavoredGherkin.build 'muFolder/features'

FlavoredGherkin.build feature_path: 'muFolder/features', title: 'My Features'


123
124
125
126
127
128
129
130
131
# File 'lib/flavored_gherkin.rb', line 123

def self.build(options = {})
  @options ||= {}
  if options.is_a? String
    @options[:input_path] = options
  elsif options.is_a? Hash
    @options.merge! options
  end
  const_get(flavour + 'Flavour').new.build title, feature_files, output_path
end

.configure {|options| ... } ⇒ Object

Configure Flavored Gherkin

Example:

FlavoredGherkin.configure do |config|
  config.title = 'My Features'
  config.feature_path = 'myFolder/features'
  config.output_path = 'myFolder/my_features'
end

Yields:

  • (options)


20
21
22
23
24
25
# File 'lib/flavored_gherkin.rb', line 20

def self.configure
  options = OpenStruct.new
  yield options if block_given?
  @options ||= {}
  @options.merge! options.marshal_dump
end

.feature_filesArray

Returns List of Feature Files

Returns:

  • (Array)

    List of Feature Files



158
159
160
161
162
163
164
165
166
167
168
# File 'lib/flavored_gherkin.rb', line 158

def self.feature_files
  @options ||= {}
  feature_path = @options[:feature_path] || @options[:input_path] || Dir.pwd
  if Pathname.new(feature_path).directory?
    Dir.glob("#{feature_path}/**/*.feature")
  elsif Pathname.new(feature_path).file?
    [feature_path]
  else
    []
  end
end

.feature_path=(feature_path) ⇒ Object

Set Feature Files Path

Example:

FlavoredGherkin.feature_path = 'muFolder/features'

Parameters:

  • feature_path (String)

    feature files path



79
80
81
82
# File 'lib/flavored_gherkin.rb', line 79

def self.feature_path=(feature_path)
  @options ||= {}
  @options[:feature_path] = feature_path
end

.flavourString

Returns Favour of Flavored Gherkin

Returns:

  • (String)

    Favour



138
139
140
141
# File 'lib/flavored_gherkin.rb', line 138

def self.flavour
  @options ||= {}
  %w[Html Pdf].include?(@options[:flavour]) ? @options[:flavour] : 'Html'
end

.flavour=(flavour) ⇒ Object

Set Flavored Gherkin Flavour

Example:

FlavoredGherkin.flavour = 'HtmlFlavour'

Parameters:

  • flavour (String)

    Flavored Gherkin Flavour



51
52
53
54
# File 'lib/flavored_gherkin.rb', line 51

def self.flavour=(flavour)
  @options ||= {}
  @options[:flavour] = flavour.capitalize
end

.input_path=(input_path) ⇒ Object

Set Feature Files Path

Example:

FlavoredGherkin.input_path = 'muFolder/features'

Parameters:

  • input_path (String)

    feature files path



93
94
95
96
# File 'lib/flavored_gherkin.rb', line 93

def self.input_path=(input_path)
  @options ||= {}
  @options[:input_path] = input_path
end

.output_pathString

Returns Flavored Gherkin Output Path

Returns:

  • (String)

    Output Path with file name without extension



175
176
177
178
179
180
181
182
183
184
185
# File 'lib/flavored_gherkin.rb', line 175

def self.output_path
  @options ||= {}
  output_path = @options[:output_path] ||= Dir.pwd + '/'
  if output_path =~ /.*[\/\\]$/
    unless Pathname(output_path).exist?
      FileUtils.mkpath output_path
    end
    output_path += title.strip.gsub(' ', '_')
  end
  output_path
end

.output_path=(output_path) ⇒ Object

Set Flavored Gherkin Output Path

Example:

FlavoredGherkin.output_path = 'myFolder/my_features'

Parameters:

  • output_path (String)

    Flavored Gherkin Output Path



107
108
109
110
# File 'lib/flavored_gherkin.rb', line 107

def self.output_path=(output_path)
  @options ||= {}
  @options[:output_path] = output_path
end

.set(option, value) ⇒ Object

Set Flavored Gherkin Options

Example:

FlavoredGherkin.set('title', 'My Features')

Parameters:

  • option (String)
  • value (String)


37
38
39
40
# File 'lib/flavored_gherkin.rb', line 37

def self.set(option, value)
  @options ||= {}
  @options[option.to_sym] = value
end

.titleString

Returns Title of Flavored Gherkin

Returns:

  • (String)

    Title



148
149
150
151
# File 'lib/flavored_gherkin.rb', line 148

def self.title
  @options ||= {}
  @options[:title] || (@options[:feature_path] || @options[:input_path] || 'Gherkin/Flavored').split('/').reverse[0..5].join(' ').delete('.')
end

.title=(title) ⇒ Object

Set Flavored Gherkin Title

Example:

FlavoredGherkin.title = 'My Features'

Parameters:

  • title (String)

    Flavored Gherkin Title



65
66
67
68
# File 'lib/flavored_gherkin.rb', line 65

def self.title=(title)
  @options ||= {}
  @options[:title] = title
end