taglob 0.0.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,47 @@
1
+ === 1.0.0 / 2008-10-08
2
+
3
+ * Important changes
4
+ * Dir.taglob('**/*.rb','tags,for,the,win') <- Will produce an array of files that contain all these tags(AND)
5
+ * Dir.taglob('**/*.rb','tags|or|the|win') <- Will produce an array of files that contain any of these tags(OR)
6
+ * rake spec SPEC_OPTS='-f specdoc' <- More infroz(this obviously needs to be run from the gem directory :P)
7
+ * taglob binary!
8
+ * $ taglob <dirname> <- produces a list of files in <dirname> with their respective tags
9
+ * $ taglob <file> <- produces a list of tags for that file
10
+ * Rake tasks!
11
+ * You can now require 'taglob/rake/tasks' in your Rakefile to get test_tag and spec_tag tasks that would be used like this:
12
+ * $ rake spec_tag tags="for,the,win"
13
+ * $ rake test_tag tags="foo|bar"
14
+ * You can also specify your own TestTagTasks in your Rakefile:
15
+ require 'taglob/rake'
16
+
17
+ Taglob::Rake::SpecTagsTask.new :spec_regression do |t|
18
+ t.pattern = 'spec/**/*.rb'
19
+ t.tags = "regression|smoke"
20
+ end
21
+ Taglob::Rake::TestTagsTask.new :test_regression do |t|
22
+ t.pattern = 'test/**/*.rb'
23
+ t.tags = "regression|smoke"
24
+ end
25
+ * CheckTagsTask will check all tags in a glob pattern against a valid list of tags
26
+ require 'taglob/rake'
27
+ task = Taglob::Rake::CheckTagsTask.new do |t|
28
+ t.pattern = 'spec/**/*.rb'
29
+ t.valid_tag_source = 'config/valid_tags.txt'
30
+ end
31
+
32
+ * Thanks:
33
+ - NolanEvans[http://github.com/nolman] did the majority of this rewrite.
34
+ - DrewOlson[http://github.com/dfg59] still doesn't have commit rights.
35
+ - CharleyBaker[http://github.com/charley], RadhikaPothukuchi, and RamaKarri were all very helpful in pairing with NolanEvans and AdamAnderson[http://github.com/scudco] in getting this gem out.
36
+
37
+ === 0.1.0 / 2008-05-19
38
+
39
+ * Important changes
40
+ * Taglob now does ANDing logic rather than ORing
41
+ This is really how it should have been to begin with. I just noobed it up is all.
42
+
43
+ In version 0.0.1 if you did Dir.taglob('**/*.rb','foo','bar') it would select files as long they contained one of the tags(foo OR bar). In version 0.1.0 it will only select files which contain both tags(foo AND bar).
44
+
1
45
  === 0.0.1 / 2008-05-14
2
46
 
3
47
  * Taglob "released"
data/Manifest.txt CHANGED
@@ -2,8 +2,24 @@ History.txt
2
2
  Manifest.txt
3
3
  README.txt
4
4
  Rakefile
5
+ bin/taglob
5
6
  lib/taglob.rb
6
- spec/spec_taglob.rb
7
+ lib/taglob/extensions.rb
8
+ lib/taglob/extensions/dir.rb
9
+ lib/taglob/extensions/file.rb
10
+ lib/taglob/extensions/string.rb
11
+ lib/taglob/rake.rb
12
+ lib/taglob/rake/check_tags_task.rb
13
+ lib/taglob/rake/tasks.rb
14
+ lib/taglob/rake/test_tags_task.rb
15
+ spec/check_tags_task_spec.rb
16
+ spec/dir_tagor_spec.rb
17
+ spec/missing_tags.txt
18
+ spec/spec_helper.rb
19
+ spec/tagged_files/epic_lulz.rb
7
20
  spec/tagged_files/foo.rb
8
21
  spec/tagged_files/foo_bar_buttz.rb
9
- spec/tagged_files/epic_lulz.rb
22
+ spec/taglob_spec.rb
23
+ spec/tasks_spec.rb
24
+ spec/test_tags_task_spec.rb
25
+ spec/valid_tags.txt
data/README.txt CHANGED
@@ -4,46 +4,82 @@
4
4
 
5
5
  tags + Dir.glob = Dir.taglob
6
6
 
7
+ http://github.com/scudco/taglob/tree/master
8
+
7
9
  == FEATURES/PROBLEMS:
8
10
 
9
11
  * easily select tagged Ruby files
12
+ * rake tasks for test::unit and rspec
13
+ * rake task for checking against a valid list of tags
14
+ * can AND or OR tags
10
15
 
11
16
  == SYNOPSIS:
12
17
 
18
+
19
+ Taglob is great. Check this out.
20
+ Imagine a bunch of files that look like
21
+ #tags: zomg,buttz,foo,important
22
+ class Lol
23
+ def lulz
24
+ puts "here are your lulz, sir"
25
+ end
26
+ end
27
+
28
+ And then you are like dang I wish I could glob these files based on the
29
+ tags I setup! What am I doing with my life???
30
+ Taglob! (like Tada! but more like its unsophisticated country cousin(in name only(parentheses)))
31
+ Dir.taglob("**/*.rb","foo","lol")
32
+ That will totally give you back all the files tagged with 'foo' and 'lol' in an array of strings representing the paths of those files.
33
+ It is really just glob with some extra stuff thrown in.
34
+ Totally small, totally useless, totally taglob.
35
+
13
36
  require 'rubygems'
14
37
  require 'taglob'
15
38
 
16
39
  Dir.taglob('**/*.rb','foo','bar','buttz').each {|file| puts "#{file} was tagged with foo or bar or buttz!"}
17
40
 
18
- == REQUIREMENTS:
41
+ On a more serious note:
42
+ * Dir.taglob('**/*.rb','tags,for,the,win') <- Will produce an array of files that contain all these tags(AND)
43
+ * Dir.taglob('**/*.rb','tags|or|the|win') <- Will produce an array of files that contain any of these tags(OR)
44
+ * rake spec SPEC_OPTS='-f specdoc' <- More infroz(this obviously needs to be run from the gem directory :P)
45
+ * taglob binary!
46
+ * $ taglob <dirname> <- produces a list of files in <dirname> with their respective tags
47
+ * $ taglob <file> <- produces a list of tags for that file
48
+ * Rake tasks!
49
+ * You can now require 'taglob/rake/tasks' in your Rakefile to get test_tag and spec_tag tasks that would be used like this:
50
+ * $ rake spec_tag tags="for,the,win"
51
+ * $ rake test_tag tags="foo|bar"
52
+ * You can also specify your own TestTagTasks in your Rakefile:
53
+ require 'taglob/rake'
54
+
55
+ Taglob::Rake::SpecTagsTask.new :spec_regression do |t|
56
+ t.pattern = 'spec/**/*.rb'
57
+ t.tags = "regression|smoke"
58
+ end
59
+ Taglob::Rake::TestTagsTask.new :test_regression do |t|
60
+ t.pattern = 'test/**/*.rb'
61
+ t.tags = "regression|smoke"
62
+ end
63
+ * CheckTagsTask will check all tags in a glob pattern against a valid list of tags
64
+ require 'taglob/rake'
65
+ task = Taglob::Rake::CheckTagsTask.new do |t|
66
+ t.pattern = 'spec/**/*.rb'
67
+ t.valid_tag_source = 'config/valid_tags.txt'
68
+ end
19
69
 
20
- * none?
21
70
 
22
71
  == INSTALL:
23
72
 
24
73
  * sudo gem install taglob
25
74
 
26
- == LICENSE:
75
+ == UNINSTALL:
27
76
 
28
- (The MIT License)
77
+ * sudo gem uninstall taglob
29
78
 
30
- Copyright (c) 2008 Adam Anderson
79
+ == REINSTALL
31
80
 
32
- Permission is hereby granted, free of charge, to any person obtaining
33
- a copy of this software and associated documentation files (the
34
- 'Software'), to deal in the Software without restriction, including
35
- without limitation the rights to use, copy, modify, merge, publish,
36
- distribute, sublicense, and/or sell copies of the Software, and to
37
- permit persons to whom the Software is furnished to do so, subject to
38
- the following conditions:
81
+ * sudo gem install taglob
39
82
 
40
- The above copyright notice and this permission notice shall be
41
- included in all copies or substantial portions of the Software.
83
+ == LICENSE:
42
84
 
43
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
44
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
45
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
46
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
47
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
48
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
49
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
85
+ The copyrights-are-an-imaginary-construct license.
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
+
3
+ require 'taglob'
1
4
  require 'rubygems'
2
5
  require 'hoe'
3
- require './lib/taglob.rb'
4
6
  require 'spec/rake/spectask'
5
7
 
6
8
  Hoe.new('Taglob', Taglob::VERSION) do |p|
@@ -13,8 +15,16 @@ Hoe.new('Taglob', Taglob::VERSION) do |p|
13
15
  p.remote_rdoc_dir = '' # Release to root
14
16
  end
15
17
 
16
-
17
18
  desc "Run all examples"
18
19
  Spec::Rake::SpecTask.new('spec') do |t|
19
20
  t.spec_files = FileList['spec/*.rb']
20
- end
21
+ end
22
+
23
+ desc "Run all examples with RCov"
24
+ Spec::Rake::SpecTask.new('rcov') do |t|
25
+ t.spec_files = FileList['spec/**/*_spec.rb']
26
+ t.libs << File.join(File.dirname(__FILE__), 'lib')
27
+ t.rcov = true
28
+ t.rcov_dir = 'artifacts'
29
+ t.rcov_opts = ['--exclude', 'spec']
30
+ end
data/bin/taglob ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
3
+ require 'taglob'
4
+
5
+ if File.directory?(ARGV[0])
6
+ Dir.tags("#{ARGV[0]}/**/*.rb").each do |file,tags|
7
+ puts "#{file}:"
8
+ puts "\t#{tags.join(',')}"
9
+ end
10
+ else
11
+ puts "\t#{ARGV[0]}: #{File.tags(ARGV[0]).join(',')}"
12
+ end
data/lib/taglob.rb CHANGED
@@ -1,23 +1,31 @@
1
- class Taglob
2
- VERSION = '0.0.1'
3
- end
1
+ # Taglob is great. Check this out.
2
+ # Imagine a bunch of files that look like
3
+ # #tags: zomg,buttz,foo,important
4
+ # class Lol
5
+ # def lulz
6
+ # puts "here are your lulz, sir"
7
+ # end
8
+ # end
9
+ #
10
+ # And then you are like dang I wish I could glob these files based on the
11
+ # tags I setup! What am I doing with my life???
12
+ # Taglob! (like Tada! but more like its unsophisticated country cousin(in name only(parentheses)))
13
+ # Dir.taglob("**/*.rb","foo","lol")
14
+ # That will totally give you back all the files tagged with 'foo' and 'lol' in an array of strings representing the paths of those files.
15
+ # It is really just glob with some extra stuff thrown in.
16
+ # Totally small, totally useless, totally taglob.
17
+
18
+ require 'taglob/extensions'
4
19
 
5
- class Dir
20
+ module Taglob
21
+ VERSION = '1.0.0'
6
22
 
7
- def self.taglob(pattern,*tags)
8
- tagged_files = []
9
- Dir.glob(pattern).each do |file|
10
- parsed_tags = []
11
- File.readlines(file).each do |line|
12
- parsed_tags = parsed_tags | self.parse_tags(line)
13
- end
14
- tagged_files << file unless (parsed_tags & tags).empty?
23
+ def self.invalid_tags(pattern,valid_tags)
24
+ invalids = {}
25
+ Dir.tags(pattern).each do |file, tags|
26
+ invalid_tags = tags - valid_tags
27
+ invalids.merge!({file => invalid_tags}) if !invalid_tags.empty?
15
28
  end
16
- tagged_files
17
- end
18
-
19
- def self.parse_tags(line)
20
- line =~ /^#tags:\s+(.*)/ ?$1.split(',') : []
29
+ invalids
21
30
  end
22
-
23
- end
31
+ end
@@ -0,0 +1,3 @@
1
+ require 'taglob/extensions/dir'
2
+ require 'taglob/extensions/file'
3
+ require 'taglob/extensions/string'
@@ -0,0 +1,36 @@
1
+ class Dir
2
+
3
+ def self.tags(pattern)
4
+ files = {}
5
+ Dir.glob(pattern).each do |file|
6
+ tags = File.tags(file)
7
+ files.merge!({file => tags}) unless tags.empty?
8
+ end
9
+ files
10
+ end
11
+
12
+ def self.taglob(pattern,tags)
13
+ if(tags.include?('|'))
14
+ Dir.tag_or(pattern,*tags.split('|'))
15
+ else
16
+ Dir.tag_and(pattern,*tags.split(','))
17
+ end
18
+ end
19
+
20
+ def self.tag_and(pattern, *tags)
21
+ tagged_files = []
22
+ self.tags(pattern).each do |file,parsed_tags|
23
+ tagged_files << file if (tags - parsed_tags).empty?
24
+ end
25
+ tagged_files
26
+ end
27
+
28
+ def self.tag_or(pattern, *tags)
29
+ tagged_files = []
30
+ self.tags(pattern).each do |file,parsed_tags|
31
+ tagged_files << file if !(tags & parsed_tags).empty?
32
+ end
33
+ tagged_files
34
+ end
35
+
36
+ end
@@ -0,0 +1,13 @@
1
+ class File
2
+ def self.tags(file)
3
+ parsed_tags = []
4
+ File.readlines(file).each do |line|
5
+ parsed_tags = parsed_tags | self.parse_tags(line)
6
+ end
7
+ parsed_tags
8
+ end
9
+
10
+ def self.parse_tags(line)
11
+ line =~ /^# ?tags:\s+(.*)/ ? $1.split(',').map {|tag| tag.strip} : []
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ class String
2
+ def tags
3
+ self =~ /^# ?tags:\s+(.*)/ ? $1.split(',').map {|tag| tag.strip} : []
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require 'taglob/rake/check_tags_task'
2
+ require 'taglob/rake/test_tags_task'
@@ -0,0 +1,31 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+ require 'taglob'
4
+
5
+ module Taglob
6
+ module Rake
7
+ class CheckTagsTask < ::Rake::TaskLib
8
+ attr_accessor :pattern
9
+ attr_accessor :valid_tag_source
10
+
11
+ def initialize(name = :check_tags)
12
+ @name = name
13
+ yield self if block_given?
14
+ define
15
+ end
16
+
17
+ def define
18
+ task @name do
19
+ invalid_tags = Taglob.invalid_tags(pattern,valid_tag_list)
20
+ invalid_tags.each {|file,tags| $stderr.puts "Invalid tags: #{tags.join(',')} found in #{file}." }
21
+ exit 1 if !invalid_tags.empty?
22
+ end
23
+ end
24
+
25
+ def valid_tag_list
26
+ var = File.readlines(valid_tag_source).collect {|line| line.chomp }
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,11 @@
1
+ require 'taglob/rake/test_tags_task'
2
+
3
+ Taglob::Rake::TestTagsTask.new do |t|
4
+ t.pattern = 'test/**/test_*.rb'
5
+ t.tags = ENV['tags']
6
+ end
7
+
8
+ Taglob::Rake::SpecTagsTask.new do |t|
9
+ t.pattern = 'spec/**/*_spec.rb'
10
+ t.tags = ENV['tags']
11
+ end
@@ -0,0 +1,47 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'spec/rake/spectask'
4
+
5
+ module Taglob
6
+ module Rake
7
+ class TagsTask
8
+ attr_accessor :pattern
9
+ attr_accessor :tags
10
+
11
+ def initialize(name)
12
+ @name = name
13
+ yield self if block_given?
14
+ define
15
+ end
16
+
17
+ def test_files
18
+ Dir.taglob(pattern,tags) unless tags.nil? || pattern.nil?
19
+ end
20
+ end
21
+
22
+ class TestTagsTask < TagsTask
23
+ def initialize(name = :test_tags)
24
+ super(name)
25
+ end
26
+
27
+ def define
28
+ ::Rake::TestTask.new @name do |t|
29
+ t.test_files = test_files
30
+ end
31
+ end
32
+ end
33
+
34
+ class SpecTagsTask < TagsTask
35
+ def initialize(name = :spec_tags)
36
+ super(name)
37
+ end
38
+
39
+ def define
40
+ ::Spec::Rake::SpecTask.new @name do |t|
41
+ t.spec_files = test_files
42
+ end
43
+ end
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,77 @@
1
+ require 'spec/spec_helper'
2
+ require 'taglob/rake'
3
+
4
+ describe Taglob::Rake::CheckTagsTask do
5
+
6
+ before :all do
7
+ @missing_tags_source = 'spec/missing_tags.txt'
8
+ @valid_tags_source = 'spec/valid_tags.txt'
9
+ end
10
+
11
+ before :each do
12
+ @file_name ="./lib/taglob/rake/check_tags_task.rb"
13
+ @rake = Rake::Application.new
14
+ Rake.application = @rake
15
+ end
16
+
17
+ after :each do
18
+ Rake.application = nil
19
+ end
20
+
21
+ it "should define a rake task depending on provided name" do
22
+ task = Taglob::Rake::CheckTagsTask.new :foozor
23
+ @rake.task_names_include?("foozor").should be_true
24
+ end
25
+
26
+ it "should be able to define rake task value in constructor do block" do
27
+ pattern = "spec/**/*_spec.rb"
28
+ task = Taglob::Rake::CheckTagsTask.new do |t|
29
+ t.pattern = pattern
30
+ end
31
+ task.pattern.should eql(pattern)
32
+ end
33
+
34
+ it "should build valid tag list from provided file" do
35
+ task = Taglob::Rake::CheckTagsTask.new do |t|
36
+ t.valid_tag_source = @missing_tags_source
37
+ end
38
+ task.valid_tag_list.should eql(['foo'])
39
+ end
40
+
41
+ it "should raise error if invalid tags present" do
42
+ $stderr.stubs(:puts)
43
+ task = Taglob::Rake::CheckTagsTask.new :error_out do |t|
44
+ t.pattern = 'spec/tagged_files/*.rb'
45
+ t.valid_tag_source = @missing_tags_source
46
+ end
47
+ lambda {@rake.invoke_task('error_out')}.should raise_error(SystemExit)
48
+ end
49
+
50
+ it "should print out the invalid file list" do
51
+ $stderr.expects(:puts).with(regexp_matches(/epic_lulz.rb/))
52
+ $stderr.expects(:puts).with(regexp_matches(/foo_bar_buttz.rb/))
53
+ task = Taglob::Rake::CheckTagsTask.new :error_out do |t|
54
+ t.pattern = 'spec/tagged_files/*.rb'
55
+ t.valid_tag_source = @missing_tags_source
56
+ end
57
+ lambda {@rake.invoke_task('error_out')}.should raise_error(SystemExit)
58
+ end
59
+
60
+ it "should print out the list of invalid tags" do
61
+ $stderr.expects(:puts).with(regexp_matches(/ bar,buttz /))
62
+ $stderr.expects(:puts).with(regexp_matches(/ epic,lulz /))
63
+ task = Taglob::Rake::CheckTagsTask.new :error_out do |t|
64
+ t.pattern = 'spec/tagged_files/*.rb'
65
+ t.valid_tag_source = @missing_tags_source
66
+ end
67
+ lambda {@rake.invoke_task('error_out')}.should raise_error(SystemExit)
68
+ end
69
+
70
+ it "should not raise error if only valid tags present" do
71
+ task = Taglob::Rake::CheckTagsTask.new :no_errors do |t|
72
+ t.pattern = 'spec/tagged_files/*.rb'
73
+ t.valid_tag_source = @valid_tags_source
74
+ end
75
+ lambda {@rake.invoke_task('no_errors')}.should_not raise_error(SystemExit)
76
+ end
77
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec/spec_helper'
2
+ require 'taglob'
3
+
4
+ describe "Dir#tagor" do
5
+ it "should find all files containing either tag" do
6
+ tagged_files = Dir.tag_or('spec/tagged_files/*.rb','bar', 'lulz')
7
+ tagged_files.should_not include('spec/tagged_files/foo.rb')
8
+ tagged_files.should include('spec/tagged_files/foo_bar_buttz.rb')
9
+ tagged_files.should include('spec/tagged_files/epic_lulz.rb')
10
+ end
11
+
12
+ it "should find any file containing the tag" do
13
+ tagged_files = Dir.tag_or('spec/tagged_files/*.rb','foo')
14
+ tagged_files.should include('spec/tagged_files/foo.rb')
15
+ tagged_files.should include('spec/tagged_files/foo_bar_buttz.rb')
16
+ tagged_files.should_not include('spec/tagged_files/epic_lulz.rb')
17
+ end
18
+
19
+ it "should not select files that are not tagged with specified tags" do
20
+ tagged_files = Dir.tag_or('spec/tagged_files/*.rb','lol','rofl')
21
+ tagged_files.should be_empty
22
+ end
23
+
24
+ end
@@ -0,0 +1 @@
1
+ foo
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require 'mocha'
4
+
5
+ lib_path = File.expand_path("#{File.dirname(__FILE__)}/../lib")
6
+ $LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
7
+
8
+ Spec::Runner.configure do |config|
9
+ config.mock_with :mocha
10
+ end
11
+
12
+ module Rake
13
+ class Application
14
+ def task_names_include?(task_name)
15
+ tasks.collect{|task| task.name }.include?(task_name)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,115 @@
1
+ require 'spec/spec_helper'
2
+ require 'taglob'
3
+
4
+ describe Dir do
5
+
6
+ it "should produce a hash of files with an array of their associated tags" do
7
+ tags = Dir.tags('spec/tagged_files/*.rb')
8
+ tags.should be_a_kind_of(Hash)
9
+ tags.should_not be_empty
10
+ tags.should have(3).items
11
+ end
12
+
13
+ it "should select files containing a superset or the same set of the specified tags" do
14
+ tagged_files = Dir.taglob('spec/tagged_files/*.rb','foo,bar,buttz')
15
+ tagged_files.should be_a_kind_of(Array)
16
+ tagged_files.should_not be_empty
17
+ tagged_files.should have(1).items
18
+ tagged_files.should_not include('spec/tagged_files/foo.rb')
19
+ tagged_files.should include('spec/tagged_files/foo_bar_buttz.rb')
20
+ end
21
+
22
+ it "should not select files that are not tagged with specified tags" do
23
+ tagged_files = Dir.taglob('spec/tagged_files/*.rb','lol,rofl')
24
+ tagged_files.should be_a_kind_of(Array)
25
+ tagged_files.should be_empty
26
+ end
27
+
28
+ it "should not care where the taglob line is in the file" do
29
+ tagged_files = Dir.taglob('spec/tagged_files/*.rb','buttz')
30
+ tagged_files.should be_a_kind_of(Array)
31
+ tagged_files.should_not be_empty
32
+ tagged_files.should have(1).items
33
+ tagged_files.should include('spec/tagged_files/foo_bar_buttz.rb')
34
+ end
35
+
36
+ it "should count every taglob line" do
37
+ tagged_files = Dir.taglob('spec/tagged_files/*.rb','epic,lulz')
38
+ tagged_files.should be_a_kind_of(Array)
39
+ tagged_files.should_not be_empty
40
+ tagged_files.should have(1).items
41
+ tagged_files.should include('spec/tagged_files/epic_lulz.rb')
42
+ end
43
+
44
+ end
45
+
46
+ describe File do
47
+
48
+ it "should produce an array of tags associated with a file" do
49
+ tags = File.tags('spec/tagged_files/foo.rb')
50
+ tags.should be_a_kind_of(Array)
51
+ tags.should include('foo')
52
+ end
53
+
54
+ it "should contain foo at first element" do
55
+ tags = File.tags('spec/tagged_files/foo.rb')
56
+ tags.first.should eql('foo')
57
+ end
58
+
59
+ end
60
+
61
+ describe String do
62
+
63
+ it "should parse tags from taglob formatted line(#tags: foo,bar,buttz)" do
64
+ tags = "#tags: foo,bar,buttz".tags
65
+ tags.should be_a_kind_of(Array)
66
+ tags.should_not be_empty
67
+ tags.should have(3).items
68
+ tags.should include('foo')
69
+ tags.should include('bar')
70
+ tags.should include('buttz')
71
+ end
72
+
73
+ it "should return an empty array for a taglob formatted line with no tags" do
74
+ tags = "#tags: ".tags
75
+ tags.should be_a_kind_of(Array)
76
+ tags.should be_empty
77
+ end
78
+
79
+ it "should return an empty array for an incorrectly formatted line" do
80
+ tags = "#tags ".tags
81
+ tags.should be_a_kind_of(Array)
82
+ tags.should be_empty
83
+ tags = "tags: foo,bar,buttz".tags
84
+ tags.should be_a_kind_of(Array)
85
+ tags.should be_empty
86
+ tags = " #tags: lololo".tags
87
+ tags.should be_a_kind_of(Array)
88
+ tags.should be_empty
89
+ end
90
+
91
+ it "should allow '#tags: ...' or '# tags: ' only" do
92
+ tags = "#tags: lol,rofl".tags
93
+ tags_with_space = "# tags: lol,rofl".tags
94
+ tags.should == tags_with_space
95
+ end
96
+
97
+ it "should ignore leading and trailing spaces in tags" do
98
+ tags = "#tags: foo , bar , buttz".tags
99
+ tags.should be_a_kind_of(Array)
100
+ tags.should_not be_empty
101
+ tags.should have(3).items
102
+ tags.should include('foo')
103
+ tags.should include('bar')
104
+ tags.should include('buttz')
105
+ end
106
+
107
+ end
108
+
109
+ describe Taglob do
110
+ it "should provide invalid tags" do
111
+ invalid_tags = Taglob.invalid_tags('spec/tagged_files/*.rb',['foo'])
112
+ invalid_tags.size.should > 0
113
+ invalid_tags.each {|file,tags| tags.should_not include('foo')}
114
+ end
115
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec/spec_helper'
2
+ describe "Premade Rake Tasks" do
3
+ before :all do
4
+ @file_name ="./lib/taglob/rake/tasks.rb"
5
+ @rake = Rake::Application.new
6
+ Rake.application = @rake
7
+ end
8
+
9
+ after :all do
10
+ Rake.application = nil
11
+ end
12
+
13
+ it "should create a rake task to run test unit tests marked with tags" do
14
+ load @file_name
15
+ @rake.task_names_include?("test_tags").should be_true
16
+ end
17
+ it "should create a rake task to run test unit tests marked with tags" do
18
+ load @file_name
19
+ @rake.task_names_include?("spec_tags").should be_true
20
+ end
21
+
22
+ end
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'spec/spec_helper'
3
+ require 'taglob/rake'
4
+
5
+ describe "Test/Spec Tags Task" do
6
+
7
+ before :all do
8
+ @file_name ="./lib/taglob/rake/test_task.rb"
9
+ @rake = Rake::Application.new
10
+ Rake.application = @rake
11
+ end
12
+
13
+ after :all do
14
+ Rake.application = nil
15
+ end
16
+
17
+ it "should create a rake task to run test unit tests marked with tags" do
18
+ task = Taglob::Rake::TestTagsTask.new :test_unit
19
+ @rake.task_names_include?("test_unit").should be_true
20
+ end
21
+
22
+ it "should create a rake task to run spec tests marked with tags" do
23
+ task = Taglob::Rake::SpecTagsTask.new :spec_tests
24
+ @rake.task_names_include?("spec_tests").should be_true
25
+ end
26
+
27
+ it "should be able to run tags grouped as a OR" do
28
+ task = Taglob::Rake::TestTagsTask.new :or_test do |t|
29
+ t.pattern = 'spec/tagged_files/*.rb'
30
+ t.tags = "bar|lulz"
31
+ end
32
+ tagged_files = task.test_files
33
+ tagged_files.should_not include('spec/tagged_files/foo.rb')
34
+ tagged_files.should include('spec/tagged_files/foo_bar_buttz.rb')
35
+ tagged_files.should include('spec/tagged_files/epic_lulz.rb')
36
+ end
37
+
38
+ it "should be able to run tags grouped as a AND" do
39
+ task = Taglob::Rake::TestTagsTask.new :and_test do |t|
40
+ t.pattern = 'spec/tagged_files/*.rb'
41
+ t.tags = "foo,bar"
42
+ end
43
+ tagged_files = task.test_files
44
+ tagged_files.should_not include('spec/tagged_files/foo.rb')
45
+ tagged_files.should include('spec/tagged_files/foo_bar_buttz.rb')
46
+ tagged_files.should_not include('spec/tagged_files/epic_lulz.rb')
47
+ end
48
+ end
@@ -0,0 +1,5 @@
1
+ foo
2
+ bar
3
+ buttz
4
+ epic
5
+ lulz
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taglob
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Anderson
@@ -9,38 +9,57 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-14 00:00:00 -07:00
12
+ date: 2008-10-11 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: hoe
17
+ type: :development
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
20
21
  - - ">="
21
22
  - !ruby/object:Gem::Version
22
- version: 1.5.1
23
+ version: 1.7.0
23
24
  version:
24
25
  description: Tagging for Ruby files
25
26
  email: adamandersonis@gmail.com
26
- executables: []
27
-
27
+ executables:
28
+ - taglob
28
29
  extensions: []
29
30
 
30
31
  extra_rdoc_files:
31
32
  - History.txt
32
33
  - Manifest.txt
33
34
  - README.txt
35
+ - spec/missing_tags.txt
36
+ - spec/valid_tags.txt
34
37
  files:
35
38
  - History.txt
36
39
  - Manifest.txt
37
40
  - README.txt
38
41
  - Rakefile
42
+ - bin/taglob
39
43
  - lib/taglob.rb
40
- - spec/spec_taglob.rb
44
+ - lib/taglob/extensions.rb
45
+ - lib/taglob/extensions/dir.rb
46
+ - lib/taglob/extensions/file.rb
47
+ - lib/taglob/extensions/string.rb
48
+ - lib/taglob/rake.rb
49
+ - lib/taglob/rake/check_tags_task.rb
50
+ - lib/taglob/rake/tasks.rb
51
+ - lib/taglob/rake/test_tags_task.rb
52
+ - spec/check_tags_task_spec.rb
53
+ - spec/dir_tagor_spec.rb
54
+ - spec/missing_tags.txt
55
+ - spec/spec_helper.rb
56
+ - spec/tagged_files/epic_lulz.rb
41
57
  - spec/tagged_files/foo.rb
42
58
  - spec/tagged_files/foo_bar_buttz.rb
43
- - spec/tagged_files/epic_lulz.rb
59
+ - spec/taglob_spec.rb
60
+ - spec/tasks_spec.rb
61
+ - spec/test_tags_task_spec.rb
62
+ - spec/valid_tags.txt
44
63
  has_rdoc: true
45
64
  homepage: http://taglob.rubyforge.org
46
65
  post_install_message:
@@ -64,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
83
  requirements: []
65
84
 
66
85
  rubyforge_project: taglob
67
- rubygems_version: 1.1.0
86
+ rubygems_version: 1.2.0
68
87
  signing_key:
69
88
  specification_version: 2
70
89
  summary: Dir.taglob selects tagged Ruby files
data/spec/spec_taglob.rb DELETED
@@ -1,70 +0,0 @@
1
- require 'lib/taglob'
2
-
3
- describe "Taglob#parse_tags" do
4
-
5
- #taglob formatted line is as follows:
6
- #tags: foo,bar,lulz,epic
7
-
8
- it "should parse tags from taglob formatted line(#tags: foo,bar,buttz)" do
9
- tags = Dir.parse_tags("#tags: foo,bar,buttz")
10
- tags.should be_a_kind_of(Array)
11
- tags.should_not be_empty
12
- tags.should have(3).items
13
- tags.should include('foo')
14
- tags.should include('bar')
15
- tags.should include('buttz')
16
- end
17
-
18
- it "should return an empty array for a taglob formatted line with no tags" do
19
- tags = Dir.parse_tags("#tags: ")
20
- tags.should be_a_kind_of(Array)
21
- tags.should be_empty
22
- end
23
-
24
- it "should return an empty array for an incorrectly formatted line" do
25
- tags = Dir.parse_tags("#tags ")
26
- tags.should be_a_kind_of(Array)
27
- tags.should be_empty
28
- tags = Dir.parse_tags("tags: foo,bar,buttz")
29
- tags.should be_a_kind_of(Array)
30
- tags.should be_empty
31
- tags = Dir.parse_tags(" #tags: lololo")
32
- tags.should be_a_kind_of(Array)
33
- tags.should be_empty
34
- end
35
-
36
- end
37
-
38
- describe "Taglob#taglob" do
39
-
40
- it "should select files tagged with specified tags" do
41
- tagged_files = Dir.taglob('spec/tagged_files/*.rb','foo','bar','buttz')
42
- tagged_files.should be_a_kind_of(Array)
43
- tagged_files.should_not be_empty
44
- tagged_files.should have(2).items
45
- tagged_files.should include('spec/tagged_files/foo.rb')
46
- tagged_files.should include('spec/tagged_files/foo_bar_buttz.rb')
47
- end
48
-
49
- it "should not select files that are not tagged with specified tags" do
50
- tagged_files = Dir.taglob('spec/tagged_files/*.rb','lol','rofl')
51
- tagged_files.should be_a_kind_of(Array)
52
- tagged_files.should be_empty
53
- end
54
-
55
- it "should not care where the taglob line is in the file" do
56
- tagged_files = Dir.taglob('spec/tagged_files/*.rb','buttz')
57
- tagged_files.should be_a_kind_of(Array)
58
- tagged_files.should_not be_empty
59
- tagged_files.should have(1).items
60
- tagged_files.should include('spec/tagged_files/foo_bar_buttz.rb')
61
- end
62
-
63
- it "should count every taglob line" do
64
- tagged_files = Dir.taglob('spec/tagged_files/*.rb','epic','lulz')
65
- tagged_files.should be_a_kind_of(Array)
66
- tagged_files.should_not be_empty
67
- tagged_files.should have(1).items
68
- tagged_files.should include('spec/tagged_files/epic_lulz.rb')
69
- end
70
- end