amqp-spec 0.3.7 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
 - data/HISTORY +4 -0
 - data/README.rdoc +63 -40
 - data/VERSION +1 -1
 - data/lib/amqp-spec.rb +3 -21
 - data/lib/amqp-spec/em_spec_shim.rb +6 -0
 - data/lib/amqp-spec/evented_example.rb +6 -6
 - data/lib/amqp-spec/rspec.rb +18 -22
 - data/spec/em_hooks_spec.rb +8 -6
 - data/spec/em_legacy_spec.rb +5 -3
 - data/spec/rspec_em_spec.rb +3 -3
 - data/spec/shared_examples.rb +11 -11
 - data/spec/spec_helper.rb +29 -24
 - metadata +4 -5
 - data/spec/problematic_rspec_spec.rb +0 -7
 
    
        data/.gitignore
    CHANGED
    
    
    
        data/HISTORY
    CHANGED
    
    
    
        data/README.rdoc
    CHANGED
    
    | 
         @@ -1,10 +1,11 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            = amqp-spec
         
     | 
| 
       2 
2 
     | 
    
         
             
            by: Arvicco
         
     | 
| 
       3 
     | 
    
         
            -
            url: http://github.com/ 
     | 
| 
      
 3 
     | 
    
         
            +
            url: http://github.com/ruby-amqp/amqp-spec
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            == Summary
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
            Simple API for writing asynchronous EventMachine/AMQP specs. Supports RSpec and RSpec2.
         
     | 
| 
      
 8 
     | 
    
         
            +
            Should work under MRI 1.8.7, 1.9.2 (and JRuby 1.6.0 - work in progress!)
         
     | 
| 
       8 
9 
     | 
    
         | 
| 
       9 
10 
     | 
    
         
             
            == Description
         
     | 
| 
       10 
11 
     | 
    
         | 
| 
         @@ -21,17 +22,17 @@ has several drawbacks. First, it is not easy to manage both EM.run and AMQP.star 
     | 
|
| 
       21 
22 
     | 
    
         
             
            at the same time. Second, AMQP is not properly stopped and deactivated upon exceptions and
         
     | 
| 
       22 
23 
     | 
    
         
             
            timeouts, resulting in state leak between examples and multiple mystereous failures.
         
     | 
| 
       23 
24 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
            AMQP-Spec is based on EM-Spec code but  
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
      
 25 
     | 
    
         
            +
            AMQP-Spec is based on EM-Spec code but extends it to support AMQP event loops (as well as
         
     | 
| 
      
 26 
     | 
    
         
            +
            RSpec2). API is very similar to EM-Spec's, only a bit extended. The final goal is to
         
     | 
| 
       26 
27 
     | 
    
         
             
            make writing AMQP specs reasonably pleasant experience and dispel the notion that evented
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
      
 28 
     | 
    
         
            +
            libs are impossible to unit-test.
         
     | 
| 
       28 
29 
     | 
    
         | 
| 
       29 
30 
     | 
    
         
             
            Mind you, you still have to properly manage your AMQP broker in order to prevent broker
         
     | 
| 
       30 
31 
     | 
    
         
             
            state from leaking between examples. You can try to combine AMQP-Spec and
         
     | 
| 
       31 
