Class: Vigia::Sail::RSpecObject

Inherits:
Object
  • Object
show all
Includes:
Hooks
Defined in:
lib/vigia/sail/rspec_object.rb

Direct Known Subclasses

Context, Example, Group, GroupInstance

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Hooks

#execute_hook, #hooks_for_object, #with_hooks

Constructor Details

#initialize(name, options, rspec) ⇒ RSpecObject

Returns a new instance of RSpecObject.



33
34
35
36
37
38
# File 'lib/vigia/sail/rspec_object.rb', line 33

def initialize(name, options, rspec)
  @name    = name
  @options = options
  @rspec   = rspec

end

Class Attribute Details

.collectionObject (readonly)

Returns the value of attribute collection.



5
6
7
# File 'lib/vigia/sail/rspec_object.rb', line 5

def collection
  @collection
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



31
32
33
# File 'lib/vigia/sail/rspec_object.rb', line 31

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



31
32
33
# File 'lib/vigia/sail/rspec_object.rb', line 31

def options
  @options
end

#rspecObject (readonly)

Returns the value of attribute rspec.



31
32
33
# File 'lib/vigia/sail/rspec_object.rb', line 31

def rspec
  @rspec
end

Class Method Details

.clean!Object



20
21
22
# File 'lib/vigia/sail/rspec_object.rb', line 20

def clean!
  @collection = {}
end

.inherited(subclass) ⇒ Object



24
25
26
# File 'lib/vigia/sail/rspec_object.rb', line 24

def inherited(subclass)
  subclass.instance_variable_set('@collection', {})
end

.register(name, options) ⇒ Object



7
8
9
10
# File 'lib/vigia/sail/rspec_object.rb', line 7

def register(name, options)
  @collection = {} if collection.nil?
  @collection.merge!(name => options)
end

.setup_and_run(name, rspec) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/vigia/sail/rspec_object.rb', line 12

def setup_and_run(name, rspec)
  items = collection.select{ |k,v| k == name }
  raise "Cannot find #{ self.name } with name #{ name }" if items.empty?
  name, options = items.first
  instance      = new(name, options, rspec)
  instance.run
end

Instance Method Details

#contextual_object(option_name: nil, object: nil, context: nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/vigia/sail/rspec_object.rb', line 40

def contextual_object(option_name: nil, object: nil, context: nil)
  context ||= rspec.described_class
  object  ||= options[option_name]
  case object
  when Symbol
    context.adapter.send(object)
  when Proc
    context.instance_exec(&object)
  else
    object
  end
end