Class: Matest::ExampleGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/matest/example_group.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope_block) ⇒ ExampleGroup

Returns a new instance of ExampleGroup.



10
11
12
13
14
15
# File 'lib/matest/example_group.rb', line 10

def initialize(scope_block)
  @scope_block = scope_block
  @specs       = []
  @lets        = []
  @statuses    = []
end

Instance Attribute Details

#letsObject (readonly)

Returns the value of attribute lets.



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

def lets
  @lets
end

#printerObject

Returns the value of attribute printer.



8
9
10
# File 'lib/matest/example_group.rb', line 8

def printer
  @printer
end

#scope_blockObject (readonly)

Returns the value of attribute scope_block.



3
4
5
# File 'lib/matest/example_group.rb', line 3

def scope_block
  @scope_block
end

#specsObject (readonly)

Returns the value of attribute specs.



4
5
6
# File 'lib/matest/example_group.rb', line 4

def specs
  @specs
end

#statusesObject (readonly)

Returns the value of attribute statuses.



6
7
8
# File 'lib/matest/example_group.rb', line 6

def statuses
  @statuses
end

Class Method Details

.let(var_name, &block) ⇒ Object



45
46
47
48
49
# File 'lib/matest/example_group.rb', line 45

def self.let(var_name, &block)
  define_method(var_name) do
    instance_variable_set(:"@#{var_name}", block.call)
  end
end

Instance Method Details

#execute!Object



27
28
29
30
31
32
33
34
# File 'lib/matest/example_group.rb', line 27

def execute!
  instance_eval(&scope_block)
  specs.shuffle.each do |spec, desc|
    res = run_spec(spec)
    printer.prints(res)
  end

end

#let(var_name, bang = false, &block) ⇒ Object



51
52
53
# File 'lib/matest/example_group.rb', line 51

def let(var_name, bang=false, &block)
  lets << Let.new(var_name, block, bang=false)
end

#let!(var_name, &block) ⇒ Object



55
56
57
# File 'lib/matest/example_group.rb', line 55

def let!(var_name, &block)
  lets << Let.new(var_name, block, bang=true)
end

#run_spec(spec) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/matest/example_group.rb', line 59

def run_spec(spec)
  status = begin
             result = spec.call
             status_class = case result
                            when true
                              Matest::SpecPassed
                            when false
                              Matest::SpecFailed
                            when Matest::SkipMe
                              Matest::SpecSkipped
                            else
                              Matest::NotANaturalAssertion
                            end
             status_class.new(spec, result)
           rescue Exception => e
             Matest::ExceptionRaised.new(spec, e, spec.description)
           end
  @statuses << status
  status
end

#spec(description = nil, &block) ⇒ Object Also known as: it, test, example



17
18
19
20
# File 'lib/matest/example_group.rb', line 17

def spec(description=nil, &block)
  current_example = block_given? ? block : Matest::SkipMe.new(caller)
  specs << Example.new(current_example, description, lets)
end

#xspec(description = nil, &block) ⇒ Object Also known as: xit, xtest, xexample



22
23
24
25
# File 'lib/matest/example_group.rb', line 22

def xspec(description=nil, &block)
  current_example = Matest::SkipMe.new(caller)
  specs << Example.new(current_example, description, [])
end