Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

List plugins embedded in non dedicated gem #373

Merged
merged 1 commit into from

4 participants

@schmurfy

It looks like it was easier than I thought !

this change includes in the "guard list" output guard plugins which are not in a "guard-xxx" gem by looking inside the gem folder if a "lib/guard/.rb" file is available.

I only updated the code for rubygems 1.8.0+ since I am not sure about the api provided below.

@thibaudgg
Owner

Can you please add some specs, thanks!

@schmurfy

specs added !

@thibaudgg
Owner

Thanks, @guard/core-team seems good to you?

@netzpirat
Owner

Yes, looks fine for me.

spec/guard_spec.rb
@@ -780,6 +780,20 @@ class Inline < Guard
gems = Guard.guard_gem_names
gems.should include("rspec")
end
+
+ it "returns the list of embedded guard gems" do
+ gem1 = stub(:gem, :name => "gem1", :full_gem_path => '/gem1' )
+ gem2 = stub(:gem, :name => "gem2", :full_gem_path => '/gem2' )
+ gem3 = stub(:gem, :name => "guard", :full_gem_path => '/guard' )
+
+ File.should_receive(:exists?).with('/gem1/lib/guard/gem1.rb').and_return(false)
+ File.should_receive(:exists?).with('/gem2/lib/guard/gem2.rb').and_return(true)
+
+ Gem::Specification.should_receive(:find_all).and_return([gem1, gem2])
@rymai Owner
rymai added a note

Shouldn't you return Gem::Specification.should_receive(:find_all).and_return([gem1, gem2, gem3]) here instead?

good catch :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@rymai
Owner

Other than my comment, it seems good to me!

@schmurfy

specs fixed.

@thibaudgg
Owner

@schmurfy can you try an empty commit to see if travis-ci build are ok now? Thanks!

@schmurfy

just rebased on master.

@thibaudgg
Owner

Great thanks!

@thibaudgg thibaudgg merged commit 8883a30 into guard:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 17, 2012
  1. @schmurfy
This page is out of date. Refresh to see the latest.
Showing with 22 additions and 1 deletion.
  1. +8 −1 lib/guard.rb
  2. +14 −0 spec/guard_spec.rb
View
9 lib/guard.rb
@@ -404,7 +404,14 @@ def locate_guard(name)
#
def guard_gem_names
if Gem::Version.create(Gem::VERSION) >= Gem::Version.create('1.8.0')
- Gem::Specification.find_all.select { |x| x.name =~ /^guard-/ }
+ Gem::Specification.find_all.select do |x|
+ if x.name =~ /^guard-/
+ true
+ elsif x.name != "guard"
+ guard_plugin_path = File.join(x.full_gem_path, "lib/guard/#{x.name}.rb")
+ File.exists?( guard_plugin_path )
+ end
+ end
else
Gem.source_index.find_name(/^guard-/)
end.map { |x| x.name.sub(/^guard-/, '') }
View
14 spec/guard_spec.rb
@@ -780,6 +780,20 @@ class Inline < Guard
gems = Guard.guard_gem_names
gems.should include("rspec")
end
+
+ it "returns the list of embedded guard gems" do
+ gem1 = stub(:gem, :name => "gem1", :full_gem_path => '/gem1' )
+ gem2 = stub(:gem, :name => "gem2", :full_gem_path => '/gem2' )
+ gem3 = stub(:gem, :name => "guard", :full_gem_path => '/guard' )
+
+ File.should_receive(:exists?).with('/gem1/lib/guard/gem1.rb').and_return(false)
+ File.should_receive(:exists?).with('/gem2/lib/guard/gem2.rb').and_return(true)
+
+ Gem::Specification.should_receive(:find_all).and_return([gem1, gem2, gem3])
+
+ Guard.guard_gem_names.should == ['gem2']
+ end
+
end
describe ".debug_command_execution" do
Something went wrong with that request. Please try again.