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
- #description ⇒ Object
- #eval_block ⇒ Object
-
#eval_each_fail_fast(examples) ⇒ Object
:nodoc:.
-
#eval_each_fail_slow(examples) ⇒ Object
:nodoc:.
- #execute(options, instance_variables) ⇒ Object
-
#full_description ⇒ Object
Concats the class description with the example description.
- #implementation_backtrace ⇒ Object
- #instance_variable_hash ⇒ Object
- #options ⇒ Object
-
#set_instance_variables_from_hash(ivars) ⇒ Object
:nodoc:.
-
#should(matcher = nil) ⇒ Object
When
shouldis called with no explicit receiver, the call is delegated to the subject of the example group. -
#should_not(matcher) ⇒ Object
Just like
should,should_notdelegates to the subject (implicit or explicit) of the example group. -
#subject ⇒ Object
:nodoc:.
- #violated(message = "") ⇒ Object
Methods included from ModuleReopeningFix
child_modules, include, included
Methods included from Pending
Methods included from Matchers
#be, #be_close, #change, #eql, #equal, #exist, #have, #have_at_least, #have_at_most, #include, #match, #raise_error, #respond_to, #satisfy, #simple_matcher, #throw_symbol
Instance Method Details
#description ⇒ Object
35 36 37 |
# File 'lib/spec/example/example_methods.rb', line 35 def description @_defined_description || ::Spec::Matchers.generated_description || "NO NAME" end |
#eval_block ⇒ Object
112 113 114 |
# File 'lib/spec/example/example_methods.rb', line 112 def eval_block instance_eval(&@_implementation) end |
#eval_each_fail_fast(examples) ⇒ Object
:nodoc:
73 74 75 76 77 |
# File 'lib/spec/example/example_methods.rb', line 73 def eval_each_fail_fast(examples) #:nodoc: examples.each do |example| instance_eval(&example) end end |
#eval_each_fail_slow(examples) ⇒ Object
:nodoc:
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/spec/example/example_methods.rb', line 79 def eval_each_fail_slow(examples) #:nodoc: first_exception = nil examples.each do |example| begin instance_eval(&example) rescue Exception => e first_exception ||= e end end raise first_exception if first_exception end |
#execute(options, instance_variables) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/spec/example/example_methods.rb', line 43 def execute(, instance_variables) .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"
99 100 101 |
# File 'lib/spec/example/example_methods.rb', line 99 def full_description "#{self.class.description} #{self.description}" end |
#implementation_backtrace ⇒ Object
116 117 118 |
# File 'lib/spec/example/example_methods.rb', line 116 def implementation_backtrace eval("caller", @_implementation) end |
#instance_variable_hash ⇒ Object
66 67 68 69 70 71 |
# File 'lib/spec/example/example_methods.rb', line 66 def instance_variable_hash instance_variables.inject({}) do |variable_hash, variable_name| variable_hash[variable_name] = instance_variable_get(variable_name) variable_hash end end |
#options ⇒ Object
39 40 41 |
# File 'lib/spec/example/example_methods.rb', line 39 def @_options end |
#set_instance_variables_from_hash(ivars) ⇒ Object
:nodoc:
103 104 105 106 107 108 109 110 |
# File 'lib/spec/example/example_methods.rb', line 103 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 |
#should(matcher = nil) ⇒ Object
When should is called with no explicit receiver, the call is delegated to the subject of the example group. This could be either an explicit subject generated by calling the block passed to ExampleGroupMethods#subject, or, if the group is describing a class, an implicitly generated instance of that class.
17 18 19 20 21 22 23 |
# File 'lib/spec/example/example_methods.rb', line 17 def should(matcher=nil) if matcher subject.should(matcher) else subject.should end end |
#should_not(matcher) ⇒ Object
Just like should, should_not delegates to the subject (implicit or explicit) of the example group.
27 28 29 |
# File 'lib/spec/example/example_methods.rb', line 27 def should_not(matcher) subject.should_not(matcher) end |
#subject ⇒ Object
:nodoc:
7 8 9 10 |
# File 'lib/spec/example/example_methods.rb', line 7 def subject # :nodoc: @subject ||= (instance_variable_get(subject_variable_name) || self.class.subject || (described_class ? described_class.new : nil)) end |
#violated(message = "") ⇒ Object
31 32 33 |
# File 'lib/spec/example/example_methods.rb', line 31 def violated(="") raise Spec::Expectations::ExpectationNotMetError.new() end |