gonzalo-bulnes / dredd-rack Goto Github PK
View Code? Open in Web Editor NEWThe Dredd API blueprint testing tool for your Rack applications.
License: GNU General Public License v3.0
The Dredd API blueprint testing tool for your Rack applications.
License: GNU General Public License v3.0
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
When I extend the Dredd::Hooks API
I want the changes to have been discussed previously
So that I know they are reasonable
Hello. Are there any plans to add support for Capybara 3.0.x ?
# 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.
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}'"
GitHub introduces topics. It would be nice if this repo had dredd
, ruby
, and dredd-hooks
.
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.
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
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 endbecause 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).
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.
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
As a developer
In order to avoid bad surprises
I want the documentation call the rke task by it name: :dredd
And the version requirement suggestion to be safe while the gem is unstable ~> 0.3.0
The underlying dredd library now supports validation swagger files. Can this functionality be exposed in dredd-rack?
As a developer
In order to be able to take profit of my habitual testing tools (e.g. FactoryGirl) to setup documentation and testing scenarios
I want to be able to write Dredd hooks in Ruby
See also: the original discussions and this proof of concept.
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\"")
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.