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

Raises an error if styleguide section comment misses section definition #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 12 additions & 1 deletion lib/kss/section.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module Kss

class SectionNotDefinedError < StandardError
end

# Public: Represents a styleguide section. Each section describes one UI
# element. A Section can be thought of as the collection of the description,
# modifiers, and styleguide reference.
Expand Down Expand Up @@ -35,7 +39,14 @@ def section
return @section unless @section.nil?

cleaned = section_comment.strip.sub(/\.$/, '') # Kill trailing period
@section = cleaned.match(/Styleguide (.+)/i)[1]
match_result = cleaned.match(/Styleguide (.+)/i)

if match_result
@section = match_result[1]
else
raise SectionNotDefinedError.new,
'No section string found in comment block.'
end

@section
end
Expand Down
6 changes: 6 additions & 0 deletions test/section_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ def setup
assert_equal '2.1.1', @section.section
end

test "raises an error if styleguide reference is not set" do
assert_raises Kss::SectionNotDefinedError do
Kss::Section.new('', 'example.css').section
end
end

test "parses word phrases as styleguide references" do
@comment_text.gsub!('2.1.1', 'Buttons - Truly Lime')
section = Kss::Section.new(@comment_text, 'example.css')
Expand Down