class FeatureFile

Attributes

file_path[RW]
scenarios[RW]

Public Class Methods

new(file_path:) click to toggle source
# File lib/kraken-mobile/models/feature_file.rb, line 15
def initialize(file_path:)
  @file_path = file_path
  @scenarios = []

  read_content
end

Public Instance Methods

all_scenarios_have_a_user_tag?() click to toggle source
# File lib/kraken-mobile/models/feature_file.rb, line 109
def all_scenarios_have_a_user_tag?
  scenarios.each do |scenario|
    user_tag = scenario.tags.select do |tag|
      tag.start_with?('@user')
    end.first
    return false if user_tag.nil?
  end
  true
end
duplicate_tags_for_a_user?() click to toggle source
# File lib/kraken-mobile/models/feature_file.rb, line 86
def duplicate_tags_for_a_user?
  taken_user_tags = {}
  scenarios.each do |scenario|
    user_tag = scenario.tags.select do |tag|
      tag.start_with?('@user')
    end.first
    return true unless taken_user_tags[user_tag].nil?

    taken_user_tags[user_tag] = user_tag
  end
  false
end
number_of_required_devices() click to toggle source
# File lib/kraken-mobile/models/feature_file.rb, line 48
def number_of_required_devices
  user_tags.count
end
number_of_required_mobile_devices() click to toggle source
# File lib/kraken-mobile/models/feature_file.rb, line 40
def number_of_required_mobile_devices
  system_tags.select { |tag| tag == '@mobile' }.count
end
number_of_required_web_devices() click to toggle source
# File lib/kraken-mobile/models/feature_file.rb, line 44
def number_of_required_web_devices
  system_tags.select { |tag| tag == '@web' }.count
end
only_one_user_tag_for_each_scenario?() click to toggle source
# File lib/kraken-mobile/models/feature_file.rb, line 99
def only_one_user_tag_for_each_scenario?
  scenarios.each do |scenario|
    user_tags = scenario.tags.select do |tag|
      tag.start_with?('@user')
    end
    return false if user_tags.count != 1
  end
  true
end
required_devices() click to toggle source
# File lib/kraken-mobile/models/feature_file.rb, line 52
def required_devices
  users = user_tags
  systems = system_tags

  users.map do |user|
    {
      user_id: user.delete_prefix('@user'),
      system_type: systems.shift || '@mobile'
    }
  end
end
right_syntax?() click to toggle source
# File lib/kraken-mobile/models/feature_file.rb, line 80
def right_syntax?
  all_scenarios_have_a_user_tag? &&
    only_one_user_tag_for_each_scenario? &&
    !duplicate_tags_for_a_user?
end
sorted_required_devices() click to toggle source
# File lib/kraken-mobile/models/feature_file.rb, line 64
def sorted_required_devices
  required_devices.sort_by do |device|
    device[:user_id].to_i
  end
end
system_tags() click to toggle source
# File lib/kraken-mobile/models/feature_file.rb, line 30
def system_tags
  @scenarios.map do |scenario|
    tags = scenario.tags
    system_tag = tags.select do |tag|
      tag.start_with?('@web') || tag.start_with?('@mobile')
    end.first
    system_tag || '@mobile'
  end
end
tags_for_user_id(user_id) click to toggle source
# File lib/kraken-mobile/models/feature_file.rb, line 70
def tags_for_user_id(user_id)
  user_tag = "@user#{user_id}"
  user_scenario = @scenarios.select do |scenario|
    scenario.tags.include?(user_tag)
  end.first
  return [] if user_scenario.nil? || user_scenario.tags.nil?

  user_scenario.tags.reject { |tag| tag == user_tag }
end
user_tags() click to toggle source
# File lib/kraken-mobile/models/feature_file.rb, line 25
def user_tags
  all_tags = @scenarios.map(&:tags).flatten.uniq
  all_tags.select { |tag| tag.start_with?('@user') }
end

Private Instance Methods

read_content() click to toggle source
# File lib/kraken-mobile/models/feature_file.rb, line 121
def read_content
  parser = Gherkin::Parser.new
  file = File.open(file_path)
  file_content = file.read
  file.close
  gherkin_document = parser.parse(file_content)
  pickles = Gherkin::Pickles::Compiler.new.compile(gherkin_document)
  pickles.each do |scenario|
    scenarios << FeatureScenario.new(
      name: scenario[:name],
      tags: scenario[:tags]
    )
  end
end