Class: Cramp::TestCase
- Inherits:
-
ActiveSupport::TestCase
- Object
- ActiveSupport::TestCase
- Cramp::TestCase
- Defined in:
- lib/cramp/test_case.rb
Instance Method Summary collapse
- #app ⇒ Object
- #create_request ⇒ Object
- #get(path, options = {}, headers = {}, &block) ⇒ Object
- #get_body(path, options = {}, headers = {}, &block) ⇒ Object
- #get_body_chunks(path, options = {}, headers = {}, &block) ⇒ Object
- #stop ⇒ Object
Instance Method Details
#app ⇒ Object
50 51 52 |
# File 'lib/cramp/test_case.rb', line 50 def app raise "Please define a method called 'app' returning an async Rack Application" end |
#create_request ⇒ Object
9 10 11 |
# File 'lib/cramp/test_case.rb', line 9 def create_request @request = Rack::MockRequest.new(app) end |
#get(path, options = {}, headers = {}, &block) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/cramp/test_case.rb', line 13 def get(path, = {}, headers = {}, &block) callback = .delete(:callback) || block headers = headers.merge('async.callback' => callback) EM.run do catch(:async) { @request.get(path, headers) } end end |
#get_body(path, options = {}, headers = {}, &block) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/cramp/test_case.rb', line 22 def get_body(path, = {}, headers = {}, &block) callback = .delete(:callback) || block response_callback = proc {|response| response[-1].each {|chunk| callback.call(chunk) } } headers = headers.merge('async.callback' => response_callback) EM.run do catch(:async) { @request.get(path, headers) } end end |
#get_body_chunks(path, options = {}, headers = {}, &block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/cramp/test_case.rb', line 32 def get_body_chunks(path, = {}, headers = {}, &block) callback = .delete(:callback) || block count = .delete(:count) || 1 stopping = false chunks = [] get_body(path, , headers) do |body_chunk| chunks << body_chunk unless stopping if chunks.count >= count stopping = true callback.call(chunks) if callback EM.next_tick { EM.stop } end end end |
#stop ⇒ Object
54 55 56 |
# File 'lib/cramp/test_case.rb', line 54 def stop EM.stop end |