diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..c80ee36 --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source "http://rubygems.org" + +gemspec diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..15ca90a --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,30 @@ +PATH + remote: . + specs: + em-spec (0.1.3) + bacon (>= 1.1.0) + eventmachine (>= 0.12.6) + rspec (>= 1.1.12) + +GEM + remote: http://rubygems.org/ + specs: + bacon (1.1.0) + diff-lcs (1.1.3) + eventmachine (0.12.10) + rake (0.9.2.2) + rspec (2.8.0) + rspec-core (~> 2.8.0) + rspec-expectations (~> 2.8.0) + rspec-mocks (~> 2.8.0) + rspec-core (2.8.0) + rspec-expectations (2.8.0) + diff-lcs (~> 1.1.2) + rspec-mocks (2.8.0) + +PLATFORMS + ruby + +DEPENDENCIES + em-spec! + rake diff --git a/Rakefile b/Rakefile index 20fc7ec..03b862d 100644 --- a/Rakefile +++ b/Rakefile @@ -3,16 +3,22 @@ task :gem => :gemspec do end task :gemspec do - + end task :install => :gem do sh 'sudo gem install em-spec-*.gem' end -task :default => :spec +task :default => [:bacon, :spec] + +desc "Run Bacon spec" +task :bacon do + sh 'bundle exec bacon test/bacon_spec.rb' +end -task :spec do - sh 'bacon test/bacon_spec.rb' - sh 'spec -f specdoc test/rspec_spec.rb test/rspec_fail_examples.rb' -end \ No newline at end of file +require 'rspec/core/rake_task' +RSpec::Core::RakeTask.new(:spec) do |t| + t.rspec_opts = ["--format documentation", "--color"] + t.pattern = "./spec/**/*_spec.rb" +end diff --git a/em-spec.gemspec b/em-spec.gemspec index 33e378d..df2a92e 100644 --- a/em-spec.gemspec +++ b/em-spec.gemspec @@ -8,15 +8,14 @@ spec = Gem::Specification.new do |s| s.description = 'Rspec and Bacon based BDD API for Ruby/EventMachine' s.has_rdoc = false s.authors = ["Aman Gupta", "Lourens Naudé", "Daniel DeLeo"] + + s.files = `git ls-files`.split("\n") + s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") + s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } + s.add_dependency('eventmachine', '>= 0.12.6') s.add_dependency('bacon', '>= 1.1.0') s.add_dependency('rspec', '>= 1.1.12') - s.files = ["README.rdoc", - "Rakefile", - "lib/em-spec/bacon.rb", - "lib/em-spec/rspec.rb", - "lib/ext/fiber18.rb", - "test/bacon_spec.rb", - "test/rspec_spec.rb", - "test/rspec_fail_examples.rb"] + + s.add_development_dependency('rake') end diff --git a/lib/em-spec/rspec.rb b/lib/em-spec/rspec.rb index 41da33c..d19aaf1 100644 --- a/lib/em-spec/rspec.rb +++ b/lib/em-spec/rspec.rb @@ -5,26 +5,29 @@ module EventMachine module SpecHelper def em(&block) - EM.run do - em_spec_exception = nil - @_em_spec_fiber = Fiber.new do - begin - block.call - rescue Exception => em_spec_exception - done + EM.next_tick do + em_spec_exception = nil + + @_em_spec_fiber = Fiber.new do + begin + block.call + rescue Exception => em_spec_exception + done + end + + Fiber.yield end - Fiber.yield - end - @_em_spec_fiber.resume + @_em_spec_fiber.resume - raise em_spec_exception if em_spec_exception + raise em_spec_exception if em_spec_exception + end end end def done - EM.next_tick{ + EM.schedule { finish_em_spec_fiber } end @@ -33,11 +36,11 @@ def done def finish_em_spec_fiber EM.stop_event_loop if EM.reactor_running? - @_em_spec_fiber.resume if @_em_spec_fiber.alive? + @_em_spec_fiber.transfer if @_em_spec_fiber.alive? end end - + module Spec include SpecHelper @@ -47,9 +50,5 @@ def instance_eval(&block) super(&block) end end - end - end - - diff --git a/test/rspec_fail_examples.rb b/spec/rspec_fail_examples_spec.rb similarity index 97% rename from test/rspec_fail_examples.rb rename to spec/rspec_fail_examples_spec.rb index 7f61bf8..a6cdf0e 100644 --- a/test/rspec_fail_examples.rb +++ b/spec/rspec_fail_examples_spec.rb @@ -2,7 +2,7 @@ describe EventMachine, "when running failing examples" do include EM::Spec - + it "should not bubble failures beyond rspec" do EM.add_timer(0.1) do :should_not_bubble.should == :failures @@ -13,6 +13,4 @@ it "should not block on failure" do 1.should == 2 end - - -end \ No newline at end of file +end diff --git a/test/rspec_spec.rb b/spec/rspec_spec.rb similarity index 86% rename from test/rspec_spec.rb rename to spec/rspec_spec.rb index 296bc1b..dcce997 100644 --- a/test/rspec_spec.rb +++ b/spec/rspec_spec.rb @@ -8,17 +8,17 @@ describe EventMachine, "when testing with EM::SpecHelper" do include EM::SpecHelper - + it "should not require a call to done when #em is not used" do 1.should == 1 end - + it "should have timers" do em do start = Time.now EM.add_timer(0.5){ - (Time.now-start).should be_close( 0.5, 0.1 ) + (Time.now-start).should be_within(0.1).of(0.5) done } end @@ -27,16 +27,16 @@ describe EventMachine, "when testing with EM::Spec" do include EM::Spec - + it 'should work' do done end it 'should have timers' do start = Time.now - + EM.add_timer(0.5){ - (Time.now-start).should be_close( 0.5, 0.1 ) + (Time.now-start).should be_within(0.1).of(0.5) done } end @@ -44,10 +44,10 @@ it 'should have periodic timers' do num = 0 start = Time.now - + timer = EM.add_periodic_timer(0.5){ if (num += 1) == 2 - (Time.now-start).should be_close( 1.0, 0.1 ) + (Time.now-start).should be_within(0.1).of(1.0) EM.__send__ :cancel_timer, timer done end @@ -61,11 +61,11 @@ done } end - + end describe "Rspec", "when running an example group after another group that uses EMSpec " do it "should work normally" do :does_not_hang.should_not be_false end -end \ No newline at end of file +end diff --git a/test/bacon_spec.rb b/test/bacon_spec.rb index 02a3f6d..1b69152 100644 --- a/test/bacon_spec.rb +++ b/test/bacon_spec.rb @@ -1,5 +1,5 @@ require 'bacon' -require File.dirname(__FILE__) + '/../lib/em-spec/bacon' +require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'em-spec', 'bacon') EM.spec_backend = EventMachine::Spec::Bacon @@ -48,4 +48,4 @@ # 1.should == 2 # end -end \ No newline at end of file +end