Module: Speccify::ExampleGroupClassMethods

Defined in:
lib/speccify.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#descObject

Returns the value of attribute desc.



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

def desc
  @desc
end

#setup_chainedObject

Returns the value of attribute setup_chained.



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

def setup_chained
  @setup_chained
end

#teardown_chainedObject

Returns the value of attribute teardown_chained.



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

def teardown_chained
  @teardown_chained
end

Instance Method Details

#after(type = :each, &block) ⇒ Object



23
24
25
26
27
28
# File 'lib/speccify.rb', line 23

def after(type = :each, &block)
  raise "unsupported after type: #{type}" unless type == :each
  passed_through_teardown = self.teardown_chained
  self.teardown_chained = lambda {instance_eval(&block);instance_eval(&passed_through_teardown) }
  define_method :teardown, &self.teardown_chained
end

#before(type = :each, &block) ⇒ Object



16
17
18
19
20
21
# File 'lib/speccify.rb', line 16

def before(type = :each, &block)
  raise "unsupported before type: #{type}" unless type == :each
  passed_through_setup = self.setup_chained
  self.setup_chained = lambda { instance_eval(&passed_through_setup);instance_eval(&block) }
  define_method :setup, &self.setup_chained
end

#describe(desc, &block) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/speccify.rb', line 30

def describe desc, &block
  cls = Class.new(self.superclass)
  Object.const_set self.name + desc.to_s.split(/\W+/).map { |s| s.capitalize }.join, cls
  cls.setup_chained = self.setup_chained
  cls.teardown_chained = self.teardown_chained
  cls.desc = self.desc + " " + desc
  cls.tests($1.constantize) if defined?(Rails) && self.name =~ /^(.*Controller)Test/
  cls.class_eval(&block)
end

#it(desc, &block) ⇒ Object



40
41
42
43
44
# File 'lib/speccify.rb', line 40

def it desc, &block
  self.before {}
  define_method "test_#{desc.gsub(/\W+/, '_').downcase}", &block if block_given?
  self.after {}
end