Faraday::Error: :hashie is not registered on Faraday::Middleware

1k views Asked by At

I am creating a wrapper gem for a RESTful API. I am getting following error when I try to add hashie middleware as per the documentation:

Magpress::Login::#call#test_0001_should return valid JWT token:
Faraday::Error: :hashie is not registered on Faraday::Middleware
    /home/amit/.rvm/gems/ruby-2.2.2@magpress/gems/faraday-0.10.0/lib/faraday.rb:184:in `lookup_middleware'
    /home/amit/.rvm/gems/ruby-2.2.2@magpress/gems/faraday-0.10.0/lib/faraday/rack_builder.rb:204:in `use_symbol'
    /home/amit/.rvm/gems/ruby-2.2.2@magpress/gems/faraday-0.10.0/lib/faraday/rack_builder.rb:84:in `use'
    /home/amit/projects/bt/magpress/lib/magpress/client.rb:24:in `block in connection'
    /home/amit/.rvm/gems/ruby-2.2.2@magpress/gems/faraday-0.10.0/lib/faraday/connection.rb:91:in `initialize'
    /home/amit/.rvm/gems/ruby-2.2.2@magpress/gems/faraday-0.10.0/lib/faraday.rb:70:in `new'
    /home/amit/.rvm/gems/ruby-2.2.2@magpress/gems/faraday-0.10.0/lib/faraday.rb:70:in `new'
    /home/amit/projects/bt/magpress/lib/magpress/client.rb:18:in `connection'
    /home/amit/projects/bt/magpress/lib/magpress/base.rb:7:in `initialize'
    /home/amit/projects/bt/magpress/test/login_spec.rb:13:in `new'
    /home/amit/projects/bt/magpress/test/login_spec.rb:13:in `block (3 levels) in <top (required)>'

Here is how I delcared dependencies in .gemspec.

...
  spec.add_dependency "faraday"
  spec.add_dependency "faraday_middleware"
  spec.add_dependency "hashie"
....

and the class that uses faraday and it's middleware

require 'faraday'
require 'faraday_middleware'
require 'hashie'
module Magpress
  class Client
    def connection(url)
      conn = ::Faraday.new(url) do |faraday|
        faraday.request :json

        faraday.response :json, :content_type => /\bjson$/

        # faraday.use :instrumentation
        faraday.use :hashie # FaradayMiddleware::Mashify
        faraday.adapter Faraday.default_adapter
      end   
      conn
    end
  end
end

farady and middlware gem versions

amit@amit:~/projects/bt/magpress$ gem list | grep faraday
faraday (0.10.0)
faraday_middleware (0.10.1)

What could be wrong here?

If I replace :hashie with FaradayMiddleware::Mashify, the errors goes away but the response.body returns instance of vanilla Hash instead of Hashie::Mash

1

There are 1 answers

0
Amit Patel On BEST ANSWER

Voila! It is fixed.

Current

faraday.response :json, :content_type !=> /\bjson$/
faraday.use :hashie # FaradayMiddleware::Mashify

After Fix

faraday.response :mashify
faraday.response :json, :content_type => /\bjson$/

I could fix by reading the code!