Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "http://rubygems.org"

gemspec
30 changes: 30 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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
18 changes: 12 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = ["--format documentation", "--color"]
t.pattern = "./spec/**/*_spec.rb"
end
15 changes: 7 additions & 8 deletions em-spec.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
35 changes: 17 additions & 18 deletions lib/em-spec/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -47,9 +50,5 @@ def instance_eval(&block)
super(&block)
end
end

end

end


Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,6 +13,4 @@
it "should not block on failure" do
1.should == 2
end


end
end
20 changes: 10 additions & 10 deletions test/rspec_spec.rb → spec/rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,27 +27,27 @@

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

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
Expand All @@ -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
end
4 changes: 2 additions & 2 deletions test/bacon_spec.rb
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -48,4 +48,4 @@
# 1.should == 2
# end

end
end