rake-version 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +5 -0
- data/VERSION +1 -1
- data/lib/rake-version.rb +4 -1
- data/lib/rake-version/config.rb +32 -0
- data/lib/rake-version/copier.rb +73 -0
- data/lib/rake-version/manager.rb +17 -6
- data/lib/rake-version/tasks.rb +4 -1
- data/rake-version.gemspec +9 -2
- data/spec/config_spec.rb +68 -0
- data/spec/context_spec.rb +0 -2
- data/spec/copier_spec.rb +166 -0
- data/spec/manager_spec.rb +25 -0
- data/spec/tasks_spec.rb +1 -0
- metadata +34 -19
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -13,6 +13,7 @@ GEM
|
|
13
13
|
rdoc
|
14
14
|
json (1.6.5)
|
15
15
|
multi_json (1.0.4)
|
16
|
+
paint (0.8.4)
|
16
17
|
rake (0.9.2.2)
|
17
18
|
rdiscount (1.6.8)
|
18
19
|
rdoc (3.12)
|
@@ -30,6 +31,9 @@ GEM
|
|
30
31
|
multi_json (~> 1.0.3)
|
31
32
|
simplecov-html (~> 0.5.3)
|
32
33
|
simplecov-html (0.5.3)
|
34
|
+
upoj-rb (0.0.5)
|
35
|
+
active_support (>= 2)
|
36
|
+
paint
|
33
37
|
yard (0.7.5)
|
34
38
|
|
35
39
|
PLATFORMS
|
@@ -44,4 +48,5 @@ DEPENDENCIES
|
|
44
48
|
rspec (~> 2.8.0)
|
45
49
|
shoulda (~> 2.11.3)
|
46
50
|
simplecov (~> 0.5.4)
|
51
|
+
upoj-rb (~> 0.0.5)
|
47
52
|
yard (~> 0.7.5)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/rake-version.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
|
2
2
|
require 'rake/tasklib'
|
3
|
+
require 'active_support/core_ext/hash'
|
3
4
|
|
4
5
|
module RakeVersion
|
5
6
|
VERSION = File.open(File.join(File.dirname(__FILE__), '..', 'VERSION'), 'r').read
|
@@ -11,6 +12,8 @@ module RakeVersion
|
|
11
12
|
class BadContext < BadArgument; end
|
12
13
|
class BadVersion < BadArgument; end
|
13
14
|
class BadBumpType < BadArgument; end
|
15
|
+
class BadFilePattern < BadArgument; end
|
16
|
+
class BadVersionPattern < BadArgument; end
|
14
17
|
|
15
18
|
def self.check_context o
|
16
19
|
self.check_type o, RakeVersion::Context, BadContext
|
@@ -27,4 +30,4 @@ module RakeVersion
|
|
27
30
|
end
|
28
31
|
end
|
29
32
|
|
30
|
-
%w( context manager tasks version ).each{ |dep| require File.join(File.dirname(__FILE__), 'rake-version', dep) }
|
33
|
+
%w( config context copier manager tasks version ).each{ |dep| require File.join(File.dirname(__FILE__), 'rake-version', dep) }
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
module RakeVersion
|
4
|
+
|
5
|
+
class Config < OpenStruct
|
6
|
+
|
7
|
+
attr_reader :extension
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
super
|
11
|
+
@copiers = []
|
12
|
+
@extension = 'rb'
|
13
|
+
end
|
14
|
+
|
15
|
+
def copy *args
|
16
|
+
options = args.extract_options!
|
17
|
+
args.unshift "src/**/*.#{@extension}" if args.blank?
|
18
|
+
args << options if options.present?
|
19
|
+
@copiers << Copier.new(*args)
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def copiers
|
24
|
+
Array.new @copiers
|
25
|
+
end
|
26
|
+
|
27
|
+
def extension= extension
|
28
|
+
raise "Expected extension to be alphanumerical, got #{extension.inspect}." unless extension.respond_to?(:to_s) and extension.to_s.match(/^[a-z0-9]+$/i)
|
29
|
+
@extension = extension.to_s
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'find'
|
2
|
+
|
3
|
+
module RakeVersion
|
4
|
+
|
5
|
+
class Copier
|
6
|
+
|
7
|
+
def initialize *args
|
8
|
+
options = HashWithIndifferentAccess.new args.extract_options!
|
9
|
+
|
10
|
+
@file_patterns = args.collect{ |arg| check_file_pattern arg }
|
11
|
+
@version_pattern = check_version_pattern(options[:version]) || /\d+\.\d+\.\d+/
|
12
|
+
@replace_all = !!options[:all]
|
13
|
+
end
|
14
|
+
|
15
|
+
def copy version, context
|
16
|
+
find_all_files(context).each{ |f| copy_version f, version }
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def check_file_pattern pattern
|
22
|
+
unless [ String, Regexp ].any?{ |klass| pattern.kind_of? klass }
|
23
|
+
raise BadFilePattern, "Expected file pattern to be a glob string or regexp, got #{pattern.class.name}."
|
24
|
+
end
|
25
|
+
pattern
|
26
|
+
end
|
27
|
+
|
28
|
+
def check_version_pattern pattern
|
29
|
+
unless pattern.nil? or pattern.kind_of? Regexp
|
30
|
+
raise BadVersionPattern, "Expected version option to be a regexp, got #{pattern.class.name}."
|
31
|
+
end
|
32
|
+
pattern
|
33
|
+
end
|
34
|
+
|
35
|
+
def copy_version file, version
|
36
|
+
File.open(file, 'r+') do |f|
|
37
|
+
contents = f.read
|
38
|
+
return unless match? contents
|
39
|
+
f.rewind
|
40
|
+
f.write process(contents, version)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def match? contents
|
45
|
+
contents.match @version_pattern
|
46
|
+
end
|
47
|
+
|
48
|
+
def process contents, version
|
49
|
+
if @replace_all
|
50
|
+
contents.gsub(@version_pattern, version.to_s)
|
51
|
+
else
|
52
|
+
contents.sub(@version_pattern, version.to_s)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def find_all_files context
|
57
|
+
@file_patterns.collect{ |p| find_files p, context }.flatten
|
58
|
+
end
|
59
|
+
|
60
|
+
def find_files pattern, context
|
61
|
+
if pattern.kind_of? String
|
62
|
+
Dir.chdir context.root
|
63
|
+
Dir.glob(pattern).select{ |f| File.file? f }
|
64
|
+
elsif pattern.kind_of? Regexp
|
65
|
+
files = []
|
66
|
+
Find.find(context.root) do |path|
|
67
|
+
files << path if File.file?(path) and path.match(pattern)
|
68
|
+
end
|
69
|
+
files
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/rake-version/manager.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
|
2
2
|
module RakeVersion
|
3
3
|
|
4
|
-
attr_accessor :namespace
|
5
|
-
attr_accessor :root
|
6
|
-
attr_accessor :version_filename
|
7
|
-
|
8
4
|
class Manager
|
9
5
|
|
6
|
+
def initialize
|
7
|
+
@copiers = []
|
8
|
+
end
|
9
|
+
|
10
10
|
def version
|
11
11
|
check_context
|
12
12
|
RakeVersion::Version.new.from_s read_version
|
@@ -14,12 +14,17 @@ module RakeVersion
|
|
14
14
|
|
15
15
|
def set version_string
|
16
16
|
check_context
|
17
|
-
save
|
17
|
+
copy save(RakeVersion::Version.new.from_s(version_string))
|
18
18
|
end
|
19
19
|
|
20
20
|
def bump type
|
21
21
|
check_context
|
22
|
-
save
|
22
|
+
copy save(version.bump(type))
|
23
|
+
end
|
24
|
+
|
25
|
+
def config= config
|
26
|
+
@copiers = config.copiers
|
27
|
+
self
|
23
28
|
end
|
24
29
|
|
25
30
|
def with_context context, &block
|
@@ -32,6 +37,12 @@ module RakeVersion
|
|
32
37
|
|
33
38
|
private
|
34
39
|
|
40
|
+
def copy version
|
41
|
+
check_context
|
42
|
+
@copiers.each{ |c| c.copy version, @context }
|
43
|
+
version
|
44
|
+
end
|
45
|
+
|
35
46
|
def check_context
|
36
47
|
raise MissingContext, "A context must be given with :with_context." unless @context
|
37
48
|
end
|
data/lib/rake-version/tasks.rb
CHANGED
@@ -5,7 +5,9 @@ module RakeVersion
|
|
5
5
|
|
6
6
|
def initialize &block
|
7
7
|
@manager = RakeVersion::Manager.new
|
8
|
-
|
8
|
+
@config = RakeVersion::Config.new
|
9
|
+
yield @config if block_given?
|
10
|
+
@manager.config = @config
|
9
11
|
define
|
10
12
|
end
|
11
13
|
|
@@ -25,6 +27,7 @@ module RakeVersion
|
|
25
27
|
namespace :bump do
|
26
28
|
|
27
29
|
[ :major, :minor, :patch ].each do |type|
|
30
|
+
desc "Bump the #{type} version"
|
28
31
|
task type do |t|
|
29
32
|
puts @manager.bump(type).to_s
|
30
33
|
end
|
data/rake-version.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "rake-version"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["AlphaHydrae"]
|
12
|
-
s.date = "2012-02-
|
12
|
+
s.date = "2012-02-25"
|
13
13
|
s.description = "Rake tasks for version management."
|
14
14
|
s.email = "hydrae.alpha@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -27,12 +27,16 @@ Gem::Specification.new do |s|
|
|
27
27
|
"Rakefile",
|
28
28
|
"VERSION",
|
29
29
|
"lib/rake-version.rb",
|
30
|
+
"lib/rake-version/config.rb",
|
30
31
|
"lib/rake-version/context.rb",
|
32
|
+
"lib/rake-version/copier.rb",
|
31
33
|
"lib/rake-version/manager.rb",
|
32
34
|
"lib/rake-version/tasks.rb",
|
33
35
|
"lib/rake-version/version.rb",
|
34
36
|
"rake-version.gemspec",
|
37
|
+
"spec/config_spec.rb",
|
35
38
|
"spec/context_spec.rb",
|
39
|
+
"spec/copier_spec.rb",
|
36
40
|
"spec/helper.rb",
|
37
41
|
"spec/manager_spec.rb",
|
38
42
|
"spec/tasks_spec.rb",
|
@@ -49,6 +53,7 @@ Gem::Specification.new do |s|
|
|
49
53
|
|
50
54
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
51
55
|
s.add_runtime_dependency(%q<rake>, ["~> 0.9.2"])
|
56
|
+
s.add_runtime_dependency(%q<upoj-rb>, ["~> 0.0.5"])
|
52
57
|
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
53
58
|
s.add_development_dependency(%q<shoulda>, ["~> 2.11.3"])
|
54
59
|
s.add_development_dependency(%q<bundler>, [">= 0"])
|
@@ -58,6 +63,7 @@ Gem::Specification.new do |s|
|
|
58
63
|
s.add_development_dependency(%q<rdiscount>, ["~> 1.6.8"])
|
59
64
|
else
|
60
65
|
s.add_dependency(%q<rake>, ["~> 0.9.2"])
|
66
|
+
s.add_dependency(%q<upoj-rb>, ["~> 0.0.5"])
|
61
67
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
62
68
|
s.add_dependency(%q<shoulda>, ["~> 2.11.3"])
|
63
69
|
s.add_dependency(%q<bundler>, [">= 0"])
|
@@ -68,6 +74,7 @@ Gem::Specification.new do |s|
|
|
68
74
|
end
|
69
75
|
else
|
70
76
|
s.add_dependency(%q<rake>, ["~> 0.9.2"])
|
77
|
+
s.add_dependency(%q<upoj-rb>, ["~> 0.0.5"])
|
71
78
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
72
79
|
s.add_dependency(%q<shoulda>, ["~> 2.11.3"])
|
73
80
|
s.add_dependency(%q<bundler>, [">= 0"])
|
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe RakeVersion::Config do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@config = RakeVersion::Config.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should be an open structure" do
|
10
|
+
lambda{ @config.fubar = true }.should_not raise_error
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'Copiers' do
|
14
|
+
|
15
|
+
it "should not have any copiers by default" do
|
16
|
+
@config.copiers.should be_empty
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should correctly create copiers" do
|
20
|
+
copiers = [
|
21
|
+
[],
|
22
|
+
[ 'src/**/*.js' ],
|
23
|
+
[ /src\/.*\.sh/ ],
|
24
|
+
[ 'src/example.js', 'src/example.rb' ],
|
25
|
+
[ 'src/**/*.rb', :all => true ]
|
26
|
+
]
|
27
|
+
copiers.each do |args|
|
28
|
+
lambda{ @config.copy *args }.should_not raise_error
|
29
|
+
end
|
30
|
+
@config.copiers.length.should == copiers.length
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should create copiers with a ruby extension glob by default" do
|
34
|
+
RakeVersion::Copier.should_receive(:new).with('src/**/*.rb')
|
35
|
+
@config.copy
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should return itself when creating a copier" do
|
39
|
+
@config.copy.should === @config
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should return a copy of its copiers array" do
|
43
|
+
@config.copy
|
44
|
+
@config.copiers.clear
|
45
|
+
@config.copiers.length.should == 1
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'Extension' do
|
50
|
+
|
51
|
+
it "should have the ruby extension by default" do
|
52
|
+
@config.extension.should == 'rb'
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should accept alphanumerical extensions" do
|
56
|
+
[ :rb, 'js', :sh, 'py', double('extension', :to_s => 'java') ].each do |ext|
|
57
|
+
lambda{ @config.extension = ext }.should_not raise_error
|
58
|
+
@config.extension.should == ext.to_s
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should not accept non-alphanumerical extensions" do
|
63
|
+
[ nil, '.', :_, [], {}, double('fubar') ].each do |invalid|
|
64
|
+
lambda{ @config.extension = invalid }.should raise_error(StandardError)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/spec/context_spec.rb
CHANGED
data/spec/copier_spec.rb
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe RakeVersion::Copier do
|
4
|
+
|
5
|
+
it "should require no arguments" do
|
6
|
+
lambda{ RakeVersion::Copier.new }.should_not raise_error
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should accept glob strings and regexps as arguments" do
|
10
|
+
[
|
11
|
+
[ 'src/**/*.js' ],
|
12
|
+
[ /src\/.*\.sh/ ],
|
13
|
+
[ 'src/example.js', 'src/example.rb' ],
|
14
|
+
[ 'src/example.sh', /src\/.*\.java/, 'src/**/*.py' ]
|
15
|
+
].each do |args|
|
16
|
+
lambda{ RakeVersion::Copier.new *args }.should_not raise_error
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should only accept glob strings and regexps as arguments" do
|
21
|
+
# we do not test a hash, as it is valid to pass an options hash
|
22
|
+
[ nil, true, false, [], Object.new, :symbol ].each do |invalid|
|
23
|
+
lambda{ RakeVersion::Copier.new invalid }.should raise_error(RakeVersion::BadFilePattern)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should take options" do
|
28
|
+
lambda{ RakeVersion::Copier.new :option1 => true, :option2 => false }.should_not raise_error
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should accept a regexp as the version option" do
|
32
|
+
lambda{ RakeVersion::Copier.new :version => /version/ }.should_not raise_error
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should only accept a regexp as the version option" do
|
36
|
+
[ true, false, [], {}, Object.new, :symbol ].each do |invalid|
|
37
|
+
lambda{ RakeVersion::Copier.new :version => invalid }.should raise_error(RakeVersion::BadVersionPattern)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'Copying' do
|
42
|
+
COPIER_SAMPLE_ROOT = '/tmp'
|
43
|
+
COPIER_SAMPLE_VERSION = '7.8.9'
|
44
|
+
COPIER_SAMPLE_FILES = {
|
45
|
+
'/tmp/src/example.rb' => "#\n# example v1.2.3\n#\n\nputs 'Hello World!'",
|
46
|
+
'/tmp/src/example.js' => "/*\n * example v2.3.4\n */\n\nconsole.log('Hello World!');\n// This is example v2.3.4",
|
47
|
+
'/tmp/src/script/sub-example.sh' => "#\n# example v3.4.5\n#\n\necho 'Hello World!'",
|
48
|
+
'/tmp/src/script/sub-example.rb' => "#\n# example v4.5.6\n#\n\nputs 'Hello World!'\n# This is example v4.5.6",
|
49
|
+
'/tmp/lib/example.java' => "/**\n * example v5.6.7\n */\n\n// not yet implemented",
|
50
|
+
'/tmp/README' => "not\na\nsource\nfile"
|
51
|
+
}
|
52
|
+
|
53
|
+
before :each do
|
54
|
+
|
55
|
+
@version = double('version', :to_s => COPIER_SAMPLE_VERSION)
|
56
|
+
@context = double('context', :root => COPIER_SAMPLE_ROOT)
|
57
|
+
|
58
|
+
File.stub(:file?) do |file|
|
59
|
+
!!COPIER_SAMPLE_FILES[file]
|
60
|
+
end
|
61
|
+
|
62
|
+
stub = Find.stub(:find)
|
63
|
+
COPIER_SAMPLE_FILES.keys.each do |k|
|
64
|
+
stub.and_yield k
|
65
|
+
end
|
66
|
+
|
67
|
+
Dir.stub(:chdir)
|
68
|
+
Dir.stub(:glob) do |pattern|
|
69
|
+
COPIER_SAMPLE_FILES.keys.select do |k|
|
70
|
+
m = pattern.match /^\*\*\/\*\.([a-z]+)$/
|
71
|
+
m and k.match(Regexp.new("\\.#{m[1]}$"))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def mock_file file
|
77
|
+
double("file #{file}", :read => COPIER_SAMPLE_FILES[file].try(:dup), :rewind => nil, :write => nil)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should copy the version to ruby files with a glob string" do
|
81
|
+
|
82
|
+
filename1, filename2 = '/tmp/src/example.rb', '/tmp/src/script/sub-example.rb'
|
83
|
+
file1, file2 = mock_file(filename1), mock_file(filename2)
|
84
|
+
File.stub(:open).and_yield(file1).and_yield(file2)
|
85
|
+
|
86
|
+
copier = RakeVersion::Copier.new '**/*.rb'
|
87
|
+
|
88
|
+
@version.should_receive(:to_s)
|
89
|
+
@context.should_receive(:root)
|
90
|
+
File.should_receive(:open).with(filename1, 'r+')
|
91
|
+
File.should_receive(:open).with(filename2, 'r+')
|
92
|
+
file1.should_receive(:write).with(COPIER_SAMPLE_FILES[filename1].sub(/1\.2\.3/, '7.8.9'))
|
93
|
+
file2.should_receive(:write).with(COPIER_SAMPLE_FILES[filename2].sub(/4\.5\.6/, '7.8.9'))
|
94
|
+
|
95
|
+
copier.copy @version, @context
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should copy the version to javascript files with a regexp" do
|
99
|
+
|
100
|
+
filename = '/tmp/src/example.js'
|
101
|
+
file = mock_file filename
|
102
|
+
File.stub(:open).and_yield(file)
|
103
|
+
|
104
|
+
copier = RakeVersion::Copier.new /\.js$/
|
105
|
+
|
106
|
+
@version.should_receive(:to_s)
|
107
|
+
@context.should_receive(:root)
|
108
|
+
File.should_receive(:open).with(filename, 'r+')
|
109
|
+
file.should_receive(:write).with(COPIER_SAMPLE_FILES[filename].sub(/2\.3\.4/, '7.8.9'))
|
110
|
+
|
111
|
+
copier.copy @version, @context
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should copy the version to files identified by several glob strings and regexps" do
|
115
|
+
|
116
|
+
filename1, filename2 = '/tmp/src/script/sub-example.sh', '/tmp/lib/example.java'
|
117
|
+
file1, file2 = mock_file(filename1), mock_file(filename2)
|
118
|
+
File.stub(:open).and_yield(file1).and_yield(file2)
|
119
|
+
|
120
|
+
copier = RakeVersion::Copier.new '**/*.sh', /lib/
|
121
|
+
|
122
|
+
@version.should_receive(:to_s)
|
123
|
+
@context.should_receive(:root)
|
124
|
+
File.should_receive(:open).with(filename1, 'r+')
|
125
|
+
File.should_receive(:open).with(filename2, 'r+')
|
126
|
+
file1.should_receive(:write).with(COPIER_SAMPLE_FILES[filename1].sub(/3\.4\.5/, '7.8.9'))
|
127
|
+
file2.should_receive(:write).with(COPIER_SAMPLE_FILES[filename2].sub(/5\.6\.7/, '7.8.9'))
|
128
|
+
|
129
|
+
copier.copy @version, @context
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should not modify files that do not match the version pattern" do
|
133
|
+
|
134
|
+
filename = '/tmp/README'
|
135
|
+
file = mock_file filename
|
136
|
+
File.stub(:open).and_yield(file)
|
137
|
+
|
138
|
+
copier = RakeVersion::Copier.new /README/
|
139
|
+
|
140
|
+
@version.should_not_receive(:to_s)
|
141
|
+
@context.should_receive(:root)
|
142
|
+
File.should_receive(:open).with(filename, 'r+')
|
143
|
+
file.should_not_receive(:write)
|
144
|
+
|
145
|
+
copier.copy @version, @context
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should replace all occurences of the version pattern if specified" do
|
149
|
+
|
150
|
+
filename1, filename2 = '/tmp/src/example.js', '/tmp/src/script/sub-example.rb'
|
151
|
+
file1, file2 = mock_file(filename1), mock_file(filename2)
|
152
|
+
File.stub(:open).and_yield(file1).and_yield(file2)
|
153
|
+
|
154
|
+
copier = RakeVersion::Copier.new /\.js$/, /sub.*\.rb$/, :all => true
|
155
|
+
|
156
|
+
@version.should_receive(:to_s)
|
157
|
+
@context.should_receive(:root)
|
158
|
+
File.should_receive(:open).with(filename1, 'r+')
|
159
|
+
File.should_receive(:open).with(filename2, 'r+')
|
160
|
+
file1.should_receive(:write).with(COPIER_SAMPLE_FILES[filename1].gsub(/2\.3\.4/, '7.8.9'))
|
161
|
+
file2.should_receive(:write).with(COPIER_SAMPLE_FILES[filename2].gsub(/4\.5\.6/, '7.8.9'))
|
162
|
+
|
163
|
+
copier.copy @version, @context
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
data/spec/manager_spec.rb
CHANGED
@@ -18,6 +18,9 @@ describe RakeVersion::Manager do
|
|
18
18
|
@version.stub(:to_s){ MANAGER_SAMPLE_VERSION }
|
19
19
|
@version.stub(:bump){ @version }
|
20
20
|
@version.stub(:kind_of?){ |type| type == RakeVersion::Version }
|
21
|
+
|
22
|
+
@copier = double('copier', :copy => nil)
|
23
|
+
@config = double('config', :copiers => [ @copier ])
|
21
24
|
end
|
22
25
|
|
23
26
|
def with_context &block
|
@@ -89,4 +92,26 @@ describe RakeVersion::Manager do
|
|
89
92
|
lambda{ @manager.with_context invalid }.should raise_error(RakeVersion::BadContext)
|
90
93
|
end
|
91
94
|
end
|
95
|
+
|
96
|
+
describe 'Copying' do
|
97
|
+
|
98
|
+
it "should ask the given config for its copiers" do
|
99
|
+
@config.should_receive :copiers
|
100
|
+
with_context{ |m| m.config = @config }
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should ask given copiers to copy the version to sources when setting the version" do
|
104
|
+
@manager.config = @config
|
105
|
+
@copier.should_receive(:copy).with(kind_of(RakeVersion::Version), @context)
|
106
|
+
with_context{ |m| m.set '1.2.3' }
|
107
|
+
end
|
108
|
+
|
109
|
+
[ :major, :minor, :patch ].each do |type|
|
110
|
+
it "should ask given copiers to copy the version to sources when bumping the #{type} version" do
|
111
|
+
@manager.config = @config
|
112
|
+
@copier.should_receive(:copy).with(kind_of(RakeVersion::Version), @context)
|
113
|
+
with_context{ |m| m.bump type }
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
92
117
|
end
|
data/spec/tasks_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rake-version
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-25 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &2153972560 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,21 @@ dependencies:
|
|
21
21
|
version: 0.9.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2153972560
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: upoj-rb
|
27
|
+
requirement: &2153971980 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.0.5
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2153971980
|
25
36
|
- !ruby/object:Gem::Dependency
|
26
37
|
name: rspec
|
27
|
-
requirement: &
|
38
|
+
requirement: &2153971380 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
40
|
requirements:
|
30
41
|
- - ~>
|
@@ -32,10 +43,10 @@ dependencies:
|
|
32
43
|
version: 2.8.0
|
33
44
|
type: :development
|
34
45
|
prerelease: false
|
35
|
-
version_requirements: *
|
46
|
+
version_requirements: *2153971380
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: shoulda
|
38
|
-
requirement: &
|
49
|
+
requirement: &2153970800 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ~>
|
@@ -43,10 +54,10 @@ dependencies:
|
|
43
54
|
version: 2.11.3
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *2153970800
|
47
58
|
- !ruby/object:Gem::Dependency
|
48
59
|
name: bundler
|
49
|
-
requirement: &
|
60
|
+
requirement: &2153970200 !ruby/object:Gem::Requirement
|
50
61
|
none: false
|
51
62
|
requirements:
|
52
63
|
- - ! '>='
|
@@ -54,10 +65,10 @@ dependencies:
|
|
54
65
|
version: '0'
|
55
66
|
type: :development
|
56
67
|
prerelease: false
|
57
|
-
version_requirements: *
|
68
|
+
version_requirements: *2153970200
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: jeweler
|
60
|
-
requirement: &
|
71
|
+
requirement: &2153969600 !ruby/object:Gem::Requirement
|
61
72
|
none: false
|
62
73
|
requirements:
|
63
74
|
- - ~>
|
@@ -65,10 +76,10 @@ dependencies:
|
|
65
76
|
version: 1.8.3
|
66
77
|
type: :development
|
67
78
|
prerelease: false
|
68
|
-
version_requirements: *
|
79
|
+
version_requirements: *2153969600
|
69
80
|
- !ruby/object:Gem::Dependency
|
70
81
|
name: simplecov
|
71
|
-
requirement: &
|
82
|
+
requirement: &2153969000 !ruby/object:Gem::Requirement
|
72
83
|
none: false
|
73
84
|
requirements:
|
74
85
|
- - ~>
|
@@ -76,10 +87,10 @@ dependencies:
|
|
76
87
|
version: 0.5.4
|
77
88
|
type: :development
|
78
89
|
prerelease: false
|
79
|
-
version_requirements: *
|
90
|
+
version_requirements: *2153969000
|
80
91
|
- !ruby/object:Gem::Dependency
|
81
92
|
name: yard
|
82
|
-
requirement: &
|
93
|
+
requirement: &2153968400 !ruby/object:Gem::Requirement
|
83
94
|
none: false
|
84
95
|
requirements:
|
85
96
|
- - ~>
|
@@ -87,10 +98,10 @@ dependencies:
|
|
87
98
|
version: 0.7.5
|
88
99
|
type: :development
|
89
100
|
prerelease: false
|
90
|
-
version_requirements: *
|
101
|
+
version_requirements: *2153968400
|
91
102
|
- !ruby/object:Gem::Dependency
|
92
103
|
name: rdiscount
|
93
|
-
requirement: &
|
104
|
+
requirement: &2153967800 !ruby/object:Gem::Requirement
|
94
105
|
none: false
|
95
106
|
requirements:
|
96
107
|
- - ~>
|
@@ -98,7 +109,7 @@ dependencies:
|
|
98
109
|
version: 1.6.8
|
99
110
|
type: :development
|
100
111
|
prerelease: false
|
101
|
-
version_requirements: *
|
112
|
+
version_requirements: *2153967800
|
102
113
|
description: Rake tasks for version management.
|
103
114
|
email: hydrae.alpha@gmail.com
|
104
115
|
executables: []
|
@@ -117,12 +128,16 @@ files:
|
|
117
128
|
- Rakefile
|
118
129
|
- VERSION
|
119
130
|
- lib/rake-version.rb
|
131
|
+
- lib/rake-version/config.rb
|
120
132
|
- lib/rake-version/context.rb
|
133
|
+
- lib/rake-version/copier.rb
|
121
134
|
- lib/rake-version/manager.rb
|
122
135
|
- lib/rake-version/tasks.rb
|
123
136
|
- lib/rake-version/version.rb
|
124
137
|
- rake-version.gemspec
|
138
|
+
- spec/config_spec.rb
|
125
139
|
- spec/context_spec.rb
|
140
|
+
- spec/copier_spec.rb
|
126
141
|
- spec/helper.rb
|
127
142
|
- spec/manager_spec.rb
|
128
143
|
- spec/tasks_spec.rb
|
@@ -142,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
142
157
|
version: '0'
|
143
158
|
segments:
|
144
159
|
- 0
|
145
|
-
hash:
|
160
|
+
hash: 1720608567818456013
|
146
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
162
|
none: false
|
148
163
|
requirements:
|