Module: MacSpec::TestingFramework::TestCaseClassMethods

Defined in:
lib/mac_spec/testing_framework/core/test_case_class_methods.rb

Overview

The methods defined in this module are available inside the TestCases.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#descObject

Returns the value of attribute desc.



6
7
8
# File 'lib/mac_spec/testing_framework/core/test_case_class_methods.rb', line 6

def desc
  @desc
end

#setup_chainedObject

:nodoc:



8
9
10
# File 'lib/mac_spec/testing_framework/core/test_case_class_methods.rb', line 8

def setup_chained
  @setup_chained
end

#teardown_chainedObject

:nodoc:



12
13
14
# File 'lib/mac_spec/testing_framework/core/test_case_class_methods.rb', line 12

def teardown_chained
  @teardown_chained
end

Instance Method Details

#all_testsObject



25
26
27
# File 'lib/mac_spec/testing_framework/core/test_case_class_methods.rb', line 25

def all_tests
  @@_tests ||= []
end

#describe(desc, &block) ⇒ Object

Define a TestCase.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/mac_spec/testing_framework/core/test_case_class_methods.rb', line 58

def describe desc, &block
  cls = Class.new(self.macspec_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.macspec_superclass = self.macspec_superclass
  cls.desc = self.desc + " " + desc
  mods = self.ancestors.select {|m| m.class.to_s == "Module" }
  orig_block = block
  block = lambda {include *mods; instance_eval(&orig_block)}
  MacSpec.add_test_case(cls) 
  cls.class_eval(&block)
  self.testcases << cls
end

#fit(desc, &block) ⇒ Object

prepend ‘f’ to focus on a test



92
93
94
# File 'lib/mac_spec/testing_framework/core/test_case_class_methods.rb', line 92

def fit desc, &block
  MacSpec.add_focused_test(self, self.it(desc, &block).to_sym)
end

#it(desc, &block) ⇒ Object

Define a test.



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/mac_spec/testing_framework/core/test_case_class_methods.rb', line 74

def it desc, &block
  self.setup {}
  desc = MacSpec::TestingFramework::Functions.make_constantizeable(desc)
  if block_given?
    test = "test_#{desc.gsub(/\W+/, '_').downcase}"
    define_method(test, &lambda {instance_eval(&block)})
    (@@_tests ||= []) << test.to_sym
    (@own_tests ||= []) << test.to_sym
  end
  self.teardown {}
  test.to_sym
end

#it_should_behave_like(sym) ⇒ Object



87
88
89
# File 'lib/mac_spec/testing_framework/core/test_case_class_methods.rb', line 87

def it_should_behave_like(sym)
  class_eval(&MacSpec.shared_example_group_for(sym))
end

#macspec_superclassObject



29
30
31
# File 'lib/mac_spec/testing_framework/core/test_case_class_methods.rb', line 29

def macspec_superclass
  @macspec_superclass
end

#macspec_superclass=(sc) ⇒ Object



33
34
35
# File 'lib/mac_spec/testing_framework/core/test_case_class_methods.rb', line 33

def macspec_superclass=(sc)
  @macspec_superclass = sc
end

#own_testsObject



21
22
23
# File 'lib/mac_spec/testing_framework/core/test_case_class_methods.rb', line 21

def own_tests
  @own_tests ||= []
end

#setup(type = :each, &block) ⇒ Object Also known as: before

Run before each Test.

The code in the block attached to this method will be run before each test in all subsequent, eventually nested testcases.



40
41
42
43
44
# File 'lib/mac_spec/testing_framework/core/test_case_class_methods.rb', line 40

def setup(type = :each, &block)
  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

#teardown(type = :each, &block) ⇒ Object Also known as: after

Run after each Test.

The code in the block attached to this method will be run after each test in all subsequent, eventually nested testcases.



50
51
52
53
54
# File 'lib/mac_spec/testing_framework/core/test_case_class_methods.rb', line 50

def teardown(type = :each, &block)
  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

#testcasesObject



16
17
18
19
# File 'lib/mac_spec/testing_framework/core/test_case_class_methods.rb', line 16

def testcases
  @@testcases ||= []
  @@testcases
end

#xit(*whatever) ⇒ Object

prepend ‘x’ to ignore a test



97
98
# File 'lib/mac_spec/testing_framework/core/test_case_class_methods.rb', line 97

def xit *whatever
end