Permalink
Browse files

formalize Reporter#report as an API to support extensions like intera…

…ctive_rspec
  • Loading branch information...
1 parent 9da117b commit f4151158fce02ee89aa77fe347ffbf9460438625 @dchelimsky dchelimsky committed Nov 1, 2011
Showing with 59 additions and 17 deletions.
  1. +2 −0 Changelog.md
  2. +1 −0 Gemfile
  3. +39 −17 lib/rspec/core/reporter.rb
  4. +17 −0 spec/rspec/core/reporter_spec.rb
View
@@ -9,6 +9,8 @@
* SharedContext supports `let` (David Chelimsky)
* Override opposing tags from the command line (David Chelimsky)
* Eliminate Ruby warnings (Matijs van Zuijlen)
+ * Make reporter.report an API (David Chelimsky)
+ * supports extension tools like interative_rspec
* Bug fixes
* Make sure the `bar` in `--tag foo:bar` makes it to DRb (Aaron Gibralter)
View
@@ -57,3 +57,4 @@ group :development do
gem "ruby-prof", "~> 0.10.0"
end
end
+gem 'interactive_rspec'
View
@@ -6,30 +6,37 @@ def initialize(*formatters)
@duration = @start = nil
end
- def report(count, seed)
- start(count)
+ # @api
+ # @overload report(count, &block)
+ # @overload report(count, seed, &block)
+ # @param [Fixnum] count the number of examples being run
+ # @param [Fixnum] seed (optional) the seed used to randomize the spec run
+ # @param [Block] block yields itself for further reporting.
+ #
+ # Initializes the report run and yields itself for further reporting. The
+ # block is required, so that the reporter can manage cleaning up after the
+ # run.
+ #
+ # ### WARNING
+ #
+ # The `seed` argument is an internal API and is not guaranteed to be
+ # supported in the future.
+ #
+ # @example
+ #
+ # reporter.report(group.examples.size) do |r|
+ # example_groups.map {|g| g.run(r) }
+ # end
+ #
+ def report(expected_example_count, seed=nil)
+ start(expected_example_count)
begin
yield self
ensure
finish(seed)
end
end
- def finish(seed)
- begin
- stop
- notify :start_dump
- notify :dump_pending
- notify :dump_failures
- notify :dump_summary, @duration, @example_count, @failure_count, @pending_count
- notify :seed, seed if seed
- ensure
- notify :close
- end
- end
-
- alias_method :abort, :finish
-
def start(expected_example_count)
@start = Time.now
notify :start, expected_example_count
@@ -66,6 +73,21 @@ def example_pending(example)
notify :example_pending, example
end
+ def finish(seed)
+ begin
+ stop
+ notify :start_dump
+ notify :dump_pending
+ notify :dump_failures
+ notify :dump_summary, @duration, @example_count, @failure_count, @pending_count
+ notify :seed, seed if seed
+ ensure
+ notify :close
+ end
+ end
+
+ alias_method :abort, :finish
+
def stop
@duration = Time.now - @start if @start
notify :stop
@@ -82,5 +82,22 @@ module RSpec::Core
reporter.example_started(example)
end
end
+
+ describe "#report" do
+ it "supports one arg (count)" do
+ Reporter.new.report(1) {}
+ end
+
+ it "supports two args (count, seed)" do
+ Reporter.new.report(1, 2) {}
+ end
+
+ it "yields itself" do
+ reporter = Reporter.new
+ yielded = nil
+ reporter.report(3) {|r| yielded = r}
+ yielded.should eq(reporter)
+ end
+ end
end
end

0 comments on commit f415115

Please sign in to comment.