-
Notifications
You must be signed in to change notification settings - Fork 61
/
Rakefile
239 lines (201 loc) · 5.84 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/usr/bin/ruby -wKU
require 'rake/clean'
require './lib/given/version'
require './lib/given/module_methods'
CLEAN.include("pkg/rspec-given-*").exclude("pkg/*.gem")
CLOBBER.include("*.gemspec", "html", "README", "README.old")
# README Formatting --------------------------------------------------
task :default => :examples
def version
Given::VERSION
end
def tag_name
"rspec-given-#{version}"
end
def tagged?
`git tag`.split.include?(tag_name)
end
def git_clean?
sh "git status | grep 'nothing to commit'", :verbose => false do |status|
return status
end
end
desc "Display the current version tag"
task :version do
puts tag_name
end
desc "Tag the current commit with #{tag_name}"
task :tag do
fail "Cannot tag, project directory is not clean" unless git_clean?
fail "Cannot tag, #{tag_name} already exists." if tagged?
sh "git tag #{tag_name}"
end
desc "Publish the gems"
task :publish_gems => [:clobber, :gem] do
FileList['pkg/*.gem'].each do |gemname|
sh "gem push #{gemname}"
end
end
# Running examples ---------------------------------------------------
desc "Run all the examples"
task :examples => [:specs, :rs_examples, :mt_examples]
desc "Run the specs"
task :specs do
puts "Running specs"
sh "rspec spec"
end
EXAMPLES = FileList['examples/**/*_spec.rb', 'examples/use_assertions.rb'].
exclude('examples/failing/*.rb').
exclude('examples/minitest/*.rb').
exclude('examples/integration/failing/*.rb')
MT_EXAMPLES = FileList['examples/minitest/**/*_spec.rb']
unless Given::NATURAL_ASSERTIONS_SUPPORTED
EXAMPLES.exclude("examples/stack/*.rb")
end
FAILING_EXAMPLES = FileList['examples/failing/**/*_spec.rb']
desc "Run the RSpec specs and examples"
task :rs => [:specs, :rs_examples]
desc "Run the Minitest tests and examples"
task :mt => [:specs, :mt_examples]
desc "Run the examples in RSpec 2"
task :rs_examples => [:verify_rspec2] do
puts "Running examples (with RSpec2)"
sh "rspec #{EXAMPLES}"
end
desc "Run the examples in Minitest"
task :mt_examples do
puts "Running examples (with Minitest)"
sh "ruby -Ilib:examples examples/loader.rb #{EXAMPLES} #{MT_EXAMPLES}"
end
desc "Run failing examples"
task :failing => [:verify_rspec2] do
puts "Running failing examples (with RSpec2)"
sh "rspec #{FAILING_EXAMPLES}"
end
task :verify_rspec1 do
sh "type spec >/dev/null 2>&1", :verbose => false do |status|
fail "You need to install RSpec 1 in order to test against it." unless status
end
end
task :verify_rspec2 do
sh "type rspec >/dev/null 2>&1", :verbose => false do |status|
fail "You need to install RSpec 2 in order to test against it." unless status
end
end
desc "Check all files load properly when independenly loaded."
task :load_check do
SRC_FILES = FileList['lib/given/*.rb'].exclude(%r(rspec1))
SRC_FILES.each do |fn|
sh %{ruby -Ilib -e 'load "#{fn}"'}
end
end
# Formatting the README ----------------------------------------------
directory 'html'
desc "Display the README file"
task :readme => ["README.md"] do
Bundler.with_clean_env do
sh "ghpreview README.md"
end
end
desc "Generate an RDoc README"
file "README.md" => ["examples/stack/stack_spec.rb", "lib/given/version.rb"] do
open("README.md") do |ins|
open("README.tmp", "w") do |outs|
state = :copy
while line = ins.gets
case state
when :copy
if line =~ /rspec-given, minitest-given, and given-core, version +\d+(\.(\d+|beta))+/i
line.gsub!(/version +\d+(\.(\d+|beta))+/i, "version #{Given::VERSION}")
outs.puts line
elsif line =~ /^<pre>/
state = :insert
else
outs.puts line
end
when :insert
outs.puts "<pre>"
outs.puts open("examples/stack/stack_spec.rb") { |codes| codes.read }
outs.puts "</pre>"
state = :skip
when :skip
state = :copy2 if line =~ /^<\/pre>/
when :copy2
outs.puts line
end
end
end
end
mv "README.md", "README.old"
mv "README.tmp", "README.md"
end
# RDoc ---------------------------------------------------------------
begin
require 'rdoc/task'
if RDoc::VERSION > "2.4.2"
RDOC_ENABLED = true
else
puts "Version of RDoc is too old, please gem install a later version"
RDOC_ENABLED = false
end
rescue LoadError => ex
RDOC_ENABLED = false
end
begin
require 'darkfish-rdoc'
DARKFISH_ENABLED = true
rescue LoadError => ex
DARKFISH_ENABLED = false
end
if RDOC_ENABLED
def md_to_rdoc(infile, outfile)
open(infile) do |ins|
open(outfile, "w") do |outs|
state = :copy
while line = ins.gets
case state
when :ignore
if line =~ /^-->/
state = :copy
end
when :pre
if line =~ /^<\/pre>/
state = :copy
else
outs.puts " #{line}"
end
when :copy
if line =~ /^<!--/
state = :ignore
elsif line =~ /^<pre>/
state = :pre
else
line.gsub!(/^####/, '====')
line.gsub!(/^###/, '===')
line.gsub!(/^##/, '==')
line.gsub!(/^#/, '=')
outs.puts line
end
end
end
end
end
end
file "README" => ["README.md"] do
md_to_rdoc("README.md", "README")
end
RDoc::Task.new("rdoc") do |rdoc|
rdoc.rdoc_dir = 'html'
rdoc.title = "RSpec/Given -- A Given/When/Then extension for RSpec"
rdoc.options = [
'--line-numbers',
'--main' , 'doc/main.rdoc',
'--title', 'Given - Given/When/Then Extensions for RSpec'
]
rdoc.options << '-SHN' << '-f' << 'darkfish' if DARKFISH_ENABLED
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('MIT-LICENSE')
rdoc.rdoc_files.include('lib/**/*.rb', 'doc/**/*.rdoc')
end
task :rdoc => "README"
end