realweb 0.1.0 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.rdoc +36 -13
  2. data/lib/realweb/server.rb +0 -1
  3. metadata +6 -6
data/README.rdoc CHANGED
@@ -1,24 +1,47 @@
1
1
  = RealWeb
2
2
 
3
- Boot a rack app in a thread or process to use as a real test endpoint.
3
+ Boot a rack app to use as a real endpoint for tests.
4
4
 
5
- === Usage
5
+ == Why?
6
6
 
7
- before(:each) do
8
- @server = RealWeb.start_server("path/to/config.ru")
9
- end
7
+ We found this very useful for gems that hit an API. Rather than mocking out all
8
+ the URIs with FakeWeb, you can just write a sample rack app that looks like the
9
+ API you're expecting. It's not uncommon to have 5+ different small rack apps
10
+ that reflect different behaviors of your remote server. We created things like
11
+ broken.ru that always responds with 500s, forbidden.ru that is always 403, and
12
+ healthy.ru that always returns happy path responses.
10
13
 
11
- after(:each) do
12
- @server.stop
13
- end
14
+ Another useful way to use this is with paired client/server libraries. We use
15
+ RealWeb to boot up the real rack server and hit it with the client from within
16
+ the specs.
17
+
18
+ == Usage
19
+
20
+ # fixtures/config.ru
21
+ run lambda { |env| [200, { 'Content-Type' => 'application/json' }, '[{thing: 1}, {thing: 2}]'] }
22
+
23
+ # thing_api_spec.rb
24
+ describe MyLibrary do
25
+ before(:each) do
26
+ @server = RealWeb.start_server("fixtures/config.ru")
27
+ end
14
28
 
15
- it "runs some action that would normally hit the api" do
16
- MyLibrary.get_list_of_things(@server.base_uri)
29
+ after(:each) do
30
+ @server.stop
31
+ end
32
+
33
+ it "runs an action that would normally hit the api" do
34
+ MyLibrary.get_list_of_things_from_api(@server.base_uri).should_not be_empty
35
+ end
17
36
  end
18
37
 
19
38
 
20
- RealWeb.start_server boots the given config.ru in a thread. When you call stop on the server object, the server is killed.
39
+ RealWeb.start_server boots the given config.ru in a thread. When you call stop
40
+ on the server object, the server is killed.
21
41
 
22
- You can specifically use a Process.fork server with start_server_in_fork.
42
+ The example uses an extremely simplistic rack app. We usually use Sinatra apps
43
+ for RealWeb backends.
23
44
 
24
- RealWeb uses WEBrick for its pure ruby server. No extra dependencies or C extensions.
45
+ == Forking Server
46
+
47
+ You can specifically use a Process.fork server with start_server_in_fork.
@@ -99,7 +99,6 @@ module RealWeb
99
99
  open(base_uri)
100
100
  return
101
101
  rescue Errno::ECONNREFUSED
102
- puts "Connection refused; retrying..."
103
102
  sleep 0.5
104
103
  end
105
104
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: realweb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ben Burkert
@@ -17,11 +17,10 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-05-28 00:00:00 -07:00
20
+ date: 2010-06-01 00:00:00 -07:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
24
- prerelease: false
25
24
  version_requirements: &id001 !ruby/object:Gem::Requirement
26
25
  none: false
27
26
  requirements:
@@ -34,8 +33,9 @@ dependencies:
34
33
  - 0
35
34
  version: 1.1.0
36
35
  requirement: *id001
37
- type: :runtime
38
36
  name: rack
37
+ type: :runtime
38
+ prerelease: false
39
39
  description: Easily runs a rack app for tests that hit web APIs
40
40
  email: cloud-engineering@engineyard.com
41
41
  executables: []