32 
     | 
    
         
             
            Moqueue[http://github.com/danielsdeleo/moqueue] if you want to abstract away actual broker
         
     | 
| 
       32 
33 
     | 
    
         
             
            interactions, but still specify some event-based expectations.
         
     | 
| 
       33 
34 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
            ==Rspec
         
     | 
| 
      
 35 
     | 
    
         
            +
            == Rspec
         
     | 
| 
       35 
36 
     | 
    
         | 
| 
       36 
37 
     | 
    
         
             
            There are several ways to use amqp-spec. To use it as a helper, include AMQP::SpecHelper
         
     | 
| 
       37 
38 
     | 
    
         
             
            in your describe block. You then use either #amqp or #em methods to wrap your evented
         
     | 
| 
         @@ -50,9 +51,9 @@ In order to setup/teardown EM state before/after your examples, you'll need to u 
     | 
|
| 
       50 
51 
     | 
    
         
             
            If you are using #amqp method, *em_before* hook will run just BEFORE AMQP connection is
         
     | 
| 
       51 
52 
     | 
    
         
             
            attempted, and *em_after* is run after AMQP is stopped.
         
     | 
| 
       52 
53 
     | 
    
         | 
| 
       53 
     | 
    
         
            -
            Sometimes, may want to setup/teardown state inside AMQP connection (inside block given 
     | 
| 
       54 
     | 
    
         
            -
            AMQP.start): for example, to make sure that the connection is established before your
         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
      
 54 
     | 
    
         
            +
            Sometimes, you may want to setup/teardown state inside AMQP connection (inside block given
         
     | 
| 
      
 55 
     | 
    
         
            +
            to AMQP.start): for example, to make sure that the connection is established before your
         
     | 
| 
      
 56 
     | 
    
         
            +
            examples run, or to pre-declare some queues and exchanges common for all examples.
         
     | 
| 
       56 
57 
     | 
    
         
             
            In this case, please use *amqp_before* and *amqp_after* hooks. These hooks run inside
         
     | 
| 
       57 
58 
     | 
    
         
             
            the AMQP.start block just before/after your example block.
         
     | 
| 
       58 
59 
     | 
    
         | 
| 
         @@ -61,11 +62,20 @@ the AMQP.start block just before/after your example block. 
     | 
|
| 
       61 
62 
     | 
    
         
             
              describe AMQP do
         
     | 
| 
       62 
63 
     | 
    
         
             
                include AMQP::SpecHelper
         
     | 
| 
       63 
64 
     | 
    
         | 
| 
       64 
     | 
    
         
            -
                default_options = {:host => 'my.amqp.broker.org', :port => '21118'}
         
     | 
| 
       65 
65 
     | 
    
         
             
                # Can be used to set default options for your amqp{} event loops
         
     | 
| 
      
 66 
     | 
    
         
            +
                default_options {:host => 'my.amqp.broker.org', :port => '21118'}
         
     | 
| 
       66 
67 
     | 
    
         | 
| 
       67 
     | 
    
         
            -
                default_timeout = 1
         
     | 
| 
       68 
68 
     | 
    
         
             
                # Can be used to set default :spec_timeout for your evented specs
         
     | 
| 
      
 69 
     | 
    
         
            +
                default_timeout 1
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
                # Runs inside the EM event loop before each block given to #amqp or #em
         
     | 
| 
      
 72 
     | 
    
         
            +
                em_before { @start = Time.now }
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
                # Runs inside the AMQP.start before each block given to #amqp
         
     | 
| 
      
 75 
     | 
    
         
            +
                amqp_before do
         
     | 
| 
      
 76 
     | 
    
         
            +
                  @channel = AMQP::Channel.new
         
     | 
| 
      
 77 
     | 
    
         
            +
                  @queue = @channel.queue('my_queue')
         
     | 
| 
      
 78 
     | 
    
         
            +
                end
         
     | 
| 
       69 
79 
     | 
    
         | 
| 
       70 
80 
     | 
    
         
             
                it "works normally when not using #amqp or #em" do
         
     | 
| 
       71 
81 
     | 
    
         
             
                  1.should == 1
         
     | 
| 
         @@ -73,10 +83,8 @@ the AMQP.start block just before/after your example block. 
     | 
|
| 
       73 
83 
     | 
    
         | 
| 
       74 
84 
     | 
    
         
             
                it "makes testing evented code easy with #em" do
         
     | 
| 
       75 
85 
     | 
    
         
             
                  em do
         
     | 
| 
       76 
     | 
    
         
            -
                    start = Time.now
         
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
86 
     | 
    
         
             
                    EM.add_timer(0.5){
         
     | 
| 
       79 
     | 
    
         
            -
                      (Time.now-start).should be_close( 0.5, 0.1 )
         
     | 
| 
      
 87 
     | 
    
         
            +
                      (Time.now - @start).should be_close( 0.5, 0.1 )
         
     | 
| 
       80 
88 
     | 
    
         
             
                      done
         
     | 
| 
       81 
89 
     | 
    
         
             
                    }
         
     | 
| 
       82 
90 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -85,13 +93,16 @@ the AMQP.start block just before/after your example block. 
     | 
|
| 
       85 
93 
     | 
    
         
             
                it "runs AMQP.start loop with options given to #amqp" do
         
     | 
| 
       86 
94 
     | 
    
         
             
                  amqp(:host => 'my.amqp.broker.org', :port => '21118')do
         
     | 
| 
       87 
95 
     | 
    
         
             
                    AMQP.conn.should be_connected
         
     | 
| 
      
 96 
     | 
    
         
            +
                    @queue.name.should == 'my_queue'
         
     | 
| 
       88 
97 
     | 
    
         
             
                    done
         
     | 
| 
       89 
98 
     | 
    
         
             
                  end
         
     | 
| 
       90 
99 
     | 
    
         
             
                end
         
     | 
| 
       91 
100 
     | 
    
         | 
| 
       92 
101 
     | 
    
         
             
                it "optionally raises timeout exception if your loop hangs for some reason" do
         
     | 
| 
       93 
102 
     | 
    
         
             
                  proc {
         
     | 
| 
       94 
     | 
    
         
            -
                    amqp(:spec_timeout => 0.5) 
     | 
| 
      
 103 
     | 
    
         
            +
                    amqp(:spec_timeout => 0.5) do
         
     | 
| 
      
 104 
     | 
    
         
            +
                    # no done!
         
     | 
| 
      
 105 
     | 
    
         
            +
                    end
         
     | 
| 
       95 
106 
     | 
    
         
             
                  }.should raise_error SpecTimeoutExceededError
         
     | 
| 
       96 
107 
     | 
    
         
             
                end
         
     | 
| 
       97 
108 
     | 
    
         | 
| 
         @@ -106,17 +117,16 @@ tear down using these hooks will be lost as example itself will run in a differe 
     | 
|
| 
       106 
117 
     | 
    
         | 
| 
       107 
118 
     | 
    
         
             
            In short, you should avoid using *before*/*after* if you include AMQP::Spec - instead, use
         
     | 
| 
       108 
119 
     | 
    
         
             
            *em_before*/*em_after* or *amqp_before*/*amqp_after* hooks that run inside the EM event
         
     | 
| 
       109 
     | 
    
         
            -
            loop.
         
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
       111 
     | 
    
         
            -
            One more note: you don't need to call #done inside evented hooks, otherwise it'll shut down
         
     | 
| 
       112 
     | 
    
         
            -
            the EM reactor.
         
     | 
| 
      
 120 
     | 
    
         
            +
            loop. You don't need to call #done inside these evented hooks, otherwise you'll shut down
         
     | 
| 
      
 121 
     | 
    
         
            +
            the EM reactor before your example runs.
         
     | 
| 
       113 
122 
     | 
    
         | 
| 
      
 123 
     | 
    
         
            +
              require 'amqp-spec'
         
     | 
| 
       114 
124 
     | 
    
         | 
| 
       115 
125 
     | 
    
         
             
              describe AMQP do
         
     | 
| 
       116 
126 
     | 
    
         
             
                include AMQP::Spec
         
     | 
| 
       117 
127 
     | 
    
         | 
| 
       118 
     | 
    
         
            -
                default_options  
     | 
| 
       119 
     | 
    
         
            -
                default_timeout  
     | 
| 
      
 128 
     | 
    
         
            +
                default_options {:host => 'my.amqp.broker.org', :port => '21118'}
         
     | 
| 
      
 129 
     | 
    
         
            +
                default_timeout 1
         
     | 
| 
       120 
130 
     | 
    
         | 
| 
       121 
131 
     | 
    
         
             
                em_before { @start = Time.now }
         
     | 
| 
       122 
132 
     | 
    
         | 
| 
         @@ -128,7 +138,7 @@ the EM reactor. 
     | 
|
| 
       128 
138 
     | 
    
         
             
                it "runs test code in an amqp block automatically" do
         
     | 
| 
       129 
139 
     | 
    
         | 
| 
       130 
140 
     | 
    
         
             
                  EM.add_timer(0.5){
         
     | 
| 
       131 
     | 
    
         
            -
                    (Time.now 
     | 
| 
      
 141 
     | 
    
         
            +
                    (Time.now - @start).should be_close( 0.5, 0.1 )
         
     | 
| 
       132 
142 
     | 
    
         
             
                    done
         
     | 
| 
       133 
143 
     | 
    
         
             
                  }
         
     | 
| 
       134 
144 
     | 
    
         
             
                end
         
     | 
| 
         @@ -139,14 +149,16 @@ the EM reactor. 
     | 
|
| 
       139 
149 
     | 
    
         
             
                end
         
     | 
| 
       140 
150 
     | 
    
         | 
| 
       141 
151 
     | 
    
         
             
                it "raises timeout exception ONLY if default_timeout was set" do
         
     | 
| 
       142 
     | 
    
         
            -
                  proc 
     | 
| 
      
 152 
     | 
    
         
            +
                  proc do
         
     | 
| 
      
 153 
     | 
    
         
            +
                    # no done!
         
     | 
| 
      
 154 
     | 
    
         
            +
                    end.should raise_error SpecTimeoutExceededError
         
     | 
| 
       143 
155 
     | 
    
         
             
                end
         
     | 
| 
       144 
156 
     | 
    
         
             
              end
         
     | 
| 
       145 
157 
     | 
    
         | 
| 
       146 
158 
     | 
    
         
             
            Finally, you can include AMQP::EMSpec in your describe block. This will run all the group
         
     | 
| 
       147 
159 
     | 
    
         
             
            examples inside em block instead of amqp. Non-evented *before*/*after* hooks should be
         
     | 
| 
       148 
160 
     | 
    
         
             
            finished with #done, same as when including AMQP::Spec, and same caution about using them
         
     | 
| 
       149 
     | 
    
         
            -
            applies.
         
     | 
| 
      
 161 
     | 
    
         
            +
            applies - use *em_before*/*em_after* instead.
         
     | 
| 
       150 
162 
     | 
    
         | 
| 
       151 
163 
     | 
    
         
             
              describe AMQP do
         
     | 
| 
       152 
164 
     | 
    
         
             
                include AMQP::EMSpec
         
     | 
| 
         @@ -168,16 +180,7 @@ applies. 
     | 
|
| 
       168 
180 
     | 
    
         
             
                end
         
     | 
| 
       169 
181 
     | 
    
         
             
              end
         
     | 
| 
       170 
182 
     | 
    
         | 
| 
       171 
     | 
    
         
            -
             
     | 
| 
       172 
     | 
    
         
            -
            ==Bacon
         
     | 
| 
       173 
     | 
    
         
            -
             
     | 
| 
       174 
     | 
    
         
            -
            ...
         
     | 
| 
       175 
     | 
    
         
            -
             
     | 
| 
       176 
     | 
    
         
            -
            ==Test::Unit
         
     | 
| 
       177 
     | 
    
         
            -
             
     | 
| 
       178 
     | 
    
         
            -
            ...
         
     | 
| 
       179 
     | 
    
         
            -
             
     | 
| 
       180 
     | 
    
         
            -
            ==General notes
         
     | 
| 
      
 183 
     | 
    
         
            +
            == General notes
         
     | 
| 
       181 
184 
     | 
    
         | 
| 
       182 
185 
     | 
    
         
             
            For a developer new to evented specs, it is not easy to internalize that the blocks given
         
     | 
| 
       183 
186 
     | 
    
         
             
            to asynchronous methods are turned into real callbacks, intended to fire some time later.
         
     | 
| 
         @@ -193,7 +196,8 @@ Take the following spec as an example: 
     | 
|
| 
       193 
196 
     | 
    
         
             
                    msg.should_not == 'data'
         
     | 
| 
       194 
197 
     | 
    
         
             
                  end
         
     | 
| 
       195 
198 
     | 
    
         
             
                  MQ.queue('queue_name').publish 'data'
         
     | 
| 
       196 
     | 
    
         
            -
                  q.unsubscribe 
     | 
| 
      
 199 
     | 
    
         
            +
                  q.unsubscribe
         
     | 
| 
      
 200 
     | 
    
         
            +
                  q.delete
         
     | 
| 
       197 
201 
     | 
    
         
             
                  done
         
     | 
| 
       198 
202 
     | 
    
         
             
                end
         
     | 
| 
       199 
203 
     | 
    
         
             
              end
         
     | 
| 
         @@ -232,19 +236,38 @@ Something like this will do the trick: 
     | 
|
| 
       232 
236 
     | 
    
         
             
                @subscribe_fired.should be_true
         
     | 
| 
       233 
237 
     | 
    
         
             
              end
         
     | 
| 
       234 
238 
     | 
    
         | 
| 
       235 
     | 
    
         
            -
            == 
     | 
| 
      
 239 
     | 
    
         
            +
            == Legacy EM-Spec based specs support
         
     | 
| 
      
 240 
     | 
    
         
            +
             
     | 
| 
      
 241 
     | 
    
         
            +
            In order to run your existing EM-Spec based specs unmodified, instead of require 'em-spec':
         
     | 
| 
      
 242 
     | 
    
         
            +
             
     | 
| 
      
 243 
     | 
    
         
            +
              require 'amqp-spec'
         
     | 
| 
      
 244 
     | 
    
         
            +
              require 'amqp-spec/em_spec_shim'
         
     | 
| 
      
 245 
     | 
    
         
            +
             
     | 
| 
      
 246 
     | 
    
         
            +
            Please note that in amqp-spec default options and default timeout are local for each
         
     | 
| 
      
 247 
     | 
    
         
            +
            example group and inherited by its nested groups, unconnected example groups DO NOT
         
     | 
| 
      
 248 
     | 
    
         
            +
            share defaults. This is different from EM-Spec where default_timeout is effectively
         
     | 
| 
      
 249 
     | 
    
         
            +
            a global setting. So please make sure you're setting default_timeout early on,
         
     | 
| 
      
 250 
     | 
    
         
            +
            in your outermost example group in order to get same behavior as in EM-Spec.
         
     | 
| 
      
 251 
     | 
    
         
            +
             
     | 
| 
      
 252 
     | 
    
         
            +
            == Extending library to spec other types of event loops
         
     | 
| 
      
 253 
     | 
    
         
            +
             
     | 
| 
      
 254 
     | 
    
         
            +
            AMQP-Spec extends EM-Spec code to cover different types of event loops.
         
     | 
| 
      
 255 
     | 
    
         
            +
            Initially, vanilla EM and AMQP event loops are supported, but the lib can be extended
         
     | 
| 
      
 256 
     | 
    
         
            +
            quite easily to spec any other type of event loop, not necesarily EM-based (such as
         
     | 
| 
      
 257 
     | 
    
         
            +
            Cool.io, ZMQMachine and whatnot). All you need to do is just write appropriate
         
     | 
| 
      
 258 
     | 
    
         
            +
            EventedExample subclass (with minimal interface of just #run and #done to start and
         
     | 
| 
      
 259 
     | 
    
         
            +
            stop your loop) and RSpec wrapper for it similar to SpecHelper#em or SpecHelper#amqp.
         
     | 
| 
      
 260 
     | 
    
         
            +
            You can then call your wrapper in RSpec examples in a way similar to #em or #amqp.
         
     | 
| 
      
 261 
     | 
    
         
            +
             
     | 
| 
      
 262 
     | 
    
         
            +
            == Limitations
         
     | 
| 
       236 
263 
     | 
    
         | 
| 
       237 
264 
     | 
    
         
             
            AMQP-Spec can be currently used with Rspec only. I suppose, it is not that difficult to
         
     | 
| 
       238 
265 
     | 
    
         
             
            extend EM-Spec's Test::Unit and Bacon support, I just do not have experience doing it.
         
     | 
| 
       239 
266 
     | 
    
         | 
| 
       240 
     | 
    
         
            -
            Another limitation, library uses 1.9 syntax and therefore not compatible with Ruby 1.8.
         
     | 
| 
       241 
     | 
    
         
            -
            Again, it seems possible to rewrite it in 1.8-compatible style, with string evals and
         
     | 
| 
       242 
     | 
    
         
            -
            all such, but I'd rather leave this work to someone else.
         
     | 
| 
       243 
     | 
    
         
            -
             
     | 
| 
       244 
267 
     | 
    
         
             
            Any help improving this library is greatly appreciated...
         
     | 
| 
       245 
268 
     | 
    
         | 
| 
       246 
269 
     | 
    
         
             
            == LICENSE:
         
     | 
| 
       247 
     | 
    
         
            -
            Copyright (c) 2010 Arvicco.
         
     | 
| 
      
 270 
     | 
    
         
            +
            Copyright (c) 2010-2011 Arvicco.
         
     | 
| 
       248 
271 
     | 
    
         
             
            Original EM-Spec code copyright (c) 2008 Aman Gupta (tmm1)
         
     | 
| 
       249 
272 
     | 
    
         | 
| 
       250 
273 
     | 
    
         
             
            See LICENSE for details.
         
     | 
    
        data/VERSION
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            0.3. 
     | 
| 
      
 1 
     | 
    
         
            +
            0.3.8
         
     | 
    
        data/lib/amqp-spec.rb
    CHANGED
    
    | 
         @@ -1,24 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'version'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
                # Requires ruby source file(s). Accepts either single filename/glob or Array of filenames/globs.
         
     | 
| 
       7 
     | 
    
         
            -
                # Accepts following options:
         
     | 
| 
       8 
     | 
    
         
            -
                # :*file*:: Lib(s) required relative to this file - defaults to __FILE__
         
     | 
| 
       9 
     | 
    
         
            -
                # :*dir*:: Required lib(s) located under this dir name - defaults to gem name
         
     | 
| 
       10 
     | 
    
         
            -
                #
         
     | 
| 
       11 
     | 
    
         
            -
                def self.require_libs(libs, opts={})
         
     | 
| 
       12 
     | 
    
         
            -
                  file = Pathname.new(opts[:file] || __FILE__)
         
     | 
| 
       13 
     | 
    
         
            -
                  [libs].flatten.each do |lib|
         
     | 
| 
       14 
     | 
    
         
            -
                    name = file.dirname + (opts[:dir] || file.basename('.*')) + lib.gsub(/(?<!.rb)$/, '.rb')
         
     | 
| 
       15 
     | 
    
         
            -
                    Pathname.glob(name.to_s).sort.each { |rb| require rb }
         
     | 
| 
       16 
     | 
    
         
            -
                  end
         
     | 
| 
       17 
     | 
    
         
            -
                end
         
     | 
| 
       18 
     | 
    
         
            -
              end
         
     | 
| 
       19 
     | 
    
         
            -
            end
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
            # Require all ruby source files located under directory lib/amqp-spec
         
     | 
| 
       22 
     | 
    
         
            -
            # If you need files in specific order, you should specify it here before the glob
         
     | 
| 
       23 
     | 
    
         
            -
            AMQP::Spec.require_libs %W[rspec]
         
     | 
| 
      
 3 
     | 
    
         
            +
            __dir = File.expand_path(File.dirname(__FILE__))
         
     | 
| 
      
 4 
     | 
    
         
            +
            $:.unshift(__dir) unless $:.include?(__dir)
         
     | 
| 
       24 
5 
     | 
    
         | 
| 
      
 6 
     | 
    
         
            +
            require "amqp-spec/rspec"
         
     | 
| 
         @@ -8,7 +8,7 @@ module AMQP 
     | 
|
| 
       8 
8 
     | 
    
         
             
                class EventedExample
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
                  # Create new evented example
         
     | 
| 
       11 
     | 
    
         
            -
                  def initialize 
     | 
| 
      
 11 
     | 
    
         
            +
                  def initialize(opts, example_group_instance, &block)
         
     | 
| 
       12 
12 
     | 
    
         
             
                    @opts, @example_group_instance, @block = opts, example_group_instance, block
         
     | 
| 
       13 
13 
     | 
    
         
             
                  end
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
         @@ -30,7 +30,7 @@ module AMQP 
     | 
|
| 
       30 
30 
     | 
    
         
             
                  #
         
     | 
| 
       31 
31 
     | 
    
         
             
                  # Please redefine it inside descendant class and call super.
         
     | 
| 
       32 
32 
     | 
    
         
             
                  #
         
     | 
| 
       33 
     | 
    
         
            -
                  def done 
     | 
| 
      
 33 
     | 
    
         
            +
                  def done(delay=nil, &block)
         
     | 
| 
       34 
34 
     | 
    
         
             
                    if delay
         
     | 
| 
       35 
35 
     | 
    
         
             
                      EM.add_timer delay, &block
         
     | 
| 
       36 
36 
     | 
    
         
             
                    else
         
     | 
| 
         @@ -40,7 +40,7 @@ module AMQP 
     | 
|
| 
       40 
40 
     | 
    
         | 
| 
       41 
41 
     | 
    
         
             
                  # Runs hooks of specified type (hopefully, inside the event loop)
         
     | 
| 
       42 
42 
     | 
    
         
             
                  #
         
     | 
| 
       43 
     | 
    
         
            -
                  def run_em_hooks 
     | 
| 
      
 43 
     | 
    
         
            +
                  def run_em_hooks(type)
         
     | 
| 
       44 
44 
     | 
    
         
             
                    @example_group_instance.class.em_hooks[type].each do |hook|
         
     | 
| 
       45 
45 
     | 
    
         
             
                      if @example_group_instance.respond_to? :instance_eval_without_event_loop
         
     | 
| 
       46 
46 
     | 
    
         
             
                        @example_group_instance.instance_eval_without_event_loop(&hook)
         
     | 
| 
         @@ -105,7 +105,7 @@ module AMQP 
     | 
|
| 
       105 
105 
     | 
    
         
             
                  # Breaks the EM event loop and finishes the spec.
         
     | 
| 
       106 
106 
     | 
    
         
             
                  # Done yields to any given block first, then stops EM event loop.
         
     | 
| 
       107 
107 
     | 
    
         
             
                  #
         
     | 
| 
       108 
     | 
    
         
            -
                  def done(delay=nil)
         
     | 
| 
      
 108 
     | 
    
         
            +
                  def done(delay = nil)
         
     | 
| 
       109 
109 
     | 
    
         
             
                    super(delay) do
         
     | 
| 
       110 
110 
     | 
    
         
             
                      yield if block_given?
         
     | 
| 
       111 
111 
     | 
    
         
             
                      EM.next_tick do
         
     | 
| 
         @@ -122,7 +122,7 @@ module AMQP 
     | 
|
| 
       122 
122 
     | 
    
         
             
                  # Run @block inside the AMQP.start loop
         
     | 
| 
       123 
123 
     | 
    
         
             
                  def run
         
     | 
| 
       124 
124 
     | 
    
         
             
                    run_em_loop do
         
     | 
| 
       125 
     | 
    
         
            -
                      AMQP.start_connection 
     | 
| 
      
 125 
     | 
    
         
            +
                      AMQP.start_connection(@opts) do
         
     | 
| 
       126 
126 
     | 
    
         
             
                        run_em_hooks :amqp_before
         
     | 
| 
       127 
127 
     | 
    
         
             
                        @block.call
         
     | 
| 
       128 
128 
     | 
    
         
             
                      end
         
     | 
| 
         @@ -132,7 +132,7 @@ module AMQP 
     | 
|
| 
       132 
132 
     | 
    
         
             
                  # Breaks the event loop and finishes the spec. It yields to any given block first,
         
     | 
| 
       133 
133 
     | 
    
         
             
                  # then stops AMQP, EM event loop and cleans up AMQP state.
         
     | 
| 
       134 
134 
     | 
    
         
             
                  #
         
     | 
| 
       135 
     | 
    
         
            -
                  def done(delay=nil)
         
     | 
| 
      
 135 
     | 
    
         
            +
                  def done(delay = nil)
         
     | 
| 
       136 
136 
     | 
    
         
             
                    super(delay) do
         
     | 
| 
       137 
137 
     | 
    
         
             
                      yield if block_given?
         
     | 
| 
       138 
138 
     | 
    
         
             
                      EM.next_tick do
         
     | 
    
        data/lib/amqp-spec/rspec.rb
    CHANGED
    
    | 
         @@ -53,39 +53,39 @@ module AMQP 
     | 
|
| 
       53 
53 
     | 
    
         
             
                  # Sets/retrieves default timeout for running evented specs for this
         
     | 
| 
       54 
54 
     | 
    
         
             
                  # example group and its nested groups.
         
     | 
| 
       55 
55 
     | 
    
         
             
                  #
         
     | 
| 
       56 
     | 
    
         
            -
                  def default_timeout  
     | 
| 
      
 56 
     | 
    
         
            +
                  def default_timeout(spec_timeout = nil)
         
     | 
| 
       57 
57 
     | 
    
         
             
                    default_options[:spec_timeout] = spec_timeout || default_options[:spec_timeout]
         
     | 
| 
       58 
58 
     | 
    
         
             
                  end
         
     | 
| 
       59 
59 
     | 
    
         | 
| 
       60 
60 
     | 
    
         
             
                  # Sets/retrieves default AMQP.start options for this example group
         
     | 
| 
       61 
61 
     | 
    
         
             
                  # and its nested groups.
         
     | 
| 
       62 
62 
     | 
    
         
             
                  #
         
     | 
| 
       63 
     | 
    
         
            -
                  def default_options  
     | 
| 
      
 63 
     | 
    
         
            +
                  def default_options(opts = nil)
         
     | 
| 
       64 
64 
     | 
    
         
             
                    metadata[:em_defaults] ||= {}
         
     | 
| 
       65 
65 
     | 
    
         
             
                    metadata[:em_defaults][self] ||= (superclass.default_options.dup rescue {})
         
     | 
| 
       66 
66 
     | 
    
         
             
                    metadata[:em_defaults][self] = opts || metadata[:em_defaults][self]
         
     | 
| 
       67 
67 
     | 
    
         
             
                  end
         
     | 
| 
       68 
68 
     | 
    
         | 
| 
       69 
69 
     | 
    
         
             
                  # Add before hook that will run inside EM event loop
         
     | 
| 
       70 
     | 
    
         
            -
                  def em_before 
     | 
| 
      
 70 
     | 
    
         
            +
                  def em_before(scope = :each, &block)
         
     | 
| 
       71 
71 
     | 
    
         
             
                    raise ArgumentError, "em_before only supports :each scope" unless :each == scope
         
     | 
| 
       72 
72 
     | 
    
         
             
                    em_hooks[:em_before] << block
         
     | 
| 
       73 
73 
     | 
    
         
             
                  end
         
     | 
| 
       74 
74 
     | 
    
         | 
| 
       75 
75 
     | 
    
         
             
                  # Add after hook that will run inside EM event loop
         
     | 
| 
       76 
     | 
    
         
            -
                  def em_after 
     | 
| 
      
 76 
     | 
    
         
            +
                  def em_after(scope = :each, &block)
         
     | 
| 
       77 
77 
     | 
    
         
             
                    raise ArgumentError, "em_after only supports :each scope" unless :each == scope
         
     | 
| 
       78 
78 
     | 
    
         
             
                    em_hooks[:em_after].unshift block
         
     | 
| 
       79 
79 
     | 
    
         
             
                  end
         
     | 
| 
       80 
80 
     | 
    
         | 
| 
       81 
81 
     | 
    
         
             
                  # Add before hook that will run inside AMQP connection (AMQP.start loop)
         
     | 
| 
       82 
     | 
    
         
            -
                  def amqp_before 
     | 
| 
      
 82 
     | 
    
         
            +
                  def amqp_before(scope = :each, &block)
         
     | 
| 
       83 
83 
     | 
    
         
             
                    raise ArgumentError, "amqp_before only supports :each scope" unless :each == scope
         
     | 
| 
       84 
84 
     | 
    
         
             
                    em_hooks[:amqp_before] << block
         
     | 
| 
       85 
85 
     | 
    
         
             
                  end
         
     | 
| 
       86 
86 
     | 
    
         | 
| 
       87 
87 
     | 
    
         
             
                  # Add after hook that will run inside AMQP connection (AMQP.start loop)
         
     | 
| 
       88 
     | 
    
         
            -
                  def amqp_after 
     | 
| 
      
 88 
     | 
    
         
            +
                  def amqp_after(scope = :each, &block)
         
     | 
| 
       89 
89 
     | 
    
         
             
                    raise ArgumentError, "amqp_after only supports :each scope" unless :each == scope
         
     | 
| 
       90 
90 
     | 
    
         
             
                    em_hooks[:amqp_after].unshift block
         
     | 
| 
       91 
91 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -94,14 +94,16 @@ module AMQP 
     | 
|
| 
       94 
94 
     | 
    
         
             
                  def em_hooks
         
     | 
| 
       95 
95 
     | 
    
         
             
                    metadata[:em_hooks] ||= {}
         
     | 
| 
       96 
96 
     | 
    
         
             
                    metadata[:em_hooks][self] ||=
         
     | 
| 
       97 
     | 
    
         
            -
                        { 
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
      
 97 
     | 
    
         
            +
                        {
         
     | 
| 
      
 98 
     | 
    
         
            +
                          :em_before   => (superclass.em_hooks[:em_before].clone rescue []),
         
     | 
| 
      
 99 
     | 
    
         
            +
                          :em_after    => (superclass.em_hooks[:em_after].clone rescue []),
         
     | 
| 
      
 100 
     | 
    
         
            +
                          :amqp_before => (superclass.em_hooks[:amqp_before].clone rescue []),
         
     | 
| 
      
 101 
     | 
    
         
            +
                          :amqp_after  => (superclass.em_hooks[:amqp_after].clone rescue [])
         
     | 
| 
      
 102 
     | 
    
         
            +
                        }
         
     | 
| 
       101 
103 
     | 
    
         
             
                  end
         
     | 
| 
       102 
104 
     | 
    
         
             
                end
         
     | 
| 
       103 
105 
     | 
    
         | 
| 
       104 
     | 
    
         
            -
                def self.included 
     | 
| 
      
 106 
     | 
    
         
            +
                def self.included(example_group)
         
     | 
| 
       105 
107 
     | 
    
         
             
                  unless example_group.respond_to? :default_timeout
         
     | 
| 
       106 
108 
     | 
    
         
             
                    example_group.extend GroupMethods
         
     | 
| 
       107 
109 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -131,7 +133,7 @@ module AMQP 
     | 
|
| 
       131 
133 
     | 
    
         
             
                # to force spec to timeout if something goes wrong and EM/AMQP loop hangs for some
         
     | 
| 
       132 
134 
     | 
    
         
             
                # reason. SpecTimeoutExceededError is raised if it happens.
         
     | 
| 
       133 
135 
     | 
    
         
             
                #
         
     | 
| 
       134 
     | 
    
         
            -
                def amqp  
     | 
| 
      
 136 
     | 
    
         
            +
                def amqp(opts = {}, &block)
         
     | 
| 
       135 
137 
     | 
    
         
             
                  opts = default_options.merge opts
         
     | 
| 
       136 
138 
     | 
    
         
             
                  @evented_example = AMQPExample.new(opts, self, &block)
         
     | 
| 
       137 
139 
     | 
    
         
             
                  @evented_example.run
         
     | 
| 
         @@ -144,8 +146,8 @@ module AMQP 
     | 
|
| 
       144 
146 
     | 
    
         
             
                # For compatibility with EM-Spec API, em method accepts either options Hash
         
     | 
| 
       145 
147 
     | 
    
         
             
                # or numeric timeout in seconds.
         
     | 
| 
       146 
148 
     | 
    
         
             
                #
         
     | 
| 
       147 
     | 
    
         
            -
                def em 
     | 
| 
       148 
     | 
    
         
            -
                  opts = default_options.merge(opts.is_a?(Hash) ? opts : {spec_timeout 
     | 
| 
      
 149 
     | 
    
         
            +
                def em(opts = {}, &block)
         
     | 
| 
      
 150 
     | 
    
         
            +
                  opts = default_options.merge(opts.is_a?(Hash) ? opts : { :spec_timeout =>  opts })
         
     | 
| 
       149 
151 
     | 
    
         
             
                  @evented_example = EMExample.new(opts, self, &block)
         
     | 
| 
       150 
152 
     | 
    
         
             
                  @evented_example.run
         
     | 
| 
       151 
153 
     | 
    
         
             
                end
         
     | 
| 
         @@ -159,13 +161,13 @@ module AMQP 
     | 
|
| 
       159 
161 
     | 
    
         
             
                # that your (default or explicit) spec timeout may fire before your delayed done
         
     | 
| 
       160 
162 
     | 
    
         
             
                # callback is due, leading to SpecTimeoutExceededError
         
     | 
| 
       161 
163 
     | 
    
         
             
                #
         
     | 
| 
       162 
     | 
    
         
            -
                def done 
     | 
| 
      
 164 
     | 
    
         
            +
                def done(*args, &block)
         
     | 
| 
       163 
165 
     | 
    
         
             
                  @evented_example.done *args, &block
         
     | 
| 
       164 
166 
     | 
    
         
             
                end
         
     | 
| 
       165 
167 
     | 
    
         | 
| 
       166 
168 
     | 
    
         
             
                # Manually sets timeout for currently running example
         
     | 
| 
       167 
169 
     | 
    
         
             
                #
         
     | 
| 
       168 
     | 
    
         
            -
                def timeout 
     | 
| 
      
 170 
     | 
    
         
            +
                def timeout(*args)
         
     | 
| 
       169 
171 
     | 
    
         
             
                  @evented_example.timeout *args
         
     | 
| 
       170 
172 
     | 
    
         
             
                end
         
     | 
| 
       171 
173 
     | 
    
         | 
| 
         @@ -208,9 +210,3 @@ module AMQP 
     | 
|
| 
       208 
210 
     | 
    
         
             
                end
         
     | 
| 
       209 
211 
     | 
    
         
             
              end
         
     | 
| 
       210 
212 
     | 
    
         
             
            end
         
     | 
| 
       211 
     | 
    
         
            -
             
     | 
| 
       212 
     | 
    
         
            -
            # Monkey patching EM to provide drop-in experience for legacy EM-Spec based examples
         
     | 
| 
       213 
     | 
    
         
            -
            module EventMachine
         
     | 
| 
       214 
     | 
    
         
            -
              Spec = AMQP::EMSpec
         
     | 
| 
       215 
     | 
    
         
            -
              SpecHelper = AMQP::SpecHelper
         
     | 
| 
       216 
     | 
    
         
            -
            end
         
     | 
    
        data/spec/em_hooks_spec.rb
    CHANGED
    
    | 
         @@ -1,7 +1,9 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
      
 3 
     | 
    
         
            +
            # Registers specific hook type as being called,
         
     | 
| 
      
 4 
     | 
    
         
            +
            # sets expectations about EM reactor and AMQP connection state
         
     | 
| 
      
 5 
     | 
    
         
            +
            def hook(type, reactor, connection)
         
     | 
| 
      
 6 
     | 
    
         
            +
              @hooks_called << type.to_sym if type
         
     | 
| 
       5 
7 
     | 
    
         
             
              if :reactor_running == reactor
         
     | 
| 
       6 
8 
     | 
    
         
             
                EM.reactor_running?.should be_true
         
     | 
| 
       7 
9 
     | 
    
         
             
              else
         
     | 
| 
         @@ -88,7 +90,7 @@ describe AMQP::SpecHelper, ".em_before/.em_after" do 
     | 
|
| 
       88 
90 
     | 
    
         
             
                context 'for non-evented specs' do
         
     | 
| 
       89 
91 
     | 
    
         
             
                  after {
         
     | 
| 
       90 
92 
     | 
    
         
             
                    @hooks_called.should == [:before]
         
     | 
| 
       91 
     | 
    
         
            -
                    hook :reactor_not_running, :amqp_not_connected }
         
     | 
| 
      
 93 
     | 
    
         
            +
                    hook :after, :reactor_not_running, :amqp_not_connected }
         
     | 
| 
       92 
94 
     | 
    
         | 
| 
       93 
95 
     | 
    
         
             
                  it 'should NOT execute em_before or em_after' do
         
     | 
| 
       94 
96 
     | 
    
         
             
                    @hooks_called.should_not include :em_before
         
     | 
| 
         @@ -109,7 +111,7 @@ describe AMQP::SpecHelper, ".em_before/.em_after" do 
     | 
|
| 
       109 
111 
     | 
    
         
             
                context 'for evented specs' do #, pending: true do
         
     | 
| 
       110 
112 
     | 
    
         
             
                  after {
         
     | 
| 
       111 
113 
     | 
    
         
             
                    @hooks_called.should include :before, :em_before, :em_after
         
     | 
| 
       112 
     | 
    
         
            -
                    hook :reactor_not_running, :amqp_not_connected }
         
     | 
| 
      
 114 
     | 
    
         
            +
                    hook :after, :reactor_not_running, :amqp_not_connected }
         
     | 
| 
       113 
115 
     | 
    
         | 
| 
       114 
116 
     | 
    
         
             
                  context 'with em block' do
         
     | 
| 
       115 
117 
     | 
    
         | 
| 
         @@ -143,7 +145,7 @@ describe AMQP::SpecHelper, ".em_before/.em_after" do 
     | 
|
| 
       143 
145 
     | 
    
         
             
                                                           :context_em_before,
         
     | 
| 
       144 
146 
     | 
    
         
             
                                                           :context_em_after,
         
     | 
| 
       145 
147 
     | 
    
         
             
                                                           :em_after
         
     | 
| 
       146 
     | 
    
         
            -
                      hook :reactor_not_running, :amqp_not_connected
         
     | 
| 
      
 148 
     | 
    
         
            +
                      hook :after, :reactor_not_running, :amqp_not_connected
         
     | 
| 
       147 
149 
     | 
    
         
             
                      }
         
     | 
| 
       148 
150 
     | 
    
         | 
| 
       149 
151 
     | 
    
         
             
                      it_should_behave_like 'hooked em specs'
         
     | 
| 
         @@ -200,7 +202,7 @@ describe AMQP::SpecHelper, ".em_before/.em_after" do 
     | 
|
| 
       200 
202 
     | 
    
         
             
                                                       :amqp_after,
         
     | 
| 
       201 
203 
     | 
    
         
             
                                                       :amqp_context_em_after,
         
     | 
| 
       202 
204 
     | 
    
         
             
                                                       :em_after]
         
     | 
| 
       203 
     | 
    
         
            -
                      hook :reactor_not_running, :amqp_not_connected }
         
     | 
| 
      
 205 
     | 
    
         
            +
                      hook :after, :reactor_not_running, :amqp_not_connected }
         
     | 
| 
       204 
206 
     | 
    
         | 
| 
       205 
207 
     | 
    
         
             
                      it_should_behave_like 'hooked amqp specs'
         
     | 
| 
       206 
208 
     | 
    
         | 
    
        data/spec/em_legacy_spec.rb
    CHANGED
    
    | 
         @@ -1,5 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
      
 3 
     | 
    
         
            +
            require 'amqp-spec/em_spec_shim'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
       3 
5 
     | 
    
         
             
            describe 'Legacy EM-Spec based examples should run unmodified' do
         
     | 
| 
       4 
6 
     | 
    
         
             
              describe EM::SpecHelper, ' when included' do
         
     | 
| 
       5 
7 
     | 
    
         
             
                include EM::SpecHelper
         
     | 
| 
         @@ -12,7 +14,7 @@ describe 'Legacy EM-Spec based examples should run unmodified' do 
     | 
|
| 
       12 
14 
     | 
    
         
             
                  start = Time.now
         
     | 
| 
       13 
15 
     | 
    
         
             
                  em do
         
     | 
| 
       14 
16 
     | 
    
         
             
                    EM.add_timer(0.5) {
         
     | 
| 
       15 
     | 
    
         
            -
                      (Time.now-start).should  
     | 
| 
      
 17 
     | 
    
         
            +
                      (Time.now-start).should be_within(0.1).of(0.5)
         
     | 
| 
       16 
18 
     | 
    
         
             
                      done
         
     | 
| 
       17 
19 
     | 
    
         
             
                    }
         
     | 
| 
       18 
20 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -25,7 +27,7 @@ describe 'Legacy EM-Spec based examples should run unmodified' do 
     | 
|
| 
       25 
27 
     | 
    
         
             
                      EM.add_timer(1) { done }
         
     | 
| 
       26 
28 
     | 
    
         
             
                    end
         
     | 
| 
       27 
29 
     | 
    
         
             
                  }.to raise_error SpecTimeoutExceededError
         
     | 
| 
       28 
     | 
    
         
            -
                  (Time.now-start).should  
     | 
| 
      
 30 
     | 
    
         
            +
                  (Time.now-start).should be_within(0.5).of(0.1)
         
     | 
| 
       29 
31 
     | 
    
         
             
                end
         
     | 
| 
       30 
32 
     | 
    
         | 
| 
       31 
33 
     | 
    
         
             
                it "should be possible to set spec timeout as an option (amqp interface compatibility)" do
         
     | 
| 
         @@ -35,7 +37,7 @@ describe 'Legacy EM-Spec based examples should run unmodified' do 
     | 
|
| 
       35 
37 
     | 
    
         
             
                      EM.add_timer(1) { done }
         
     | 
| 
       36 
38 
     | 
    
         
             
                    end
         
     | 
| 
       37 
39 
     | 
    
         
             
                  }.to raise_error SpecTimeoutExceededError
         
     | 
| 
       38 
     | 
    
         
            -
                  (Time.now-start).should  
     | 
| 
      
 40 
     | 
    
         
            +
                  (Time.now-start).should be_within(0.1).of(0.5)
         
     | 
| 
       39 
41 
     | 
    
         
             
                end
         
     | 
| 
       40 
42 
     | 
    
         
             
              end
         
     | 
| 
       41 
43 
     | 
    
         | 
    
        data/spec/rspec_em_spec.rb
    CHANGED
    
    | 
         @@ -12,7 +12,7 @@ describe 'Plain EM, no AMQP' do 
     | 
|
| 
       12 
12 
     | 
    
         
             
                  start = Time.now
         
     | 
| 
       13 
13 
     | 
    
         
             
                  em do
         
     | 
| 
       14 
14 
     | 
    
         
             
                    EM.add_timer(0.5) {
         
     | 
| 
       15 
     | 
    
         
            -
                      (Time.now-start).should  
     | 
| 
      
 15 
     | 
    
         
            +
                      (Time.now-start).should be_within(0.1).of(0.5)
         
     | 
| 
       16 
16 
     | 
    
         
             
                      done
         
     | 
| 
       17 
17 
     | 
    
         
             
                    }
         
     | 
| 
       18 
18 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -25,7 +25,7 @@ describe 'Plain EM, no AMQP' do 
     | 
|
| 
       25 
25 
     | 
    
         
             
                      EM.add_timer(1) { done }
         
     | 
| 
       26 
26 
     | 
    
         
             
                    end
         
     | 
| 
       27 
27 
     | 
    
         
             
                  }.to raise_error SpecTimeoutExceededError
         
     | 
| 
       28 
     | 
    
         
            -
                  (Time.now-start).should  
     | 
| 
      
 28 
     | 
    
         
            +
                  (Time.now-start).should be_within(0.1).of(0.5)
         
     | 
| 
       29 
29 
     | 
    
         
             
                end
         
     | 
| 
       30 
30 
     | 
    
         | 
| 
       31 
31 
     | 
    
         
             
                it "should be possible to set spec timeout as an option (amqp interface compatibility)" do
         
     | 
| 
         @@ -35,7 +35,7 @@ describe 'Plain EM, no AMQP' do 
     | 
|
| 
       35 
35 
     | 
    
         
             
                      EM.add_timer(1) { done }
         
     | 
| 
       36 
36 
     | 
    
         
             
                    end
         
     | 
| 
       37 
37 
     | 
    
         
             
                  }.to raise_error SpecTimeoutExceededError
         
     | 
| 
       38 
     | 
    
         
            -
                  (Time.now-start).should  
     | 
| 
      
 38 
     | 
    
         
            +
                  (Time.now-start).should be_within(0.1).of(0.5)
         
     | 
| 
       39 
39 
     | 
    
         
             
                end
         
     | 
| 
       40 
40 
     | 
    
         
             
              end
         
     | 
| 
       41 
41 
     | 
    
         | 
    
        data/spec/shared_examples.rb
    CHANGED
    
    | 
         @@ -16,7 +16,7 @@ shared_examples_for 'SpecHelper examples' do 
     | 
|
| 
       16 
16 
     | 
    
         
             
                start = Time.now
         
     | 
| 
       17 
17 
     | 
    
         
             
                amqp do
         
     | 
| 
       18 
18 
     | 
    
         
             
                  EM.add_timer(0.5) {
         
     | 
| 
       19 
     | 
    
         
            -
                    (Time.now-start).should  
     | 
| 
      
 19 
     | 
    
         
            +
                    (Time.now-start).should be_within(0.1).of(0.5)
         
     | 
| 
       20 
20 
     | 
    
         
             
                    done
         
     | 
| 
       21 
21 
     | 
    
         
             
                  }
         
     | 
| 
       22 
22 
     | 
    
         
             
                end
         
     | 
| 
         @@ -85,7 +85,7 @@ shared_examples_for 'done examples' do 
     | 
|
| 
       85 
85 
     | 
    
         
             
                  done(0.2) { @block_called = true; EM.reactor_running?.should == true }
         
     | 
| 
       86 
86 
     | 
    
         
             
                end
         
     | 
| 
       87 
87 
     | 
    
         
             
                @block_called.should == true
         
     | 
| 
       88 
     | 
    
         
            -
                (Time.now-start).should  
     | 
| 
      
 88 
     | 
    
         
            +
                (Time.now-start).should be_within(0.1).of(0.2)
         
     | 
| 
       89 
89 
     | 
    
         
             
              end
         
     | 
| 
       90 
90 
     | 
    
         | 
| 
       91 
91 
     | 
    
         
             
              it 'should have delayed done (when em is used)' do
         
     | 
| 
         @@ -94,7 +94,7 @@ shared_examples_for 'done examples' do 
     | 
|
| 
       94 
94 
     | 
    
         
             
                  done(0.2) { @block_called = true; EM.reactor_running?.should == true }
         
     | 
| 
       95 
95 
     | 
    
         
             
                end
         
     | 
| 
       96 
96 
     | 
    
         
             
                @block_called.should == true
         
     | 
| 
       97 
     | 
    
         
            -
                (Time.now-start).should  
     | 
| 
      
 97 
     | 
    
         
            +
                (Time.now-start).should be_within(0.1).of(0.2)
         
     | 
| 
       98 
98 
     | 
    
         
             
              end
         
     | 
| 
       99 
99 
     | 
    
         
             
            end
         
     | 
| 
       100 
100 
     | 
    
         | 
| 
         @@ -104,7 +104,7 @@ shared_examples_for 'timeout examples' do 
     | 
|
| 
       104 
104 
     | 
    
         
             
              it 'should timeout before reaching done because of default spec timeout' do
         
     | 
| 
       105 
105 
     | 
    
         
             
                expect { amqp { EM.add_timer(2) { done } } }.
         
     | 
| 
       106 
106 
     | 
    
         
             
                    to raise_error SpecTimeoutExceededError
         
     | 
| 
       107 
     | 
    
         
            -
                (Time.now-@start).should  
     | 
| 
      
 107 
     | 
    
         
            +
                (Time.now-@start).should be_within(0.1).of(1.0)
         
     | 
| 
       108 
108 
     | 
    
         
             
              end
         
     | 
| 
       109 
109 
     | 
    
         | 
| 
       110 
110 
     | 
    
         
             
              it 'should timeout before reaching done because of explicit in-loop timeout' do
         
     | 
| 
         @@ -114,19 +114,19 @@ shared_examples_for 'timeout examples' do 
     | 
|
| 
       114 
114 
     | 
    
         
             
                    EM.add_timer(0.5) { done }
         
     | 
| 
       115 
115 
     | 
    
         
             
                  end
         
     | 
| 
       116 
116 
     | 
    
         
             
                }.to raise_error SpecTimeoutExceededError
         
     | 
| 
       117 
     | 
    
         
            -
                (Time.now-@start).should  
     | 
| 
      
 117 
     | 
    
         
            +
                (Time.now-@start).should be_within(0.1).of(0.2)
         
     | 
| 
       118 
118 
     | 
    
         
             
              end
         
     | 
| 
       119 
119 
     | 
    
         | 
| 
       120 
120 
     | 
    
         
             
              specify "spec timeout given in amqp options has higher priority than default" do
         
     | 
| 
       121 
121 
     | 
    
         
             
                expect { amqp(:spec_timeout => 0.2) {} }.
         
     | 
| 
       122 
122 
     | 
    
         
             
                    to raise_error SpecTimeoutExceededError
         
     | 
| 
       123 
     | 
    
         
            -
                (Time.now-@start).should  
     | 
| 
      
 123 
     | 
    
         
            +
                (Time.now-@start).should be_within(0.1).of(0.2)
         
     | 
| 
       124 
124 
     | 
    
         
             
              end
         
     | 
| 
       125 
125 
     | 
    
         | 
| 
       126 
126 
     | 
    
         
             
              specify "but timeout call inside amqp loop has even higher priority" do
         
     | 
| 
       127 
127 
     | 
    
         
             
                expect { amqp(:spec_timeout => 0.5) { timeout(0.2) } }.
         
     | 
| 
       128 
128 
     | 
    
         
             
                    to raise_error SpecTimeoutExceededError
         
     | 
| 
       129 
     | 
    
         
            -
                (Time.now-@start).should  
     | 
| 
      
 129 
     | 
    
         
            +
                (Time.now-@start).should be_within(0.1).of(0.2)
         
     | 
| 
       130 
130 
     | 
    
         
             
              end
         
     | 
| 
       131 
131 
     | 
    
         | 
| 
       132 
132 
     | 
    
         
             
              specify "AMQP connection should not leak between examples" do
         
     | 
| 
         @@ -138,7 +138,7 @@ shared_examples_for 'timeout examples' do 
     | 
|
| 
       138 
138 
     | 
    
         | 
| 
       139 
139 
     | 
    
         
             
                specify 'default timeout should be 0.2' do
         
     | 
| 
       140 
140 
     | 
    
         
             
                  expect { em { EM.add_timer(2) { done } } }.to raise_error SpecTimeoutExceededError
         
     | 
| 
       141 
     | 
    
         
            -
                  (Time.now-@start).should  
     | 
| 
      
 141 
     | 
    
         
            +
                  (Time.now-@start).should be_within(0.1).of(0.2)
         
     | 
| 
       142 
142 
     | 
    
         
             
                end
         
     | 
| 
       143 
143 
     | 
    
         | 
| 
       144 
144 
     | 
    
         
             
                context 'deeply embedded context can set up separate defaults' do
         
     | 
| 
         @@ -146,7 +146,7 @@ shared_examples_for 'timeout examples' do 
     | 
|
| 
       146 
146 
     | 
    
         | 
| 
       147 
147 
     | 
    
         
             
                  specify 'default timeout should be 0.5' do
         
     | 
| 
       148 
148 
     | 
    
         
             
                    expect { amqp { EM.add_timer(2) { done } } }.to raise_error SpecTimeoutExceededError
         
     | 
| 
       149 
     | 
    
         
            -
                    (Time.now-@start).should  
     | 
| 
      
 149 
     | 
    
         
            +
                    (Time.now-@start).should be_within(0.1).of(0.5)
         
     | 
| 
       150 
150 
     | 
    
         
             
                  end
         
     | 
| 
       151 
151 
     | 
    
         
             
                end
         
     | 
| 
       152 
152 
     | 
    
         
             
              end
         
     | 
| 
         @@ -167,7 +167,7 @@ shared_examples_for 'Spec examples' do 
     | 
|
| 
       167 
167 
     | 
    
         
             
                start = Time.now
         
     | 
| 
       168 
168 
     | 
    
         | 
| 
       169 
169 
     | 
    
         
             
                EM.add_timer(0.2) {
         
     | 
| 
       170 
     | 
    
         
            -
                  (Time.now-start).should  
     | 
| 
      
 170 
     | 
    
         
            +
                  (Time.now-start).should be_within(0.1).of(0.2)
         
     | 
| 
       171 
171 
     | 
    
         
             
                  done
         
     | 
| 
       172 
172 
     | 
    
         
             
                }
         
     | 
| 
       173 
173 
     | 
    
         
             
              end
         
     | 
| 
         @@ -178,7 +178,7 @@ shared_examples_for 'Spec examples' do 
     | 
|
| 
       178 
178 
     | 
    
         | 
| 
       179 
179 
     | 
    
         
             
                timer = EM.add_periodic_timer(0.2) {
         
     | 
| 
       180 
180 
     | 
    
         
             
                  if (num += 1) == 2
         
     | 
| 
       181 
     | 
    
         
            -
                    (Time.now-start).should  
     | 
| 
      
 181 
     | 
    
         
            +
                    (Time.now-start).should be_within(0.1).of(0.5)
         
     | 
| 
       182 
182 
     | 
    
         
             
                    EM.cancel_timer timer
         
     | 
| 
       183 
183 
     | 
    
         
             
                    done
         
     | 
| 
       184 
184 
     | 
    
         
             
                  end
         
     | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | 
         @@ -18,31 +18,36 @@ end 
     | 
|
| 
       18 
18 
     | 
    
         
             
            def done
         
     | 
| 
       19 
19 
     | 
    
         
             
            end
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
            RSPEC 
     | 
| 
      
 21 
     | 
    
         
            +
            RSPEC       = rspec2? ? RSpec : Spec
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
23 
     | 
    
         
             
            amqp_config = File.dirname(__FILE__) + '/amqp.yml'
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
               
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
      
 25 
     | 
    
         
            +
            AMQP_OPTS   = unless File.exists? amqp_config
         
     | 
| 
      
 26 
     | 
    
         
            +
                            {:user  => 'guest',
         
     | 
| 
      
 27 
     | 
    
         
            +
                             :pass  => 'guest',
         
     | 
| 
      
 28 
     | 
    
         
            +
                             :host  => '10.211.55.2',
         
     | 
| 
      
 29 
     | 
    
         
            +
                             :vhost => '/'}
         
     | 
| 
      
 30 
     | 
    
         
            +
                          else
         
     | 
| 
      
 31 
     | 
    
         
            +
                            class Hash
         
     | 
| 
      
 32 
     | 
    
         
            +
                              def symbolize_keys
         
     | 
| 
      
 33 
     | 
    
         
            +
                                self.inject({}) { |result, (key, value)|
         
     | 
| 
      
 34 
     | 
    
         
            +
                                  new_key         = case key
         
     | 
| 
      
 35 
     | 
    
         
            +
                                                      when String then
         
     | 
| 
      
 36 
     | 
    
         
            +
                                                        key.to_sym
         
     | 
| 
      
 37 
     | 
    
         
            +
                                                      else
         
     | 
| 
      
 38 
     | 
    
         
            +
                                                        key
         
     | 
| 
      
 39 
     | 
    
         
            +
                                                    end
         
     | 
| 
      
 40 
     | 
    
         
            +
                                  new_value       = case value
         
     | 
| 
      
 41 
     | 
    
         
            +
                                                      when Hash then
         
     | 
| 
      
 42 
     | 
    
         
            +
                                                        value.symbolize_keys
         
     | 
| 
      
 43 
     | 
    
         
            +
                                                      else
         
     | 
| 
      
 44 
     | 
    
         
            +
                                                        value
         
     | 
| 
      
 45 
     | 
    
         
            +
                                                    end
         
     | 
| 
      
 46 
     | 
    
         
            +
                                  result[new_key] = new_value
         
     | 
| 
      
 47 
     | 
    
         
            +
                                  result
         
     | 
| 
      
 48 
     | 
    
         
            +
                                }
         
     | 
| 
       34 
49 
     | 
    
         
             
                              end
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
                                    value
         
     | 
| 
       40 
     | 
    
         
            -
                                end
         
     | 
| 
       41 
     | 
    
         
            -
                    result[new_key] = new_value
         
     | 
| 
       42 
     | 
    
         
            -
                    result
         
     | 
| 
       43 
     | 
    
         
            -
                  }
         
     | 
| 
       44 
     | 
    
         
            -
                end
         
     | 
| 
       45 
     | 
    
         
            -
              end
         
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
              AMQP_OPTS = YAML::load_file(amqp_config).symbolize_keys[:test]
         
     | 
| 
       48 
     | 
    
         
            -
            end
         
     | 
| 
      
 50 
     | 
    
         
            +
                            end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                            YAML::load_file(amqp_config).symbolize_keys[:test]
         
     | 
| 
      
 53 
     | 
    
         
            +
                          end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version 
     | 
|
| 
       5 
5 
     | 
    
         
             
              segments: 
         
     | 
| 
       6 
6 
     | 
    
         
             
              - 0
         
     | 
| 
       7 
7 
     | 
    
         
             
              - 3
         
     | 
| 
       8 
     | 
    
         
            -
              -  
     | 
| 
       9 
     | 
    
         
            -
              version: 0.3. 
     | 
| 
      
 8 
     | 
    
         
            +
              - 8
         
     | 
| 
      
 9 
     | 
    
         
            +
              version: 0.3.8
         
     | 
| 
       10 
10 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       11 
11 
     | 
    
         
             
            authors: 
         
     | 
| 
       12 
12 
     | 
    
         
             
            - Arvicco
         
     | 
| 
         @@ -14,7 +14,7 @@ autorequire: 
     | 
|
| 
       14 
14 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       15 
15 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
            date: 2011-01- 
     | 
| 
      
 17 
     | 
    
         
            +
            date: 2011-01-26 00:00:00 +03:00
         
     | 
| 
       18 
18 
     | 
    
         
             
            default_executable: 
         
     | 
| 
       19 
19 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       20 
20 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
         @@ -74,6 +74,7 @@ extra_rdoc_files: 
     | 
|
| 
       74 
74 
     | 
    
         
             
            - README.rdoc
         
     | 
| 
       75 
75 
     | 
    
         
             
            files: 
         
     | 
| 
       76 
76 
     | 
    
         
             
            - lib/amqp-spec/amqp.rb
         
     | 
| 
      
 77 
     | 
    
         
            +
            - lib/amqp-spec/em_spec_shim.rb
         
     | 
| 
       77 
78 
     | 
    
         
             
            - lib/amqp-spec/evented_example.rb
         
     | 
| 
       78 
79 
     | 
    
         
             
            - lib/amqp-spec/rspec.rb
         
     | 
| 
       79 
80 
     | 
    
         
             
            - lib/amqp-spec.rb
         
     | 
| 
         @@ -83,7 +84,6 @@ files: 
     | 
|
| 
       83 
84 
     | 
    
         
             
            - spec/em_legacy_spec.rb
         
     | 
| 
       84 
85 
     | 
    
         
             
            - spec/em_metadata_spec.rb
         
     | 
| 
       85 
86 
     | 
    
         
             
            - spec/failing_rspec_spec.rb
         
     | 
| 
       86 
     | 
    
         
            -
            - spec/problematic_rspec_spec.rb
         
     | 
| 
       87 
87 
     | 
    
         
             
            - spec/rspec_amqp_spec.rb
         
     | 
| 
       88 
88 
     | 
    
         
             
            - spec/rspec_em_spec.rb
         
     | 
| 
       89 
89 
     | 
    
         
             
            - spec/shared_examples.rb
         
     | 
| 
         @@ -144,7 +144,6 @@ test_files: 
     | 
|
| 
       144 
144 
     | 
    
         
             
            - spec/em_legacy_spec.rb
         
     | 
| 
       145 
145 
     | 
    
         
             
            - spec/em_metadata_spec.rb
         
     | 
| 
       146 
146 
     | 
    
         
             
            - spec/failing_rspec_spec.rb
         
     | 
| 
       147 
     | 
    
         
            -
            - spec/problematic_rspec_spec.rb
         
     | 
| 
       148 
147 
     | 
    
         
             
            - spec/rspec_amqp_spec.rb
         
     | 
| 
       149 
148 
     | 
    
         
             
            - spec/rspec_em_spec.rb
         
     | 
| 
       150 
149 
     | 
    
         
             
            - spec/shared_examples.rb
         
     |