westfieldlabs / apivore

Tests your rails API against its Swagger description of end-points, models, and query parameters.
Apache License 2.0
213 stars 66 forks source link

Fails to pull swagger json #94

Closed nblumoe closed 8 years ago

nblumoe commented 8 years ago

apivore does not succeed on pulling a swagger JSON. After not having had any success with the proper, local JSON, we tried the one of the Swagger Pet demo, which did not work either:

1) the API and tests all documented routes
     Failure/Error: subject { Apivore::SwaggerChecker.instance_for('http://petstore.swagger.io/v2/swagger.json') }

     RuntimeError:
       Unable to perform GET request for swagger json: http://petstore.swagger.io/v2/swagger.json - undefined method `call' for nil:NilClass
       Did you mean?  caller.
     # /Users/nblu/.rvm/gems/ruby-2.3.1@bit.abe-face/bundler/gems/apivore-275e799ea72c/lib/apivore/swagger_checker.rb:78:in `rescue in fetch_swagger!'
     # /Users/nblu/.rvm/gems/ruby-2.3.1@bit.abe-face/bundler/gems/apivore-275e799ea72c/lib/apivore/swagger_checker.rb:75:in `fetch_swagger!'
     # /Users/nblu/.rvm/gems/ruby-2.3.1@bit.abe-face/bundler/gems/apivore-275e799ea72c/lib/apivore/swagger_checker.rb:70:in `load_swagger_doc!'
     # /Users/nblu/.rvm/gems/ruby-2.3.1@bit.abe-face/bundler/gems/apivore-275e799ea72c/lib/apivore/swagger_checker.rb:64:in `initialize'
     # /Users/nblu/.rvm/gems/ruby-2.3.1@bit.abe-face/bundler/gems/apivore-275e799ea72c/lib/apivore/swagger_checker.rb:6:in `new'
     # /Users/nblu/.rvm/gems/ruby-2.3.1@bit.abe-face/bundler/gems/apivore-275e799ea72c/lib/apivore/swagger_checker.rb:6:in `instance_for'
     # ./spec/requests/api_spec.rb:4:in `block (2 levels) in <top (required)>'
     # ./spec/requests/api_spec.rb:12:in `block (3 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # NoMethodError:
     #   undefined method `call' for nil:NilClass
     #   Did you mean?  caller

We are on Rails 5.0.0

nblumoe commented 8 years ago

The issue was with rack-test not getting a reference to the Rails application. In the end a simple fix is to add the following to spec_helper.rb: require File.expand_path("../../config/environment", __FILE__)