Class: Dredd::Rack::RakeTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/dredd/rack/rake_task.rb

Overview

A clonable Rake task powered by a Dredd::Rack::Runner

Examples:

require 'dredd/rack'
Dredd::Rack::RakeTask.new # run it with `rake dredd`

# Customize the name or description of the Rake task:
namespace :blueprint do
  desc 'Verify an API complies with its blueprint'
  Dredd::Rack::RakeTask.new(:verify)
end
# run it with `rake blueprint:verify`

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ RakeTask

Define a task with a custom name, arguments and description



35
36
37
38
39
40
41
42
43
44
# File 'lib/dredd/rack/rake_task.rb', line 35

def initialize(*args)
  @name = args.shift || :dredd
  @description = 'Run Dredd::Rack API blueprint verification'
  @runner = Dredd::Rack::Runner.new(ENV['API_HOST'])

  desc description unless ::Rake.application.last_comment
  task name, args do
    run_task(runner)
  end
end

Instance Attribute Details

#descriptionObject (readonly)

Return the task’s description



29
30
31
# File 'lib/dredd/rack/rake_task.rb', line 29

def description
  @description
end

#nameObject (readonly)

Return the task’s name



26
27
28
# File 'lib/dredd/rack/rake_task.rb', line 26

def name
  @name
end

#runnerObject (readonly)

Return the Dredd::Rack::Runner instance



32
33
34
# File 'lib/dredd/rack/rake_task.rb', line 32

def runner
  @runner
end

Instance Method Details

#run_task(runner) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/dredd/rack/rake_task.rb', line 46

def run_task(runner)
  abort dredd_not_available_message unless dredd_available?

  puts starting_message

  puts command_message(runner)

  success = runner.run
  exit_status = $?.exitstatus

  puts connection_error_message(runner) unless success if dredd_connection_error?(exit_status)

  abort unless exit_status == 0
end