diff --git a/lib/theme_bandit/parser/css.rb b/lib/theme_bandit/parser/css.rb index 81208ce..ce135db 100644 --- a/lib/theme_bandit/parser/css.rb +++ b/lib/theme_bandit/parser/css.rb @@ -10,7 +10,7 @@ def get_css_files def link_tags document.css('link').select do |tag| - tag.attribute('rel').value == 'stylesheet' + tag.attribute('rel') && tag.attribute('rel').value == 'stylesheet' end end diff --git a/test/fixtures/index.html b/test/fixtures/index.html index 9a1a8bf..467a08e 100644 --- a/test/fixtures/index.html +++ b/test/fixtures/index.html @@ -7,6 +7,7 @@ + diff --git a/test/support/common.rb b/test/support/common.rb index 93ddacc..b8f765a 100644 --- a/test/support/common.rb +++ b/test/support/common.rb @@ -1,5 +1,7 @@ def load_html_fixture - @fixture ||= File.read(File.open("#{Dir.pwd}/test/fixtures/index.html", 'r')) + # @fixture ||= File.read(File.open("#{Dir.pwd}/test/fixtures/index.html", 'r')) + + @fixture ||= File.read(File.expand_path("../../fixtures/index.html", __FILE__)) end def load_css_fixture diff --git a/test/test_css_parser.rb b/test/test_css_parser.rb new file mode 100644 index 0000000..9730a66 --- /dev/null +++ b/test/test_css_parser.rb @@ -0,0 +1,24 @@ +require_relative 'helper' + + describe ThemeBandit::CSSParser do + + before do + #parse index.html fixture with Nokogiri + document = Nokogiri::HTML(load_html_fixture) + + #Create a struct and include the CSSParser module + CSSParser = Struct.new(:document) do + include ThemeBandit::CSSParser + end + + #create new instance of CSSParser and set the document instance variable to the parsed fixture + @css_parser = CSSParser.new(document) + end + + it 'parses only tags with rel="stylesheet"' do + assert_equal(@css_parser.link_tags.map{|tag| tag.to_s}, [ + "", + "" + ]) + end + end \ No newline at end of file diff --git a/test/test_document_writer.rb b/test/test_document_writer.rb index 40f9f75..6646376 100644 --- a/test/test_document_writer.rb +++ b/test/test_document_writer.rb @@ -1,4 +1,4 @@ -require 'helper' +require_relative 'helper' describe ThemeBandit::DocumentWriter do diff --git a/test/test_rack_generator.rb b/test/test_rack_generator.rb index 3f5dc46..bfd7b40 100644 --- a/test/test_rack_generator.rb +++ b/test/test_rack_generator.rb @@ -1,4 +1,4 @@ -require 'helper' +require_relative 'helper' describe ThemeBandit::RackGenerator do