Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Json classnames to JSON #359

Merged
merged 15 commits into from
Apr 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rspec_api_documentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module Writers
autoload :HtmlWriter
autoload :TextileWriter
autoload :MarkdownWriter
autoload :JsonWriter
autoload :JSONWriter
autoload :AppendJsonWriter
autoload :JsonIodocsWriter
autoload :IndexHelper
Expand Down
2 changes: 2 additions & 0 deletions lib/rspec_api_documentation/api_documentation.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'rspec_api_documentation/writers/json_iodocs_writer'

module RspecApiDocumentation
class ApiDocumentation
attr_reader :configuration, :index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def write
File.open(configuration.docs_dir.join("combined.json"), "w+") do |f|
examples = []
index.examples.each do |rspec_example|
examples << Formatter.to_json(JsonExample.new(rspec_example, configuration))
examples << Formatter.to_json(JSONExample.new(rspec_example, configuration))
end

f.write "["
Expand Down
4 changes: 2 additions & 2 deletions lib/rspec_api_documentation/writers/json_iodocs_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def sections
end

def examples
@index.examples.map { |example| JsonExample.new(example, @configuration) }
@index.examples.map { |example| JsonIodocsExample.new(example, @configuration) }
end

def as_json(opts = nil)
Expand All @@ -48,7 +48,7 @@ def as_json(opts = nil)
end
end

class JsonExample
class JsonIodocsExample
def initialize(example, configuration)
@example = example
end
Expand Down
12 changes: 6 additions & 6 deletions lib/rspec_api_documentation/writers/json_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

module RspecApiDocumentation
module Writers
class JsonWriter < Writer
class JSONWriter < Writer
delegate :docs_dir, :to => :configuration

def write
File.open(docs_dir.join("index.json"), "w+") do |f|
f.write Formatter.to_json(JsonIndex.new(index, configuration))
f.write Formatter.to_json(JSONIndex.new(index, configuration))
end
write_examples
end

def write_examples
index.examples.each do |example|
json_example = JsonExample.new(example, configuration)
json_example = JSONExample.new(example, configuration)
FileUtils.mkdir_p(docs_dir.join(json_example.dirname))
File.open(docs_dir.join(json_example.dirname, json_example.filename), "w+") do |f|
f.write Formatter.to_json(json_example)
Expand All @@ -23,7 +23,7 @@ def write_examples
end
end

class JsonIndex
class JSONIndex
def initialize(index, configuration)
@index = index
@configuration = configuration
Expand All @@ -34,7 +34,7 @@ def sections
end

def examples
@index.examples.map { |example| JsonExample.new(example, @configuration) }
@index.examples.map { |example| JSONExample.new(example, @configuration) }
end

def as_json(opts = nil)
Expand All @@ -61,7 +61,7 @@ def section_hash(section)
end
end

class JsonExample
class JSONExample
def initialize(example, configuration)
@example = example
@host = configuration.curl_host
Expand Down
7 changes: 4 additions & 3 deletions spec/writers/json_example_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# -*- coding: utf-8 -*-
require 'spec_helper'
require 'rspec_api_documentation/writers/json_writer'

describe RspecApiDocumentation::Writers::JsonExample do
describe RspecApiDocumentation::Writers::JSONExample do
let(:configuration) { RspecApiDocumentation::Configuration.new }

describe "#dirname" do
it "strips out leading slashes" do
example = double(resource_name: "/test_string")

json_example =
RspecApiDocumentation::Writers::JsonExample.new(example, configuration)
RspecApiDocumentation::Writers::JSONExample.new(example, configuration)

expect(json_example.dirname).to eq "test_string"
end
Expand All @@ -18,7 +19,7 @@
example = double(resource_name: "test_string/test")

json_example =
RspecApiDocumentation::Writers::JsonExample.new(example, configuration)
RspecApiDocumentation::Writers::JSONExample.new(example, configuration)

expect(json_example.dirname).to eq "test_string/test"
end
Expand Down
2 changes: 1 addition & 1 deletion spec/writers/json_writer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe RspecApiDocumentation::Writers::JsonWriter do
describe RspecApiDocumentation::Writers::JSONWriter do
let(:index) { RspecApiDocumentation::Index.new }
let(:configuration) { RspecApiDocumentation::Configuration.new }

Expand Down