floehopper / mocha

Mocha is a mocking and stubbing library for Ruby

This URL has Read+Write access

mocha / Rakefile
df0e13bd » floehopper 2006-07-16 Tweaks to README and TODO. ... 1 require 'rake/rdoctask'
2 require 'rake/gempackagetask'
9b16c5a7 » floehopper 2007-03-13 Use Rake::TestTask to run t... 3 require 'rake/testtask'
6ada427d » floehopper 2006-09-06 Added publish_packages rake... 4
5 module Mocha
80d816f2 » floehopper 2009-07-01 Prepare for 0.9.7 release. 6 VERSION = "0.9.7"
6ada427d » floehopper 2006-09-06 Added publish_packages rake... 7 end
df0e13bd » floehopper 2006-07-16 Tweaks to README and TODO. ... 8
438491b7 » floehopper 2007-12-26 Improved rake task descript... 9 desc "Run all tests"
58acf4d1 » floehopper 2008-07-24 Added primitive performance... 10 task 'default' => ['test:units', 'test:acceptance', 'test:performance']
2e5eccb4 » floehopper 2008-02-15 Namespaced test rake tasks.... 11
12 namespace 'test' do
13
14 unit_tests = FileList['test/unit/**/*_test.rb']
15 acceptance_tests = FileList['test/acceptance/*_test.rb']
16
17 desc "Run unit tests"
18 Rake::TestTask.new('units') do |t|
19 t.libs << 'test'
20 t.test_files = unit_tests
21 t.verbose = true
22 t.warning = true
23 end
24
25 desc "Run acceptance tests"
26 Rake::TestTask.new('acceptance') do |t|
27 t.libs << 'test'
28 t.test_files = acceptance_tests
29 t.verbose = true
30 t.warning = true
31 end
32
68dd3e3d » floehopper 2008-02-15 Comment out rcov task to fi... 33 # require 'rcov/rcovtask'
34 # Rcov::RcovTask.new('coverage') do |t|
35 # t.libs << 'test'
36 # t.test_files = unit_tests + acceptance_tests
37 # t.verbose = true
38 # t.warning = true
39 # t.rcov_opts << '--sort coverage'
40 # t.rcov_opts << '--xref'
41 # end
9b16c5a7 » floehopper 2007-03-13 Use Rake::TestTask to run t... 42
58acf4d1 » floehopper 2008-07-24 Added primitive performance... 43 desc "Run performance tests"
44 task 'performance' do
45 require 'test/acceptance/stubba_example_test'
46 require 'test/acceptance/mocha_example_test'
47 iterations = 1000
48 puts "\nBenchmarking with #{iterations} iterations..."
49 [MochaExampleTest, StubbaExampleTest].each do |test_case|
50 puts "#{test_case}: #{benchmark_test_case(test_case, iterations)} seconds."
51 end
52 end
53
54 end
55
56 def benchmark_test_case(klass, iterations)
57 require 'benchmark'
db4ae0aa » floehopper 2009-02-05 Added support for 'test-uni... 58 require 'test/unit/ui/console/testrunner'
59 begin
60 require 'test/unit/ui/console/outputlevel'
61 silent_option = { :output_level => Test::Unit::UI::Console::OutputLevel::SILENT }
62 rescue LoadError
63 silent_option = Test::Unit::UI::SILENT
64 end
65 time = Benchmark.realtime { iterations.times { Test::Unit::UI::Console::TestRunner.run(klass, silent_option) } }
1e4ce2c5 » floehopper 2006-07-16 Added first draft of README... 66 end
67
df0e13bd » floehopper 2006-07-16 Tweaks to README and TODO. ... 68 desc 'Generate RDoc'
2e5eccb4 » floehopper 2008-02-15 Namespaced test rake tasks.... 69 Rake::RDocTask.new('rdoc') do |task|
c38bdc68 » floehopper 2006-08-11 Tweaks so that I can releas... 70 task.main = 'README'
d6a0f261 » floehopper 2007-09-06 Renamed Matches parameter m... 71 task.title = "Mocha #{Mocha::VERSION}"
df0e13bd » floehopper 2006-07-16 Tweaks to README and TODO. ... 72 task.rdoc_dir = 'doc'
9cd0e8d4 » floehopper 2007-06-08 Added RDoc template which h... 73 task.template = File.expand_path(File.join(File.dirname(__FILE__), "templates", "html_with_google_analytics"))
b509aaec » floehopper 2007-12-29 Generate rdoc for StateMach... 74 task.rdoc_files.include(
75 'README',
76 'RELEASE',
77 'COPYING',
78 'MIT-LICENSE',
79 'agiledox.txt',
83b5b735 » floehopper 2009-02-09 Renamed Mocha::Standalone t... 80 'lib/mocha/api.rb',
b509aaec » floehopper 2007-12-29 Generate rdoc for StateMach... 81 'lib/mocha/mock.rb',
82 'lib/mocha/expectation.rb',
83 'lib/mocha/object.rb',
84 'lib/mocha/parameter_matchers.rb',
85 'lib/mocha/parameter_matchers',
54c2b63e » floehopper 2008-03-09 Added configurable warnings... 86 'lib/mocha/state_machine.rb',
87 'lib/mocha/configuration.rb',
88 'lib/mocha/stubbing_error.rb'
b509aaec » floehopper 2007-12-29 Generate rdoc for StateMach... 89 )
df0e13bd » floehopper 2006-07-16 Tweaks to README and TODO. ... 90 end
93cad010 » floehopper 2009-02-01 Added a release rake task t... 91
92 desc "Generate all documentation"
93 task 'generate_docs' => ['clobber_rdoc', 'rdoc', 'examples', 'agiledox.txt']
df0e13bd » floehopper 2006-07-16 Tweaks to README and TODO. ... 94
cf66c622 » floehopper 2006-07-17 Added publish_rdoc take task. 95 desc "Upload RDoc to RubyForge"
93cad010 » floehopper 2009-02-01 Added a release rake task t... 96 task 'publish_docs' do
ca229583 » floehopper 2009-01-28 Ruby 1.9 includes rake, but... 97 require 'rake/contrib/sshpublisher'
cf66c622 » floehopper 2006-07-17 Added publish_rdoc take task. 98 Rake::SshDirPublisher.new("jamesmead@rubyforge.org", "/var/www/gforge-projects/mocha", "doc").upload
99 end
100
901b45fe » floehopper 2006-07-22 Added agiledox and rubyforg... 101 desc "Generate agiledox-like documentation for tests"
c38bdc68 » floehopper 2006-08-11 Tweaks so that I can releas... 102 file 'agiledox.txt' do
901b45fe » floehopper 2006-07-22 Added agiledox and rubyforg... 103 File.open('agiledox.txt', 'w') do |output|
104 tests = FileList['test/**/*_test.rb']
105 tests.each do |file|
106 m = %r".*/([^/].*)_test.rb".match(file)
107 output << m[1]+" should:\n"
108 test_definitions = File::readlines(file).select {|line| line =~ /.*def test.*/}
109 test_definitions.sort.each do |definition|
110 m = %r"test_(should_)?(.*)".match(definition)
111 output << " - "+m[2].gsub(/_/," ") << "\n"
112 end
113 end
114 end
115 end
116
2d337e03 » floehopper 2006-09-03 Major overhaul of rdocs - o... 117 desc "Convert example ruby files to syntax-highlighted html"
2e5eccb4 » floehopper 2008-02-15 Namespaced test rake tasks.... 118 task 'examples' do
93144e0c » floehopper 2007-06-08 Fix load path for coderay. 119 require 'coderay'
2d337e03 » floehopper 2006-09-03 Major overhaul of rdocs - o... 120 mkdir_p 'doc/examples'
121 File.open('doc/examples/coderay.css', 'w') do |output|
122 output << CodeRay::Encoders[:html]::CSS.new.stylesheet
123 end
124 ['mocha', 'stubba', 'misc'].each do |filename|
125 File.open("doc/examples/#{filename}.html", 'w') do |file|
126 file << "<html>"
127 file << "<head>"
128 file << %q(<link rel="stylesheet" media="screen" href="coderay.css" type="text/css">)
129 file << "</head>"
130 file << "<body>"
131 file << CodeRay.scan_file("examples/#{filename}.rb").html.div
132 file << "</body>"
133 file << "</html>"
134 end
135 end
136 end
137
28502984 » jamesmead 2008-11-03 Gem::manage_gems is depreca... 138 Gem.manage_gems if Gem::RubyGemsVersion < '1.2.0'
1e4ce2c5 » floehopper 2006-07-16 Added first draft of README... 139
94a273bd » thewoolleyman 2008-12-18 Add rake task to update moc... 140 def build_specification(version = Mocha::VERSION)
141 Gem::Specification.new do |s|
142 s.name = "mocha"
143 s.summary = "Mocking and stubbing library"
144 s.version = version
145 s.platform = Gem::Platform::RUBY
146 s.author = 'James Mead'
147 s.description = <<-EOF
148 Mocking and stubbing library with JMock/SchMock syntax, which allows mocking and stubbing of methods on real (non-mock) classes.
149 EOF
cd78ad60 » floehopper 2008-12-20 Updated mailing list email ... 150 s.email = 'mocha-developer@googlegroups.com'
94a273bd » thewoolleyman 2008-12-18 Add rake task to update moc... 151 s.homepage = 'http://mocha.rubyforge.org'
152 s.rubyforge_project = 'mocha'
153
154 s.has_rdoc = true
155 s.extra_rdoc_files = ['README', 'COPYING']
156 s.rdoc_options << '--title' << 'Mocha' << '--main' << 'README' << '--line-numbers'
157
158 s.add_dependency('rake')
159 s.files = FileList['{lib,test,examples}/**/*.rb', '[A-Z]*'].exclude('TODO').to_a
160 end
1e4ce2c5 » floehopper 2006-07-16 Added first draft of README... 161 end
162
94a273bd » thewoolleyman 2008-12-18 Add rake task to update moc... 163 specification = build_specification
164
1e4ce2c5 » floehopper 2006-07-16 Added first draft of README... 165 Rake::GemPackageTask.new(specification) do |package|
d39ad5f5 » floehopper 2007-06-29 Replace tabs with spaces. 166 package.need_zip = true
167 package.need_tar = true
2d337e03 » floehopper 2006-09-03 Major overhaul of rdocs - o... 168 end
6ada427d » floehopper 2006-09-06 Added publish_packages rake... 169
94a273bd » thewoolleyman 2008-12-18 Add rake task to update moc... 170 desc 'Generate updated gemspec with unique version, which will cause gem to be auto-built on github.'
171 task :update_gemspec do
172 File.open('mocha.gemspec', 'w') do |output|
173 output << build_specification(Mocha::VERSION + '.' + Time.now.strftime('%Y%m%d%H%M%S')).to_ruby
174 end
175 end
176
2e5eccb4 » floehopper 2008-02-15 Namespaced test rake tasks.... 177 task 'verify_user' do
6ada427d » floehopper 2006-09-06 Added publish_packages rake... 178 raise "RUBYFORGE_USER environment variable not set!" unless ENV['RUBYFORGE_USER']
179 end
180
2e5eccb4 » floehopper 2008-02-15 Namespaced test rake tasks.... 181 task 'verify_password' do
6ada427d » floehopper 2006-09-06 Added publish_packages rake... 182 raise "RUBYFORGE_PASSWORD environment variable not set!" unless ENV['RUBYFORGE_PASSWORD']
183 end
184
185 desc "Publish package files on RubyForge."
93cad010 » floehopper 2009-02-01 Added a release rake task t... 186 task 'publish_packages' => ['verify_user', 'verify_password', 'clobber_package', 'package'] do
6ada427d » floehopper 2006-09-06 Added publish_packages rake... 187 require 'meta_project'
188 require 'rake/contrib/xforge'
189 release_files = FileList[
190 "pkg/mocha-#{Mocha::VERSION}.gem",
191 "pkg/mocha-#{Mocha::VERSION}.tgz",
192 "pkg/mocha-#{Mocha::VERSION}.zip"
193 ]
194
195 Rake::XForge::Release.new(MetaProject::Project::XForge::RubyForge.new('mocha')) do |release|
196 release.user_name = ENV['RUBYFORGE_USER']
197 release.password = ENV['RUBYFORGE_PASSWORD']
198 release.files = release_files.to_a
199 release.release_name = "Mocha #{Mocha::VERSION}"
200 release.release_changes = ''
201 release.release_notes = ''
202 end
203 end
93cad010 » floehopper 2009-02-01 Added a release rake task t... 204
205 desc "Do a full release."
206 task 'release' => ['default', 'generate_docs', 'publish_packages', 'publish_docs', 'update_gemspec'] do
207 puts
208 puts "*** Remember to commit newly generated gemspec after release ***"
209 puts
210 end