From 36bf9d78d80b21319b51ef5ec099129be552fa70 Mon Sep 17 00:00:00 2001 From: Andrew Crump Date: Wed, 29 Feb 2012 22:23:18 +0000 Subject: [PATCH] Revert changes since 0.11.0, refs #14. 3e48a..9750f --- .gitignore | 1 - Gemfile | 1 - Rakefile | 11 +- .../continuous_integration_support.feature | 25 +- features/support/cookbook_helpers.rb | 9 - lib/foodcritic/domain.rb | 9 +- lib/foodcritic/helpers.rb | 115 +++------ lib/foodcritic/linter.rb | 15 +- spec/foodcritic/helpers_spec.rb | 228 ------------------ spec/foodcritic/linter_spec.rb | 14 -- spec/spec_helper.rb | 4 - 11 files changed, 57 insertions(+), 375 deletions(-) delete mode 100644 spec/foodcritic/helpers_spec.rb delete mode 100644 spec/foodcritic/linter_spec.rb delete mode 100644 spec/spec_helper.rb diff --git a/.gitignore b/.gitignore index 4333eb4a..48a030fd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,5 @@ chef_dsl_metadata.json coverage doc pkg -*.swp tmp Gemfile.lock diff --git a/Gemfile b/Gemfile index 1c9661b1..39ee3c8f 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,6 @@ gem 'foodcritic', :path => '.' group :test do gem 'aruba', '~> 0.4.11' gem 'cucumber', '~> 1.1.8' - gem 'minitest', '~> 2.11.2' gem 'simplecov', '~> 0.5.4' end diff --git a/Rakefile b/Rakefile index 686e4a8b..49b1ec54 100644 --- a/Rakefile +++ b/Rakefile @@ -1,23 +1,16 @@ require 'rubygems' require 'bundler' -require 'rake/testtask' require 'cucumber' require 'cucumber/rake/task' require 'yard' -task :default => ['chef_dsl_metadata.json', :install, :test, :features] +task :default => ['chef_dsl_metadata.json', :install, :features] Bundler.setup Bundler::GemHelper.install_tasks -Rake::TestTask.new do |t| - t.pattern = 'spec/**/*_spec.rb' -end - Cucumber::Rake::Task.new(:features) do |t| t.cucumber_opts = ['-f', 'progress'] - if ENV.has_key?('FC_FORK_PROCESS') and ENV['FC_FORK_PROCESS'] == true.to_s - t.cucumber_opts += ['-t', '~@repl', 'features'] - end + t.cucumber_opts += ['-t', '~@repl', 'features'] if ENV.has_key?('FC_FORK_PROCESS') and ENV['FC_FORK_PROCESS'] == true.to_s end YARD::Rake::YardocTask.new diff --git a/features/continuous_integration_support.feature b/features/continuous_integration_support.feature index ac4b1463..dc2c4480 100644 --- a/features/continuous_integration_support.feature +++ b/features/continuous_integration_support.feature @@ -16,20 +16,11 @@ Feature: Continuous Integration Support And the build status should be Examples: - | cookbook_matches | tag_arguments | warnings_shown | build_status | - | FC002,FC003,FC004 | | FC002,FC003,FC004 | successful | - | FC002,FC003,FC004 | -t style | FC002,FC004 | successful | - | FC002,FC003,FC004 | -f style | FC002,FC003,FC004 | failed | - | FC002,FC003,FC004 | -f FC005 | FC002,FC003,FC004 | successful | - | FC002,FC003,FC004 | -f FC003,FC004 | FC002,FC003,FC004 | failed | - | FC002,FC003,FC004 | --epic-fail FC003 | FC002,FC003,FC004 | failed | - | FC002,FC003 | -f any | FC002,FC003 | failed | - | FC002,FC003 | -f any -f ~FC014 | FC002,FC003 | failed | - | FC002,FC003 | -f any,~FC014 | FC002,FC003 | failed | - | FC002 | -f ~FC002 | FC002 | successful | - | FC002,FC003 | -f ~FC002 | FC002,FC003 | failed | - | FC002,FC003 | -f any -f ~FC002 | FC002,FC003 | failed | - | FC002 | -f any,~FC002 | FC002 | failed | - | FC002 | -f any -f ~FC002 | FC002 | successful | - | FC002,FC003 | -f any,~FC002 | FC002,FC003 | failed | - | FC002,FC003 | -f ~FC002 -f ~FC004 | FC002,FC003 | failed | + | cookbook_matches | tag_arguments | warnings_shown | build_status | + | FC002,FC003,FC004 | | FC002,FC003,FC004 | successful | + | FC002,FC003,FC004 | -t style | FC002,FC004 | successful | + | FC002,FC003,FC004 | -f style | FC002,FC003,FC004 | failed | + | FC002,FC003,FC004 | -f FC005 | FC002,FC003,FC004 | successful | + | FC002,FC003,FC004 | -f FC003,FC004 | FC002,FC003,FC004 | failed | + | FC002,FC003,FC004 | --epic-fail FC003 | FC002,FC003,FC004 | failed | + | FC002,FC003 | -f any | FC002,FC003 | failed | diff --git a/features/support/cookbook_helpers.rb b/features/support/cookbook_helpers.rb index 2e98905d..997cfb5b 100644 --- a/features/support/cookbook_helpers.rb +++ b/features/support/cookbook_helpers.rb @@ -58,7 +58,6 @@ def cookbook_that_matches_rules(codes) end end write_recipe(recipe) - write_readme('Hello World') # Don't trigger FC011 end # Create a cookbook with a LRWP @@ -274,14 +273,6 @@ def nil_if_unspecified(str) str == 'unspecified' ? nil : str end - # Create a README with the provided content. - # - # @param [String] content The recipe content. - # @param [String] cookbook_name Optional name of the cookbook. - def write_readme(content, cookbook_name = 'example') - write_file "cookbooks/#{cookbook_name}/README.md", content.strip - end - # Create a recipe with the provided content. # # @param [String] content The recipe content. diff --git a/lib/foodcritic/domain.rb b/lib/foodcritic/domain.rb index 4d2a9a6e..f3249e23 100644 --- a/lib/foodcritic/domain.rb +++ b/lib/foodcritic/domain.rb @@ -51,8 +51,7 @@ def to_s # A rule to be matched against. class Rule - attr_accessor :code, :name, :cookbook, :recipe, :provider, :resource - attr_writer :tags + attr_accessor :code, :name, :cookbook, :recipe, :provider, :resource, :tags # Create a new rule # @@ -63,10 +62,6 @@ def initialize(code, name) @tags = [code] end - def tags - ['any'] + @tags - end - # Returns a string representation of this rule. # # @return [String] Rule as a string. @@ -75,4 +70,4 @@ def to_s end end -end +end \ No newline at end of file diff --git a/lib/foodcritic/helpers.rb b/lib/foodcritic/helpers.rb index 834ef0f5..cf33064a 100644 --- a/lib/foodcritic/helpers.rb +++ b/lib/foodcritic/helpers.rb @@ -13,10 +13,8 @@ module Helpers # @param [Nokogiri::XML::Node] node The node to create a match for # @return [Hash] Hash with the matched node name and position with the recipe def match(node) - raise ArgumentError.new unless node.respond_to?(:xpath) pos = node.xpath('descendant::pos').first - return nil if pos.nil? - {:matched => node.respond_to?(:name) ? node.name : '', :line => pos['line'].to_i, :column => pos['column'].to_i} + {:matched => node.respond_to?(:name) ? node.name : '', :line => pos['line'], :column => pos['column']} end # Create a match for a specified file. Use this if the presence of the file triggers the warning rather than content. @@ -25,19 +23,16 @@ def match(node) # @return [Hash] Hash with the match details # @see FoodCritic::Helpers#match def file_match(file) - raise ArgumentError.new("Filename cannot be nil") if file.nil? {:filename => file, :matched => file, :line => 1, :column => 1} end # Does the specified recipe check for Chef Solo? # # @param [Nokogiri::XML::Node] ast The AST of the cookbook recipe to check. - # @return [Boolean] True if there is a test for Chef::Config[:solo] in the - # recipe + # @return [Boolean] True if there is a test for Chef::Config[:solo] in the recipe def checks_for_chef_solo?(ast) - ! ast.xpath(%q{//if/aref[count(descendant::const[@value = 'Chef' or - @value = 'Config']) = 2 - and count(descendant::ident[@value='solo']) > 0]}).empty? + ! ast.xpath(%q{//if/aref[count(descendant::const[@value = 'Chef' or @value = 'Config']) = 2 and + count(descendant::ident[@value='solo']) > 0]}).empty? end # Is the chef-solo-search library available? @@ -45,38 +40,32 @@ def checks_for_chef_solo?(ast) # @param [String] recipe_path The path to the current recipe # @return [Boolean] True if the chef-solo-search library is available. def chef_solo_search_supported?(recipe_path) - return false if recipe_path.nil? || ! File.exists?(recipe_path) - cbk_tree_path = Pathname.new(File.join(recipe_path, '../../..')) - search_libs = Dir[File.join(cbk_tree_path.realpath, "*/libraries/search.rb")] + search_libs = Dir[File.join(Pathname.new(File.join(recipe_path, '../../..')).realpath, "*/libraries/search.rb")] search_libs.any? do |lib| - ! read_file(lib).xpath(%q{//class[count(descendant::const[@value='Chef' - or @value='Recipe']) = 2]/descendant::def/ident[@value='search']}).empty? + ! read_file(lib).xpath(%q{//class[count(descendant::const[@value='Chef' or @value='Recipe']) = 2]/ + descendant::def/ident[@value='search']}).empty? end end # Searches performed by the specified recipe. # # @param [Nokogiri::XML::Node] ast The AST of the cookbook recipe to check. - # @return [Array] The AST nodes in the recipe where searches are performed + # @return [Boolean] True if the recipe performs a search def searches(ast) - return [] unless ast.respond_to?(:xpath) ast.xpath("//fcall/ident[@value = 'search']") end - # Searches performed by the specified recipe that are literal strings. - # Searches with a query formed from a subexpression will be ignored. + # Searches performed by the specified recipe that are literal strings. Searches with a query formed from a + # subexpression will be ignored. # - # @param [Nokogiri::XML::Node] ast The AST of the cookbook recipe to check - # @return [Array] The matching nodes + # @param [Nokogiri::XML::Node] ast The AST of the cookbook recipe to check. + # @return [Nokogiri::XML::Node] The matching nodes def literal_searches(ast) - return [] unless ast.respond_to?(:xpath) - ast.xpath("//method_add_arg[fcall/ident/@value = 'search' and - count(descendant::string_embexpr) = 0]/descendant::tstring_content") + ast.xpath("//method_add_arg[fcall/ident/@value = 'search' and count(descendant::string_embexpr) = 0]/descendant::tstring_content") end class AttFilter def is_att_type(value) - return [] unless value.respond_to?(:select) value.select{|n| %w{node default override set normal}.include?(n.to_s)} end end @@ -84,34 +73,24 @@ def is_att_type(value) # Find attribute accesses by type. # # @param [Nokogiri::XML::Node] ast The AST of the cookbook recipe to check - # @param [Symbol] accessed_via The approach used to access the attributes - # (:string, :symbol or :vivified) - # @param [Boolean] exclude_with_dots Exclude attribute accesses that mix - # strings/symbols with dot notation. + # @param [Symbol] accessed_via The approach used to access the attributes (:string, :symbol or :vivified) + # @param [Boolean] exclude_with_dots Exclude attribute accesses that mix strings/symbols with dot notation. # @return [Array] The matching nodes if any def attribute_access(ast, accessed_via, exclude_with_dots) - return [] unless ast.respond_to?(:xpath) - unless [:vivified, :symbol, :string].include? accessed_via - raise ArgumentError.new "Node type not recognised" - end - - (if accessed_via == :vivified - calls = ast.xpath(%q{//*[self::call or self::field] - [is_att_type(vcall/ident/@value) or - is_att_type(var_ref/ident/@value)][@value='.']}, AttFilter.new) - calls.select do |call| - call.xpath("aref/args_add_block").size == 0 and - (call.xpath("descendant::ident").size > 1 and - ! dsl_methods.include?(call.xpath("ident/@value").to_s.to_sym)) + (if accessed_via == :vivified + calls = ast.xpath(%Q{//*[self::call or self::field][is_att_type(vcall/ident/@value) or + is_att_type(var_ref/ident/@value)][@value='.']}, AttFilter.new) + calls.select do |call| + call.xpath("aref/args_add_block").size == 0 and (call.xpath("descendant::ident").size > 1 and + ! dsl_methods.include?(call.xpath("ident/@value").to_s.to_sym)) + end + else + accessed_via = 'tstring_content' if accessed_via == :string + expr = '//*[self::aref_field or self::aref][is_att_type(descendant::ident' + expr += '[not(ancestor::aref/call)]' if exclude_with_dots + expr += "/@value)]/descendant::#{accessed_via}" + ast.xpath(expr, AttFilter.new) end - else - accessed_via = 'tstring_content' if accessed_via == :string - expr = '//*[self::aref_field or self::aref]' - expr += '[is_att_type(descendant::ident' - expr += '[not(ancestor::aref/call)]' if exclude_with_dots - expr += "/@value)]/descendant::#{accessed_via}" - ast.xpath(expr, AttFilter.new) - end ).sort end @@ -119,14 +98,10 @@ def attribute_access(ast, accessed_via, exclude_with_dots) # TODO: Include blockless resources # # @param [Nokogiri::XML::Node] ast The AST of the cookbook recipe to check - # @param [String] type The type of resource to look for (or nil for all - # resources) + # @param [String] type The type of resource to look for (or nil for all resources) # @return [Array] AST nodes of Chef resources. def find_resources(ast, type = nil) - return [] unless ast.respond_to?(:xpath) - scope_type = '' - scope_type = "[@value='#{type}']" unless type.nil? - ast.xpath("//method_add_block[command/ident#{scope_type}]") + ast.xpath(%Q{//method_add_block[command/ident#{type.nil? ? '' : "[@value='#{type}']"}]}) end # Return the type, e.g. 'package' for a given resource @@ -134,33 +109,21 @@ def find_resources(ast, type = nil) # @param [Nokogiri::XML::Node] resource The resource AST # @return [String] The type of resource def resource_type(resource) - unless resource.respond_to?(:xpath) - raise ArgumentError.new "Resource must support #xpath" - end - type = resource.xpath('string(command/ident/@value)') - if type.empty? - raise ArgumentError.new "Provided AST node is not a resource" - end - type + resource.xpath('string(command/ident/@value)') end # Retrieve the name attribute associated with the specified resource. # - # @param [Nokogiri::XML::Node] resource The resource AST to lookup the name - # attribute under + # @param [Nokogiri::XML::Node] resource The resource AST to lookup the name attribute under # @return [String] The name attribute value def resource_name(resource) - unless resource.respond_to?(:xpath) - raise ArgumentError.new "Resource must support #xpath" - end resource.xpath('string(command//tstring_content/@value)') end # Retrieve a single-valued attribute from the specified resource. # # @param [String] name The attribute name - # @param [Nokogiri::XML::Node] resource The resource AST to lookup the - # attribute under + # @param [Nokogiri::XML::Node] resource The resource AST to lookup the attribute under # @return [String] The attribute value for the specified attribute def resource_attribute(name, resource) resource_attributes(resource)[name] @@ -172,8 +135,7 @@ def resource_attribute(name, resource) # @return [Hash] The resource attributes def resource_attributes(resource) atts = {:name => resource_name(resource)} - resource.xpath('do_block/descendant::command - [count(ancestor::do_block) = 1]').each do |att| + 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 @@ -189,20 +151,15 @@ def resource_attributes(resource) # @param [Nokogiri::XML::Node] ast The recipe AST # @return [Hash] The matching resources def resources_by_type(ast) - unless ast.respond_to?(:xpath) - raise ArgumentError.new "AST must support #xpath" - end result = Hash.new{|hash, key| hash[key] = Array.new} - find_resources(ast).each do |resource| - result[resource_type(resource)] << resource - end + find_resources(ast).each{|resource| result[resource_type(resource)] << resource} result end # Retrieve the attributes as a hash for all resources of a given type. # # @param [Nokogiri::XML::Node] ast The recipe AST - # @return [Hash] Resources keyed by type, with an array for each + # @return [Hash] An array of resource attributes keyed by type. def resource_attributes_by_type(ast) result = {} resources_by_type(ast).each do |type,resources| diff --git a/lib/foodcritic/linter.rb b/lib/foodcritic/linter.rb index b4c59595..94a43ddf 100644 --- a/lib/foodcritic/linter.rb +++ b/lib/foodcritic/linter.rb @@ -39,7 +39,6 @@ def initialize # @option options [Array] fail_tags The tags to fail the build on # @return [FoodCritic::Review] A review of your cookbooks, with any warnings issued. def check(cookbook_path, options) - raise ArgumentError.new "Cookbook path is required" if cookbook_path.nil? @last_cookbook_path, @last_options = cookbook_path, options load_rules unless defined? @rules warnings = []; last_dir = nil; matched_rule_tags = Set.new @@ -55,14 +54,13 @@ def check(cookbook_path, options) rule_matches += matches(rule.cookbook, cookbook_dir) if last_dir != cookbook_dir rule_matches.each do |match| warnings << Warning.new(rule, {:filename => file}.merge(match)) - matched_rule_tags << rule.tags + matched_rule_tags += rule.tags end end last_dir = cookbook_dir end - @review = Review.new(cookbook_path, warnings, - should_fail_build?(options[:fail_tags], matched_rule_tags)) + @review = Review.new(cookbook_path, warnings, should_fail_build?(options[:fail_tags], matched_rule_tags)) binding.pry if options[:repl] @review @@ -116,8 +114,13 @@ def files_to_process(dir) # @param [Set] matched_tags The tags of warnings we have matches for # @return [Boolean] True if the build should be failed def should_fail_build?(fail_tags, matched_tags) - return false if fail_tags.empty? - matched_tags.any?{|tags| matching_tags?(fail_tags, tags)} + if fail_tags.empty? + false + elsif fail_tags.include? 'any' + true + else + matching_tags?(fail_tags, matched_tags) + end end # Evaluate the specified tags diff --git a/spec/foodcritic/helpers_spec.rb b/spec/foodcritic/helpers_spec.rb deleted file mode 100644 index 523bf526..00000000 --- a/spec/foodcritic/helpers_spec.rb +++ /dev/null @@ -1,228 +0,0 @@ -require_relative '../spec_helper' - -describe FoodCritic::Helpers do - - let(:api) { Object.new.extend(FoodCritic::Helpers) } - - describe "#match" do - it "raises if the provided node is nil" do - lambda{api.match(nil)}.must_raise(ArgumentError) - end - it "raises if the provided node does not support XPath" do - lambda{api.match(Object.new)}.must_raise(ArgumentError) - end - it "returns nil if there is no nested position node" do - node = MiniTest::Mock.new - node.expect :xpath, [], ['descendant::pos'] - api.match(node).must_be_nil - end - it "uses the position of the first position node if there are multiple" do - node = MiniTest::Mock.new - node.expect(:xpath, - [{'name' => 'pos', 'line' => '1', 'column' => '10'}, - {'name' => 'pos', 'line' => '3', 'column' => '16'}], ['descendant::pos']) - match = api.match(node) - match[:line].must_equal(1) - match[:column].must_equal(10) - end - describe :matched_node_name do - let(:node) do - node = MiniTest::Mock.new - node.expect :xpath, [{'name' => 'pos', 'line' => '1', 'column' => '10'}], - ['descendant::pos'] - node - end - it "includes the name of the node in the match" do - node.expect :name, 'command' - api.match(node).must_equal({:matched => 'command', :line => 1, - :column => 10}) - end - it "sets the matched name to empty if the element does not have a name" do - api.match(node).must_equal({:matched => '', :line => 1, :column => 10}) - end - end - end - - describe :file_match do - it "includes the provided filename in the match" do - api.file_match("foo.rb")[:filename].must_equal "foo.rb" - end - it "retains the full provided filename path in the match" do - api.file_match("foo/bar/foo.rb")[:filename].must_equal "foo/bar/foo.rb" - end - it "raises an error if the provided filename is nil" do - lambda{api.file_match(nil)}.must_raise(ArgumentError) - end - it "sets the line and column to the beginning of the file" do - match = api.file_match("bar.rb") - match[:line].must_equal 1 - match[:column].must_equal 1 - end - end - - describe "#checks_for_chef_solo?" do - let(:ast) { ast = MiniTest::Mock.new } - it "returns false if there is no reference to chef solo" do - ast.expect :xpath, [], [String] - refute api.checks_for_chef_solo?(ast) - end - it "returns true if there is one reference to chef solo" do - ast.expect :xpath, ['aref'], [String] - assert api.checks_for_chef_solo?(ast) - end - it "returns true if there are multiple references to chef solo" do - ast.expect :xpath, ['aref', 'aref'], [String] - assert api.checks_for_chef_solo?(ast) - end - end - describe "#chef_solo_search_supported?" do - it "returns false if the recipe path is nil" do - refute api.chef_solo_search_supported?(nil) - end - it "returns false if the recipe path does not exist" do - refute api.chef_solo_search_supported?('/tmp/non-existent-path') - end - end - describe "#searches" do - let(:ast) { ast = MiniTest::Mock.new } - it "returns empty if the AST does not support XPath expressions" do - api.searches('not-an-ast').must_be_empty - end - it "returns empty if the AST has no elements" do - ast.expect :xpath, [], [String] - api.searches(ast).must_be_empty - end - it "returns the AST elements for each use of search" do - ast.expect :xpath, ['ident'], [String] - api.searches(ast).must_equal ['ident'] - end - end - describe "#literal_searches" do - let(:ast) { ast = MiniTest::Mock.new } - it "returns empty if the AST does not support XPath expressions" do - api.literal_searches(nil).must_be_empty - end - it "returns empty if the AST has no elements" do - ast.expect :xpath, [], [String] - api.literal_searches(ast).must_be_empty - end - it "returns the AST elements for each literal search" do - ast.expect :xpath, ['tstring_content'], [String] - api.literal_searches(ast).must_equal ['tstring_content'] - end - end - describe :AttFilter do - describe "#is_att_type" do - let(:filter) { FoodCritic::Helpers::AttFilter.new } - it "returns empty if the argument is not enumerable" do - filter.is_att_type(nil).must_be_empty - end - it "filters out values that are not Chef node attribute types" do - nodes = %w{node node badger default override ostrich set normal} - filter.is_att_type(nodes).uniq.size.must_equal 5 - end - it "returns all filtered nodes" do - nodes = %w{node node override default normal set set override} - filter.is_att_type(nodes).must_equal nodes - end - it "returns empty if there are no Chef node attribute types" do - nodes = %w{squirrel badger pooh tigger} - filter.is_att_type(nodes).must_be_empty - end - end - end - describe "#attribute_access" do - let(:ast) { ast = MiniTest::Mock.new } - it "returns empty if the provided ast does not support XPath" do - api.attribute_access(nil, :vivified, false).must_be_empty - end - it "returns empty if the provided ast has no matches" do - ast.expect :xpath, [], [String] - [:vivified, :string, :symbol].each do |access_type| - api.attribute_access([], :vivified, false).must_be_empty - end - end - it "raises if the specified node type is not recognised" do - ast.expect :xpath, [], [String] - lambda do - api.attribute_access(ast, :cymbals, false) - end.must_raise(ArgumentError) - end - it "does not raise if the specified node type is valid" do - ast.expect :xpath, [], [String, FoodCritic::Helpers::AttFilter] - [:vivified, :symbol, :string].each do |access_type| - api.attribute_access(ast, access_type, false) - end - end - end - describe "#find_resources" do - let(:ast) { MiniTest::Mock.new } - it "returns empty unless the ast supports XPath" do - api.find_resources(nil, nil).must_be_empty - end - it "restricts by resource type when provided" do - ast.expect :xpath, ['method_add_block'], - ["//method_add_block[command/ident[@value='file']]"] - api.find_resources(ast, 'file') - ast.verify - end - it "does not restrict by resource type when not provided" do - ast.expect :xpath, ['method_add_block'], - ["//method_add_block[command/ident]"] - api.find_resources(ast, nil) - ast.verify - end - it "returns any matches" do - ast.expect :xpath, ['method_add_block'], [String] - api.find_resources(ast, nil).must_equal ['method_add_block'] - end - end - describe "#resource_type" do - it "raises if the resource does not support XPath" do - lambda {api.resource_type(nil)}.must_raise ArgumentError - end - it "raises if the resource type cannot be determined" do - ast = MiniTest::Mock.new - ast.expect :xpath, '', [String] - lambda {api.resource_type(ast)}.must_raise ArgumentError - end - it "returns the resource type for a resource" do - ast = MiniTest::Mock.new - ast.expect :xpath, 'directory', [String] - api.resource_type(ast).must_equal 'directory' - end - end - describe "#resource_name" do - it "raises if the resource does not support XPath" do - lambda {api.resource_name('foo')}.must_raise ArgumentError - end - it "returns the resource name for a resource" do - ast = MiniTest::Mock.new - ast.expect :xpath, 'bob', [String] - api.resource_name(ast).must_equal 'bob' - end - end - describe "#resource_attributes" do - it "raises if the resource does not support XPath" do - lambda{api.resource_attributes(nil)}.must_raise ArgumentError - end - end - describe "#resources_by_type" do - it "raises if the ast does not support XPath" do - lambda{api.resources_by_type(nil)}.must_raise ArgumentError - end - it "returns an empty hash if there are no resources" do - ast = MiniTest::Mock.new.expect :xpath, [], [String] - api.resources_by_type(ast).keys.must_be_empty - end - end - describe "#resource_attributes_by_type" do - it "raises if the ast does not support XPath" do - lambda{api.resource_attributes_by_type(nil)}.must_raise ArgumentError - end - it "returns an empty hash if there are no resources" do - ast = MiniTest::Mock.new.expect :xpath, [], [String] - api.resource_attributes_by_type(ast).keys.must_be_empty - end - end -end diff --git a/spec/foodcritic/linter_spec.rb b/spec/foodcritic/linter_spec.rb deleted file mode 100644 index 069d4b32..00000000 --- a/spec/foodcritic/linter_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require_relative '../spec_helper' - -describe FoodCritic::Linter do - - it "should be instantiable" do - FoodCritic::Linter.new.wont_be_nil - end - - it "should raise if a cookbook path is not provided" do - linter = FoodCritic::Linter.new - lambda {linter.check(nil, {})}.must_raise(ArgumentError) - end - -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb deleted file mode 100644 index 066d4bfd..00000000 --- a/spec/spec_helper.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'foodcritic' -require 'minitest/spec' -require 'minitest/autorun' -require 'minitest/pride'