faraday 0.2.0 → 0.2.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.
@@ -6,17 +6,17 @@ This mess is gonna get raw, like sushi. So, haters to the left.
6
6
 
7
7
  == Usage
8
8
 
9
- conn = Alice::Connection.new(:url => 'http://sushi.com') do |builder|
10
- builder.use Alice::Request::Yajl # convert body to json with Yajl lib
11
- builder.use Alice::Adapter::Logger # log the request somewhere?
12
- builder.use Alice::Adapter::Typhoeus # make http request with typhoeus
13
- builder.use Alice::Response::Yajl # # parse body with yajl
9
+ conn = Faraday::Connection.new(:url => 'http://sushi.com') do |builder|
10
+ builder.use Faraday::Request::Yajl # convert body to json with Yajl lib
11
+ builder.use Faraday::Adapter::Logger # log the request somewhere?
12
+ builder.use Faraday::Adapter::Typhoeus # make http request with typhoeus
13
+ builder.use Faraday::Response::Yajl # # parse body with yajl
14
14
 
15
15
  # or use shortcuts
16
- builder.request :yajl # Alice::Request::Yajl
17
- builder.adapter :logger # Alice::Adapter::Logger
18
- builder.adapter :typhoeus # Alice::Adapter::Typhoeus
19
- builder.response :yajl # Alice::Response::Yajl
16
+ builder.request :yajl # Faraday::Request::Yajl
17
+ builder.adapter :logger # Faraday::Adapter::Logger
18
+ builder.adapter :typhoeus # Faraday::Adapter::Typhoeus
19
+ builder.response :yajl # Faraday::Response::Yajl
20
20
  end
21
21
 
22
22
  resp1 = conn.get '/nigiri/sake.json'
@@ -29,21 +29,21 @@ This mess is gonna get raw, like sushi. So, haters to the left.
29
29
  == Testing
30
30
 
31
31
  # It's possible to define stubbed request outside a test adapter block.
32
- stubs = Alice::Test::Stubs.new do |stub|
33
- stub.get('/tamago') { [200, 'egg', {} }
32
+ stubs = Faraday::Test::Stubs.new do |stub|
33
+ stub.get('/tamago') { [200, {}, 'egg' }
34
34
  end
35
35
 
36
36
  # You can pass stubbed request to the test adapter or define them in a block
37
37
  # or a combination of the two.
38
- test = Alice::Connection.new do |builder|
38
+ test = Faraday::Connection.new do |builder|
39
39
  builder.adapter :test, stubs do |stub|
40
- stub.get('/ebi') {[ 200, 'shrimp', {} ]}
40
+ stub.get('/ebi') {[ 200, {}, 'shrimp' ]}
41
41
  end
42
42
  end
43
43
 
44
44
  # It's also possible to stub additional requests after the connection has
45
45
  # been initialized. This is useful for testing.
46
- stubs.get('/uni') {[ 200, 'urchin', {} ]}
46
+ stubs.get('/uni') {[ 200, {}, 'urchin' ]}
47
47
 
48
48
  resp = test.get '/tamago'
49
49
  resp.body # => 'egg'
@@ -53,6 +53,12 @@ This mess is gonna get raw, like sushi. So, haters to the left.
53
53
  resp.body # => 'urchin'
54
54
  resp = test.get '/else' #=> raises "no such stub" error
55
55
 
56
+ # If you like, you can treat your stubs as mocks by verifying that all of the
57
+ # stubbed calls were made. NOTE that this feature is still fairly
58
+ # experimental: It will not verify the order or count of any stub, only that
59
+ # it was called once during the course of the test.
60
+ stubs.verify_stubbed_calls
61
+
56
62
  == TODO
57
63
 
58
64
  * Add curb/em-http support
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{faraday}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["rick"]
12
- s.date = %q{2010-01-12}
12
+ s.date = %q{2010-02-04}
13
13
  s.description = %q{HTTP/REST API client library with pluggable components}
14
14
  s.email = %q{technoweenie@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -56,12 +56,29 @@ module Faraday
56
56
  def new_stub(request_method, path, body=nil, &block)
57
57
  (@stack[request_method] ||= []) << Stub.new(path, body, block)
58
58
  end
59
+
60
+ # Raises an error if any of the stubbed calls have not been made.
61
+ def verify_stubbed_calls
62
+ failed_stubs = []
63
+ @stack.each do |method, stubs|
64
+ unless stubs.size == 0
65
+ failed_stubs.concat(stubs.map {|stub|
66
+ "Expected #{method} #{stub}."
67
+ })
68
+ end
69
+ end
70
+ raise failed_stubs.join(" ") unless failed_stubs.size == 0
71
+ end
59
72
  end
60
73
 
61
74
  class Stub < Struct.new(:path, :body, :block)
62
75
  def matches?(request_path, request_body)
63
76
  request_path == path && request_body == body
64
77
  end
78
+
79
+ def to_s
80
+ "#{path} #{body}"
81
+ end
65
82
  end
66
83
 
67
84
  def initialize app, stubs=nil, &block
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - rick
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-12 00:00:00 -08:00
12
+ date: 2010-02-04 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency