module Lopata::Role::DSL

To be included in Lopata::ScenarioBuilder

Public Instance Methods

as(*args, &block) click to toggle source

Enumerate the roles the scenario to be runned under. If not invoked the default role only will be used.

The scenario should be set to use the role via before_scenario step using current_role param.

@param args [Array<Symbol>] list of roles the scenario to be runned with. @param block [Block] the block to calculate role from scenario metadata.

# File lib/lopata/role.rb, line 45
def as(*args, &block)
  @roles = args.flatten
  @roles << Lopata::ScenarioBuilder::CalculatedValue.new(&block) if block_given?
  @use_all_roles = true
  @role_options = nil
end
as_first(*args, &block) click to toggle source

Enumerate the roles the scenario can be run.

The scenario should be set to use the role via before_scenario step using current_role param.

Only first role will be used if scenario has no options or diagonales. Some first roles will be used if options or diagonales are declared, in order of appearence.

Use this to describe possible roles, but not needed to run scenario with all of them in order to save time of running.

@param args [Array<Symbol>] list of roles the scenario to be runned with.

# File lib/lopata/role.rb, line 63
def as_first(*args, &block)
  @roles = args.flatten
  @use_all_roles = false
  @role_options = nil
end
build_role_options() click to toggle source

@private

# File lib/lopata/role.rb, line 88
def build_role_options
  return [] unless roles
  role_variants = roles.map { |r| [Lopata.configuration.role_descriptions[r], r] }
  [Lopata::ScenarioBuilder::Diagonal.new(:as, role_variants, @use_all_roles)]
end
diagonals() click to toggle source

@private

Calls superclass method
# File lib/lopata/role.rb, line 101
def diagonals
  super + role_options
end
role_options() click to toggle source

@private

# File lib/lopata/role.rb, line 70
def role_options
  @role_options ||= build_role_options
end
roles() click to toggle source

@private

# File lib/lopata/role.rb, line 95
def roles
  return false if @without_user
  @roles ||= [Lopata.configuration.default_role].compact
end
without_user() click to toggle source

Marks scenario to be runned without user.

@example

Lopata.define 'scenario withou user' do
  without_user
  it 'does not define the user' do
    expect(current_role).to be_nil
  end
end
# File lib/lopata/role.rb, line 83
def without_user
  @without_user = true
end