Class: AktionTest::SpecHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/aktion_test/spec_helper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSpecHelper

Returns a new instance of SpecHelper.



19
20
21
# File 'lib/aktion_test/spec_helper.rb', line 19

def initialize
  reset
end

Instance Attribute Details

#modulesObject (readonly)

Returns the value of attribute modules.



5
6
7
# File 'lib/aktion_test/spec_helper.rb', line 5

def modules
  @modules
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/aktion_test/spec_helper.rb', line 5

def options
  @options
end

#scope(name = '') ⇒ Object

Raises:

  • (ArgumentError)


47
48
49
50
51
52
53
54
55
56
57
# File 'lib/aktion_test/spec_helper.rb', line 47

def scope(name='')
  return @scope if name.blank?
  raise ArgumentError.new("A block is required when applying a temporary scope") unless block_given?

  begin
    scope << name
    yield
  ensure
    scope.pop
  end
end

Class Method Details

.build(&block) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/aktion_test/spec_helper.rb', line 9

def build(&block)
  new.tap do |sh|
    if block_given?
      sh.instance_eval(&block)
      sh.compile!
    end
  end
end

Instance Method Details

#compile!Object



59
60
61
62
63
# File 'lib/aktion_test/spec_helper.rb', line 59

def compile!
  modules.each &:prepare
  modules.each &:configure
  modules.each &:cleanup
end

#resetObject



23
24
25
26
# File 'lib/aktion_test/spec_helper.rb', line 23

def reset
  @modules = []
  @scope   = %w(AktionTest Module)
end

#use(*names) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/aktion_test/spec_helper.rb', line 28

def use(*names)
  options = names.extract_options!
  return names.each {|name| use name} if names.many?

  name = names.first

  klass = case name
  when Class then name
  when /^::/ then name.constantize
  else "#{@scope.join('::')}::#{name}".constantize
  end

  unless klass.ancestors.include? AktionTest::Module::Base
    raise ArgumentError.new("#{klass.name} must inherit from AktionTest::Module::Base") 
  end

  modules << klass.new(self, options)
end