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.



14
15
16
# File 'lib/speccify.rb', line 14

def desc
  @desc
end

#setup_chainedObject

Returns the value of attribute setup_chained.



14
15
16
# File 'lib/speccify.rb', line 14

def setup_chained
  @setup_chained
end

#teardown_chainedObject

Returns the value of attribute teardown_chained.



14
15
16
# File 'lib/speccify.rb', line 14

def teardown_chained
  @teardown_chained
end

Instance Method Details

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



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

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



25
26
27
28
29
30
# File 'lib/speccify.rb', line 25

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



39
40
41
42
43
44
45
46
47
# File 'lib/speccify.rb', line 39

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



49
50
51
52
53
# File 'lib/speccify.rb', line 49

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