Class: Micronaut::Example
Instance Attribute Summary collapse
-
#behaviour ⇒ Object
readonly
Returns the value of attribute behaviour.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#example_block ⇒ Object
readonly
Returns the value of attribute example_block.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Instance Method Summary collapse
- #execution_result ⇒ Object
- #file_path ⇒ Object
-
#initialize(behaviour, desc, options, example_block = nil) ⇒ Example
constructor
A new instance of Example.
- #inspect ⇒ Object
- #record_results(results = {}) ⇒ Object
- #run(behaviour_instance) ⇒ Object
- #run_after_each ⇒ Object
- #run_before_each ⇒ Object
- #run_failed(exception) ⇒ Object
- #run_finished(status, results = {}) ⇒ Object
- #run_passed ⇒ Object
- #run_pending(message = 'Not yet implemented') ⇒ Object
- #run_started ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(behaviour, desc, options, example_block = nil) ⇒ Example
Returns a new instance of Example.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/micronaut/example.rb', line 7 def initialize(behaviour, desc, , example_block=nil) @behaviour, @description, @options, @example_block = behaviour, desc, , example_block @metadata = @behaviour..dup @metadata[:description] = description @metadata[:execution_result] = {} @metadata[:caller] = .delete(:caller) if @metadata[:caller] @metadata[:file_path] = @metadata[:caller].split(":")[0].strip @metadata[:line_number] = @metadata[:caller].split(":")[1].to_i end @metadata.update() end |
Instance Attribute Details
#behaviour ⇒ Object (readonly)
Returns the value of attribute behaviour.
5 6 7 |
# File 'lib/micronaut/example.rb', line 5 def behaviour @behaviour end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
5 6 7 |
# File 'lib/micronaut/example.rb', line 5 def description @description end |
#example_block ⇒ Object (readonly)
Returns the value of attribute example_block.
5 6 7 |
# File 'lib/micronaut/example.rb', line 5 def example_block @example_block end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
5 6 7 |
# File 'lib/micronaut/example.rb', line 5 def @metadata end |
Instance Method Details
#execution_result ⇒ Object
24 25 26 |
# File 'lib/micronaut/example.rb', line 24 def execution_result @metadata[:execution_result] end |
#file_path ⇒ Object
28 29 30 |
# File 'lib/micronaut/example.rb', line 28 def file_path @metadata[:file_path] || behaviour.file_path end |
#inspect ⇒ Object
102 103 104 |
# File 'lib/micronaut/example.rb', line 102 def inspect "#{@metadata[:behaviour][:name]} - #{@metadata[:description]}" end |
#record_results(results = {}) ⇒ Object
20 21 22 |
# File 'lib/micronaut/example.rb', line 20 def record_results(results={}) @metadata[:execution_result].update(results) end |
#run(behaviour_instance) ⇒ Object
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 92 93 94 95 96 97 98 99 100 |
# File 'lib/micronaut/example.rb', line 67 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_each ⇒ Object
60 61 62 63 64 65 |
# File 'lib/micronaut/example.rb', line 60 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_each ⇒ Object
55 56 57 58 |
# File 'lib/micronaut/example.rb', line 55 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
44 45 46 |
# File 'lib/micronaut/example.rb', line 44 def run_failed(exception) run_finished 'failed', :exception_encountered => exception end |
#run_finished(status, results = {}) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/micronaut/example.rb', line 48 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_passed ⇒ Object
36 37 38 |
# File 'lib/micronaut/example.rb', line 36 def run_passed run_finished 'passed' end |
#run_pending(message = 'Not yet implemented') ⇒ Object
40 41 42 |
# File 'lib/micronaut/example.rb', line 40 def run_pending(='Not yet implemented') run_finished 'pending', :pending_message => end |
#run_started ⇒ Object
32 33 34 |
# File 'lib/micronaut/example.rb', line 32 def run_started record_results :started_at => Time.now end |
#to_s ⇒ Object
106 107 108 |
# File 'lib/micronaut/example.rb', line 106 def to_s inspect end |