guard-phpspec 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ module Guard
2
+ VERSION = "0.0.2"
3
+
4
+ module Version
5
+ MAJOR = Integer(VERSION.split('.')[0])
6
+ MINOR = Integer(VERSION.split('.')[1])
7
+ PATCH = Integer(VERSION.split('.')[2])
8
+
9
+ def self.to_a
10
+ [MAJOR, MINOR, PATCH]
11
+ end
12
+
13
+ def self.to_s
14
+ VERSION
15
+ end
16
+ end
17
+
18
+ # Guard::PHPSpecVersion used in gem spec
19
+ module PHPSpecVersion
20
+ VERSION = Version.to_s
21
+ end
22
+ end
@@ -0,0 +1,271 @@
1
+ # vim: syntax=ruby
2
+ require 'rake/clean'
3
+ #------------------------------------------------------------------------------
4
+ # If you want to Develop on this project just run 'rake develop' and you'll
5
+ # have all you need to get going. If you want to use bundler for development,
6
+ # then run 'rake develop:using_bundler'
7
+ #------------------------------------------------------------------------------
8
+ namespace :develop do
9
+
10
+ # Install all the development and runtime dependencies of this gem using the
11
+ # gemspec.
12
+ task :default do
13
+ require 'rubygems/dependency_installer'
14
+ installer = Gem::DependencyInstaller.new
15
+
16
+ This.set_coverage_gem
17
+
18
+ puts "Installing gem depedencies needed for development"
19
+ This.platform_gemspec.dependencies.each do |dep|
20
+ if dep.matching_specs.empty? then
21
+ puts "Installing : #{dep}"
22
+ installer.install dep
23
+ else
24
+ puts "Skipping : #{dep} -> already installed #{dep.matching_specs.first.full_name}"
25
+ end
26
+ end
27
+ puts "\n\nNow run 'rake test'"
28
+ end
29
+
30
+ # Create a Gemfile that just references the gemspec
31
+ file 'Gemfile' => :gemspec do
32
+ File.open( "Gemfile", "w+" ) do |f|
33
+ f.puts 'source :rubygems'
34
+ f.puts 'gemspec'
35
+ end
36
+ end
37
+
38
+ desc "Create a bundler Gemfile"
39
+ task :using_bundler => 'Gemfile' do
40
+ puts "Now you can 'bundle'"
41
+ end
42
+
43
+ # Gemfiles are build artifacts
44
+ CLOBBER << FileList['Gemfile*']
45
+ end
46
+ desc "Boostrap development"
47
+ task :develop => "develop:default"
48
+
49
+ #------------------------------------------------------------------------------
50
+ # Minitest - standard TestTask
51
+ #------------------------------------------------------------------------------
52
+ begin
53
+ require 'rake/testtask'
54
+ Rake::TestTask.new( :test ) do |t|
55
+ t.ruby_opts = %w[ -w -rubygems ]
56
+ t.libs = %w[ lib spec ]
57
+ t.pattern = "spec/**/*_spec.rb"
58
+ end
59
+
60
+ task :test_requirements
61
+ task :test => :test_requirements
62
+ task :default => :test
63
+ rescue LoadError
64
+ This.task_warning( 'test' )
65
+ end
66
+
67
+ #------------------------------------------------------------------------------
68
+ # RDoc - standard rdoc rake task, although we must make sure to use a more
69
+ # recent version of rdoc since it is the one that has 'tomdoc' markup
70
+ #------------------------------------------------------------------------------
71
+ begin
72
+ gem 'rdoc' # otherwise we get the wrong task from stdlib
73
+ require 'rdoc/task'
74
+ RDoc::Task.new do |t|
75
+ t.markup = 'tomdoc'
76
+ t.rdoc_dir = 'doc'
77
+ t.main = 'README.md'
78
+ t.title = "#{This.name} #{This.version}"
79
+ t.rdoc_files.include( FileList['*.{rdoc,md,txt}'], FileList['ext/**/*.c'],
80
+ FileList['lib/**/*.rb'] )
81
+ end
82
+ rescue LoadError => le
83
+ This.task_warning( 'rdoc' )
84
+ end
85
+
86
+ #------------------------------------------------------------------------------
87
+ # Coverage - optional code coverage, rcov for 1.8 and simplecov for 1.9, so
88
+ # for the moment only rcov is listed.
89
+ #------------------------------------------------------------------------------
90
+ if RUBY_VERSION < "1.9.0"
91
+ begin
92
+ require 'rcov/rcovtask'
93
+ Rcov::RcovTask.new( 'coverage' ) do |t|
94
+ t.libs << 'spec'
95
+ t.pattern = 'spec/**/*_spec.rb'
96
+ t.verbose = true
97
+ t.rcov_opts << "-x ^/" # remove all the global files
98
+ t.rcov_opts << "--sort coverage" # so we see the worst files at the top
99
+ end
100
+ rescue LoadError
101
+ This.task_warning( 'rcov' )
102
+ end
103
+ else
104
+ begin
105
+ require 'simplecov'
106
+ desc 'Run tests with code coverage'
107
+ task :coverage do
108
+ ENV['COVERAGE'] = 'true'
109
+ Rake::Task[:test].execute
110
+ end
111
+ CLOBBER << FileList["coverage"]
112
+ rescue LoadError
113
+ This.task_warning( 'simplecov' )
114
+ end
115
+ end
116
+
117
+ #------------------------------------------------------------------------------
118
+ # Manifest - We want an explicit list of thos files that are to be packaged in
119
+ # the gem. Most of this is from Hoe.
120
+ #------------------------------------------------------------------------------
121
+ namespace 'manifest' do
122
+ desc "Check the manifest"
123
+ task :check => :clean do
124
+ files = FileList["**/*", ".*"].exclude( This.exclude_from_manifest ).to_a.sort
125
+ files = files.select{ |f| File.file?( f ) }
126
+
127
+ tmp = "Manifest.tmp"
128
+ File.open( tmp, 'w' ) do |f|
129
+ f.puts files.join("\n")
130
+ end
131
+
132
+ begin
133
+ sh "diff -du Manifest.txt #{tmp}"
134
+ ensure
135
+ rm tmp
136
+ end
137
+ puts "Manifest looks good"
138
+ end
139
+
140
+ desc "Generate the manifest"
141
+ task :generate => :clean do
142
+ files = %x[ git ls-files ].split("\n").sort
143
+ files.reject! { |f| f =~ This.exclude_from_manifest }
144
+ File.open( "Manifest.txt", "w" ) do |f|
145
+ f.puts files.join("\n")
146
+ end
147
+ end
148
+ end
149
+
150
+ #------------------------------------------------------------------------------
151
+ # Fixme - look for fixmes and report them
152
+ #------------------------------------------------------------------------------
153
+ namespace :fixme do
154
+ task :default => 'manifest:check' do
155
+ This.manifest.each do |file|
156
+ next if file == __FILE__
157
+ next unless file =~ %r/(txt|rb|md|rdoc|css|html|xml|css)\Z/
158
+ puts "FIXME: Rename #{file}" if file =~ /fixme/i
159
+ IO.readlines( file ).each_with_index do |line, idx|
160
+ prefix = "FIXME: #{file}:#{idx+1}".ljust(42)
161
+ puts "#{prefix} => #{line.strip}" if line =~ /fixme/i
162
+ end
163
+ end
164
+ end
165
+
166
+ def fixme_project_root
167
+ This.project_path( '../fixme' )
168
+ end
169
+
170
+ def fixme_project_path( subtree )
171
+ fixme_project_root.join( subtree )
172
+ end
173
+
174
+ def local_fixme_files
175
+ This.manifest.select { |p| p =~ %r|^tasks/| }
176
+ end
177
+
178
+ def outdated_fixme_files
179
+ local_fixme_files.reject do |local|
180
+ upstream = fixme_project_path( local )
181
+ Digest::SHA256.file( local ) == Digest::SHA256.file( upstream )
182
+ end
183
+ end
184
+
185
+ def fixme_up_to_date?
186
+ outdated_fixme_files.empty?
187
+ end
188
+
189
+ desc "See if the fixme tools are outdated"
190
+ task :outdated => :release_check do
191
+ if fixme_up_to_date? then
192
+ puts "Fixme files are up to date."
193
+ else
194
+ outdated_fixme_files.each do |f|
195
+ puts "#{f} is outdated"
196
+ end
197
+ end
198
+ end
199
+
200
+ desc "Update outdated fixme files"
201
+ task :update => :release_check do
202
+ if fixme_up_to_date? then
203
+ puts "Fixme files are already up to date."
204
+ else
205
+ puts "Updating fixme files:"
206
+ outdated_fixme_files.each do |local|
207
+ upstream = fixme_project_path( local )
208
+ puts " * #{local}"
209
+ FileUtils.cp( upstream, local )
210
+ end
211
+ puts "Use your git commands as appropriate."
212
+ end
213
+ end
214
+ end
215
+ desc "Look for fixmes and report them"
216
+ task :fixme => "fixme:default"
217
+
218
+ #------------------------------------------------------------------------------
219
+ # Gem Specification
220
+ #------------------------------------------------------------------------------
221
+ # Really this is only here to support those who use bundler
222
+ desc "Build the #{This.name}.gemspec file"
223
+ task :gemspec do
224
+ File.open( This.gemspec_file, "wb+" ) do |f|
225
+ f.write This.platform_gemspec.to_ruby
226
+ end
227
+ end
228
+
229
+ # the gemspec is also a dev artifact and should not be kept around.
230
+ CLOBBER << This.gemspec_file.to_s
231
+
232
+ # .rbc files from ruby 2.0
233
+ CLOBBER << FileList["**/*.rbc"]
234
+
235
+ # The standard gem packaging task, everyone has it.
236
+ require 'rubygems/package_task'
237
+ Gem::PackageTask.new( This.platform_gemspec ) do
238
+ # nothing
239
+ end
240
+
241
+ #------------------------------------------------------------------------------
242
+ # Release - the steps we go through to do a final release, this is pulled from
243
+ # a compbination of mojombo's rakegem, hoe and hoe-git
244
+ #
245
+ # 1) make sure we are on the master branch
246
+ # 2) make sure there are no uncommitted items
247
+ # 3) check the manifest and make sure all looks good
248
+ # 4) build the gem
249
+ # 5) do an empty commit to have the commit message of the version
250
+ # 6) tag that commit as the version
251
+ # 7) push master
252
+ # 8) push the tag
253
+ # 7) pus the gem
254
+ #------------------------------------------------------------------------------
255
+ task :release_check do
256
+ unless `git branch` =~ /^\* master$/
257
+ abort "You must be on the master branch to release!"
258
+ end
259
+ unless `git status` =~ /^nothing to commit/m
260
+ abort "Nope, sorry, you have unfinished business"
261
+ end
262
+ end
263
+
264
+ desc "Create tag v#{This.version}, build and push #{This.platform_gemspec.full_name} to rubygems.org"
265
+ task :release => [ :release_check, 'manifest:check', :gem ] do
266
+ sh "git commit --allow-empty -a -m 'Release #{This.version}'"
267
+ sh "git tag -a -m 'v#{This.version}' v#{This.version}"
268
+ sh "git push origin master"
269
+ sh "git push origin v#{This.version}"
270
+ sh "gem push pkg/#{This.platform_gemspec.full_name}.gem"
271
+ end
@@ -0,0 +1,209 @@
1
+ require 'pathname'
2
+
3
+ # Public: A Class containing all the metadata and utilities needed to manage a
4
+ # ruby project.
5
+ class ThisProject
6
+ # The name of this project
7
+ attr_accessor :name
8
+
9
+ # The author's name
10
+ attr_accessor :author
11
+
12
+ # The email address of the author(s)
13
+ attr_accessor :email
14
+
15
+ # The homepage of this project
16
+ attr_accessor :homepage
17
+
18
+ # The regex of files to exclude from the manifest
19
+ attr_accessor :exclude_from_manifest
20
+
21
+ # The hash of Gem::Specifications keyed' by platform
22
+ attr_accessor :gemspecs
23
+
24
+ # Public: Initialize ThisProject
25
+ #
26
+ # Yields self
27
+ def initialize(&block)
28
+ @exclude_from_manifest = %r/\.(git|DS_Store)|^(doc|coverage|pkg|tmp)|Gemfile*|\.(gemspec|swp|jar|bundle|so|rvmrc)$|~$/
29
+ @gemspecs = Hash.new
30
+ yield self if block_given?
31
+ end
32
+
33
+ # Public: return the version of ThisProject
34
+ #
35
+ # Search the ruby files in the project looking for the one that has the
36
+ # version string in it. This does not eval any code in the project, it parses
37
+ # the source code looking for the string.
38
+ #
39
+ # Returns a String version
40
+ def version
41
+ [ "lib/#{ name }.rb", "lib/#{ name }/version.rb" ].each do |v|
42
+ path = project_path( v )
43
+ line = path.read[/^\s*VERSION\s*=\s*.*/]
44
+ if line then
45
+ return line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
46
+ end
47
+ end
48
+ end
49
+
50
+ # Internal: Return a section of an RDoc file with the given section name
51
+ #
52
+ # path - the relative path in the project of the file to parse
53
+ # section_name - the section out of the file from which to parse data
54
+ #
55
+ # Retuns the text of the section as an array of paragrphs.
56
+ def section_of( file, section_name )
57
+ re = /^[=#]+ (.*)$/
58
+ sectional = project_path( file )
59
+ parts = sectional.read.split( re )[1..-1]
60
+ parts.map! { |p| p.strip }
61
+
62
+ sections = Hash.new
63
+ Hash[*parts].each do |k,v|
64
+ sections[k] = v.split("\n\n")
65
+ end
66
+ return sections[section_name]
67
+ end
68
+
69
+ # Internal: print out a warning about the give task
70
+ def task_warning( task )
71
+ warn "WARNING: '#{task}' tasks are not defined. Please run 'rake develop'"
72
+ end
73
+
74
+ # Internal: Return the full path to the file that is relative to the project
75
+ # root.
76
+ #
77
+ # path - the relative path of the file from the project root
78
+ #
79
+ # Returns the Pathname of the file
80
+ def project_path( *relative_path )
81
+ project_root.join( *relative_path )
82
+ end
83
+
84
+ # Internal: The absolute path of this file
85
+ #
86
+ # Returns the Pathname of this file.
87
+ def this_file_path
88
+ Pathname.new( __FILE__ ).expand_path
89
+ end
90
+
91
+ # Internal: The root directory of this project
92
+ #
93
+ # This is defined as being the directory that is in the path of this project
94
+ # that has the first Rakefile
95
+ #
96
+ # Returns the Pathname of the directory
97
+ def project_root
98
+ this_file_path.ascend do |p|
99
+ rakefile = p.join( 'Rakefile' )
100
+ return p if rakefile.exist?
101
+ end
102
+ end
103
+
104
+ # Internal: Returns the contents of the Manifest.txt file as an array
105
+ #
106
+ # Returns an Array of strings
107
+ def manifest
108
+ manifest_file = project_path( "Manifest.txt" )
109
+ abort "You need a Manifest.txt" unless manifest_file.readable?
110
+ manifest_file.readlines.map { |l| l.strip }
111
+ end
112
+
113
+ # Internal: Return the files that define the extensions
114
+ #
115
+ # Returns an Array
116
+ def extension_conf_files
117
+ manifest.grep( /extconf.rb\Z/ )
118
+ end
119
+
120
+ # Internal: Returns the gemspace associated with the current ruby platform
121
+ def platform_gemspec
122
+ gemspecs[platform]
123
+ end
124
+
125
+ def core_gemspec
126
+ Gem::Specification.new do |spec|
127
+ spec.name = name
128
+ spec.version = version
129
+ spec.author = author
130
+ spec.email = email
131
+ spec.homepage = homepage
132
+
133
+ spec.summary = summary
134
+ spec.description = description
135
+
136
+ spec.files = manifest
137
+ spec.executables = spec.files.grep(/^bin/) { |f| File.basename(f) }
138
+ spec.test_files = spec.files.grep(/^spec/)
139
+
140
+ spec.extra_rdoc_files += spec.files.grep(/(txt|rdoc|md)$/)
141
+ spec.rdoc_options = [ "--main" , 'README.md',
142
+ "--markup", "tomdoc" ]
143
+ end
144
+ end
145
+
146
+ # Internal: Return the gemspec for the ruby platform
147
+ def ruby_gemspec( core = core_gemspec, &block )
148
+ yielding_gemspec( 'ruby', core, &block )
149
+ end
150
+
151
+ # Internal: Return the gemspec for the jruby platform
152
+ def java_gemspec( core = core_gemspec, &block )
153
+ yielding_gemspec( 'java', core, &block )
154
+ end
155
+
156
+ # Internal: give an initial spec and a key, create a new gemspec based off of
157
+ # it.
158
+ #
159
+ # This will force the new gemspecs 'platform' to be that of the key, since the
160
+ # only reason you would have multiple gemspecs at this point is to deal with
161
+ # different platforms.
162
+ def yielding_gemspec( key, core )
163
+ spec = gemspecs[key] ||= core.dup
164
+ spec.platform = key
165
+ yield spec if block_given?
166
+ return spec
167
+ end
168
+
169
+ # Internal: Set the recovery gem development dependency
170
+ #
171
+ # These are dynamically set since they cannot be hard coded as there is
172
+ # no way to ship them correctly in the gemspec
173
+ #
174
+ # Returns nothing.
175
+ def set_coverage_gem
176
+ if RUBY_VERSION < "1.9.0"
177
+ platform_gemspec.add_development_dependency( 'rcov', '~> 1.0.0' )
178
+ else
179
+ platform_gemspec.add_development_dependency( 'simplecov', '~> 0.7.1' )
180
+ end
181
+ end
182
+
183
+ # Internal: Return the platform of ThisProject at the current moment in time.
184
+ def platform
185
+ (RUBY_PLATFORM == "java") ? 'java' : Gem::Platform::RUBY
186
+ end
187
+
188
+ # Internal: Return the DESCRIPTION section of the README.rdoc file
189
+ def description_section
190
+ section_of( 'README.md', 'DESCRIPTION')
191
+ end
192
+
193
+ # Internal: Return the summary text from the README
194
+ def summary
195
+ description_section.first
196
+ end
197
+
198
+ # Internal: Return the full description text from the READEM
199
+ def description
200
+ description_section.join(" ").tr("\n", ' ').gsub(/[{}]/,'').gsub(/\[[^\]]+\]/,'') # strip rdoc
201
+ end
202
+
203
+ # Internal: The path to the gemspec file
204
+ def gemspec_file
205
+ project_path( "#{ name }.gemspec" )
206
+ end
207
+ end
208
+
209
+ This = ThisProject.new