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.



7
8
9
# File 'lib/speccify.rb', line 7

def desc
  @desc
end

#setup_procObject

Returns the value of attribute setup_proc.



7
8
9
# File 'lib/speccify.rb', line 7

def setup_proc
  @setup_proc
end

#teardown_procObject

Returns the value of attribute teardown_proc.



7
8
9
# File 'lib/speccify.rb', line 7

def teardown_proc
  @teardown_proc
end

Instance Method Details

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



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

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

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



18
19
20
21
22
23
# File 'lib/speccify.rb', line 18

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

#describe(desc, &block) ⇒ Object



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

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_proc = self.setup_proc
  cls.teardown_proc = self.teardown_proc
  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



42
43
44
45
46
# File 'lib/speccify.rb', line 42

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