spec/monkey_service_spec.rb in MonkeyEngine-1.1.0 vs spec/monkey_service_spec.rb in MonkeyEngine-2.0.0
- old
+ new
@@ -1,20 +1,21 @@
+# frozen_string_literal: true
+
require 'MonkeyService'
require 'MonkeyFactory'
require 'MonkeyEngine'
describe 'MonkeyService' do
-
before(:all) do
@it = MonkeyEngine::MonkeyService.instance
# Register us before we do anything, so we can be notified of everything.
@it.add_observer self
- @it.add(MonkeyFactory::create :groucho)
- @it.add(MonkeyFactory::create :harpo)
- @it.add(MonkeyFactory::create :chico)
+ @it.add(MonkeyFactory.create(:groucho))
+ @it.add(MonkeyFactory.create(:harpo))
+ @it.add(MonkeyFactory.create(:chico))
end
after(:all) do
# Kill all the threads.
@it.kill_all!
@@ -22,15 +23,15 @@
# Give them a little bit to finish.
@it.join_all(10)
end
def update(time, action, param)
- puts "Time: [#{time}], Action: [#{action}], Param: [#{param}]"
+ # puts "Time: [#{time}], Action: [#{action}], Param: [#{param}]"
+ puts "Time: [#{time}], Action: [#{action}], Param: <not shown>"
end
context 'initialization' do
-
it 'it should have 3 monkeys' do
@it.count.should == 3
end
it 'should have monkey harpo' do
@@ -42,31 +43,29 @@
end
it 'should have monkey chico' do
@it.exists?(:chico).should == true
end
-
end
context 'methods' do
-
it "'get' should raise an exception if invalid argument type is sent" do
- lambda { @it.get(999) }.should raise_exception MonkeyEngine::Exceptions::InvalidArgumentTypeException
+ -> { @it.get(999) }.should raise_exception MonkeyEngine::Exceptions::InvalidArgumentTypeException
end
it "'add' should raise an exception if adding a non-unique object" do
- lambda { @it.add(MonkeyFactory::create :chico) }.should raise_exception MonkeyEngine::Exceptions::UniqueObjectException
+ lambda {
+ @it.add(MonkeyFactory.create(:chico))
+ }.should raise_exception MonkeyEngine::Exceptions::UniqueObjectException
end
it "'any_alive?' should return objects that are alive" do
@it.any_alive?.should == true
end
-
end
context 'clean up' do
-
it 'no monkeys should be alive if killed by the service' do
# Kill all the threads.
@it.kill_all!
# Give them a little bit to finish.
@@ -76,21 +75,19 @@
end
it 'kill_all! should return all monkeys killed' do
monkey_service = MonkeyEngine::MonkeyService.instance
- monkey_service.add(MonkeyFactory::create :a)
- monkey_service.add(MonkeyFactory::create :b)
- monkey_service.add(MonkeyFactory::create :c)
+ monkey_service.add(MonkeyFactory.create(:a))
+ monkey_service.add(MonkeyFactory.create(:b))
+ monkey_service.add(MonkeyFactory.create(:c))
monkeys = monkey_service.get_all
killed_monkeys = monkey_service.kill_all!
monkey_service.join_all(10)
(monkeys == killed_monkeys).should == true
end
-
end
-
-end
\ No newline at end of file
+end