Class: RSpec::Core::Example
- Inherits:
-
Object
- Object
- RSpec::Core::Example
- Defined in:
- lib/rspec/core/example.rb
Defined Under Namespace
Modules: Procsy
Instance Attribute Summary collapse
-
#example_group_instance ⇒ Object
readonly
Returns the value of attribute example_group_instance.
-
#exception ⇒ Object
readonly
Returns the first exception raised, if any, in the context of running this example.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #all_apply?(filters) ⇒ Boolean
- #around_hooks ⇒ Object
- #example_group ⇒ Object
- #fail_fast(reporter, exception) ⇒ Object
-
#initialize(example_group_class, desc, options, example_block = nil) ⇒ Example
constructor
A new instance of Example.
- #run(example_group_instance, reporter) ⇒ Object
- #set_exception(exception) ⇒ Object
Constructor Details
#initialize(example_group_class, desc, options, example_block = nil) ⇒ Example
Returns a new instance of Example.
19 20 21 22 23 24 |
# File 'lib/rspec/core/example.rb', line 19 def initialize(example_group_class, desc, , example_block=nil) @example_group_class, @options, @example_block = example_group_class, , example_block @metadata = @example_group_class..for_example(desc, ) @exception = nil @pending_declared_in_example = false end |
Instance Attribute Details
#example_group_instance ⇒ Object (readonly)
Returns the value of attribute example_group_instance.
5 6 7 |
# File 'lib/rspec/core/example.rb', line 5 def example_group_instance @example_group_instance end |
#exception ⇒ Object (readonly)
Returns the first exception raised, if any, in the context of running this example.
9 10 11 |
# File 'lib/rspec/core/example.rb', line 9 def exception @exception end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
5 6 7 |
# File 'lib/rspec/core/example.rb', line 5 def @metadata end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/rspec/core/example.rb', line 5 def @options end |
Class Method Details
.delegate_to_metadata(*keys) ⇒ Object
11 12 13 14 15 |
# File 'lib/rspec/core/example.rb', line 11 def self.(*keys) keys.each do |key| define_method(key) {@metadata[key]} end end |
.procsy(metadata, &block) ⇒ Object
89 90 91 |
# File 'lib/rspec/core/example.rb', line 89 def self.procsy(, &block) Proc.new(&block).extend(Procsy).with() end |
Instance Method Details
#all_apply?(filters) ⇒ Boolean
34 35 36 |
# File 'lib/rspec/core/example.rb', line 34 def all_apply?(filters) @metadata.all_apply?(filters) || @example_group_class.all_apply?(filters) end |
#around_hooks ⇒ Object
30 31 32 |
# File 'lib/rspec/core/example.rb', line 30 def around_hooks @around_hooks ||= example_group.around_hooks_for(self) end |
#example_group ⇒ Object
26 27 28 |
# File 'lib/rspec/core/example.rb', line 26 def example_group @example_group_class end |
#fail_fast(reporter, exception) ⇒ Object
83 84 85 86 87 |
# File 'lib/rspec/core/example.rb', line 83 def fail_fast(reporter, exception) start(reporter) set_exception(exception) finish(reporter) end |
#run(example_group_instance, reporter) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rspec/core/example.rb', line 40 def run(example_group_instance, reporter) @example_group_instance = example_group_instance @example_group_instance.example = self start(reporter) begin unless pending with_around_hooks do begin run_before_each @example_group_instance.instance_eval(&@example_block) rescue Pending::PendingDeclaredInExample => e @pending_declared_in_example = e. rescue Exception => e set_exception(e) ensure run_after_each end end end rescue Exception => e set_exception(e) ensure @example_group_instance.instance_variables.each do |ivar| @example_group_instance.instance_variable_set(ivar, nil) end @example_group_instance = nil begin assign_auto_description rescue Exception => e set_exception(e) end end finish(reporter) end |
#set_exception(exception) ⇒ Object
79 80 81 |
# File 'lib/rspec/core/example.rb', line 79 def set_exception(exception) @exception ||= exception end |