Module: Canned::Definition::ClassMethods

Defined in:
lib/canned/definition.rb

Instance Method Summary collapse

Instance Method Details

#profile(_name, _options = {}, &_block) ⇒ Object

Creates a new profile and evaluates the given block using the profile context.

Parameters:

  • _name (String|Symbol)

    Profile name.

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

    Various options: none for now



56
57
58
59
60
61
62
63
# File 'lib/canned/definition.rb', line 56

def profile(_name, _options={}, &_block)
  _name = _name.to_sym
  raise Canned::SetupError.new "Duplicated profile identifier '#{_name}'" if profiles.has_key? _name

  profile = Canned::Profile.new
  ProfileDsl.new(profile, profiles).instance_eval &_block
  profiles[_name] = profile
end

#test(_name, &_block) ⇒ Object

Defines a new test that can be used in “certifies” instructions

IMPORTANT Tests are executed in the same context as upon blocks,

Parameters:

  • _name (Symbol)

    test identifier

  • _block (Block)

    test block, arity must be 0



47
48
49
# File 'lib/canned/definition.rb', line 47

def test(_name, &_block)
  raise SetupError.new "Duplicated test identifier" if tests.has_key? _name
end

#validate(_ctx, _acting_as, _action) ⇒ Object

 Returns true if _action is avaliable for _profile under the given _ctx.

Parameters:

  • _ctx (Canned2::TestContext)

    The test context to be used

  • _acting_as (string)

    The name of profile to be tested

  • _actions (String|Array<String>)

    The action or actions to test



71
72
73
74
75
76
# File 'lib/canned/definition.rb', line 71

def validate(_ctx, _acting_as, _action)
  profile = profiles[_acting_as.to_sym]
  raise Canned::SetupError.new "Profile not found '#{_acting_as}'" if profile.nil?
  _ctx = Canned::Context::Default.new(_ctx, tests, InmmutableStack.new)
  profile.validate _ctx, Array(_action)
end