Permalink
Browse files

Make notification AST available, refs #31.

  • Loading branch information...
1 parent 243ec01 commit 70cf4ac6b79fb416b4720b4d5315bbbaba1a0940 @acrmp acrmp committed May 20, 2012
Showing with 27 additions and 6 deletions.
  1. +7 −5 lib/foodcritic/api.rb
  2. +20 −1 spec/foodcritic/api_spec.rb
View
@@ -221,12 +221,14 @@ def resource_attributes(resource)
atts[:name] = name unless name.empty?
resource.xpath('do_block/descendant::command
[count(ancestor::do_block) = 1]').each do |att|
- if att.xpath('descendant::symbol').empty?
- att_value = att.xpath('string(descendant::tstring_content/@value)')
- else
- att_value =
+ att_value =
+ if ! att.xpath('args_add_block[count(descendant::args_add)>1]').empty?
+ att.xpath('args_add_block').first
+ elsif att.xpath('descendant::symbol').empty?
+ att.xpath('string(descendant::tstring_content/@value)')
+ else
att.xpath('string(descendant::symbol/ident/@value)').to_sym
- end
+ end
atts[att.xpath('string(ident/@value)')] = att_value
end
resource.xpath("do_block/descendant::method_add_block[
@@ -396,7 +396,26 @@ def str_to_atts(str)
atts['not_if'].must_respond_to :xpath
atts['not_if'].name.must_equal 'brace_block'
end
-
+ it "includes notifications in the result" do
+ atts = str_to_atts(%q{
+ template "/etc/httpd.conf" do
+ notifies :restart, "service[apache]"
+ end
+ })
+ atts['notifies'].wont_be_nil
+ atts['notifies'].must_respond_to :xpath
+ atts['notifies'].name.must_equal 'args_add_block'
+ end
+ it "includes old-style notifications in the result" do
+ atts = str_to_atts(%q{
+ template "/etc/httpd.conf" do
+ notifies :restart, resources(:service => "apache")
+ end
+ })
+ atts['notifies'].wont_be_nil
+ atts['notifies'].must_respond_to :xpath
+ atts['notifies'].name.must_equal 'args_add_block'
+ end
end
end

0 comments on commit 70cf4ac

Please sign in to comment.