casualjim / caricature

Transparently mock Ruby, CLR and DLR objects in IronRuby

This URL has Read+Write access

commit  8088ab410b0c5d167472735b9777e3b872e0d73e
tree    5d9a05011363da28c930bf70bdf7fde207895e82
parent  0b8ffe50bd94ebc688d8398af736033a0fc4fe25
caricature / Rakefile
100644 311 lines (258 sloc) 10.28 kb
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
require 'rubygems'
require 'fileutils'
require 'rake/rdoctask'
 
$:.unshift 'lib'
require 'caricature'
 
desc "The default task is to run all the specs"
task :default => [:clr_models, :spec]
 
%w(bacon spec).each do |fw|
 
  gem_name = fw == "bacon" ? fw : "r#{fw}"
 
  desc "Runs all the #{gem_name} specs"
  task fw.to_sym do
    system "i#{fw} #{Dir.glob("spec/#{gem_name}/**/*_spec.rb").join(' ')}"
  end
 
  namespace fw.to_sym do
 
    desc "runs the #{gem_name} examples for the different classes"
    task :unit do
      specs = Dir.glob("spec/#{gem_name}/unit/**/*_spec.rb")
      system "i#{fw} #{specs.join(' ')}"
    end
 
    desc "runs the #{gem_name} integration examples"
    task :integration do
      specs = Dir.glob("spec/#{gem_name}/integration/**/*_spec.rb")
      system "i#{fw} #{specs.join(' ')}"
    end
  end
end
 
 
 
def csc
  system "gmcs"
  $?.pid.zero? ? "csc" : "gmcs"
end
 
desc "Compiles the clr models"
task :clr_models do
  Dir.chdir(File.dirname(__FILE__))
  files = Dir.glob("spec/models/*.cs").join(' ') #.collect { |f| f.gsub(/\//, "\\") }.join(" ")
  system "#{csc} /noconfig /target:library /debug+ /debug:full /out:spec/bin/ClrModels.dll #{files}"
end
 
##############################################################################
# OPTIONS
##############################################################################
 
PKG_NAME = 'caricature'
PKG_VERSION = Caricature::VERSION
AUTHORS = ['Ivan Porto Carrero']
EMAIL = "ivan@flanders.co.nz"
HOMEPAGE = "http://casualjim.github.com/caricature"
SUMMARY = "Caricature brings simple mocking to Ruby, DLR and CLR."
 
# These are the common rdoc options that are shared between generation of
# rdoc files using BOTH 'rake rdoc' and the installation by users of a
# RubyGem version which builds rdoc's along with its installation. Any
# rdoc options that are ONLY for developers running 'rake rdoc' should be
# added in the 'Rake::RDocTask' block below.
RDOC_OPTIONS = [
                "--quiet",
                "--title", SUMMARY,
                "--main", "README.rdoc",
                "--line-numbers",
                "--format","darkfish"
                ]
 
# Extra files outside of the lib dir that should be included with the rdocs.
RDOC_FILES = (%w( README.rdoc)).sort
 
# The full file list used for rdocs, tarballs, gems, and for generating the xmpp4r.gemspec.
PKG_FILES = (%w( Rakefile caricature.gemspec ) + RDOC_FILES + Dir["{lib,spec}/**/*"]).sort
 
# RDOC
#######
Rake::RDocTask.new do |rd|
 
  # which dir should rdoc files be installed in?
  rd.rdoc_dir = 'rdoc'
 
  # the full list of files to be included
  rd.rdoc_files.include(RDOC_FILES, "lib/**/*.rb")
 
  # the full list of options that are common between gem build
  # and 'rake rdoc' build of docs.
  rd.options = RDOC_OPTIONS
 
  # Devs Only : Uncomment to also document private methods in the rdocs
  # Please don't check this change in to the source repo.
  #rd.options << '--all'
 
  # Devs Only : Uncomment to generate dot (graphviz) diagrams along with rdocs.
  # This requires that graphiz (dot) be installed as a local binary and on your path.
  # See : http://www.graphviz.org/
  # Please don't check this change in to the source repo as it introduces a binary dependency.
  #rd.options << '--diagram'
  #rd.options << '--fileboxes'
 
end
 
desc "Check syntax of all Ruby files."
task :check_syntax do
  `find . -name "*.rb" |xargs -n1 ruby -c |grep -v "Syntax OK"`
  puts "* Done"
end
 
##############################################################################
# PACKAGING & INSTALLATION
##############################################################################
 
# What files/dirs should 'rake clean' remove?
#CLEAN.include ["*.gem", "pkg", "rdoc", "coverage"]
 
