spec/useless/doc/ui/godel_spec.rb in useless-doc-0.2.3 vs spec/useless/doc/ui/godel_spec.rb in useless-doc-0.3.0

- old
+ new

@@ -1,125 +1,165 @@ require File.dirname(__FILE__) + '/../../../spec_helper' require 'nokogiri' +require 'useless/doc' +require 'useless/doc/router' require 'useless/doc/ui/godel' -require 'useless/doc/serialization/load' describe Useless::Doc::UI::Godel do - describe '.resource' do - before(:each) do - json = load_document('api.json').read - api = Useless::Doc::Serialization::Load.api json - result = Useless::Doc::UI::Godel.api(api) - @doc = Nokogiri::HTML(result) - end + describe '.html' do + context 'for a Core::Domain instance' do + before(:all) do + router = Useless::Doc::Router.default + json = load_document('domain.json').read + domain = Useless::Doc.load.domain(json) + result = Useless::Doc::UI::Godel.new(router).html(domain) + @doc = Nokogiri::HTML(result) + end - it 'should render the URL in the only h1' do - h1s = @doc.css('h1') - h1s.length.should == 1 - h1s.first.content.should == 'twonk.useless.io' - end + it 'should render the name in the only h1' do + h1s = @doc.css('h1') + h1s.length.should == 1 + h1s.first.content.should == 'Useless' + end - it 'should render the API description in a top-level p' do - description = @doc.css('body > p') - description.length.should == 1 - description.first.content.should == 'Twonk information. Duh.' - end + it 'should render the domain description in an article p' do + description = @doc.css('article p.description.domain') + description.length.should == 1 + description.first.content.should == 'A collection of useless APIs.' + end - it 'should render resouce paths as h2s' do - h2s = @doc.css('h2') - h2s.length.should == 2 - h2s.map { |h2| h2.content }.should match_array(['/twonks/:id', '/twonks/:id/werp']) - end + it 'should render API names as a\'s, with correct doc URLs' do + as = @doc.css('a.name') + as.length.should == 2 + as.map { |a| a.content }.should match_array(['The Jah API', 'The Twonk API']) + as.map { |a| a['href'] }.should match_array(['http://jah.doc.useless.io', 'http://twonk.doc.useless.io']) + end - it 'should render resouce descriptions as ps within the section' do - ps = @doc.css('section > p') - ps.length.should == 2 - ps.map { |h2| h2.content }.should match_array(['The most critical aspect.', 'That other shit.']) + it 'should render API descriptions as ps within the section' do + ps = @doc.css('section > p') + ps.length.should == 2 + ps.map { |h2| h2.content }.should match_array(['Jah, jah, jah.', 'TWONK!!!']) + end end - it 'should add a link for each method, with an appropriate description' do - as = @doc.css('table td a') - td_content = @doc.css('table td').map { |td| td.content } - as.find { |a| a.content == 'GET' }['href'].should == '/twonks/:id#GET' - td_content.should include 'Get dat twonk.' + context 'for a Core::API instance' do + before(:all) do + json = load_document('api.json').read + router = Useless::Doc::Router.default + api = Useless::Doc.load.api(json) + result = Useless::Doc::UI::Godel.new(router).html(api) + @doc = Nokogiri::HTML(result) + end - as.find { |a| a.content == 'POST' }['href'].should == '/twonks/:id/werp#POST' - td_content.should include 'Make dem werps.' - end - end + it 'should render the URL in the only h1' do + h1s = @doc.css('h1') + h1s.length.should == 1 + h1s.first.content.should == 'Twonk API' + end - describe '.resource' do - before(:each) do - json = load_document('twonk.json').read - resource = Useless::Doc::Serialization::Load.resource json - result = Useless::Doc::UI::Godel.resource(resource) - @doc = Nokogiri::HTML(result) - end + it 'should render the API description in an article p' do + description = @doc.css('article p.description.api') + description.length.should == 1 + description.first.content.should == 'Twonk information. Duh.' + end - it 'should render the path within the only h1' do - h1s = @doc.css('h1') - h1s.length.should == 1 - h1s.first.content.should == '/twonks/:id' - end + it 'should render resouce paths as a\'s' do + as = @doc.css('a.path') + as.length.should == 2 + as.map { |a| a.content }.should match_array(['/twonks/:id', '/twonks/:id/werp']) + end - it 'should render the methods as h2s' do - h2s = @doc.css('h2') - h2s.length.should == 2 - h2s.map { |h2| h2.content }.should match_array(['GET', 'PUT']) - end + it 'should render resouce descriptions as ps within the section' do + ps = @doc.css('section > p') + ps.length.should == 2 + ps.map { |h2| h2.content }.should match_array(['The most critical aspect.', 'That other shit.']) + end - it 'should render response codes as h3s' do - h3s = @doc.css('h3') - h3s.length.should == 3 - h3s.map { |h3| h3.content }.should match_array(['404', '200', '201']) - end + it 'should add a link for each method, with an appropriate description' do + as = @doc.css('table td a') + td_content = @doc.css('table td').map { |td| td.content } + as.find { |a| a.content == 'GET' }['href'].should == '/twonks/:id#GET' + td_content.should include 'Get dat twonk.' - it 'should contain the method and response code descriptions in ps' do - p_content = @doc.css('p').map { |p| p.content } - p_content.should include 'The most critical aspect.' - p_content.should include 'Retrieve a representation of an individual twonk.' - p_content.should include 'A twonk with the specified ID could not be found.' - p_content.should include 'The specified twonk was retrieved successfully.' - p_content.should include 'The specified twonk was updated successfully.' + as.find { |a| a.content == 'POST' }['href'].should == '/twonks/:id/werp#POST' + td_content.should include 'Make dem werps.' + end end - it 'should add parameter information to a table' do - [ - { key: 'id', description: 'The ID of the desired twonk.' }, - { key: 'werp', description: 'Self-explanatory.' }, - { key: 'id', description: 'The ID of the twonk to be updated.' } - ].each do |param| - @doc.css('table').find do |table| - table.content.match(param[:key]) and - table.content.match(param[:description]) - end.should_not be_nil + context 'for a Core::Resource instance' do + before(:each) do + json = load_document('twonk.json').read + router = Useless::Doc::Router.default + resource = Useless::Doc.load.resource json + result = Useless::Doc::UI::Godel.new(router).html(resource) + @doc = Nokogiri::HTML(result) end - end - it 'should add body information to a table' do - [ - { key: 'name', description: 'The name of the twonk.' }, - { key: 'created_by', description: 'The short name of the user who created the twonk.' }, - { key: 'hoinked_by', description: 'The ID of the person who hoinked this twonk.' } - ].each do |attribute| + it 'should render the path within the only h1' do + h1s = @doc.css('h1') + h1s.length.should == 1 + h1s.first.content.should == '/twonks/:id' + end + + it 'should render the methods as h2s' do + h2s = @doc.css('h2') + h2s.length.should == 2 + h2s.map { |h2| h2.content }.should match_array(['GET', 'PUT']) + end + + it 'should render response codes as h3s' do + h3s = @doc.css('h3') + h3s.length.should == 3 + h3s.map { |h3| h3.content }.should match_array(['404 Not Found', '200 OK', '201 Created']) + end + + it 'should contain the method and response code descriptions in ps' do + p_content = @doc.css('p').map { |p| p.content } + p_content.should include 'The most critical aspect.' + p_content.should include 'Retrieve a representation of an individual twonk.' + p_content.should include 'A twonk with the specified ID could not be found.' + p_content.should include 'The specified twonk was retrieved successfully.' + p_content.should include 'The specified twonk was updated successfully.' + end + + it 'should add parameter information to a table' do + [ + { key: 'id', description: 'The ID of the desired twonk.' }, + { key: 'werp', description: 'Self-explanatory.' }, + { key: 'id', description: 'The ID of the twonk to be updated.' } + ].each do |param| + @doc.css('table').find do |table| + table.content.match(param[:key]) and + table.content.match(param[:description]) + end.should_not be_nil + end + end + + it 'should add body information to a table' do + [ + { key: 'name', description: 'The name of the twonk.' }, + { key: 'created_by', description: 'The short name of the user who created the twonk.' }, + { key: 'hoinked_by', description: 'The ID of the person who hoinked this twonk.' } + ].each do |attribute| + @doc.css('table').find do |table| + table.content.match(attribute[:key]) and + table.content.match(attribute[:description]) + end.should_not be_nil + end + end + + it 'should add header information to a table' do @doc.css('table').find do |table| - table.content.match(attribute[:key]) and - table.content.match(attribute[:description]) + table.content.match('User-Agent') and + table.content.match('The thingy you\'re using.') end.should_not be_nil end - end - it 'should add header information to a table' do - @doc.css('table').find do |table| - table.content.match('User-Agent') and - table.content.match('The thingy you\'re using.') - end.should_not be_nil - end - - it 'should include authentication information in lis' do - li_content = @doc.css('li').map { |li| li.content } - li_content.should include 'Authentication Required' - li_content.should include 'Authentication Not Required' + it 'should include authentication information in lis' do + li_content = @doc.css('li').map { |li| li.content } + li_content.should include 'Authentication Required' + li_content.should include 'Authentication Not Required' + end end end end