require File.expand_path(File.dirname(__FILE__) + '/spec_helper') require 'hx' describe Hx::PathSubset::Predicate do it "accepts anything when the accept and reject patterns are nil" do filter = Hx::PathSubset::Predicate.new(nil, nil) filter.accept?("blah").should be_true end it "accepts only paths matching the accept pattern when it is specified" do filter = Hx::PathSubset::Predicate.new("foo", nil) filter.accept?("foo").should be_true filter.accept?("bar").should be_false end it "accepts only paths not matching reject, when only that is specified" do filter = Hx::PathSubset::Predicate.new(nil, "foo") filter.accept?("foo").should be_false filter.accept?("bar").should be_true end it "matches the difference of accept and reject when both are specified" do filter = Hx::PathSubset::Predicate.new("foo/*", "foo/bar") filter.accept?("foo/bar").should be_false filter.accept?("foo/baz").should be_true filter.accept?("bar").should be_false end it "shouldn't match across slashes with single star" do filter = Hx::PathSubset::Predicate.new("foo/*", nil) filter.accept?("bar").should be_false filter.accept?("foo").should be_false filter.accept?("foo/bar").should be_true filter.accept?("foo/bar/baz").should be_false end it "should match across slashes with double star" do filter = Hx::PathSubset::Predicate.new("foo/**", nil) filter.accept?("bar").should be_false filter.accept?("foo").should be_false filter.accept?("foo/bar").should be_true filter.accept?("foo/bar/baz").should be_true end end