net-httpstub 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.0.2 / 2009-04-26
2
+
3
+ * support Net::HTTP.push_file.
4
+
5
+
1
6
  == 0.0.1 / 2009-04-25
2
7
 
3
8
  * initial release
data/Rakefile CHANGED
@@ -18,7 +18,7 @@ DESCRIPTION = "net-httpstub is a stub of Net::HTTP."
18
18
  RUBYFORGE_PROJECT = "net-httpstub"
19
19
  HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
20
20
  BIN_FILES = %w( )
21
- VERS = "0.0.1"
21
+ VERS = "0.0.2"
22
22
 
23
23
  sudo = 'sudo ' unless /mswin|mingw/ =~ RUBY_PLATFORM
24
24
 
data/lib/net/httpstub.rb CHANGED
@@ -6,12 +6,25 @@ module Net
6
6
  @@responses = []
7
7
 
8
8
  class << HTTP
9
- # push response list and stub mode.
9
+ # push the res to the response list,
10
+ # and set stub mode on.
10
11
  def push(res)
11
12
  @@responses.push add_header(res)
12
13
  self.stub = true
13
14
  end
14
15
 
16
+ # push the content of filename to the response list,
17
+ # and set stub mode on.
18
+ def push_file(filename, base_path = ".")
19
+ unless filename == File.expand_path(filename)
20
+ base_path = File.expand_path(base_path)
21
+ base_path = File.dirname(base_path) unless File.directory?(base_path)
22
+ filename = File.join(base_path, filename)
23
+ end
24
+ res = open(filename){|f| f.read}
25
+ push(res)
26
+ end
27
+
15
28
  # return stub mode.
16
29
  def stub
17
30
  @stub || false
@@ -26,10 +26,34 @@ HTTP/1.1 404 Not Found
26
26
  assert_equal "", res.body
27
27
  end
28
28
  end
29
-
30
29
  end
31
30
 
32
31
  class HttpstubTest < Test::Unit::TestCase
32
+ def test_push_file
33
+ Net::HTTP.push_file "response.txt", __FILE__
34
+ Net::HTTP.start('www.example.com') do |http|
35
+ res = http.get('/')
36
+ assert_equal "response body", res.body
37
+ end
38
+ end
39
+
40
+ def test_push_file2
41
+ Net::HTTP.push_file "test/response.txt"
42
+ Net::HTTP.start('www.example.com') do |http|
43
+ res = http.get('/')
44
+ assert_equal "response body", res.body
45
+ end
46
+ end
47
+
48
+ def test_push_file3
49
+ filename = File.expand_path("test/response.txt")
50
+ Net::HTTP.push_file filename, "/" # ignore "/"
51
+ Net::HTTP.start('www.example.com') do |http|
52
+ res = http.get('/')
53
+ assert_equal "response body", res.body
54
+ end
55
+ end
56
+
33
57
  def test_stub
34
58
  assert_equal false, Net::HTTP.stub?
35
59
  assert_equal false, Net::HTTP.stub
data/test/response.txt ADDED
@@ -0,0 +1 @@
1
+ response body
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-httpstub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - momotaro
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-25 00:00:00 +09:00
12
+ date: 2009-04-26 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -27,6 +27,7 @@ files:
27
27
  - ChangeLog
28
28
  - Rakefile
29
29
  - test/net-httpstub_test.rb
30
+ - test/response.txt
30
31
  - test/test_helper.rb
31
32
  - lib/net/httpstub.rb
32
33
  has_rdoc: true