diff options
| author | Zack Hobson | 2014-04-21 12:56:40 -0700 | 
|---|---|---|
| committer | Zack Hobson | 2014-04-21 13:06:14 -0700 | 
| commit | 3bc51e96c7a88dfdf8d003c669d4af33d92ab90c (patch) | |
| tree | 8f996ddf2773482e3d0cddcbabcb77ab15819009 | |
| parent | 92974b1fa9d8a975a8583eba967a346de1e20781 (diff) | |
| download | hcl-3bc51e96c7a88dfdf8d003c669d4af33d92ab90c.tar.bz2 | |
remove dependency on fakeweb and net::http
By using pure faraday for the test and error handling code,
the way is cleared for dropping in alternative http clients.
| -rw-r--r-- | Gemfile.lock | 4 | ||||
| -rw-r--r-- | hcl.gemspec | 1 | ||||
| -rw-r--r-- | lib/hcl/app.rb | 2 | ||||
| -rw-r--r-- | lib/hcl/net.rb | 6 | ||||
| -rw-r--r-- | test/app_test.rb | 2 | ||||
| -rw-r--r-- | test/test_helper.rb | 12 | 
6 files changed, 14 insertions, 13 deletions
| diff --git a/Gemfile.lock b/Gemfile.lock index f34297f..dc8c996 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -18,12 +18,11 @@ GEM      coderay (1.1.0)      docile (1.1.2)      escape_utils (1.0.1) -    fakeweb (1.3.0)      faraday (0.9.0)        multipart-post (>= 1.2, < 3)      ffi (1.9.3-java)      gem-man (0.3.0) -    highline (1.6.20) +    highline (1.6.21)      hpricot (0.8.6)      hpricot (0.8.6-java)      metaclass (0.0.2) @@ -72,7 +71,6 @@ PLATFORMS    ruby  DEPENDENCIES -  fakeweb    hcl!    minitest    mocha diff --git a/hcl.gemspec b/hcl.gemspec index d254d49..1191bb0 100644 --- a/hcl.gemspec +++ b/hcl.gemspec @@ -28,7 +28,6 @@ Gem::Specification.new do |s|    s.add_development_dependency 'mocha'    s.add_development_dependency 'yard'    s.add_development_dependency 'simplecov' -  s.add_development_dependency 'fakeweb'    s.add_development_dependency 'minitest'  end diff --git a/lib/hcl/app.rb b/lib/hcl/app.rb index 0cda7b4..14f626d 100644 --- a/lib/hcl/app.rb +++ b/lib/hcl/app.rb @@ -66,7 +66,7 @@ module HCl        rescue RuntimeError => e          $stderr.puts "Error: #{e}"          exit 1 -      rescue SocketError => e +      rescue Faraday::Error => e          $stderr.puts "Connection failed. (#{e.message})"          exit 1        rescue HarvestMiddleware::ThrottleFailure => e diff --git a/lib/hcl/net.rb b/lib/hcl/net.rb index 730e5b4..ac794d6 100644 --- a/lib/hcl/net.rb +++ b/lib/hcl/net.rb @@ -19,7 +19,11 @@ module HCl          "https://#{subdomain}.harvestapp.com"        ) do |f|          f.use :harvest, login, password -        f.adapter Faraday.default_adapter +        if opts['test_adapter'] +          f.adapter :test, opts['test_adapter'] +        else +          f.adapter Faraday.default_adapter +        end        end      end diff --git a/test/app_test.rb b/test/app_test.rb index de10989..4c997d7 100644 --- a/test/app_test.rb +++ b/test/app_test.rb @@ -40,7 +40,7 @@ class AppTest < HCl::TestCase    def test_socket_error      app = HCl::App.new -    app.expects(:show).raises(SocketError) +    app.expects(:show).raises(Faraday::Error)      app.expects(:exit).with(1)      app.process_args('show').run      assert_match /connection failed/i, error_output diff --git a/test/test_helper.rb b/test/test_helper.rb index 95cb0b4..4d1c3a5 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -22,7 +22,7 @@ require 'hcl'  require 'minitest/autorun'  require 'mocha/setup'  require 'fileutils' -require 'fakeweb' +require 'faraday'  require 'debugger' if ENV['DEBUG']  # require test extensions/helpers @@ -31,20 +31,20 @@ Dir[File.dirname(__FILE__) + '/ext/*.rb'].each { |ext| require ext }  class HCl::TestCase < MiniTest::Test    attr_reader :http    def setup -    FakeWeb.allow_net_connect = false +    @stubs = Faraday::Adapter::Test::Stubs.new      @http = HCl::Net.new \        'login' => 'bob',        'password' => 'secret', -      'subdomain' => 'bobclock' +      'subdomain' => 'bobclock', +      'test_adapter' => @stubs    end    def register_uri method, path, data={} -    FakeWeb.register_uri(method, "https://bob:secret@bobclock.harvestapp.com#{path}", -                         body: Yajl::Encoder.encode(data)) +    @stubs.send(method, path) { [200, {}, Yajl::Encoder.encode(data)] }    end    def teardown -    FakeWeb.clean_registry +    @stubs.verify_stubbed_calls    end  end | 
