test/hyperclient/entry_point_test.rb in hyperclient-0.2.0 vs test/hyperclient/entry_point_test.rb in hyperclient-0.3.0
- old
+ new
@@ -1,51 +1,34 @@
require_relative '../test_helper'
require 'hyperclient/entry_point'
module Hyperclient
describe EntryPoint do
- let(:api) do
+ let(:entry_point) do
EntryPoint.new 'http://my.api.org'
end
- before do
- stub_request(:get, "http://my.api.org/").
- to_return(body: '{"_links": {"self": {"href": "http://my.api.org"}}}', headers: {content_type: 'application/json'})
- end
-
- describe 'initialize' do
- it 'initializes a Resource at the entry point' do
- api.links['self'].url.must_equal 'http://my.api.org'
+ describe 'connection' do
+ it 'creates a Faraday connection with the entry point url' do
+ entry_point.connection.url_prefix.to_s.must_equal 'http://my.api.org/'
end
- it 'setups the HTTP config' do
- options = {:headers => {'accept-encoding' => 'deflate, gzip'}}
-
- api = EntryPoint.new('http://my.api.org', options)
-
- api.config[:headers].must_include 'accept-encoding'
+ it 'creates a Faraday connection with the default headers' do
+ entry_point.headers['Content-Type'].must_equal 'application/json'
+ entry_point.headers['Accept'].must_equal 'application/json'
end
- it 'sets the base_uri for HTTP' do
- api = EntryPoint.new('http://my.api.org')
-
- api.config[:base_uri].must_equal 'http://my.api.org'
+ it 'creates a Faraday connection with the default block' do
+ handlers = entry_point.connection.builder.handlers
+ handlers.must_include FaradayMiddleware::EncodeJson
+ handlers.must_include FaradayMiddleware::ParseJson
+ handlers.must_include Faraday::Adapter::NetHttp
end
end
- describe 'method missing' do
- it 'delegates undefined methods to the API when they exist' do
- Resource.any_instance.expects(:foo).returns 'foo'
- api.foo.must_equal 'foo'
- end
-
- it 'responds to missing methods' do
- Resource.any_instance.expects(:respond_to?).with('foo').returns(true)
- api.respond_to?(:foo).must_equal true
- end
-
- it 'raises an error when the method does not exist in the API' do
- lambda { api.this_method_does_not_exist }.must_raise(NoMethodError)
+ describe 'initialize' do
+ it 'sets a Link with the entry point url' do
+ entry_point.url.must_equal 'http://my.api.org'
end
end
end
end
\ No newline at end of file