require 'spec_helper' RSpec.describe Pluginscan::FileFinder, type: :file do describe ".count" do it "returns 0 when there are no files" do setup_tempdir('tmp') finder = Pluginscan::FileFinder.new('tmp') expect(finder.count).to eq 0 end it "returns 0 when there are only directories" do setup_tempdir('tmp') add_directory('tmp', 'foo') finder = Pluginscan::FileFinder.new('tmp') expect(finder.count).to eq 0 end it "returns 3 when there are 3 files" do setup_tempdir('tmp') add_php_file('tmp') add_directory('tmp', 'foo') add_non_php_file('tmp/foo') add_directory('tmp', 'foo/bar') add_php_file('tmp/foo/bar') finder = Pluginscan::FileFinder.new('tmp') expect(finder.count).to eq 3 end it "caches the value" do setup_tempdir('tmp') add_php_file('tmp') finder = Pluginscan::FileFinder.new('tmp') finder.count setup_tempdir('tmp') # We removed the file, but the result should stay the same: expect(finder.count).to eq 1 end end describe ".php_files" do it "returns [] when there are no files" do setup_tempdir('tmp') finder = Pluginscan::FileFinder.new('tmp') expect(finder.php_files).to eq [] end it "returns [] when there are only directories" do setup_tempdir('tmp') add_directory('tmp', 'foo') finder = Pluginscan::FileFinder.new('tmp') expect(finder.php_files).to eq [] end it "returns two filenames when there are 2 php files" do setup_tempdir('tmp') php_file_name1 = add_php_file('tmp') add_directory('tmp', 'foo') add_non_php_file('tmp/foo') add_directory('tmp', 'foo/bar') php_file_name2 = add_php_file('tmp/foo/bar') finder = Pluginscan::FileFinder.new('tmp') expect(finder.php_files).to eq [php_file_name1, php_file_name2] end it "caches the result" do setup_tempdir('tmp') php_file_name = add_php_file('tmp') finder = Pluginscan::FileFinder.new('tmp') finder.php_files setup_tempdir('tmp') # We removed the file, but the result should stay the same: expect(finder.php_files).to eq [php_file_name] end end end