-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRakefile
75 lines (65 loc) · 2.81 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
require 'rubygems'
require 'bundler/setup'
Bundler::GemHelper.install_tasks
namespace :db do
desc "Create database structure"
task :prepare do
require 'active_record'
require File.expand_path("../spec/support/active_record/initializer", __FILE__)
require File.expand_path("../spec/support/active_record/schema", __FILE__)
end
desc "Copy all database.yml.example files to database.yml"
task :config do
Dir.glob('spec/support/*/database.yml.example').each do |example_yml|
database_yml = example_yml.sub(/\.example$/, '')
FileUtils.copy(example_yml, database_yml) unless File.exists?(database_yml)
end
end
end
desc "Convert rspec specs to test/unit tests"
task :rspec_to_test do
Dir.chdir File.dirname(__FILE__)
data = IO.read('spec/blueprints_spec.rb')
data.gsub!("spec_helper", "test_helper")
data.gsub!("describe Blueprints do", 'class BlueprintsTest < ActiveSupport::TestCase')
# lambda {
# demolish :just_orange
# }.should raise_error(ArgumentError)
data.gsub!(/(\s+)lambda \{\n(.*)\n(\s+)\}.should raise_error\((.*)\)/, "\\1assert_raise(\\4) do\n\\2\n\\3end")
# should =~ => assert_similar
data.gsub!(/^(\s+)(.*)\.should\s*=~\s*(.*)/, '\1assert_similar(\2, \3)')
# A.should_not include(B) => assert(!A.include?(B))
data.gsub!(/^(\s+)(.*)\.should_not\s*include\((.*)\)/, '\1assert(!\2.include?(\3))')
# A.should include(B) => assert(A.include?(B))
data.gsub!(/^(\s+)(.*)\.should\s*include\((.*)\)/, '\1assert(\2.include?(\3))')
# .should_not => assert(!())
data.gsub!(/^(\s+)(.*)\.should_not(.*)/, '\1assert(!(\2\3))')
# .should => assert()
data.gsub!(/^(\s+)(.*)\.should(.*)/, '\1assert(\2\3)')
# be_nil => .nil?
data.gsub!(/ be_([^\(\)]*)/, '.\1?')
# have(2).items => .size == 2
data.gsub!(/ have\((\d+)\)\.items/, '.size == \1')
data.gsub!(/^(\s+)describe/, '\1context')
data.gsub!(/^(\s+)it (["'])(should )?/, '\1should \2')
data.gsub!(/^(\s+)before.*do/, '\1setup do')
data.gsub!(/^(\s+)after.*do/, '\1teardown do')
File.open('test/blueprints_test.rb', 'w') { |f| f.write(data) }
end
task :default => [:rspec_to_test, 'db:config', 'db:prepare'] do
commands = [
["Unit specs", "rspec -c spec/unit/*_spec.rb"],
["Active record integration", "rspec -c spec/blueprints_spec.rb"],
["No ORM integration", "rspec -c spec/blueprints_spec.rb", 'none'],
["Mongoid integration", "rspec -c spec/blueprints_spec.rb", 'mongoid'],
["Mongo mapper integration", "rspec -c spec/blueprints_spec.rb", 'mongo_mapper'],
["Test::Unit", "ruby test/blueprints_test.rb"],
["Cucumber", "cucumber features/blueprints.feature -f progress"],
]
statuses = commands.collect do |label, command, orm|
puts "#{label}:"
ENV['ORM'] = orm
system command
end
exit 1 unless statuses.all? { |status| status }
end