Giter Site home page Giter Site logo

gonzalo-bulnes / dredd-rack Goto Github PK

View Code? Open in Web Editor NEW
50.0 50.0 14.0 129 KB

The Dredd API blueprint testing tool for your Rack applications.

License: GNU General Public License v3.0

Ruby 100.00%
api-blueprint dredd dredd-hooks rack rails ruby testing-tools

dredd-rack's People

Contributors

gonzalo-bulnes avatar jesperronn avatar maxim-filimonov avatar rylnd avatar tobiashm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dredd-rack's Issues

Rake task always throwing InvalidCommandError for local api

Tried running the following dredd rake task definition:

Dredd::Rack::RakeTask.new do |task|
  task.runner.configure do |config|
      config.paths_to_blueprints 'apiary.apib'
      config.reporter :apiary
      config.custom ["apiaryApiKey:#{ENV['APIARY_KEY']}", "apiaryApiName:#{ENV['APIARY_NAME']}"]
      config.language :ruby
      config.level :info
      config.sorted!
  end
end

Result in a InvalidCommandError exception since the following pre-condition happens before the capybara server is launched and the instance variable @api_endpoint is setup.

https://github.com/gonzalo-bulnes/dredd-rack/blob/master/lib/dredd/rack/runner.rb#L99

Task definition can't be in lib/tasks/

# lib/tasks/dredd_rack.rake
require 'dredd/rack'

Dredd::Rack::RakeTask.new

causes the same symptoms as described in #8.

The reason is that the hook that loads all these tasks, Rails.application.load_tasks, seems to load local tasks before the environment task, such that this condition is never met.

I wish I had the time and/or knowledge to figure out how to make this work. For now, placing the task definition after the load_tasks hook in the Rakefile is a reasonable workaround.

Can't have spaces in headers without encapsulation as string.

I found that I was unable to get headers with spaces working until I had encapsulated the whole thing in a string. This was far from obvious in the documentation and it was only a great deal of trial and error that led me to find the problem.

This should either be resolved, or the documentation updated.

For example this did not work:

options.header "Authorization: Bearer #{token}"

But this did

options.header "'Authorization: Bearer #{token}'"

Rails applications that are served automatically always respond with HTTP 500

Given a Rails application configured to use Dredd::Rack
And the corresponding valid API blueprint
When I start the Rails server on http://localhost:3000
And I run rake dredd API_HOST=http://localhost:3000
Then the API blueprint validation succeeds as expected

When I run rake dredd
Then a local server is automatically setup
But the API blueprint validation unexpectedly fails on error 500

Notes: That does not happen with Sinatra applications, and seems to be related to #8.

InvalidCommandError when defining a simple `paths_to_blueprints`

As a developer
Given I am testing a local API
And I defined the blueprints location by providing a single argument to Runner#paths_to_blueprints - e.g. dredd.paths_to_blueprints('doc/*.apib')
When I run Dredd
Then I expect the local server URL to be defined automatically
And the API to be tested
But I get an InvalidCommandError instead

See #17, where @rylnd wrote:

Currently one is unable to do the following:

Dredd::Rack::RakeTask.new do |task|
  task.runner.configure do |dredd|
    dredd.paths_to_blueprints 'doc/*.apib'
  end
end

because the task exits early due to the # of arguments being checked before we attempt to run the server (which has the side effect of adding an argument).

Rake task does not load initializers

Following the README for setting up dredd-rack, we end up with a rake task definition and an initializer file. However, the initializer is not run by the rake task, and thus Dredd::Rack.app is nil when the test runs, resulting in a 500 response and subsequent failures.

We happened to solve this by explicitly requiring the environment in the rake task:

task dredd: :environment

I realize the documentation also recommends placing the assignment of Dredd::Rack.app in either app.rb or the Rakefile, but the standard location for that kind of thing seems like an initializer, so I would expect that to work as well.

Perhaps we missed something? Please advise.

Allow dredd command customization

Would be great to be able to override default dredd command. Since I launch dredd in a dockerized application, the way to go is to not install npm packages globaly but locally in the project directory.

I currently had to monkey patch dredd-rack with the following code to be able to change dredd's command:

module Dredd
  module Rack
    class Runner
      def initialize(api_endpoint=nil)
        @dredd_command = '$(npm bin)/dredd'
        @paths_to_blueprints = 'doc/*.apib doc/*.apib.md'
        @api_endpoint = api_endpoint || ''
        @command_parts = []

        yield self if block_given?
      end
    end
  end
end

module Dredd
  module Rack
    class RakeTask
      def dredd_available?
        true
      end
    end
  end
end

Support swagger files

The underlying dredd library now supports validation swagger files. Can this functionality be exposed in dredd-rack?

Spaces in only tasks

I think there is a bug with space handling for only parameter. It's quite common to have spaces in api names and resources groupes. Usually when dredd needs to be run we would wrap those names in quotes to prevent shell confusion.
For example,
Manually we do

dredd ./*.apib ./*.apib *.apib.mb  --only "Mobile Data > Realtime > GET" http://localhost:3000

Same parameters does not work with dredd-rack

    dredd = Dredd::Rack::Runner.new do |options|
      options.paths_to_blueprints './*.apib ./*.apib *.apib.mb'
      options.only("Mobile Data > Realtime > GET")
    end

=> dredd ./*.apib ./*.apib *.apib.mb  --only Mobile Data > Realtime > GET http://localhost:3000

Workaround is to use quotes inside quotes:

   options.only("""Mobile Data > Realtime > GET""")

OR

 options.only("\"Mobile Data > Realtime > GET\"")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.