Permalink
Browse files

Adding 'pending' support from within example (paired with Kabari

Hendrick). Closes #7.
  • Loading branch information...
1 parent 21d6f6b commit 5fa50304dea6d73cca91a0b3eed76aeaaeeb670d @ajwalters ajwalters committed with dchelimsky Apr 18, 2010
@@ -1,4 +1,3 @@
-@wip
Feature: pending examples
Rspec offers three ways to indicate that an example is disabled pending
@@ -8,10 +7,10 @@ Feature: pending examples
Given a file named "example_without_block_spec.rb" with:
"""
describe "an example" do
- it "has not yet been implemented"
+ it "is a pending example"
end
"""
- When I run "spec example_without_block_spec.rb"
+ When I run "rspec example_without_block_spec.rb"
Then the exit status should be 0
And I should see "1 example, 0 failures, 1 pending"
And I should see "Not Yet Implemented"
@@ -26,7 +25,7 @@ Feature: pending examples
end
end
"""
- When I run "spec pending_without_block_spec.rb"
+ When I run "rspec pending_without_block_spec.rb"
Then the exit status should be 0
And I should see "1 example, 0 failures, 1 pending"
And I should see "(something else getting finished)"
@@ -43,7 +42,7 @@ Feature: pending examples
end
end
"""
- When I run "spec pending_with_failing_block_spec.rb"
+ When I run "rspec pending_with_failing_block_spec.rb"
Then the exit status should be 0
And I should see "1 example, 0 failures, 1 pending"
And I should see "(something else getting finished)"
@@ -60,7 +59,7 @@ Feature: pending examples
end
end
"""
- When I run "spec pending_with_passing_block_spec.rb"
+ When I run "rspec pending_with_passing_block_spec.rb"
Then the exit status should not be 0
And I should see "1 example, 1 failure"
And I should see "FIXED"
View
@@ -18,6 +18,7 @@
require 'rspec/core/formatters'
require 'rspec/core/backward_compatibility'
require 'rspec/core/version'
+require 'rspec/core/errors'
module Rspec
module Core
View
@@ -0,0 +1,14 @@
+module Rspec
+ module Core
+ # If Test::Unit is loaed, we'll use its error as baseclass, so that Test::Unit
+ # will report unmet RSpec expectations as failures rather than errors.
+ superclass = ['Test::Unit::AssertionFailedError', '::StandardError'].map do |c|
+ eval(c) rescue nil
+ end.compact.first
+
+ class PendingExampleFixedError < superclass
+ end
+ end
+end
+
+
@@ -47,7 +47,8 @@ def run_passed(reporter=nil)
run_finished reporter, 'passed'
end
- def run_pending(reporter=nil, message='Not yet implemented')
+ def run_pending(reporter=nil)
+ message = metadata[:execution_result][:pending_message] || 'Not Yet Implemented'
run_finished reporter, 'pending', :pending_message => message
end
@@ -126,6 +127,7 @@ def run(example_group_instance, reporter)
all_systems_nominal
end
+
end
end
@@ -190,7 +190,6 @@ def self.run(reporter)
eval_before_alls(example_group_instance)
success = run_examples(example_group_instance, reporter)
eval_after_alls(example_group_instance)
-
success
end
@@ -226,6 +225,21 @@ def __reset__
__memoized.clear
end
+ def pending(message = nil)
+ running_example.metadata[:pending] = true
+ running_example.metadata[:execution_result][:pending_message] = message if message
+ if block_given?
+ begin
+ result = yield
+ rescue Exception => e
+ end
+ if result
+ running_example.metadata[:pending] = false
+ raise Rspec::Core::PendingExampleFixedError.new
+ end
+ end
+ end
+
end
end
end
@@ -11,12 +11,15 @@ def dump_failures
failed_examples.each_with_index do |failed_example, index|
exception = failed_example.execution_result[:exception_encountered]
padding = ' '
-
- output.puts "#{index.next}) #{failed_example}"
- output.puts "#{padding}Failure/Error: #{read_failed_line(exception, failed_example).strip}"
-
- exception.message.split("\n").each do |line|
- output.puts "#{padding}#{colorise(line, exception).strip}"
+ if exception.is_a?(Rspec::Core::PendingExampleFixedError)
+ output.puts "#{index.next}) #{failed_example} FIXED"
+ output.puts "#{padding}Expected pending '#{failed_example.metadata[:execution_result][:pending_message]}' to fail. No Error was raised."
+ else
+ output.puts "#{index.next}) #{failed_example}"
+ output.puts "#{padding}Failure/Error: #{read_failed_line(exception, failed_example).strip}"
+ exception.message.split("\n").each do |line|
+ output.puts "#{padding}#{colorise(line, exception).strip}"
+ end
end
format_backtrace(exception.backtrace, failed_example).each do |backtrace_info|
@@ -73,8 +76,8 @@ def dump_pending
unless pending_examples.empty?
output.puts
output.puts "Pending:"
- pending_examples.each do |pending_example, message|
- output.puts " #{pending_example}"
+ pending_examples.each do |pending_example|
+ output.puts " #{pending_example} (#{pending_example.metadata[:execution_result][:pending_message]})"
output.puts grey(" # #{format_caller(pending_example.metadata[:location])}")
end
end

0 comments on commit 5fa5030

Please sign in to comment.