hyperclient 0.0.8 → 0.1.0

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.
@@ -1,32 +0,0 @@
1
- require_relative '../test_helper'
2
- require 'hyperclient/resource_factory'
3
-
4
- module Hyperclient
5
- describe ResourceFactory do
6
- let(:resource) do
7
- ResourceFactory.resource('/path/to/resource')
8
- end
9
-
10
- before do
11
- Hyperclient::Resource.entry_point = 'http://myapi.org'
12
- end
13
-
14
- describe 'resource' do
15
- it 'creates a new resource when is not present in the identity map' do
16
- resource = ResourceFactory.resource('/path/to/resource')
17
-
18
- resource.url.must_include '/path/to/resource'
19
- end
20
-
21
- it 'returns the resource when is already present in the identity map' do
22
- new_resource = ResourceFactory.resource('/path/to/resource')
23
-
24
- new_resource.object_id.must_equal resource.object_id
25
- end
26
-
27
- it 'raises if the given url is nil' do
28
- proc { ResourceFactory.resource(nil) }.must_raise MissingURLException
29
- end
30
- end
31
- end
32
- end
@@ -1,68 +0,0 @@
1
- require_relative 'test_helper'
2
- require 'hyperclient'
3
-
4
- describe Hyperclient do
5
- let(:api) do
6
- Class.new do
7
- include Hyperclient
8
- end
9
- end
10
-
11
- describe 'entry point' do
12
- it 'sets the entry point for Hyperclient::Resource' do
13
- api.entry_point {'http://my.api.org'}
14
-
15
- Hyperclient::Resource.new('/').url.must_include 'http://my.api.org'
16
- end
17
- end
18
-
19
- describe 'entry' do
20
- before do
21
- api.entry_point {'http://my.api.org'}
22
- end
23
-
24
- it 'initializes a Resource at the entry point' do
25
- api.new.entry.url.must_equal 'http://my.api.org'
26
- end
27
-
28
- it 'also works with entry points that are not in the root' do
29
- api.entry_point {'http://my.api.org/api'}
30
- api.new.entry.url.must_equal 'http://my.api.org/api'
31
- end
32
-
33
- it 'sets the Resource name' do
34
- api.new.name.must_equal 'Entry point'
35
- end
36
- end
37
-
38
- describe 'auth' do
39
- it 'sets authentication type' do
40
- api.auth{ {type: :digest, user: nil, password: nil} }
41
-
42
- api.http_options[:http][:auth][:type].must_equal :digest
43
- end
44
-
45
- it 'sets the authentication credentials' do
46
- api.auth{ {type: :digest, user: 'user', password: 'secret'} }
47
-
48
- api.http_options[:http][:auth][:credentials].must_include 'user'
49
- api.http_options[:http][:auth][:credentials].must_include 'secret'
50
- end
51
- end
52
-
53
- describe 'method missing' do
54
- class Hyperclient::Resource
55
- def foo
56
- 'foo'
57
- end
58
- end
59
-
60
- it 'delegates undefined methods to the API when they exist' do
61
- api.new.foo.must_equal 'foo'
62
- end
63
-
64
- it 'raises an error when the method does not exist in the API' do
65
- lambda { api.new.this_method_does_not_exist }.must_raise(NoMethodError)
66
- end
67
- end
68
- end