Skip to content

Commit

Permalink
Add spec for FileMatch
Browse files Browse the repository at this point in the history
  • Loading branch information
Nullreff committed Nov 24, 2013
1 parent 71397b5 commit 9f398f3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/bukin/file_match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def match_helper(search, file_name)
elsif search.is_a? ::Regexp
search =~ file_name
elsif search.respond_to? :any?
search.any? {|item| match_helper(item)}
search.any? {|item| match_helper(item, file_name)}
else
false
end
Expand Down
39 changes: 39 additions & 0 deletions spec/file_match_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require 'spec_helper'
require 'bukin'

describe Bukin::FileMatch do
it 'matches anything passed to it' do
match = Bukin::FileMatch.any
match.should =~ 'filename.jar'
match.should =~ 'another-file-name.jar'
match.should =~ 'yet_another.zip'
end

it 'matches a string' do
match = Bukin::FileMatch.new('filename.jar')
match.should =~ 'filename.jar'
match.should_not =~ 'another-file-name.jar'
match.should_not =~ 'yet_another.zip'
end

it 'matches a regex' do
match = Bukin::FileMatch.new(/^.*\.jar$/)
match.should =~ 'filename.jar'
match.should =~ 'another-file-name.jar'
match.should_not =~ 'yet_another.zip'
end

it 'matches an array of matches' do
match = Bukin::FileMatch.new(['filename.jar', 'another-file-name.jar'])
match.should =~ 'filename.jar'
match.should =~ 'another-file-name.jar'
match.should_not =~ 'yet_another.zip'
end

it 'matches none for other types' do
match = Bukin::FileMatch.new(:filename)
match.should_not =~ 'filename.jar'
match.should_not =~ 'another-file-name.jar'
match.should_not =~ 'yet_another.zip'
end
end

0 comments on commit 9f398f3

Please sign in to comment.