fredo 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
data/fredo.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{fredo}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["ilpoldo"]
12
- s.date = %q{2010-03-24}
12
+ s.date = %q{2010-04-26}
13
13
  s.description = %q{Mocks web services by plugging Net::Http straight into Rack}
14
14
  s.email = %q{ilpoldo@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -38,6 +38,11 @@ module Net #:nodoc: all
38
38
  def request_with_fredo(request, body = nil, &block)
39
39
  request_body = body
40
40
 
41
+ case request_body
42
+ when nil then body = StringIO.new
43
+ when String then body = StringIO.new(body)
44
+ end
45
+
41
46
  uri = URI.parse(request.path)
42
47
  protocol = use_ssl? ? "https" : "http"
43
48
  full_path = "#{protocol}://#{self.address}:#{self.port}#{request.path}"
@@ -50,7 +55,7 @@ module Net #:nodoc: all
50
55
  'SERVER_PORT' => self.port,
51
56
  'rack.version' => [1,1],
52
57
  'rack.url_scheme' => protocol,
53
- 'rack.input' => body || StringIO.new,
58
+ 'rack.input' => body,
54
59
  'rack.errors' => $stderr,
55
60
  'rack.multithread' => true,
56
61
  'rack.multiprocess' => true,
data/spec/fredo_spec.rb CHANGED
@@ -31,6 +31,31 @@ describe Fredo do
31
31
  response.read.should eql(body)
32
32
  # response.header["Content-Type"].should eql("text/html")
33
33
  end
34
+
35
+ it "can hijack a ssl resource" do
36
+ body = "Don't trust this website."
37
+
38
+ Fredo.get 'https://web-bank.com' do
39
+ body
40
+ end
41
+
42
+ response = open('https://web-bank.com')
43
+ response.read.should eql(body)
44
+ # response.header["Content-Type"].should eql("text/html")
45
+ end
46
+
47
+ it "deals with post requests" do
48
+ body = "This is the post body"
49
+
50
+ Fredo.post 'http://postyourthoughts.com' do
51
+ body
52
+ end
53
+
54
+ url = URI.parse 'http://postyourthoughts.com'
55
+ http = Net::HTTP.new(url.host)
56
+ http.post('/', 'query=foo', 'content-type' => 'text/plain').body.should eql([body])
57
+ end
58
+
34
59
  end
35
60
 
36
61
  context "registry" do
@@ -40,7 +65,7 @@ describe Fredo do
40
65
  Fredo::Registry.routes['GET'].should_not be_empty
41
66
  end
42
67
 
43
- it "is clears in every spec" do
68
+ it "it clears in every spec" do
44
69
  # Automate?
45
70
  Fredo.forget
46
71
  Fredo::Registry.routes.should be_empty
@@ -58,6 +83,16 @@ describe Fredo do
58
83
  response = open('http://www.twitter.com/sam')
59
84
  response.read.should include('It ain\'t sam')
60
85
  end
86
+
87
+ it "parses query parameters" do
88
+
89
+ Fredo.get 'http://www.google.com/search' do
90
+ "You are looking for #{params['q']}"
91
+ end
92
+
93
+ response = open('http://www.google.com/search?q=happyness')
94
+ response.read.should include('You are looking for happyness')
95
+ end
61
96
 
62
97
  it "plays nice with regex" do
63
98
  Fredo.get 'http://www.google.com/*' do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 3
9
- version: 0.1.3
8
+ - 4
9
+ version: 0.1.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - ilpoldo
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-24 00:00:00 +00:00
17
+ date: 2010-04-26 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency