BVB Source Codes

hologram Show document_block_spec.rb Source code

Return Download hologram: download document_block_spec.rb Source code - Download hologram Source code - Type:.rb
  1. require 'spec_helper'
  2.  
  3. describe Hologram::DocumentBlock do
  4.  
  5.   let(:config) do
  6.     { 'name' => 'foo', 'category' => 'bar', 'title' => 'baz', 'parent' => 'pop' }
  7.   end
  8.   let(:markdown){ 'blah' }
  9.   let(:doc_block){ subject.class.new(config, markdown) }
  10.  
  11.   context '.from_comment' do
  12.     let(:doc) do
  13. <<-eos
  14. /*doc
  15. ---
  16. title: Some other style
  17. name: otherStyle
  18. category: Foo
  19. ---
  20. Markdown stuff
  21. */
  22. eos
  23.     end
  24.  
  25.     let(:bad_doc) do
  26. <<-eos
  27. /*doc
  28. ---
  29. : :
  30. ---
  31. Markdown stuff
  32. */
  33. eos
  34.     end
  35.  
  36.     it 'initializes a new document block from a matching comment' do
  37.       doc_block = Hologram::DocumentBlock.from_comment(doc)
  38.       expect(doc_block).to be_a Hologram::DocumentBlock
  39.     end
  40.  
  41.     it 'raises CommentLoadError when the yaml section is bad' do
  42.       expect{
  43.         Hologram::DocumentBlock.from_comment(bad_doc)
  44.       }.to raise_error Hologram::CommentLoadError
  45.     end
  46.  
  47.     it 'returns nothing if its not a valid doc block' do
  48.       doc_block = Hologram::DocumentBlock.from_comment('foo')
  49.       expect(doc_block).to be_nil
  50.     end
  51.  
  52.     it 'sets up the usual attrs using the YAML and markdown text' do
  53.       doc_block = Hologram::DocumentBlock.from_comment(doc)
  54.       expect(doc_block.name).to eql 'otherStyle'
  55.       expect(doc_block.categories).to eql ['Foo']
  56.       expect(doc_block.title).to eql 'Some other style'
  57.       expect(doc_block.markdown).to eql "/*doc\n\nMarkdown stuff\n*/\n"
  58.     end
  59.   end
  60.  
  61.   context '#set_members' do
  62.     it 'sets accessors for the the block config' do
  63.       expect(doc_block.send('name')).to eql 'foo'
  64.       expect(doc_block.send('categories')).to eql ['bar']
  65.       expect(doc_block.send('title')).to eql 'baz'
  66.       expect(doc_block.send('parent')).to eql 'pop'
  67.     end
  68.   end
  69.  
  70.   context '#get_hash' do
  71.     let(:meta) do
  72.       { name: 'foo', categories: ['bar'], title: 'baz', parent: 'pop' }
  73.     end
  74.  
  75.     it 'returns a hash of meta info' do
  76.       expect(doc_block.get_hash).to eql meta
  77.     end
  78.   end
  79.  
  80.   context '#is_valid?' do
  81.     context 'when name and markdown is present' do
  82.       it 'returns true' do
  83.         expect(doc_block.is_valid?).to eql true
  84.       end
  85.     end
  86.  
  87.     context 'when name is not present' do
  88.       let(:invalid_doc_block) do
  89.         subject.class.new(config.merge(name: nil))
  90.       end
  91.  
  92.       it 'returns false' do
  93.         expect(invalid_doc_block.is_valid?).to eql false
  94.       end
  95.  
  96.       it 'populates errors' do
  97.         invalid_doc_block.is_valid?
  98.         expect(invalid_doc_block.errors).to include('Missing name or title config value')
  99.       end
  100.     end
  101.  
  102.     context 'when markdown is not present' do
  103.       let(:invalid_doc_block) do
  104.         subject.class.new(config)
  105.       end
  106.  
  107.       it 'returns false' do
  108.         expect(invalid_doc_block.is_valid?).to eql false
  109.       end
  110.  
  111.       it 'populates errors' do
  112.         invalid_doc_block.is_valid?
  113.         expect(invalid_doc_block.errors).to include('Missing required markdown')
  114.       end
  115.     end
  116.   end
  117.  
  118.   context '#markdown_with_heading' do
  119.     context 'when include_sub_nav is false' do
  120.       it 'returns markdown with a specified header' do
  121.         expect(doc_block.markdown_with_heading(2)).to eql "\n\n<h2 id=\"foo\" class=\"styleguide\">baz</h2>blah"
  122.       end
  123.     end
  124.  
  125.     context 'when include_sub_nav is true' do
  126.       context 'when the component has no children' do
  127.         it 'returns markdown with no nav' do
  128.           expect(doc_block.markdown_with_heading(2, include_sub_nav: true)).to eql "\n\n<h2 id=\"foo\" class=\"styleguide\">baz</h2>blah"
  129.         end
  130.       end
  131.  
  132.       context 'when the component has children' do
  133.         before do
  134.           doc_block.children['child-one'] = double( name: 'child-one', title: 'Child 1' )
  135.           doc_block.children['child-two'] = double( name: 'child-two', title: 'Child 2' )
  136.         end
  137.  
  138.         it 'returns markdown with no nav' do
  139.           expected_output = <<-eos
  140.  
  141.  
  142. <h2 id="foo" class="styleguide">baz</h2>
  143. <ul class="section-nav">
  144.   <li><a href="#child-one">Child 1</a></li>
  145.   <li><a href="#child-two">Child 2</a></li>
  146. </ul>
  147. blah
  148. eos
  149.           expect(doc_block.markdown_with_heading(2, include_sub_nav: true)).to eql expected_output.rstrip
  150.         end
  151.       end
  152.     end
  153.   end
  154. end
  155.  
downloaddocument_block_spec.rb Source code - Download hologram Source code
Related Source Codes/Software:
www.html5rocks.com - ....a top-notch resource for web developer 2017-05-12
MTStatusBarOverlay - A custom iOS status bar overlay seen in Apps like ... 2017-05-12
blueprint - Reverse engineer server configuration ... 2017-05-12
PullToRefresh - A simple iPhone TableViewController for adding the... 2017-05-12
mrjob - Run MapReduce jobs on Hadoop or Amazon Web Service... 2017-05-11
isso - a Disqus alternative https:... 2017-05-12
python3-cookbook - "The Python Cookbook" 3 rd Edition Translatio 2017-05-12
TSA-Travel-Sentry-master-keys - 3D reproduction of TSA Master key 2017-05-12
fatfree - A powerful yet easy-to-use PHP micro-framework des... 2017-05-13
rolify - Role management library with the resource scoping 2017-05-13
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top