Skip to content

Commit

Permalink
(PDOC-206) adds more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eputnam committed Mar 1, 2018
1 parent 0d6e245 commit 49511fb
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 224 deletions.
3 changes: 1 addition & 2 deletions lib/puppet-strings/yard/code_objects/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ class PuppetStrings::Yard::CodeObjects::Task < PuppetStrings::Yard::CodeObjects:
attr_reader :statement

# Initializes a JSON task code object.
# @param [String] source The task's JSON file source
# @param [String] filepath Path to task's .json file
# @param statement TaskStatement object
# @return [void]
def initialize(statement)
@name = statement.name
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet-strings/yard/parsers/json/task_statement.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module PuppetStrings::Yard::Parsers::JSON
# Represents the Puppet Task statement.
class TaskStatement
attr_reader :line, :comments, :comments_range, :json, :file
attr_reader :line, :comments, :comments_range, :json, :file, :source

def initialize(json, source, file)
@file = file
Expand Down
72 changes: 70 additions & 2 deletions spec/unit/puppet-strings/yard/code_objects/task_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,77 @@
require 'spec_helper'
require 'puppet-strings/yard/code_objects/task'
require 'puppet-strings/yard/parsers/json/task_statement'

describe PuppetStrings::Yard::CodeObjects::Task do
let(:source) { <<-SOURCE
{
"description": "Allows you to backup your database to local file.",
"input_method": "stdin",
"parameters": {
"database": {
"description": "Database to connect to",
"type": "Optional[String[1]]"
},
"user": {
"description": "The user",
"type": "Optional[String[1]]"
},
"password": {
"description": "The password",
"type": "Optional[String[1]]"
},
"sql": {
"description": "Path to file you want backup to",
"type": "String[1]"
}
}
}
SOURCE
}
let(:json) { JSON.parse(source) }
let(:statement) { PuppetStrings::Yard::Parsers::JSON::TaskStatement.new(json, source, "test.json") }
subject { PuppetStrings::Yard::CodeObjects::Task.new(statement) }

it do
subject
describe '#type' do
it 'returns the correct type' do
expect(subject.type).to eq(:puppet_task)
end
end

describe '#source' do
it 'returns the source' do
expect(subject.source).to eq(source)
end
end

describe '#to_hash' do
let(:expected) do
{ :name => "test",
"description" => "Allows you to backup your database to local file.",
"input_method" => "stdin",
"parameters" =>
{"database" => {
"description" => "Database to connect to",
"type" => "Optional[String[1]]"
},
"user"=> {
"description"=>"The user",
"type"=>"Optional[String[1]]"
},
"password"=> {
"description"=>"The password",
"type"=>"Optional[String[1]]"
},
"sql"=> {
"description"=>"Path to file you want backup to",
"type"=>"String[1]"
}
}
}
end

it 'returns the correct hash' do
expect(subject.to_hash).to eq(expected)
end
end
end
219 changes: 0 additions & 219 deletions spec/unit/puppet-strings/yard/handlers/json/handler_spec.rb

This file was deleted.

Loading

0 comments on commit 49511fb

Please sign in to comment.