Skip to content

Commit

Permalink
Merge branch 'add-dredd-command-option'
Browse files Browse the repository at this point in the history
As a developer
In order to be able to use Dredd::Rack with installations of
Dredd that are not global
And, for example, use it inside a Docker container
I want to define a custom Dredd command
And I want that configuration to be used by all the defined Rake tasks

Closes #25
  • Loading branch information
gonzalo-bulnes committed Jun 14, 2016
2 parents d1f4b46 + e062e52 commit b23ce29
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 9 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added

- Add **dredd_command** option - with help from @gottfrois
- Add configuration handler for convenient initializers

## [0.8.2] - 2016-06-08

### Fixed

- Fix inaccurate counting of command arguments for local API
- Fix inaccurate counting of command arguments for local API - @rylnd
- Minor fix missing documentation for Dredd v1.0.8 options

## [0.8.1] - 2016-05-07
Expand Down Expand Up @@ -72,6 +79,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
The original implementation of the Rake task was shared in this [gist][gist].

[gist]: https://gist.github.com/gonzalo-bulnes/eec3f73cc7d6605add21
[Unreleased]: https://github.com/gonzalo-bulnes/dredd-rack/compare/v0.8.2...master
[0.8.2]: https://github.com/gonzalo-bulnes/dredd-rack/compare/v0.8.1...v0.8.2
[0.8.1]: https://github.com/gonzalo-bulnes/dredd-rack/compare/v0.7.1...v0.8.1
[0.8.0]: https://github.com/gonzalo-bulnes/dredd-rack/compare/v0.7.1...v0.8.0
Expand Down
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@ Define which application Dredd::Rack must serve automatically:

require 'dredd/rack'

# Allow the automatic setup of a local application server when necessary
#
# Find the name of your application in its `config.ru` file.
Dredd::Rack.app = Example::Application # or Rails.application, Sinatra::Application...
Dredd::Rack.configure do |config|
# Allow the automatic setup of a local application server when necessary
#
# Find the name of your application in its `config.ru` file.
config.app = Example::Application # or Rails.application, Sinatra::Application...

# Optionally, you can define a custom Dredd command:
config.dredd_command = 'dredd'
end

```

Usage
Expand Down
17 changes: 17 additions & 0 deletions lib/dredd/rack/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,26 @@ def app=(object)
@@app = object
end

# Return the command to be runned to invoke Dredd
def dredd_command
@@dredd_command
end

# Set a custom Dredd command
#
# command - the command String
def dredd_command=(command)
@@dredd_command = command
end

# Default configuration
@@app = nil
@@dredd_command = 'dredd'

# Allow the default configuration to be overwritten from initializers
def configure
yield self if block_given?
end
end
end
end
3 changes: 1 addition & 2 deletions lib/dredd/rack/rake_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ def initialize(*args, &task_block)
private

def dredd_available?
`which dredd`
$?.exitstatus == 0
system ['which', Dredd::Rack.dredd_command].join(' ')
end

def dredd_connection_error?(exit_status)
Expand Down
2 changes: 1 addition & 1 deletion lib/dredd/rack/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Runner
# api_endpoint - the API URL as a String
#
def initialize(api_endpoint=nil)
@dredd_command = 'dredd'
@dredd_command = Dredd::Rack.dredd_command
@paths_to_blueprints = 'doc/*.apib doc/*.apib.md'
@api_endpoint = api_endpoint || ''
@command_parts = []
Expand Down
11 changes: 10 additions & 1 deletion spec/lib/dredd/rack/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@

let(:subject) { @klass }

describe 'provides #app which' do
describe 'provides .app which' do

it_behaves_like 'a configuration option', 'app'

it "defauts to nil", private: true do
expect(subject.app).to be_nil
end
end

describe 'provides .dredd_command which' do

it_behaves_like 'a configuration option', 'dredd_command'

it "defauts to 'dredd'", private: true do
expect(subject.dredd_command).to eq 'dredd'
end
end
end
end

0 comments on commit b23ce29

Please sign in to comment.