Module: RSpec::Core::Pending

Included in:
ExampleGroup
Defined in:
lib/rspec/core/pending.rb

Defined Under Namespace

Classes: PendingDeclaredInExample, PendingExampleFixedError

Constant Summary collapse

NO_REASON_GIVEN =
'No reason given'
NOT_YET_IMPLEMENTED =
'Not yet implemented'

Instance Method Summary collapse

Instance Method Details

#pendingObject #pending(message) ⇒ Object #pending(message, &block) ⇒ Object

Note:

‘before(:each)` hooks are eval’d when you use the ‘pending` method within an example. If you want to declare an example `pending` and bypass the `before` hooks as well, you can pass `:pending => true` to the `it` method:

it "does something", :pending => true do
  # ...
end

Stops execution of an example, and reports it as pending. Takes an optional message and block.

Examples:


describe "an example" do
  # reported as "Pending: no reason given"
  it "is pending with no message" do
    pending
    this_does_not_get_executed
  end

  # reported as "Pending: something else getting finished"
  it "is pending with a custom message" do
    pending("something else getting finished")
    this_does_not_get_executed
  end

  # reported as "Pending: something else getting finished"
  it "is pending with a failing block" do
    pending("something else getting finished") do
      raise "this is the failure"
    end
  end

  # reported as failure, saying we expected the block to fail but
  # it passed.
  it "is pending with a passing block" do
    pending("something else getting finished") do
      true.should be(true)
    end
  end
end

Parameters:

  • message (String)

    optional message to add to the summary report.

  • block (Block)

    optional block. If it fails, the example is reported as pending. If it executes cleanly the example fails.

Raises:



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/rspec/core/pending.rb', line 71

def pending(*args)
  return self.class.before(:each) { pending(*args) } unless example

  options = args.last.is_a?(Hash) ? args.pop : {}
  message = args.first || NO_REASON_GIVEN

  if options[:unless] || (options.has_key?(:if) && !options[:if])
    return block_given? ? yield : nil
  end

  example.[:pending] = true
  example.[:execution_result][:pending_message] = message
  if block_given?
    begin
      result = begin
                 yield
                 example.example_group_instance.instance_eval { verify_mocks_for_rspec }
               end
      example.[:pending] = false
    rescue Exception => e
      example.execution_result[:exception] = e
    ensure
      teardown_mocks_for_rspec
    end
    raise PendingExampleFixedError.new if result
  end
  raise PendingDeclaredInExample.new(message)
end