changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/pre_commit/lib/pre_commit/rspec.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1class PreCommit::Rspec < PreCommit
2 def pre_commit
3 check_for_gem_dependencies
4 fix_cr_lf
5 touch_revision_storing_files
6 pre_commit_core
7 pre_commit_textmate_bundle
8 pre_commit_rails
9 ok_to_commit
10 end
11
12 def check_for_gem_dependencies
13 require "rubygems"
14 gem 'rake'
15 gem 'webby'
16 gem 'coderay'
17 gem 'RedCloth'
18 gem 'syntax'
19 gem 'diff-lcs'
20 gem 'heckle' unless PLATFORM == "i386-mswin32"
21 gem 'hpricot'
22 end
23
24 def fix_cr_lf
25 files = FileList['**/*.rb'].
26 exclude('example_rails_app/vendor/**').
27 exclude('rspec/translated_specs/**')
28 $\="\n"
29 files.each do |f|
30 raw_content = File.read(f)
31 fixed_content = ""
32 raw_content.each_line do |line|
33 fixed_content << line
34 end
35 unless raw_content == fixed_content
36 File.open(f, "w") do |io|
37 io.print fixed_content
38 end
39 end
40 end
41 end
42
43 # TODO - move me up to the project root
44 def touch_revision_storing_files
45 files = [
46 'rspec/lib/spec/version.rb',
47 'rspec_on_rails/lib/spec/rails/version.rb'
48 ]
49 build_time_utc = Time.now.utc.strftime('%Y%m%d%H%M%S')
50 files.each do |path|
51 abs_path = File.join(root_dir, path)
52 content = File.open(abs_path).read
53 touched_content = content.gsub(/BUILD_TIME_UTC = (\d*)/, "BUILD_TIME_UTC = #{build_time_utc}")
54 File.open(abs_path, 'w') do |io|
55 io.write touched_content
56 end
57 end
58 end
59
60 def pre_commit_core
61 Dir.chdir 'rspec' do
62 rake = (PLATFORM == "i386-mswin32") ? "rake.bat" : "rake"
63 system("#{rake} pre_commit --verbose --trace")
64 raise "RSpec Core pre_commit failed" if error_code?
65 end
66 end
67
68 def pre_commit_textmate_bundle
69 Dir.chdir 'RSpec.tmbundle/Support' do
70 rake = (PLATFORM == "i386-mswin32") ? "rake.bat" : "rake"
71 system("#{rake} spec --verbose --trace")
72 raise "RSpec Textmate Bundle specs failed" if error_code?
73 end
74 end
75
76 def install_dependencies
77 Dir.chdir 'example_rails_app' do
78 rake_sh("-f Multirails.rake install_dependencies")
79 end
80 end
81
82 def update_dependencies
83 Dir.chdir 'example_rails_app' do
84 rake_sh("-f Multirails.rake update_dependencies")
85 end
86 end
87
88 def pre_commit_rails
89 Dir.chdir 'example_rails_app' do
90 rake = (PLATFORM == "i386-mswin32") ? "rake.cmd" : "rake"
91 cmd = "#{rake} -f Multirails.rake pre_commit --trace"
92 system(cmd)
93 if error_code?
94 message = <<-EOF
95 ############################################################
96 RSpec on Rails Plugin pre_commit failed. For more info:
97
98 cd example_rails_app
99 #{cmd}
100
101 ############################################################
102 EOF
103 raise message.gsub(/^ /, '')
104 end
105 end
106 end
107
108 def ok_to_commit
109 puts "OK TO COMMIT"
110 end
111end