spec/fdoc/cli_spec.rb in fdoc-0.3.0 vs spec/fdoc/cli_spec.rb in fdoc-0.3.1

- old
+ new

@@ -3,13 +3,14 @@ describe Fdoc::Cli do let(:fixtures_path) { File.expand_path("../../fixtures", __FILE__) } let(:temporary_path) { Dir.mktmpdir("fdoc-cli") } let(:fdoc_path) { File.expand_path("fdoc", temporary_path) } let(:html_path) { File.expand_path("html", temporary_path) } - let(:options) { {} } + let(:markdown_path) { File.expand_path("markdown", temporary_path) } + let(:options) { { :format => 'html' } } - subject(:cli) { Fdoc::Cli.new([fdoc_path], options) } + subject { Fdoc::Cli.new([fdoc_path], options) } before { FileUtils.mkdir_p(fdoc_path) } around { |e| capture(:stdout, &e) } @@ -26,118 +27,155 @@ context "when the fdoc path does not exist" do before { FileUtils.rmdir(fdoc_path) } it "raises an exception" do expect do - cli.convert(fdoc_path) + subject.convert(fdoc_path) end.to raise_exception(Fdoc::NotFound) end end context "when the fdoc path exists" do context "when the destination does not exist" do it "makes a destination directory" do expect do - cli.convert(fdoc_path) + subject.convert(fdoc_path) end.to change { File.directory?(html_path) }.to(true) end end context "when the destination exists as a file" do before { FileUtils.touch(html_path) } it "raises an exception" do expect do - cli.convert(fdoc_path) + subject.convert(fdoc_path) end.to raise_exception(Fdoc::NotADirectory) end end it "copies the css to the destination" do expect do - cli.convert(fdoc_path) + subject.convert(fdoc_path) end.to change { File.exist?(styles_css_path) }.from(false) end - context "when there is a meta service fdoc" do - let(:root_html) { File.expand_path("index.html", html_path) } - let(:members_html) do - File.expand_path("members_api/index.html", html_path) - end - let(:endpoint_html) do - File.expand_path("members_api/add-PUT.html", html_path) - end - + shared_examples "when there is a meta service fdoc" do before { with_fixture("sample_group.fdoc.meta") } context "when no service fdoc exists" do - specify { expect { cli.convert(fdoc_path) }.to raise_error } + specify { expect { subject.convert(fdoc_path) }.to raise_error } end context "when a service fdoc exists" do before { with_fixture("members/members.fdoc.service") } - it "creates a root-level html file" do + it "creates a root-level file" do expect do - cli.convert(fdoc_path) - end.to change { File.exist?(root_html) }.from(false) + subject.convert(fdoc_path) + end.to change { File.exist?(root_file) }.from(false) end - it "writes the service-level html file" do + it "writes the service-level file" do expect do - cli.convert(fdoc_path) - end.to change { File.exist?(members_html) }.from(false) + subject.convert(fdoc_path) + end.to change { File.exist?(members_file) }.from(false) end context "when an endpoint fdoc exists" do before { with_fixture("members/add-PUT.fdoc") } - it "writes the endpoint html file" do + it "writes the endpoint file" do expect do - cli.convert(fdoc_path) - end.to change { File.exist?(endpoint_html) }.from(false) + subject.convert(fdoc_path) + end.to change { File.exist?(endpoint_file) }.from(false) end end end end - context "when there is no meta service fdoc" do - let(:root_html) { File.expand_path("index.html", html_path) } - let(:endpoint_html) do - File.expand_path("add-PUT.html", html_path) - end + shared_examples "when there is no meta service fdoc" do context "when no service fdoc exists" do it "creates a dummy index" do expect do - cli.convert(fdoc_path) - end.to change { File.exist?(root_html) }.from(false) + subject.convert(fdoc_path) + end.to change { File.exist?(root_file) }.from(false) end end context "when a service fdoc exists" do before do with_fixture("members/members.fdoc.service", "a.fdoc.service") end it "writes the service-level html file" do expect do - cli.convert(fdoc_path) - end.to change { File.exist?(root_html) }.from(false) + subject.convert(fdoc_path) + end.to change { File.exist?(root_file) }.from(false) end context "when an endpoint fdoc exists" do before { with_fixture("members/add-PUT.fdoc", "add-PUT.fdoc") } it "writes the endpoint html file" do expect do - cli.convert(fdoc_path) - end.to change { File.exist?(endpoint_html) }.from(false) + subject.convert(fdoc_path) + end.to change { File.exist?(endpoint_file) }.from(false) end end end end + + context "output HTML" do + + context "when there is no meta service fdoc" do + let(:root_file) { File.expand_path("index.html", html_path) } + let(:members_file) do + File.expand_path("members_api/index.html", html_path) + end + let(:endpoint_file) do + File.expand_path("members_api/add-PUT.html", html_path) + end + + it_behaves_like "when there is a meta service fdoc" + end + + context "when there is no meta service fdoc" do + let(:root_file) { File.expand_path("index.html", html_path) } + let(:endpoint_file) do + File.expand_path("add-PUT.html", html_path) + end + it_behaves_like "when there is no meta service fdoc" + end + + end + + context "output Markdown" do + let(:options) { { :format => 'markdown' } } + + context "when there is no meta service fdoc" do + let(:root_file) { File.expand_path("index.md", markdown_path) } + let(:members_file) do + File.expand_path("members_api/index.md", markdown_path) + end + let(:endpoint_file) do + File.expand_path("members_api/add-PUT.md", markdown_path) + end + + it_behaves_like "when there is a meta service fdoc" + end + + context "when there is no meta service fdoc" do + let(:root_file) { File.expand_path("index.md", markdown_path) } + let(:endpoint_file) do + File.expand_path("add-PUT.md", markdown_path) + end + it_behaves_like "when there is no meta service fdoc" + end + end + end end describe "accessors" do before do @@ -201,16 +239,25 @@ end end describe "#html_options" do let(:html_path) { "/a/great/place/to/keep/html"} + let(:template_path) { '/a/great/place/to/keep/templates' } - before { subject.destination_root = html_path } + before do + subject.origin_path = fdoc_path + subject.destination_root = html_path + end its(:html_options) { should include(:static_html => true) } its(:html_options) { should include(:html_directory => html_path) } + context "when a template_directory is provided" do + let(:options) { { :format => 'html', :templates => template_path } } + its(:html_options) { should include(:template_directory => template_path) } + end + context "when url_base_path is not provided" do its(:html_options) { should include(:url_base_path => nil) } end context "when url_base_path is provided" do @@ -220,11 +267,11 @@ its(:html_options) { should include(:url_base_path => url_base_path) } end end describe "#inside_service" do - let(:presenter) { cli.service_presenters.first } + let(:presenter) { subject.service_presenters.first } before do subject.origin_path = fdoc_path subject.destination_root = html_path end @@ -234,11 +281,11 @@ with_fixture("sample_group.fdoc.meta") with_fixture("members/members.fdoc.service") end it "leaves the output directory" do - cli.inside_service_presenter(presenter) do + subject.inside_service_presenter(presenter) do Dir.pwd.should =~ %r|#{html_path}/members_api$| end end end @@ -246,10 +293,10 @@ before do with_fixture("members/members.fdoc.service", "members.fdoc.service") end it "does not leave the output directory" do - cli.inside_service_presenter(presenter) do + subject.inside_service_presenter(presenter) do Dir.pwd.should =~ /#{html_path}$/ end end end end