Class: AktionTest::SpecHelper
- Inherits:
-
Object
- Object
- AktionTest::SpecHelper
- Defined in:
- lib/aktion_test/spec_helper.rb
Instance Attribute Summary collapse
-
#modules ⇒ Object
readonly
Returns the value of attribute modules.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
- #scope(name = '') ⇒ Object
Class Method Summary collapse
Instance Method Summary collapse
- #compile! ⇒ Object
-
#initialize ⇒ SpecHelper
constructor
A new instance of SpecHelper.
- #reset ⇒ Object
- #use(*names) ⇒ Object
Constructor Details
#initialize ⇒ SpecHelper
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
#modules ⇒ Object (readonly)
Returns the value of attribute modules.
5 6 7 |
# File 'lib/aktion_test/spec_helper.rb', line 5 def modules @modules end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/aktion_test/spec_helper.rb', line 5 def @options end |
#scope(name = '') ⇒ Object
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 |
#reset ⇒ Object
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) = names. 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, ) end |