begin
  require 'rake/gempackagetask'
 
  spec = Gem::Specification.new do |s|
    s.name = PKG_NAME
    s.version = PKG_VERSION
    s.authors = AUTHORS
    s.email = EMAIL
    s.homepage = HOMEPAGE
    s.rubyforge_project = PKG_NAME
    s.summary = SUMMARY
    s.description = s.summary
    s.platform = Gem::Platform::RUBY
    s.require_path = 'lib'
    s.executables = []
    s.files = PKG_FILES
    s.test_files = []
    s.has_rdoc = true
    s.extra_rdoc_files = RDOC_FILES
    s.rdoc_options = RDOC_OPTIONS
    s.required_ruby_version = ">= 1.8.4"
    s.add_dependency 'uuidtools', ">= 2.0.0"
  end
 
  Rake::GemPackageTask.new(spec) do |pkg|
    pkg.gem_spec = spec
    pkg.need_tar = true
    pkg.need_zip = true
  end
 
  namespace :gem do
 
    desc "Run :package and install the .gem locally"
    task :install => [:update_gemspec, :package] do
      sh %{sudo gem install --local pkg/#{PKG_NAME}-#{PKG_VERSION}.gem}
    end
 
    desc "Like gem:install but without ri or rdocs"
    task :install_fast => [:update_gemspec, :package] do
      sh %{sudo gem install --local pkg/#{PKG_NAME}-#{PKG_VERSION}.gem --no-rdoc --no-ri}
    end
 
    desc "Run :clean and uninstall the .gem"
    task :uninstall => :clean do
      sh %{sudo gem uninstall #{PKG_NAME}}
    end
 
    # Thanks to the Merb project for this code.
    desc "Update Github Gemspec"
    task :update_gemspec do
      skip_fields = %w(new_platform original_platform date)
 
      result = "# WARNING : RAKE AUTO-GENERATED FILE. DO NOT MANUALLY EDIT!\n"
      result << "# RUN : 'rake gem:update_gemspec'\n\n"
      result << "Gem::Specification.new do |s|\n"
      spec.instance_variables.sort.each do |ivar|
        value = spec.instance_variable_get(ivar)
        name = ivar.to_s.split("@").last
        next if skip_fields.include?(name) || value.nil? || value == "" || (value.respond_to?(:empty?) && value.empty?)
        if name == "dependencies"
          value.each do |d|
            dep, *ver = d.to_s.split(" ")
            result << " s.add_dependency #{dep.inspect}, #{ver.join(" ").inspect.gsub(/[()]/, "")}\n"
          end
        else
          case value
          when Array
            value = name != "files" ? value.inspect : value.sort.uniq.inspect.split(",").join(",\n")
          when String, Fixnum, true, false
            value = value.inspect
          else
            value = value.to_s.inspect
          end
          result << " s.#{name} = #{value}\n"
        end
      end
      result << "end"
      File.open(File.join(File.dirname(__FILE__), "#{spec.name}.gemspec"), "w"){|f| f << result}
    end
 
  end # namespace :gem
 
  # also keep the gemspec up to date each time we package a tarball or gem
  task :package => ['gem:update_gemspec']
  task :gem => ['gem:update_gemspec']
 
rescue LoadError
  puts <<EOF
###
Packaging Warning : RubyGems is apparently not installed on this
system and any file add/remove/rename will not
be auto-updated in the 'caricature.gemspec' when you run any
package tasks. All such file changes are recommended
to be packaged on a system with RubyGems installed
if you intend to push commits to the Git repo so the
gemspec will also stay in sync for others.
###
EOF
end
 
# we are apparently on a system that does not have RubyGems installed.
# Lets try to provide only the basic tarball package tasks as a fallback.
unless defined? Gem
  begin
    require 'rake/packagetask'
    Rake::PackageTask.new(PKG_NAME, PKG_VERSION) do |p|
      p.package_files = PKG_FILES
      p.need_tar = true
      p.need_zip = true
    end
  rescue LoadError
    puts <<EOF
###
Warning : Unable to require the 'rake/packagetask'. Is Rake installed?
###
EOF
  end
end
 
 
# # Generate all the Rake tasks
# # Run 'rake -T' to see list of generated tasks (from gem root directory)
# $hoe = Hoe.spec 'cloudslide' do
# self.developer 'Ivan Porto Carrero', 'ivan@flanders.co.nz'
# self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
# self.rubyforge_name = self.name # TODO this is default value
# self.extra_deps = [['uuidtools','>= 2.0.0'], ['newgem', '>= 1.5.2']]
# end
#
# require 'newgem/tasks'
# Dir['tasks/**/*.rake'].each { |t| load t }
 
# TODO - want other tests/tasks run by default? Add them to the list
# remove_task :default
# task :default => [:spec, :features]
 
# file_list = Dir.glob("lib/**/*.rb")
 
# desc "Create RDoc documentation"
# file 'doc/index.html' => file_list do
# puts "######## Creating RDoc documentation"
# system "rdoc --title 'Caricature isolation framework documentation' -m README README.markdown lib/"
# end
#
# desc "An alias for creating the RDoc documentation"
# task :rdoc do
# Rake::Task['doc/index.html'].invoke
# end
 
# begin
#
# Jeweler::Tasks.new do |gemspec|
# gemspec.name = "caricature"
# gemspec.summary = "Caricature - Bringing simple mocking to the DLR"
# gemspec.email = "ivan@flanders.co.nz"
# gemspec.homepage = "http://github.com/casualjim/caricature"
# gemspec.description = "This project aims to make interop between IronRuby objects and .NET objects easier. The idea is that it integrates nicely with bacon and later rspec and that it transparently lets you mock ironruby ojbects as well as CLR objects/interfaces. Caricature handles interfaces, interface inheritance, CLR objects, CLR object instances, Ruby classes and instances of Ruby classes."
# gemspec.authors = ["Ivan Porto Carrero"]
# gemspec.rubyforge_project = 'caricature' # This line would be new
# end
# rescue LoadError
# puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
# end
#
 begin
   require 'rake/contrib/sshpublisher'
   namespace :rubyforge do
 
     desc "Release gem and RDoc documentation to RubyForge"
     task :release => ["rubyforge:release:gem", 'rubyforge:release:docs']
 
     namespace :release do
       desc "Publish RDoc to RubyForge."
       task :docs => [:rdoc] do
         config = YAML.load(
             File.read(File.expand_path('~/.rubyforge/user-config.yml'))
         )
 
         host = "#{config['username']}@rubyforge.org"
         remote_dir = "/var/www/gforge-projects/caricature/"
         local_dir = 'doc'
 
         Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
       end
     end
   end
 rescue LoadError
   puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
 end