Module: Spec::Example::ExampleMethods
- Extended by:
- ModuleReopeningFix
- 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_block ⇒ Object
:nodoc:.
-
#eval_each_fail_fast(blocks) ⇒ Object
:nodoc:.
-
#eval_each_fail_slow(blocks) ⇒ Object
:nodoc:.
-
#execute(options, instance_variables) ⇒ Object
:nodoc:.
-
#full_description ⇒ Object
Concats the class description with the example description.
-
#implementation_backtrace ⇒ Object
Deprecated - use backtrace().
-
#instance_variable_hash ⇒ Object
:nodoc:.
-
#options ⇒ Object
:nodoc:.
-
#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, #change, clear_generated_description, #eql, #equal, #exist, generated_description, #has, #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
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.
103 104 105 |
# File 'lib/spec/example/example_methods.rb', line 103 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"
21 22 23 |
# File 'lib/spec/example/example_methods.rb', line 21 def description @_defined_description || ::Spec::Matchers.generated_description || "NO NAME" end |
#eval_block ⇒ Object
:nodoc:
98 99 100 |
# File 'lib/spec/example/example_methods.rb', line 98 def eval_block # :nodoc: instance_eval(&@_implementation) end |
#eval_each_fail_fast(blocks) ⇒ Object
:nodoc:
71 72 73 74 75 |
# File 'lib/spec/example/example_methods.rb', line 71 def eval_each_fail_fast(blocks) # :nodoc: blocks.each do |block| instance_eval(&block) end end |
#eval_each_fail_slow(blocks) ⇒ Object
:nodoc:
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/spec/example/example_methods.rb', line 77 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(options, instance_variables) ⇒ Object
:nodoc:
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/spec/example/example_methods.rb', line 41 def execute(, instance_variables) # :nodoc: .reporter.example_started(self) set_instance_variables_from_hash(instance_variables) execution_error = nil Timeout.timeout(.timeout) do begin before_each_example eval_block rescue Exception => e execution_error ||= e end begin after_each_example rescue Exception => e execution_error ||= e end end .reporter.example_finished(self, execution_error) success = execution_error.nil? || ExamplePendingError === execution_error end |
#full_description ⇒ Object
Concats the class description with the example description.
describe Account do
it "should start with a balance of 0" do
...
full_description
=> "Account should start with a balance of 0"
33 34 35 |
# File 'lib/spec/example/example_methods.rb', line 33 def full_description "#{self.class.description} #{self.description}" end |
#implementation_backtrace ⇒ Object
Deprecated - use backtrace()
108 109 110 111 112 113 114 |
# File 'lib/spec/example/example_methods.rb', line 108 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 |
#instance_variable_hash ⇒ Object
:nodoc:
64 65 66 67 68 69 |
# File 'lib/spec/example/example_methods.rb', line 64 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:
37 38 39 |
# File 'lib/spec/example/example_methods.rb', line 37 def # :nodoc: @_options end |
#set_instance_variables_from_hash(ivars) ⇒ Object
:nodoc:
89 90 91 92 93 94 95 96 |
# File 'lib/spec/example/example_methods.rb', line 89 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 ['@_implementation', '@_defined_description', '@_matcher_description', '@method_name'].include?(variable_name.to_s) instance_variable_set variable_name, value end end end |
#violated(message = "") ⇒ Object
9 10 11 |
# File 'lib/spec/example/example_methods.rb', line 9 def violated(="") raise Spec::Expectations::ExpectationNotMetError.new() end |