Permalink
Browse files

Minitest integration tests and test runner

  • Loading branch information...
1 parent 7ec4dbe commit 24a9cc747a6973dde72f3603cd48892286bb36ae @markiz markiz committed Feb 17, 2012
View
@@ -26,8 +26,9 @@ group :test do
gem 'win32console'
gem 'rspec', '~>1.3.0', :require => 'spec'
else
- gem 'rspec', '~> 2.5.0'
+ gem 'rspec', '~> 2.5.0', :require => nil
end
+ gem 'minitest', :require => nil
gem "eventmachine"
gem "cool.io", :platforms => :ruby
@@ -0,0 +1,75 @@
+require "spec_helper"
+
+describe "EventedSpec AMQP bindings" do
+ include EventedSpec::SpecHelper
+ default_timeout 0.5
+
+ def amqp_running?
+ EM.reactor_running? && !!AMQP.connection
+ end # amqp_running?
+
+
+ it "runs after amqp is connected" do
+ amqp_running?.must_equal false
+ amqp do
+ amqp_running?.must_equal true
+ done
+ end
+ amqp_running?.must_equal false
+ end
+
+ describe "hooks" do
+ def hooks
+ @hooks ||= []
+ end
+
+ before { hooks << :before }
+ em_before { hooks << :em_before }
+ amqp_before { hooks << :amqp_before }
+ amqp_after { hooks << :amqp_after }
+ em_after { hooks << :em_after }
+ after { hooks << :after }
+
+ it "execute in proper order" do
+ hooks.must_equal [:before]
+ amqp do
+ hooks.must_equal [:before, :em_before, :amqp_before]
+ done
+ end
+ hooks.must_equal [:before, :em_before, :amqp_before,
+ :amqp_after, :em_after]
+ end
+ end
+
+ describe EventedSpec::AMQPSpec do
+ include EventedSpec::AMQPSpec
+
+ it "runs after amqp is connected" do
+ amqp_running?.must_equal true
+ done
+ end
+ end
+
+ describe "actual amqp functionality" do
+ def publish_and_consume_once(queue_name="test_sink", data="data")
+ AMQP::Channel.new do |channel, _|
+ exchange = channel.direct(queue_name)
+ queue = channel.queue(queue_name).bind(exchange)
+ queue.subscribe do |hdr, msg|
+ hdr.must_be_kind_of AMQP::Header
+ msg.must_equal data
+ done { queue.unsubscribe; queue.delete }
+ end
+ EM.add_timer(0.2) do
+ exchange.publish data
+ end
+ end
+ end
+
+ it "can connect and publish something" do
+ amqp do
+ publish_and_consume_once
+ end
+ end
+ end
+end
@@ -0,0 +1,45 @@
+require 'spec_helper'
+
+describe EventedSpec do
+ describe "inclusion of helper modules" do
+ include EventedSpec::SpecHelper
+
+ it "creates reactor launchers" do
+ [:em, :amqp, :coolio].each do |method|
+ self.respond_to?(method).must_equal true
+ end
+ end
+
+ it "adds various helpers" do
+ [:done, :timeout, :delayed].each do |method|
+ self.must_respond_to method
+ end
+ end
+
+ it "creates hooks and other group helpers" do
+ [:em_before, :em_after, :amqp_before,
+ :amqp_after, :coolio_before, :coolio_after,
+ :default_timeout, :default_options].each do |method|
+ self.class.must_respond_to method
+ end
+ end
+
+ describe "propagation to sub contexts" do
+ it "should work" do
+ [:em, :amqp, :coolio].each do |method|
+ self.must_respond_to method
+ end
+
+ [:done, :timeout, :delayed].each do |method|
+ self.must_respond_to method
+ end
+
+ [:em_before, :em_after, :amqp_before,
+ :amqp_after, :coolio_before, :coolio_after,
+ :default_timeout, :default_options].each do |method|
+ self.class.must_respond_to method
+ end
+ end
+ end
+ end
+end
@@ -0,0 +1,64 @@
+require "spec_helper"
+
+if !(RUBY_PLATFORM =~ /java/)
+ describe "EventedSpec cool.io bindings" do
+ def coolio_running?
+ !!Coolio::Loop.default.instance_variable_get(:@running)
+ end # coolio_running?
+
+ include EventedSpec::SpecHelper
+ default_timeout 0.5
+
+ it "can run inside of em loop" do
+ coolio_running?.must_equal false
+ coolio do
+ coolio_running?.must_equal true
+ done
+ end
+ coolio_running?.must_equal false
+ end
+
+ describe "hooks" do
+ describe "hooks" do
+ def hooks
+ @hooks ||= []
+ end
+
+ before { hooks << :before }
+ coolio_before { hooks << :coolio_before }
+ coolio_after { hooks << :coolio_after }
+ after { hooks << :after }
+
+ it "execute in proper order" do
+ hooks.must_equal [:before]
+ coolio do
+ hooks.must_equal [:before, :coolio_before]
+ done
+ end
+ hooks.must_equal [:before, :coolio_before, :coolio_after]
+ end
+ end
+ end
+
+
+ describe "#delayed" do
+ default_timeout 0.7
+ it "works as intended" do
+ coolio do
+ time = Time.now
+ delayed(0.3) { Time.now.must_be_close_to time + 0.3, 0.1 }
+ done(0.4)
+ end
+ end
+ end
+
+ describe EventedSpec::CoolioSpec do
+ include EventedSpec::CoolioSpec
+ it "wraps the whole example" do
+ coolio_running?.must_equal true
+ done
+ end
+ end
+
+ end
+end
@@ -0,0 +1,54 @@
+require 'spec_helper'
+
+describe "EventedSpec EventMachine bindings" do
+ include EventedSpec::SpecHelper
+ default_timeout 0.5
+
+ it "can run inside of em loop" do
+ EM.reactor_running?.must_equal false
+ em do
+ EM.reactor_running?.must_equal true
+ done
+ end
+ EM.reactor_running?.must_equal false
+ end
+
+ describe "hooks" do
+ def hooks
+ @hooks ||= []
+ end
+
+ before { hooks << :before }
+ em_before { hooks << :em_before }
+ em_after { hooks << :em_after }
+ after { hooks << :after }
+
+ it "execute in proper order" do
+ hooks.must_equal [:before]
+ em do
+ hooks.must_equal [:before, :em_before]
+ done
+ end
+ hooks.must_equal [:before, :em_before, :em_after]
+ end
+ end
+
+ describe "#delayed" do
+ default_timeout 0.7
+ it "works as intended" do
+ em do
+ time = Time.now
+ delayed(0.3) { Time.now.must_be_close_to time + 0.3, 0.1 }
+ done(0.4)
+ end
+ end
+ end
+
+ describe EventedSpec::EMSpec do
+ include EventedSpec::EMSpec
+ it "wraps the whole example" do
+ EM.reactor_running?.must_equal true
+ done
+ end
+ end
+end
@@ -0,0 +1 @@
+require 'evented-spec'
View
@@ -0,0 +1,18 @@
+require 'bundler'
+Bundler.setup
+Bundler.require :default, :test
+
+spec_dir = File.expand_path("..", __FILE__)
+lib_dir = File.expand_path("../../lib", __FILE__)
+if ARGV.delete('--minitest')
+ require 'minitest/spec'
+ require 'minitest/autorun'
+ $LOAD_PATH.unshift "#{spec_dir}/minitest"
+ $LOAD_PATH.unshift lib_dir
+ Dir.glob("#{spec_dir}/**/*_minispec.rb").each {|spec| require spec }
+else
+ require 'rspec'
+ require 'rspec/autorun'
+ Dir.glob("#{spec_dir}/**/*_spec.rb").each {|spec| require spec }
+end
+

0 comments on commit 24a9cc7

Please sign in to comment.