-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: François de Metz <fdemetz@af83.com>
- Loading branch information
1 parent
faca7d1
commit 5963dda
Showing
6 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source :rubygems | ||
|
||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
em-eventsource (0.0.1) | ||
em-http-request (= 1.0.0.beta4) | ||
eventmachine (= 1.0.0.beta3) | ||
|
||
GEM | ||
remote: http://rubygems.org/ | ||
specs: | ||
addressable (2.2.6) | ||
em-http-request (1.0.0.beta.4) | ||
addressable (>= 2.2.3) | ||
em-socksify | ||
eventmachine (>= 1.0.0.beta.3) | ||
http_parser.rb (>= 0.5.1) | ||
em-socksify (0.1.0) | ||
eventmachine | ||
eventmachine (1.0.0.beta.3) | ||
http_parser.rb (0.5.1) | ||
minitest (2.3.1) | ||
rake (0.9.2) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
bundler | ||
em-eventsource! | ||
minitest (~> 2.0) | ||
rake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'rake/testtask' | ||
|
||
Rake::TestTask.new do |t| | ||
t.pattern = "spec/*_spec.rb" | ||
end | ||
|
||
task :default => :test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper') | ||
require "minitest/autorun" | ||
|
||
describe EventMachine::EventSource do | ||
it "connect and handle message" do | ||
EM.run do | ||
source = EventMachine::EventSource.new("http://example.com/streaming") | ||
source.message do |message| | ||
message.must_be :==, 'hello world' | ||
source.close | ||
EM.stop | ||
end | ||
EM.add_timer(1) do | ||
req = source.instance_variable_get "@req" | ||
req.stream_data("data: hello world\n") | ||
end | ||
source.start | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require "em-eventsource" | ||
|
||
module EventMachine | ||
class MockHttpRequest | ||
attr_reader :url, :get_args | ||
|
||
def initialize(url) | ||
@url = url | ||
@streams = [] | ||
@errors = [] | ||
@headers = [] | ||
end | ||
|
||
def get(*args) | ||
@get_args = args | ||
end | ||
|
||
def stream(&block) | ||
@streams << block | ||
end | ||
|
||
def errback(&block) | ||
@errors << block | ||
end | ||
|
||
def headers(&block) | ||
@headers << block | ||
end | ||
|
||
def stream_data(data) | ||
@streams.each { |stream| stream.call(data) } | ||
end | ||
|
||
def close | ||
|
||
end | ||
end | ||
|
||
class HttpRequest | ||
def self.new(url) | ||
EM::MockHttpRequest.new(url) | ||
end | ||
end | ||
end |