Skip to content
Snippets Groups Projects
Unverified Commit 30910669 authored by Rémy Coutable's avatar Rémy Coutable Committed by GitHub
Browse files

Merge pull request #889 from AlexWayfer/add-equal-method-for-watcher

Add `#==` method for `Guard::Watcher`
parents 936472ff 0344fe6a
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -26,6 +26,13 @@ module Guard
@pattern = Pattern.create(pattern)
end
 
# Compare with other watcher
# @param other [Guard::Watcher] other watcher for comparing
# @return [true, false] equal or not
def ==(other)
action == other.action && pattern == other.pattern
end
# Finds the files that matches a Guard plugin.
#
# @param [Guard::Plugin] guard the Guard plugin which watchers are used
Loading
Loading
Loading
Loading
@@ -2,10 +2,20 @@ module Guard
class Watcher
class Pattern
class Matcher
attr_reader :matcher
def initialize(obj)
@matcher = obj
end
 
# Compare with other matcher
# @param other [Guard::Watcher::Pattern::Matcher]
# other matcher for comparing
# @return [true, false] equal or not
def ==(other)
matcher == other.matcher
end
def match(string_or_pathname)
@matcher.match(normalized(string_or_pathname))
end
Loading
Loading
Loading
Loading
@@ -42,6 +42,18 @@ RSpec.describe Guard::Watcher::Pattern::Matcher do
end
end
 
describe "#==" do
it "returns true for equal matchers" do
expect(described_class.new(/spec_helper\.rb/)).
to eq(described_class.new(/spec_helper\.rb/))
end
it "returns false for unequal matchers" do
expect(described_class.new(/spec_helper\.rb/)).
not_to eq(described_class.new(/spec_helper\.r/))
end
end
describe "integration" do
describe "#match result" do
subject { described_class.new(obj).match(filename) }
Loading
Loading
Loading
Loading
@@ -36,6 +36,18 @@ RSpec.describe Guard::Watcher do
end
end
 
describe "#==" do
it "returns true for equal watchers" do
expect(described_class.new(/spec_helper\.rb/)).
to eq(described_class.new(/spec_helper\.rb/))
end
it "returns false for unequal watchers" do
expect(described_class.new(/spec_helper\.rb/)).
not_to eq(described_class.new(/spec_helper\.r/))
end
end
describe ".match_files" do
let(:plugin) { instance_double("Guard::Plugin", options: {}) }
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment