Skip to content
This repository has been archived by the owner on Sep 19, 2020. It is now read-only.

Commit

Permalink
Coerce :immediately to :immediate, refs #31.
Browse files Browse the repository at this point in the history
Avoids users of #notifications having to switch on both.
  • Loading branch information
Andrew Crump committed Jun 6, 2012
1 parent b38e49e commit dfdacec
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 10 deletions.
9 changes: 8 additions & 1 deletion lib/foodcritic/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,14 @@ def notifications(ast)
:action =>
notifies.xpath('descendant::symbol[1]/ident/@value').to_s.to_sym,
:notification_timing =>
timing.empty? ? :delayed : timing.first.to_s.to_sym
if timing.empty?
:delayed
else
case timing.first.to_s.to_sym
when :immediately, :immediate then :immediate
else timing.first.to_s.to_sym
end
end
}

end.compact
Expand Down
56 changes: 47 additions & 9 deletions spec/foodcritic/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ def parse_ast(str)
:action => :restart,
:resource_type => :service,
:resource_name => 'nscd',
:notification_timing => :immediately,
:notification_timing => :immediate,
:style => :old
}]
)
Expand All @@ -645,7 +645,7 @@ def parse_ast(str)
:action => :restart,
:resource_type => :service,
:resource_name => 'nscd',
:notification_timing => :immediately,
:notification_timing => :immediate,
:style => :old
}]
)
Expand All @@ -664,7 +664,7 @@ def parse_ast(str)
:action => :restart,
:resource_type => :service,
:resource_name => 'nscd',
:notification_timing => :immediately,
:notification_timing => :immediate,
:style => :new
}]
)
Expand All @@ -683,7 +683,7 @@ def parse_ast(str)
:action => :restart,
:resource_type => :service,
:resource_name => 'nscd',
:notification_timing => :immediately,
:notification_timing => :immediate,
:style => :new
}]
)
Expand Down Expand Up @@ -920,36 +920,74 @@ def parse_ast(str)
})).first[:notification_timing].must_equal(:delayed)
end
end
describe "sets the notification timing to immediately if specified" do
describe "sets the notification timing to immediate if specified as immediate" do
it "old-style notifications" do
api.notifications(parse_ast(%q{
template "/etc/foo.conf" do
notifies :run, resources(execute => "robespierre"), :immediate
end
})).first[:notification_timing].must_equal(:immediate)
end
it "old-style subscriptions" do
api.notifications(parse_ast(%q{
template "/etc/foo.conf" do
subscribes :run, resources(execute => "robespierre"), :immediate
end
})).first[:notification_timing].must_equal(:immediate)
end
it "new-style notifications" do
api.notifications(parse_ast(%q{
template "/etc/foo.conf" do
notifies :run, "execute[robespierre]", :immediate
end
})).first[:notification_timing].must_equal(:immediate)
end
it "new-style subscriptions" do
api.notifications(parse_ast(%q{
template "/etc/foo.conf" do
subscribes :run, "execute[robespierre]", :immediate
end
})).first[:notification_timing].must_equal(:immediate)
end

end
describe "sets the notification timing to immediate if specified as immediately" do
it "old-style notifications" do
api.notifications(parse_ast(%q{
template "/etc/foo.conf" do
notifies :run, resources(execute => "robespierre"), :immediately
end
})).first[:notification_timing].must_equal(:immediately)
})).first[:notification_timing].must_equal(:immediate)
end
it "old-style subscriptions" do
api.notifications(parse_ast(%q{
template "/etc/foo.conf" do
subscribes :run, resources(execute => "robespierre"), :immediately
end
})).first[:notification_timing].must_equal(:immediately)
})).first[:notification_timing].must_equal(:immediate)
end
it "new-style notifications" do
api.notifications(parse_ast(%q{
template "/etc/foo.conf" do
notifies :run, "execute[robespierre]", :immediately
end
})).first[:notification_timing].must_equal(:immediately)
})).first[:notification_timing].must_equal(:immediate)
end
it "new-style subscriptions" do
api.notifications(parse_ast(%q{
template "/etc/foo.conf" do
subscribes :run, "execute[robespierre]", :immediately
end
})).first[:notification_timing].must_equal(:immediately)
})).first[:notification_timing].must_equal(:immediate)
end
end
it "passes unrecognised notification timings through unchanged" do
api.notifications(parse_ast(%q{
template "/etc/foo.conf" do
notifies :run, resources(execute => "robespierre"), :forthwith
end
})).first[:notification_timing].must_equal(:forthwith)
end
describe "resource names as expressions" do
describe "returns the AST for an embedded string" do
it "old-style notifications" do
Expand Down

0 comments on commit dfdacec

Please sign in to comment.