Module: Spec::Example::ExampleMethods
- Extended by:
- ModuleReopeningFix
- Includes:
- Pending, Subject::ExampleMethods, Matchers
- Included in:
- ExampleGroup, Test::Unit::TestCase
- Defined in:
- lib/spec/example/example_methods.rb
Instance Method Summary collapse
-
#backtrace ⇒ Object
Provides the backtrace up to where this example was declared.
-
#description ⇒ Object
Declared description for this example:.
-
#eval_each_fail_fast(blocks) ⇒ Object
:nodoc:.
-
#eval_each_fail_slow(blocks) ⇒ Object
:nodoc:.
-
#execute(run_options, instance_variables) ⇒ Object
:nodoc:.
-
#implementation_backtrace ⇒ Object
Deprecated - use backtrace().
- #initialize(description, options = {}, &implementation) ⇒ Object
-
#instance_variable_hash ⇒ Object
:nodoc:.
-
#options ⇒ Object
:nodoc:.
-
#run_after_each ⇒ Object
Run all the after(:each) blocks for this example.
-
#run_before_each ⇒ Object
Run all the before(:each) blocks for this example.
-
#set_instance_variables_from_hash(ivars) ⇒ Object
:nodoc:.
- #violated(message = "") ⇒ Object
Methods included from ModuleReopeningFix
child_modules, include, included
Methods included from Pending
Methods included from Matchers
#be, #be_a, #be_close, #be_instance_of, #be_kind_of, #change, clear_generated_description, #eql, #equal, #exist, generated_description, #have, #have_at_least, #have_at_most, #include, last_matcher, last_matcher=, last_should, last_should=, #match, #method_missing, #raise_error, #respond_to, #satisfy, #simple_matcher, #throw_symbol, #wrap_expectation
Methods included from DSL::Matchers
Methods included from Subject::ExampleMethods
#should, #should_not, #subject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Spec::Matchers
Instance Method Details
#backtrace ⇒ Object
Provides the backtrace up to where this example was declared.
87 88 89 |
# File 'lib/spec/example/example_methods.rb', line 87 def backtrace @_backtrace end |
#description ⇒ Object
Declared description for this example:
describe Account do
it "should start with a balance of 0" do
...
description
=> "should start with a balance of 0"
20 21 22 |
# File 'lib/spec/example/example_methods.rb', line 20 def description @_defined_description || ::Spec::Matchers.generated_description || "NO NAME" end |
#eval_each_fail_fast(blocks) ⇒ Object
:nodoc:
54 55 56 |
# File 'lib/spec/example/example_methods.rb', line 54 def eval_each_fail_fast(blocks) # :nodoc: blocks.each {|block| instance_eval(&block)} end |
#eval_each_fail_slow(blocks) ⇒ Object
:nodoc:
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/spec/example/example_methods.rb', line 58 def eval_each_fail_slow(blocks) # :nodoc: first_exception = nil blocks.each do |block| begin instance_eval(&block) rescue Exception => e first_exception ||= e end end raise first_exception if first_exception end |
#execute(run_options, instance_variables) ⇒ Object
:nodoc:
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/spec/example/example_methods.rb', line 28 def execute(, instance_variables) # :nodoc: # FIXME - there is no reason to have example_started pass a name # - in fact, it would introduce bugs in cases where no docstring # is passed to it() .reporter.example_started("") set_instance_variables_from_hash(instance_variables) execution_error = nil Timeout.timeout(.timeout) do begin before_each_example instance_eval(&@_implementation) rescue Exception => e execution_error ||= e end begin after_each_example rescue Exception => e execution_error ||= e end end .reporter.example_finished(ExampleDescription.new(description, ), execution_error) success = execution_error.nil? || ExamplePendingError === execution_error end |
#implementation_backtrace ⇒ Object
Deprecated - use backtrace()
92 93 94 95 96 97 98 |
# File 'lib/spec/example/example_methods.rb', line 92 def implementation_backtrace Kernel.warn <<-WARNING ExampleMethods#implementation_backtrace is deprecated and will be removed from a future version. Please use ExampleMethods#backtrace instead. WARNING backtrace end |
#initialize(description, options = {}, &implementation) ⇒ Object
110 111 112 113 114 115 |
# File 'lib/spec/example/example_methods.rb', line 110 def initialize(description, ={}, &implementation) @_options = @_defined_description = description @_implementation = implementation @_backtrace = caller end |
#instance_variable_hash ⇒ Object
:nodoc:
70 71 72 73 74 75 |
# File 'lib/spec/example/example_methods.rb', line 70 def instance_variable_hash # :nodoc: instance_variables.inject({}) do |variable_hash, variable_name| variable_hash[variable_name] = instance_variable_get(variable_name) variable_hash end end |
#options ⇒ Object
:nodoc:
24 25 26 |
# File 'lib/spec/example/example_methods.rb', line 24 def # :nodoc: @_options end |
#run_after_each ⇒ Object
Run all the after(:each) blocks for this example
106 107 108 |
# File 'lib/spec/example/example_methods.rb', line 106 def run_after_each example_group_hierarchy.run_after_each(self) end |
#run_before_each ⇒ Object
Run all the before(:each) blocks for this example
101 102 103 |
# File 'lib/spec/example/example_methods.rb', line 101 def run_before_each example_group_hierarchy.run_before_each(self) end |
#set_instance_variables_from_hash(ivars) ⇒ Object
:nodoc:
77 78 79 80 81 82 83 84 |
# File 'lib/spec/example/example_methods.rb', line 77 def set_instance_variables_from_hash(ivars) # :nodoc: ivars.each do |variable_name, value| # Ruby 1.9 requires variable.to_s on the next line unless ['@_defined_description', '@_options', '@_implementation', '@method_name'].include?(variable_name.to_s) instance_variable_set variable_name, value end end end |
#violated(message = "") ⇒ Object
8 9 10 |
# File 'lib/spec/example/example_methods.rb', line 8 def violated(="") raise Spec::Expectations::ExpectationNotMetError.new() end |