spec/defer_spec.rb in em-promise-1.0.3 vs spec/defer_spec.rb in em-promise-1.1.0
- old
+ new
@@ -2,14 +2,14 @@
require 'bundler/setup'
require 'em-promise'
-describe EventMachine::Defer do
+describe EventMachine::Q do
before :each do
- @deferred = EM::Defer.new
+ @deferred = EM::Q.defer
@promise = @deferred.promise
@log = []
@default_fail = proc { |reason|
fail(reason)
EM.stop
@@ -84,11 +84,11 @@
}
end
it "should allow deferred resolution with a new promise" do
- deferred2 = EM::Defer.new
+ deferred2 = EM::Q.defer
EventMachine.run {
@promise.then(proc {|result|
result.should == :foo
EM.stop
}, @default_fail)
@@ -188,11 +188,11 @@
}
end
it "should not defer rejection with a new promise" do
- deferred2 = EM::Defer.new
+ deferred2 = EM::Q.defer
EventMachine.run {
@promise.then(@default_fail, @default_fail)
begin
@deferred.reject(deferred2.promise)
rescue => e
@@ -203,11 +203,11 @@
end
end
- describe EventMachine::Defer::Promise do
+ describe EventMachine::Q::Promise do
describe 'then' do
it "should allow registration of a success callback without an errback and resolve" do
EventMachine.run {
@@ -312,11 +312,11 @@
@log << result
'ERROR'
})
@promise.then(@default_fail, proc {|result|
@log << result
- EM::Defer.reject('some reason')
+ EM::Q.reject('some reason')
})
@promise.then(@default_fail, proc {|result|
@log << result
:alt2
})
@@ -391,11 +391,11 @@
describe 'reject' do
it "should package a string into a rejected promise" do
EventMachine.run {
- rejectedPromise = EM::Defer.reject('not gonna happen')
+ rejectedPromise = EM::Q.reject('not gonna happen')
@promise.then(nil, proc {|reason|
@log << reason
})
@@ -409,11 +409,11 @@
end
it "should return a promise that forwards callbacks if the callbacks are missing" do
EventMachine.run {
- rejectedPromise = EM::Defer.reject('not gonna happen')
+ rejectedPromise = EM::Q.reject('not gonna happen')
@promise.then(nil, proc {|reason|
@log << reason
})
@@ -434,11 +434,11 @@
describe 'all' do
it "should resolve all of nothing" do
EventMachine.run {
- EM::Defer.all().then(proc {|result|
+ EM::Q.all.then(proc {|result|
@log << result
}, @default_fail)
EM.next_tick do
@log.should == [[]]
@@ -447,14 +447,14 @@
}
end
it "should take an array of promises and return a promise for an array of results" do
EventMachine.run {
- deferred1 = EM::Defer.new
- deferred2 = EM::Defer.new
+ deferred1 = EM::Q.defer
+ deferred2 = EM::Q.defer
- EM::Defer.all(@promise, deferred1.promise, deferred2.promise).then(proc {|result|
+ EM::Q.all(@promise, deferred1.promise, deferred2.promise).then(proc {|result|
result.should == [:foo, :bar, :baz]
EM.stop
}, @default_fail)
EM.defer { @deferred.resolve(:foo) }
@@ -464,13 +464,13 @@
end
it "should reject the derived promise if at least one of the promises in the array is rejected" do
EventMachine.run {
- deferred1 = EM::Defer.new
- deferred2 = EM::Defer.new
+ deferred1 = EM::Q.defer
+ deferred2 = EM::Q.defer
- EM::Defer.all(@promise, deferred1.promise, deferred2.promise).then(@default_fail, proc {|reason|
+ EM::Q.all(@promise, deferred1.promise, deferred2.promise).then(@default_fail, proc {|reason|
reason.should == :baz
EM.stop
})
EM.defer { @deferred.resolve(:foo) }