Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rspec 2 support added

  • Loading branch information...
commit c5a223dc8cda9bec8a1d1ccb62817ba0b1eee190 1 parent f7aa93e
@arvicco arvicco authored
View
2  .bundle/config
@@ -0,0 +1,2 @@
+---
+BUNDLE_DISABLE_SHARED_GEMS: "1"
View
2  .rspec
@@ -0,0 +1,2 @@
+--color
+--format nested
View
4 Gemfile
@@ -3,6 +3,6 @@ source :gemcutter
gem 'amqp'
group :test do
- gem 'rspec', '~>1.3.0'
+ gem 'rspec', '~>2.0.0'
+# gem 'rspec', '~>1.3.0', require: 'spec'
end
-
View
24 Gemfile.lock
@@ -0,0 +1,24 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ amqp (0.6.7)
+ eventmachine (>= 0.12.4)
+ diff-lcs (1.1.2)
+ eventmachine (0.12.11)
+ rspec (2.0.1)
+ rspec-core (~> 2.0.1)
+ rspec-expectations (~> 2.0.1)
+ rspec-mocks (~> 2.0.1)
+ rspec-core (2.0.1)
+ rspec-expectations (2.0.1)
+ diff-lcs (>= 1.1.2)
+ rspec-mocks (2.0.1)
+ rspec-core (~> 2.0.1)
+ rspec-expectations (~> 2.0.1)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ amqp
+ rspec (~> 2.0.0)
View
4 HISTORY
@@ -61,3 +61,7 @@
== 0.1.13 / 2010-10-23
* Release
+
+== 0.2.0 / 2010-10-28
+
+* Rspec 2 support added
View
2  VERSION
@@ -1 +1 @@
-0.1.13
+0.2.0
View
35 lib/amqp-spec/rspec.rb
@@ -55,25 +55,42 @@ module SpecHelper
SpecTimeoutExceededError = Class.new(RuntimeError)
def self.included(example_group)
- ::Spec::Example::ExampleGroup.instance_exec do
- unless defined? default_spec_timeout
+# unless defined? self.default_timeout
+ if defined?(RSpec)
+ example_group.instance_exec do
+ metadata[:em_default_options] = {}
+ metadata[:em_default_timeout] = nil
+
+ def self.default_timeout(spec_timeout=nil)
+ metadata[:em_default_timeout] = spec_timeout if spec_timeout
+ metadata[:em_default_timeout]
+ end
+
+ def self.default_options(opts=nil)
+ metadata[:em_default_options] = opts if opts
+ metadata[:em_default_options]
+ end
+ end
+ else
+ ::Spec::Example::ExampleGroup.instance_exec do
@@_em_default_options = {}
@@_em_default_timeout = nil
- def self.default_spec_timeout(spec_timeout=nil)
+ def self.default_timeout(spec_timeout=nil)
@@_em_default_timeout = spec_timeout if spec_timeout
@@_em_default_timeout
end
- alias default_timeout default_spec_timeout
-
def self.default_options(opts=nil)
@@_em_default_options = opts if opts
@@_em_default_options
end
end
+
+# end
end
+
end
# Yields to given block inside EM.run and AMQP.start loops. This method takes any option that is
@@ -88,12 +105,12 @@ def self.default_options(opts=nil)
# if something goes wrong and EM/AMQP loop hangs for some reason. SpecTimeoutExceededError is raised.
#
def amqp opts={}, &block
- opts = @@_em_default_options.merge opts
+ opts = self.class.default_options.merge opts
begin
EM.run do
@_em_spec_with_amqp = true
@_em_spec_exception = nil
- spec_timeout = opts.delete(:spec_timeout) || @@_em_default_timeout
+ spec_timeout = opts.delete(:spec_timeout) || self.class.default_timeout
timeout(spec_timeout) if spec_timeout
@_em_spec_fiber = Fiber.new do
begin
@@ -117,8 +134,8 @@ def amqp opts={}, &block
# Yields to block inside EM loop, :spec_timeout option (in seconds) is used to force spec to timeout
# if something goes wrong and EM/AMQP loop hangs for some reason. SpecTimeoutExceededError is raised.
- def em(spec_timeout = @@_em_default_timeout, &block)
- spec_timeout = spec_timeout[:spec_timeout] || @@_em_default_timeout if spec_timeout.is_a?(Hash)
+ def em(spec_timeout = self.class.default_timeout, &block)
+ spec_timeout = spec_timeout[:spec_timeout] || self.class.default_timeout if spec_timeout.is_a?(Hash)
EM.run do
@_em_spec_with_amqp = false
@_em_spec_exception = nil
View
14 spec/failing_rspec_spec.rb
@@ -1,6 +1,6 @@
-require_relative 'spec_helper.rb'
+require 'spec_helper'
-context 'Following examples should all be failing:' do
+describe 'Following examples should all be failing:' do
describe EventMachine, " when running failing examples" do
include AMQP::EMSpec
@@ -17,8 +17,12 @@
end
describe EventMachine, " when testing with AMQP::EMSpec with a maximum execution time per test" do
-
include AMQP::EMSpec
+
+ # For RSpec 1, default_timeout and default_options are global
+ # For RSpec 2, default_timeout and default_options are example-group local, inheritable by nested groups
+ default_timeout 1
+
it 'should timeout before reaching done' do
EM.add_timer(2) { done }
end
@@ -33,7 +37,9 @@
include AMQP::Spec
- default_timeout 1 # Because we may need to run this spec file separately
+ # For RSpec 1, default_timeout and default_options are global
+ # For RSpec 2, default_timeout and default_options are example-group local, inheritable by nested groups
+ default_timeout 1
it 'should timeout before reaching done' do
EM.add_timer(2) { done }
View
2  spec/problematic_rspec_spec.rb
@@ -1,5 +1,5 @@
require_relative 'spec_helper.rb'
-context '!!!!!!!!! LEAKING OR PROBLEMATIC EXAMPLES !!!!!!!!!' do
+describe '!!!!!!!!! LEAKING OR PROBLEMATIC EXAMPLES !!!!!!!!!' do
end
View
20 spec/rspec_amqp_spec.rb
@@ -1,11 +1,5 @@
require_relative 'spec_helper.rb'
-describe 'Rspec' do
- it 'should work as normal without AMQP-Spec' do
- 1.should == 1
- end
-end
-
def publish_and_consume_once(queue_name="test_sink", data="data")
amqp do
q = MQ.queue(queue_name)
@@ -20,7 +14,13 @@ def publish_and_consume_once(queue_name="test_sink", data="data")
end
end
-context 'Evented AMQP specs' do
+describe RSPEC do
+ it 'should work as normal without AMQP-Spec' do
+ 1.should == 1
+ end
+end
+
+describe 'Evented AMQP specs' do
describe AMQP, " when testing with AMQP::SpecHelper" do
include AMQP::SpecHelper
@@ -55,7 +55,7 @@ def publish_and_consume_once(queue_name="test_sink", data="data")
amqp do
:this.should == :fail
end
- }.to raise_error Spec::Expectations::ExpectationNotMetError
+ }.to raise_error RSPEC::Expectations::ExpectationNotMetError
AMQP.conn.should == nil
end
@@ -65,7 +65,7 @@ def publish_and_consume_once(queue_name="test_sink", data="data")
done
:this.should == :fail
end
- }.to raise_error Spec::Expectations::ExpectationNotMetError
+ }.to raise_error RSPEC::Expectations::ExpectationNotMetError
AMQP.conn.should == nil
end
@@ -91,7 +91,7 @@ def publish_and_consume_once(queue_name="test_sink", data="data")
end
end
-describe "Rspec", " when running an example group after another group that uses AMQP-Spec " do
+describe RSPEC, " when running an example group after another group that uses AMQP-Spec " do
it "should work normally" do
:does_not_hang.should_not be_false
end
View
4 spec/rspec_em_spec.rb
@@ -1,6 +1,6 @@
require_relative 'spec_helper.rb'
-context 'Plain EM, no AMQP' do
+describe 'Plain EM, no AMQP' do
describe EventMachine, " when testing with AMQP::SpecHelper" do
include AMQP::SpecHelper
@@ -46,7 +46,7 @@
end
end
-describe "Rspec", " when running an example group after groups that uses EM specs " do
+describe RSPEC, " when running an example group after groups that uses EM specs " do
it "should work normally" do
:does_not_hang.should_not be_false
end
View
83 spec/shared_examples.rb
@@ -61,48 +61,6 @@
it_should_behave_like 'timeout examples'
end
-shared_examples_for 'Spec examples' do
- after do
- EM.reactor_running?.should == true
-# AMQP.conn.should be_nil # You're inside running amqp block, stupid!
- done
- end
-
- 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)
- done
- }
- end
-
- it 'should have periodic timers' do
- num = 0
- start = Time.now
-
- timer = EM.add_periodic_timer(0.25) {
- if (num += 1) == 2
- (Time.now-start).should be_close(0.5, 0.1)
- EM.cancel_timer timer
- done
- end
- }
- end
-
- it 'should have deferrables' do
- defr = EM::DefaultDeferrable.new
- defr.timeout(0.5)
- defr.errback {
- done
- }
- end
-end
-
shared_examples_for 'done examples' do
it 'should yield to block given to done (when amqp is used)' do
@@ -138,7 +96,6 @@
end
end
-
shared_examples_for 'timeout examples' do
before { @start = Time.now }
@@ -175,4 +132,44 @@
end
end
+shared_examples_for 'Spec examples' do
+ after do
+ EM.reactor_running?.should == true
+# AMQP.conn.should be_nil # You're inside running amqp block, stupid!
+ done
+ end
+
+ it 'should work' do
+ done
+ end
+
+ it 'should have timers' do
+ start = Time.now
+
+ EM.add_timer(0.25) {
+ (Time.now-start).should be_close(0.25, 0.1)
+ done
+ }
+ end
+
+ it 'should have periodic timers' do
+ num = 0
+ start = Time.now
+ timer = EM.add_periodic_timer(0.25) {
+ if (num += 1) == 2
+ (Time.now-start).should be_close(0.5, 0.1)
+ EM.cancel_timer timer
+ done
+ end
+ }
+ end
+
+ it 'should have deferrables' do
+ defr = EM::DefaultDeferrable.new
+ defr.timeout(0.25)
+ defr.errback {
+ done
+ }
+ end
+end
View
13 spec/spec_helper.rb
@@ -1,17 +1,18 @@
-#$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
-
$LOAD_PATH << "." unless $LOAD_PATH.include? "." # moronic 1.9.2 breaks things bad
-require 'spec'
-require 'yaml'
+require 'bundler'
+Bundler.setup
+Bundler.require :test
+require 'yaml'
require 'amqp-spec/rspec'
require 'shared_examples'
-#require File.join(File.dirname(__FILE__), '..', 'lib', 'amqp-spec', 'rspec.rb')
+
+RSPEC = defined?(RSpec) ? RSpec : Spec
amqp_config = File.dirname(__FILE__) + '/amqp.yml'
-if File.exists? amqp_config
+if File.exists? amqp_config
class Hash
def symbolize_keys
self.inject({}) { |result, (key, value)|
View
10 tasks/spec.rake
@@ -2,17 +2,13 @@ desc 'Alias to spec:spec'
task :spec => 'spec:spec'
namespace :spec do
- require 'spec/rake/spectask'
+ require 'rspec/core/rake_task'
desc "Run all specs"
- Spec::Rake::SpecTask.new(:spec) do |t|
- t.spec_opts = ['--options', %Q{"#{BASE_PATH}/spec/spec.opts"}]
- t.spec_files = FileList['spec/**/*_spec.rb']
- end
+ RSpec::Core::RakeTask.new(:spec){|task|}
desc "Run specs with RCov"
- Spec::Rake::SpecTask.new(:rcov) do |t|
- t.spec_files = FileList['spec/**/*_spec.rb']
+ RSpec::Core::RakeTask.new(:rcov) do |t|
t.rcov = true
t.rcov_opts = ['--exclude', 'spec']
end
Please sign in to comment.
Something went wrong with that request. Please try again.