Class: Micronaut::Example

Inherits:
Object show all
Defined in:
lib/micronaut/example.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(behaviour, desc, options, example_block = nil) ⇒ Example

Returns a new instance of Example.



7
8
9
10
11
12
13
# File 'lib/micronaut/example.rb', line 7

def initialize(behaviour, desc, options, example_block=nil)
  @behaviour, @description, @options, @example_block = behaviour, desc, options, example_block
   = @behaviour..dup
  [:description] = description
  [:execution_result] = {}
  .update(options)
end

Instance Attribute Details

#behaviourObject (readonly)

Returns the value of attribute behaviour.



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

def behaviour
  @behaviour
end

#descriptionObject (readonly)

Returns the value of attribute description.



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

def description
  @description
end

#example_blockObject (readonly)

Returns the value of attribute example_block.



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

def example_block
  @example_block
end

#metadataObject (readonly)

Returns the value of attribute metadata.



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

def 
  
end

Instance Method Details

#execution_resultObject



19
20
21
# File 'lib/micronaut/example.rb', line 19

def execution_result
  [:execution_result]
end

#inspectObject



93
94
95
# File 'lib/micronaut/example.rb', line 93

def inspect
  "#{@metadata[:behaviour][:name]} - #{@metadata[:description]}"
end

#record_results(results = {}) ⇒ Object



15
16
17
# File 'lib/micronaut/example.rb', line 15

def record_results(results={})
  [:execution_result].update(results)
end

#run(behaviour_instance) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/micronaut/example.rb', line 58

def run(behaviour_instance)
  @behaviour_instance = behaviour_instance
  @behaviour_instance.running_example = self

  run_started

  all_systems_nominal = true
  exception_encountered = nil
  
  begin
    run_before_each
    @behaviour_instance.instance_eval(&example_block) if example_block
  rescue Exception => e
    exception_encountered = e
    all_systems_nominal = false
  end

  begin
    run_after_each
  rescue Exception => e
    exception_encountered ||= e
    all_systems_nominal = false
  ensure
    @behaviour_instance.running_example = nil
  end
  
  if exception_encountered
    run_failed(exception_encountered) 
  else
    example_block ? run_passed : run_pending
  end

  all_systems_nominal
end

#run_after_eachObject



51
52
53
54
55
56
# File 'lib/micronaut/example.rb', line 51

def run_after_each
  @behaviour.eval_after_eachs(@behaviour_instance)
  @behaviour_instance._verify_mocks if @behaviour_instance.respond_to?(:_verify_mocks)
ensure
  @behaviour_instance._teardown_mocks if @behaviour_instance.respond_to?(:_teardown_mocks)
end

#run_before_eachObject



46
47
48
49
# File 'lib/micronaut/example.rb', line 46

def run_before_each
  @behaviour_instance._setup_mocks if @behaviour_instance.respond_to?(:_setup_mocks)
  @behaviour.eval_before_eachs(@behaviour_instance)
end

#run_failed(exception) ⇒ Object



35
36
37
# File 'lib/micronaut/example.rb', line 35

def run_failed(exception)
  run_finished 'failed', :exception_encountered => exception
end

#run_finished(status, results = {}) ⇒ Object



39
40
41
42
43
44
# File 'lib/micronaut/example.rb', line 39

def run_finished(status, results={})
  record_results results.update(:status => status)
  finish_time = Time.now
  record_results :finished_at => finish_time, :run_time => (finish_time - execution_result[:started_at])
  Micronaut.configuration.formatter.example_finished(self)
end

#run_passedObject



27
28
29
# File 'lib/micronaut/example.rb', line 27

def run_passed
  run_finished 'passed'
end

#run_pending(message = 'Not yet implemented') ⇒ Object



31
32
33
# File 'lib/micronaut/example.rb', line 31

def run_pending(message='Not yet implemented')
  run_finished 'pending', :pending_message => message
end

#run_startedObject



23
24
25
# File 'lib/micronaut/example.rb', line 23

def run_started
  record_results :started_at => Time.now
end

#to_sObject



97
98
99
# File 'lib/micronaut/example.rb', line 97

def to_s
  inspect
end