Permalink
Browse files

Make specs green when not running in concurrent mode.

  • Loading branch information...
1 parent a7c793e commit 6eaf3982420cd2ab818eea0682f25421fac4b1e0 @alloy committed Mar 6, 2012
Showing with 52 additions and 20 deletions.
  1. +2 −2 bin/macbacon
  2. +40 −17 lib/mac_bacon.rb
  3. +10 −1 test/spec_bacon.rb
View
@@ -62,8 +62,8 @@ opts = OptionParser.new("", 24, ' ') { |opts|
Bacon.bactrackes = false
}
- opts.on("-c", "--concurrent", "runs multiple specs concurrently on multiple threads") {
- Bacon::Dispatch.concurrent = true
+ opts.on("-c", "--concurrent", "runs multiple specs concurrently on multiple GCD threads") {
+ Bacon.concurrent = true
}
opts.on("-a", "--automatic", "gather tests from ./test/, include ./lib/") {
View
@@ -19,9 +19,6 @@
module Bacon
VERSION = "1.3"
- Shared = Hash.new { |_, name|
- raise NameError, "no such context: #{name.inspect}"
- }
class << self
attr_accessor :restrict_name, :restrict_context
@@ -61,10 +58,24 @@ def requirements
# Bacon.performSelector('run', withObject:nil, afterDelay:0)
def run
@timer ||= Time.now
- self.performSelector("run_all_specs_concurrent", withObject:nil, afterDelay:0)
+ self.performSelector(concurrent? ? "run_all_specs_concurrent" : "run_all_specs_serial", withObject:nil, afterDelay:0)
NSApplication.sharedApplication.run
end
+ def run_all_specs_serial
+ contexts.each do |context|
+ context.specifications.each do |spec|
+ begin
+ spec.run
+ rescue Object => e
+ puts "An error bubbled up, this should really not happen! The error was: #{e.message}\n\t#{e.backtrace.join("\n\t")}"
+ raise e
+ end
+ end
+ end
+ bacon_did_finish
+ end
+
def run_all_specs_concurrent
main_queue = Dispatch::Queue.main
concurrent_queue = Dispatch::Queue.concurrent
@@ -77,7 +88,7 @@ def run_all_specs_concurrent
spec.performSelector('run', withObject:nil, afterDelay:0)
CFRunLoopRun() unless context.run_on_main_thread? # Should already have a running runloop!
rescue Object => e
- puts "An error occurred on a GCD thread, this should really not happen! The error was: #{e.message}\n\t#{e.backtrace.join("\n\t")}"
+ puts "An error bubbled up on a GCD thread, this should really not happen! The error was: #{e.message}\n\t#{e.backtrace.join("\n\t")}"
end
end
end
@@ -86,13 +97,7 @@ def run_all_specs_concurrent
#group.notify(main_queue) do
group.notify(concurrent_queue) do
#Dispatch::Queue.main.sync do
- Bacon.dispatch_on_main_thread do
- if delegate.respond_to?('bacon_did_finish')
- delegate.bacon_did_finish
- end
- handle_summary
- exit Counter.not_passed
- end
+ Bacon.dispatch_on_main_thread { bacon_did_finish }
end
end
@@ -105,13 +110,28 @@ def dispatch_on_main_thread(&block)
end
end
+ private
+
+ def bacon_did_finish
+ if delegate.respond_to?('bacon_did_finish')
+ delegate.bacon_did_finish
+ end
+ handle_summary
+ exit Counter.not_passed
+ end
+
end
- self.restrict_name = //
+
+ Shared = Hash.new { |_, name|
+ raise NameError, "no such context: #{name.inspect}"
+ }
+
+ self.restrict_name = //
self.restrict_context = //
- self.backtraces = true
- # TODO for now we always run concurrent, because I ripped out the code needed for non-concurrent running
- self.concurrent = true
+ self.backtraces = true
+ self.concurrent = false
+
module Counter
class << self
@@ -137,6 +157,7 @@ def errors
end
end
+
# TODO for now we'll just use dots, which works best in a concurrent env
module SpecDoxOutput
def handle_context_begin(context)
@@ -183,8 +204,8 @@ def handle_summary
puts summary
end
end
+ extend SpecDoxOutput
- extend SpecDoxOutput # default
class Error < RuntimeError
attr_accessor :count_as
@@ -203,6 +224,7 @@ def count_as_error?
end
end
+
class Context
attr_reader :specification
@@ -276,6 +298,7 @@ def describe(*args, &block)
end
end # Context
+
class Specification
attr_reader :description, :context
attr_accessor :delegate
View
@@ -426,7 +426,16 @@ class << self
end
end
else
- puts "[!] Skipping the concurrency related specs, as Bacon is not running in concurrent mode. Enable it with the `-c' command-line option."
+ puts "[!] Skipping the majority of the concurrency related specs, as Bacon is not running in concurrent mode. Enable it with the `-c' command-line option."
+ describe "Concurrency" do
+ it "returns that the specifications of the context should be run on the main thread by default" do
+ self.class.should.run_on_main_thread
+ end
+
+ it "forces the specifications to run on the main thread" do
+ Dispatch::Queue.current.to_s.should == Dispatch::Queue.main.to_s
+ end
+ end
end
describe "delegate callbacks" do

0 comments on commit 6eaf398

Please sign in to comment.