Module: Spec::Example::ExampleMethods

Extended by:
ModuleReopeningFix
Includes:
Mack::Routes::Urls, Mack::Testing::Helpers, Pending, Matchers
Included in:
ExampleGroup, Test::Unit::TestCase
Defined in:
lib/mack/testing/rspec.rb,
lib/gems/rspec-1.1.12/lib/spec/example/example_methods.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods included from ModuleReopeningFix

child_modules, include, included

Methods included from Pending

#pending

Methods included from Matchers

#__original_match, #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

Methods included from Mack::Testing::Helpers

#assigns, #clear_session, #cookies, #delete, #file_for_upload, #get, #in_session, #post, #put, #remote_test, #remove_cookie, #request, #response, #responses, #session, #set_cookie, #temp_app_config

Methods included from Mack::Routes::Urls

create_method, #redirect_html, #url_for_pattern

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Spec::Matchers

Instance Method Details

#backtraceObject

Provides the backtrace up to where this example was declared.



118
119
120
# File 'lib/gems/rspec-1.1.12/lib/spec/example/example_methods.rb', line 118

def backtrace
  @_backtrace
end

#descriptionObject



36
37
38
# File 'lib/gems/rspec-1.1.12/lib/spec/example/example_methods.rb', line 36

def description
  @_defined_description || ::Spec::Matchers.generated_description || "NO NAME"
end

#eval_blockObject

:nodoc:



113
114
115
116
117
# File 'lib/gems/rspec-1.1.12/lib/spec/example/example_methods.rb', line 113

def eval_block
  in_session do
    mack_eval_block
  end
end

#eval_each_fail_fast(examples) ⇒ Object

:nodoc:



74
75
76
77
78
# File 'lib/gems/rspec-1.1.12/lib/spec/example/example_methods.rb', line 74

def eval_each_fail_fast(examples) # :nodoc:
  examples.each do |example|
    instance_eval(&example)
  end
end

#eval_each_fail_slow(examples) ⇒ Object

:nodoc:



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/gems/rspec-1.1.12/lib/spec/example/example_methods.rb', line 80

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



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/gems/rspec-1.1.12/lib/spec/example/example_methods.rb', line 44

def execute(options, instance_variables)
  options.reporter.example_started(self)
  set_instance_variables_from_hash(instance_variables)
  
  execution_error = nil
  Timeout.timeout(options.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

  options.reporter.example_finished(self, execution_error)
  success = execution_error.nil? || ExamplePendingError === execution_error
end

#full_descriptionObject

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"


100
101
102
# File 'lib/gems/rspec-1.1.12/lib/spec/example/example_methods.rb', line 100

def full_description
  "#{self.class.description} #{self.description}"
end

#implementation_backtraceObject

Deprecated - use backtrace()



123
124
125
126
127
128
129
# File 'lib/gems/rspec-1.1.12/lib/spec/example/example_methods.rb', line 123

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_hashObject

:nodoc:



67
68
69
70
71
72
# File 'lib/gems/rspec-1.1.12/lib/spec/example/example_methods.rb', line 67

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

#optionsObject



40
41
42
# File 'lib/gems/rspec-1.1.12/lib/spec/example/example_methods.rb', line 40

def options
  @_options
end

#set_instance_variables_from_hash(ivars) ⇒ Object

:nodoc:



104
105
106
107
108
109
110
111
# File 'lib/gems/rspec-1.1.12/lib/spec/example/example_methods.rb', line 104

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.



18
19
20
21
22
23
24
# File 'lib/gems/rspec-1.1.12/lib/spec/example/example_methods.rb', line 18

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.



28
29
30
# File 'lib/gems/rspec-1.1.12/lib/spec/example/example_methods.rb', line 28

def should_not(matcher)
  subject.should_not(matcher)
end

#subjectObject

:nodoc: this is somewhat experimental



7
8
9
10
11
# File 'lib/gems/rspec-1.1.12/lib/spec/example/example_methods.rb', line 7

def subject # :nodoc: this is somewhat experimental
  @subject ||= ( instance_variable_get(subject_variable_name) ||
                 instance_eval(&self.class.subject_block) ||
                 (described_class ? described_class.new : nil) )
end

#violated(message = "") ⇒ Object



32
33
34
# File 'lib/gems/rspec-1.1.12/lib/spec/example/example_methods.rb', line 32

def violated(message="")
  raise Spec::Expectations::ExpectationNotMetError.new(message)
end