-
Notifications
You must be signed in to change notification settings - Fork 60
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
WIP: Test page's code blocks #74
base: master
Are you sure you want to change the base?
Changes from 1 commit
3de8edf
d38693e
f4cbfb5
92643b1
ceadc09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require 'spec_helper' | ||
require 'kramdown' | ||
require 'ap' | ||
require 'pp' | ||
site = File.join(File.dirname(__FILE__), '..','content', '**', '*.md') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not |
||
PAGES = Dir.glob(site) | ||
|
||
def extract_code(element,prev_element) | ||
codes = [] | ||
if element.type == :codespan \ | ||
&& !element.value.nil? \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this ever occur? It could probable be removed and BTW. I quite prefer |
||
&& !codes.include?(element.value) \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I'd prefer to include even the already existing codes and only avoid executing / checking the same one multiple times. |
||
&& ((prev_element.children.size == 1) || (element.value[/^\n/])) #element value hasn't got any sibling or begin with '\n' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please move the comment above the |
||
codes.push element.value | ||
end | ||
element.children.each do |child| | ||
codes += extract_code(child, element) | ||
end | ||
codes | ||
end | ||
|
||
PAGES.each do |page| | ||
generated_page = Kramdown::Document.new(File.read(page)) | ||
codes = extract_code(generated_page.root,generated_page) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like you could pass just |
||
|
||
describe 'Code blocks on markdown' do | ||
|
||
|
||
before :each do | ||
codes.each do |code| | ||
code.gsub! "\n",'' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather this would be solved in the extractor itself. (multiple lines = multiple commands) |
||
end | ||
end | ||
it 'have good syntax' do | ||
codes.each do |code| | ||
if code[/^\$/] #code starts with '$' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems to me like we want to have different tests for various |
||
expect(system('bash', '-n', '-c', code, '&>/dev/null')).to be_truthy,"Something wrong with: '#{code}'" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could build an Array of |
||
elsif code[/^\#/] #code starts with '#' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're actually comparing only the first character from string, which can be done as: code[0] == ?# |
||
#ap code | ||
else #code starts with something else | ||
#ap code | ||
end | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove debug requirements.