forked from nsabiyera/Oak
/
Rakefile.rb
134 lines (107 loc) · 4.26 KB
/
Rakefile.rb
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
#MIT License
#http://www.github.com/amirrajan/rake-dot-net
#Copyright (c) 2011 Amir Rajan
require './RakeDotNet/command_shell.rb'
require './RakeDotNet/web_deploy.rb'
require './RakeDotNet/iis_express.rb'
require './RakeDotNet/sln_builder.rb'
require './RakeDotNet/file_sync.rb'
require 'net/http'
require 'yaml'
require './stacktrace.rb'
task :rake_dot_net_initialize do
yml = YAML::load File.open("dev.yml")
@solution_name = yml["solution_name"]
@test_dll = yml["test_dll"]
@test_runner_command = "#{ yml["test_runner"] } #{ @test_dll }"
@database_name = yml["database_name"]
@database_server = yml["database_server"]
@sh = CommandShell.new
@sln = SlnBuilder.new
@sln.msbuild_path = "C:\\Program Files (x86)\\MSBuild\\14.0\\Bin\\msbuild.exe"
end
desc "builds and deploys website to directories iis express will use to run app"
task :default => [:build]
desc "builds the solution"
task :build => :rake_dot_net_initialize do
@sln.build @solution_name
end
desc "run nspec tests"
task :tests => :build do
results = `#{@test_runner_command}`
puts results
write_stack_trace results
end
desc "run nspec tests tagged with Tag[\"wip\"]"
task :wip => :build do
sh @test_runner_command + " --tag wip"
end
desc "run nspec tests tagged with args passed in"
task :test_for_tag, [:tag] => :build do |t, args|
command = @test_runner_command + " --tag #{args[:tag]}"
results = `#{command}`
puts results
write_stack_trace results
end
desc "run nspec tests"
task :tests_excluding_performance => :build do
sh @test_runner_command + " --tag ~performance"
end
desc "generates ctags"
task :tags do
sh "ctags --recurse --exclude=\"Sample Apps\""
end
desc "creates the databases needed to run oak tests"
task :create_db => :rake_dot_net_initialize do
execute_sql "master", "create database #{ @database_name }", @database_server
execute_sql "master", "create database #{ @database_name }2", @database_server
puts "\nDone.\n\n"
puts "If you received DB connection errors, run the command: rake list_db_servers"
end
desc "lists database servers on the network and provides a rake command for updating your database connection string"
task :list_db_servers => :rake_dot_net_initialize do
puts "scanning the network for db servers (this may take a while)"
puts "if you already know what database server you want to connect to,"
puts "you can change your connection strings in the application by running the command:"
puts "rake update_db_server[server_name], example: rake update_db_server[\'.\\sqlexpress\']"
puts "looking....\n\n"
output = `sqlcmd -Lc`
puts "here are your db servers and the rake command to update your connection strings:\n\n"
output.each_line do |line|
puts "rake update_db_server[\'#{line.strip}\']" if line.strip != ""
end
puts "\nRun the command exactly as it is displayed above, including single quotes around the server name"
end
desc "updates all database connection string server values to the value specified, example: rake update_db_server[./sqlexpress]"
task :update_db_server, [:new_value] => :rake_dot_net_initialize do |t, args|
raise "You need to specify a new database server name, example: rake update_db_server[./sqlexpress]" if args[:new_value].nil?
[
"Oak.Tests/App.config"
].each do |file|
if File.exist? file
puts "updating connection string in: #{ file }"
content = File.open(file).read
content.gsub!("Data Source=#{ @database_server };", "Data Source=#{ args[:new_value] };")
File.open(file, "w") { |f| f.write(content) }
puts "done"
end
end
puts "updating dev.yml"
content = File.open("dev.yml").read
content.gsub!("database_server: #{ @database_server }",
"database_server: #{ args[:new_value] }")
File.open("dev.yml", "w") { |f| f.write(content) }
puts "done"
puts "if you ran this because of errors related to rake create_db, run rake create_db again now"
end
def execute_sql database, sql, server
puts `sqlcmd -d #{ database } -S #{ server } -Q \"#{ sql }\"`
end
def write_stack_trace test_output
stacktrace = ""
if test_output.match /FAILURES/
stacktrace = test_output.split('**** FAILURES ****').last.strip
stacktrace = stacktrace.split(/^.*Examples, /).first.strip
end
File.open("stacktrace.txt", 'w') { |f| f.write(stacktrace) }
end