mockingbird 0.1.0 → 0.1.1
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/README.md +15 -9
- data/lib/mockingbird.rb +2 -1
- data/lib/mockingbird/commands.rb +7 -3
- data/lib/mockingbird/server.rb +1 -1
- data/lib/mockingbird/version.rb +1 -1
- metadata +4 -20
data/README.md
CHANGED
@@ -1,14 +1,20 @@
|
|
1
1
|
Mockingbird
|
2
2
|
===========
|
3
|
-
Mockingbird
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
Mockingbird makes it easy to test code that relies on the
|
4
|
+
[Twitter Streaming API](http://dev.twitter.com/pages/streaming_api). It's a
|
5
|
+
server with a simple script-like configuration DSL that makes it easy to
|
6
|
+
describe the behaviors you want. Mockingbird can be used to simulate bad data,
|
7
|
+
unexpected status codes, hard disconnects, etc. It's currently used heavily to
|
8
|
+
test the [flamingo](http://github.com/hayesdavis/flamingo) Streaming API
|
9
|
+
service.
|
7
10
|
|
8
|
-
Mockingbird uses eventmachine
|
9
|
-
it's a drop-in replacement for
|
10
|
-
|
11
|
-
a mockingbird
|
11
|
+
Mockingbird uses [eventmachine](http://github.com/eventmachine/eventmachine/)
|
12
|
+
to run as an actual streaming HTTP server so it's a drop-in replacement for
|
13
|
+
the server at stream.twitter.com. To test code that uses the Streaming API,
|
14
|
+
connect to a running mockingbird server instead of stream.twitter.com. Most
|
15
|
+
Twitter Streaming API clients, such as
|
16
|
+
[twitter-stream](http://github.com/voloko/twitter-stream), allow you to easily
|
17
|
+
change these host and port settings.
|
12
18
|
|
13
19
|
Since mockingbird is designed for testing, it includes a simple
|
14
20
|
Mockingbird#setup and Mockingbird#teardown interface that makes it easy to
|
@@ -36,7 +42,7 @@ Here's what this does in plain english:
|
|
36
42
|
* On a connection, send '{"foo":"bar"}' down to the client
|
37
43
|
* Wait 1 second
|
38
44
|
* Then send '{"foo2":"bar2"}' down to the client 5 times
|
39
|
-
* Then send each line from some/file.txt to the
|
45
|
+
* Then send each line from some/file.txt to the client, waiting 1 second in
|
40
46
|
between sends
|
41
47
|
* Close the connection
|
42
48
|
|
data/lib/mockingbird.rb
CHANGED
@@ -23,6 +23,7 @@ module Mockingbird
|
|
23
23
|
# Options are
|
24
24
|
# :host - The host to listen on. 0.0.0.0 by default
|
25
25
|
# :port - The port to listen on. 4879 by default
|
26
|
+
# :quiet - Silence debug-output. Default is to be verbose
|
26
27
|
#
|
27
28
|
# The block is a Mockingbird configuration (see README).
|
28
29
|
def setup(opts={},&block)
|
@@ -33,7 +34,7 @@ module Mockingbird
|
|
33
34
|
Server.start!(opts)
|
34
35
|
end
|
35
36
|
Process.detach(@pid)
|
36
|
-
puts "Waiting for Mockingbird to start..."
|
37
|
+
puts "Waiting for Mockingbird to start..." unless opts[:quiet]
|
37
38
|
sleep(1) # Necessary to make sure the forked proc is up and running
|
38
39
|
@pid
|
39
40
|
end
|
data/lib/mockingbird/commands.rb
CHANGED
@@ -106,8 +106,8 @@ module Mockingbird
|
|
106
106
|
end
|
107
107
|
|
108
108
|
def run(conn)
|
109
|
-
unless
|
110
|
-
chunk =
|
109
|
+
unless io.eof?
|
110
|
+
chunk = io.readline.chomp
|
111
111
|
conn.send_chunk(chunk)
|
112
112
|
if delay
|
113
113
|
EM.add_timer(delay) { run(conn) }
|
@@ -116,12 +116,16 @@ module Mockingbird
|
|
116
116
|
end
|
117
117
|
else
|
118
118
|
# Reset for future calls
|
119
|
-
|
119
|
+
io.rewind
|
120
120
|
advance(conn)
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
124
|
private
|
125
|
+
def io
|
126
|
+
@io
|
127
|
+
end
|
128
|
+
|
125
129
|
def delay
|
126
130
|
if @delay.respond_to?(:call)
|
127
131
|
@delay.call
|
data/lib/mockingbird/server.rb
CHANGED
@@ -23,7 +23,7 @@ module Mockingbird
|
|
23
23
|
host = opts[:host]
|
24
24
|
port = opts[:port]
|
25
25
|
EventMachine::run do
|
26
|
-
puts "Mockingbird is mocking you on #{host}:#{port} (pid=#{$$})"
|
26
|
+
puts "Mockingbird is mocking you on #{host}:#{port} (pid=#{$$})" unless opts[:quiet]
|
27
27
|
EventMachine::start_server host, port, self
|
28
28
|
end
|
29
29
|
end
|
data/lib/mockingbird/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mockingbird
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 0
|
10
|
-
version: 0.1.0
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.1
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Hayes Davis
|
@@ -15,7 +10,7 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date:
|
13
|
+
date: 2012-02-18 00:00:00 -08:00
|
19
14
|
default_executable:
|
20
15
|
dependencies:
|
21
16
|
- !ruby/object:Gem::Dependency
|
@@ -26,11 +21,6 @@ dependencies:
|
|
26
21
|
requirements:
|
27
22
|
- - ">="
|
28
23
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 47
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
- 12
|
33
|
-
- 0
|
34
24
|
version: 0.12.0
|
35
25
|
type: :runtime
|
36
26
|
version_requirements: *id001
|
@@ -72,23 +62,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
72
62
|
requirements:
|
73
63
|
- - ">="
|
74
64
|
- !ruby/object:Gem::Version
|
75
|
-
hash: 3
|
76
|
-
segments:
|
77
|
-
- 0
|
78
65
|
version: "0"
|
79
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
67
|
none: false
|
81
68
|
requirements:
|
82
69
|
- - ">="
|
83
70
|
- !ruby/object:Gem::Version
|
84
|
-
hash: 3
|
85
|
-
segments:
|
86
|
-
- 0
|
87
71
|
version: "0"
|
88
72
|
requirements: []
|
89
73
|
|
90
74
|
rubyforge_project:
|
91
|
-
rubygems_version: 1.
|
75
|
+
rubygems_version: 1.6.2
|
92
76
|
signing_key:
|
93
77
|
specification_version: 3
|
94
78
|
summary: Mockingbird is a mock server for testing with the Twitter Streaming API.
|