cutest-cj 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/cutest +2 -2
- data/lib/cutest.rb +99 -78
- data/lib/database.rb +79 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e0da3c613aef3fc93c3ac27ed1b87d7c6692e48
|
4
|
+
data.tar.gz: b88f125813019b0f2fad5f17d8ffa01d906bff7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 869dd7f32331cef95d6d466ed1352e6f1cfdb533d9eab5fde59a347d9c899b7df7348977575117098ad7a299e5f621cd09b518d68d93216a980fe7881c7bc0e5
|
7
|
+
data.tar.gz: 93e979f6511b572a51533f3271e259c380e8cf25672a2fb9f552b5bcda53e26dd171066586cda7c4d28491dd89efd90a0394e4bffba6fe9991d60d39c8862ad8
|
data/bin/cutest
CHANGED
@@ -7,9 +7,9 @@ if ARGV.empty?
|
|
7
7
|
exit
|
8
8
|
end
|
9
9
|
|
10
|
-
require_relative "../lib/cutest"
|
11
10
|
require "clap"
|
12
11
|
require "mocoso"
|
12
|
+
require_relative "../lib/cutest"
|
13
13
|
|
14
14
|
files = Clap.run ARGV,
|
15
15
|
"-r" => lambda { |file| require file },
|
@@ -25,7 +25,7 @@ files = Clap.run ARGV,
|
|
25
25
|
if files.any?
|
26
26
|
begin
|
27
27
|
env = '.env'
|
28
|
-
rack_env = "
|
28
|
+
rack_env = "#{env}.#{ENV['RACK_ENV']}"
|
29
29
|
|
30
30
|
if File.file? rack_env
|
31
31
|
Cutest.load_envs rack_env
|
data/lib/cutest.rb
CHANGED
@@ -1,112 +1,131 @@
|
|
1
1
|
require 'benchmark'
|
2
|
+
require 'ostruct'
|
2
3
|
|
3
4
|
class Cutest
|
5
|
+
autoload :Database, 'database'
|
6
|
+
|
4
7
|
unless defined?(VERSION)
|
5
|
-
VERSION = "1.3.
|
8
|
+
VERSION = "1.3.1"
|
6
9
|
FILTER = %r[/(ruby|jruby|rbx)[-/]([0-9\.])+]
|
7
10
|
CACHE = Hash.new { |h, k| h[k] = File.readlines(k) }
|
8
11
|
end
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
13
|
+
class AssertionFailed < StandardError; end
|
14
|
+
|
15
|
+
class << self
|
16
|
+
|
17
|
+
attr_accessor :config, :reset_config
|
18
|
+
|
19
|
+
def setup
|
20
|
+
yield config
|
14
21
|
end
|
15
|
-
end
|
16
22
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
ensure
|
21
|
-
$VERBOSE = old_verbose
|
22
|
-
end
|
23
|
+
def config
|
24
|
+
@config || reset_config!
|
25
|
+
end
|
23
26
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
27
|
+
def reset_config!
|
28
|
+
@config = OpenStruct.new database: {}
|
29
|
+
end
|
30
|
+
|
31
|
+
def load_envs env
|
32
|
+
File.foreach env do |line|
|
33
|
+
key, value = line.split "="
|
34
|
+
ENV[key] = value.gsub('\n', '').strip
|
28
35
|
end
|
29
|
-
else
|
30
|
-
Cutest.now_run files
|
31
36
|
end
|
32
|
-
end
|
33
37
|
|
34
|
-
|
35
|
-
|
36
|
-
|
38
|
+
def silence_warnings
|
39
|
+
old_verbose, $VERBOSE = $VERBOSE, nil
|
40
|
+
yield
|
41
|
+
ensure
|
42
|
+
$VERBOSE = old_verbose
|
43
|
+
end
|
37
44
|
|
38
|
-
|
45
|
+
def run(files)
|
46
|
+
if !cutest[:warnings]
|
47
|
+
Cutest.silence_warnings do
|
48
|
+
Cutest.now_run files
|
49
|
+
end
|
50
|
+
else
|
51
|
+
Cutest.now_run files
|
52
|
+
end
|
39
53
|
end
|
40
54
|
|
41
|
-
|
55
|
+
def now_run files
|
56
|
+
status = files.all? do |file|
|
57
|
+
run_file(file)
|
42
58
|
|
43
|
-
|
44
|
-
|
59
|
+
Process.wait2.last.success?
|
60
|
+
end
|
45
61
|
|
46
|
-
|
47
|
-
fork do
|
48
|
-
begin
|
49
|
-
load(file)
|
50
|
-
rescue LoadError, SyntaxError
|
51
|
-
display_error
|
52
|
-
exit 1
|
53
|
-
|
54
|
-
rescue StandardError
|
55
|
-
trace = $!.backtrace
|
56
|
-
pivot = trace.index { |line| line.match(file) }
|
57
|
-
|
58
|
-
puts " \e[93mTest: \e[0m%s\e[31m✘\e[0m\n" % (cutest[:test] != '' ? "#{cutest[:test]} " : '')
|
59
|
-
|
60
|
-
if pivot
|
61
|
-
other = trace[0..pivot].select { |line| line !~ FILTER }
|
62
|
-
other.reverse.each { |line| display_trace(line) }
|
63
|
-
else
|
64
|
-
display_trace(trace.first)
|
65
|
-
end
|
62
|
+
puts
|
66
63
|
|
67
|
-
|
64
|
+
status
|
65
|
+
end
|
68
66
|
|
69
|
-
|
67
|
+
def run_file(file)
|
68
|
+
fork do
|
69
|
+
begin
|
70
|
+
load(file)
|
71
|
+
rescue LoadError, SyntaxError
|
72
|
+
display_error
|
70
73
|
exit 1
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
74
|
+
|
75
|
+
rescue StandardError
|
76
|
+
trace = $!.backtrace
|
77
|
+
pivot = trace.index { |line| line.match(file) }
|
78
|
+
|
79
|
+
puts " \e[93mTest: \e[0m%s\e[31m✘\e[0m\n" % (cutest[:test] != '' ? "#{cutest[:test]} " : '')
|
80
|
+
|
81
|
+
if pivot
|
82
|
+
other = trace[0..pivot].select { |line| line !~ FILTER }
|
83
|
+
other.reverse.each { |line| display_trace(line) }
|
84
|
+
else
|
85
|
+
display_trace(trace.first)
|
86
|
+
end
|
87
|
+
|
88
|
+
display_error
|
89
|
+
|
90
|
+
if not cutest[:pry_rescue]
|
91
|
+
exit 1
|
92
|
+
else
|
93
|
+
begin
|
94
|
+
Process.waitall
|
95
|
+
rescue ThreadError, Interrupt
|
96
|
+
# Ignore this as it's caused by Process.waitall when using -p
|
97
|
+
end
|
76
98
|
end
|
77
99
|
end
|
78
100
|
end
|
79
101
|
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def self.code(fn, ln)
|
83
|
-
begin
|
84
|
-
CACHE[fn][ln.to_i - 1].strip
|
85
|
-
rescue
|
86
|
-
"(Can't display line)"
|
87
|
-
end
|
88
|
-
end
|
89
102
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
103
|
+
def code(fn, ln)
|
104
|
+
begin
|
105
|
+
CACHE[fn][ln.to_i - 1].strip
|
106
|
+
rescue
|
107
|
+
"(Can't display line)"
|
95
108
|
end
|
96
109
|
end
|
97
110
|
|
98
|
-
|
99
|
-
|
100
|
-
|
111
|
+
def display_error
|
112
|
+
if cutest[:backtrace]
|
113
|
+
bt = $!.backtrace
|
114
|
+
bt.each do |line|
|
115
|
+
display_trace line
|
116
|
+
end
|
117
|
+
end
|
101
118
|
|
102
|
-
|
103
|
-
|
119
|
+
puts " \033[93m#{$!.class}: \033[31m#{$!.message}"
|
120
|
+
puts ""
|
121
|
+
end
|
104
122
|
|
105
|
-
|
106
|
-
|
107
|
-
end
|
123
|
+
def display_trace(line)
|
124
|
+
fn, ln = line.split(":")
|
108
125
|
|
109
|
-
|
126
|
+
puts " → \033[0mfile: #{fn} ↪#{ln}\e[0m"
|
127
|
+
puts " → \033[90mline: #{code(fn, ln)}\e[0m"
|
128
|
+
end
|
110
129
|
end
|
111
130
|
|
112
131
|
class Scope
|
@@ -184,10 +203,12 @@ module Kernel
|
|
184
203
|
cutest[:test] = name
|
185
204
|
|
186
205
|
if !cutest[:only] || cutest[:only] == name
|
206
|
+
print ' '
|
187
207
|
time_taken = Benchmark.measure do
|
188
208
|
prepare.each { |blk| blk.call }
|
189
209
|
block.call(setup && setup.call)
|
190
|
-
|
210
|
+
end
|
211
|
+
puts ''
|
191
212
|
puts " \033[93mTest: \033[0m#{cutest[:test]} \033[32m✔\033[0m"
|
192
213
|
puts "\e[94m#{time_taken}\033[0m"
|
193
214
|
end
|
@@ -229,6 +250,6 @@ module Kernel
|
|
229
250
|
|
230
251
|
# Executed when an assertion succeeds.
|
231
252
|
def success
|
232
|
-
|
253
|
+
print "•"
|
233
254
|
end
|
234
255
|
end
|
data/lib/database.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
class Cutest
|
2
|
+
module Database
|
3
|
+
extend self
|
4
|
+
|
5
|
+
module Helper
|
6
|
+
require 'active_record'
|
7
|
+
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def factory *attrs
|
13
|
+
attrs.each do |key, value|
|
14
|
+
if key.is_a? Hash
|
15
|
+
key.each do |k, v|
|
16
|
+
send("#{k}=", v) unless send("#{k}").present?
|
17
|
+
end
|
18
|
+
else
|
19
|
+
send("#{key}=", value) unless send("#{key}").present?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
if respond_to?(:creator_id) and not creator_id
|
24
|
+
self.creator_id = Cutest.config.creator_id
|
25
|
+
end
|
26
|
+
|
27
|
+
if respond_to?(:updater_id) and not updater_id
|
28
|
+
self.updater_id = Cutest.config.updater_id
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def reset
|
34
|
+
connect
|
35
|
+
|
36
|
+
ignore_tables = %w(schema_migrations)
|
37
|
+
|
38
|
+
if config.key? :ignore_tables
|
39
|
+
ignore_tables.concat config[:ignore_tables]
|
40
|
+
end
|
41
|
+
|
42
|
+
conn = ActiveRecord::Base.connection
|
43
|
+
tables = conn.execute("show tables").map { |r| r[0] }
|
44
|
+
|
45
|
+
tables.each do |t|
|
46
|
+
unless ignore_tables.include? t
|
47
|
+
conn.execute("SET FOREIGN_KEY_CHECKS = 0")
|
48
|
+
conn.execute("TRUNCATE #{t}")
|
49
|
+
conn.execute("SET FOREIGN_KEY_CHECKS = 1")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def connect
|
55
|
+
return if ActiveRecord::Base.connected?
|
56
|
+
|
57
|
+
ActiveRecord::Base.default_timezone = Time.zone
|
58
|
+
|
59
|
+
db = URI.parse config[:url]
|
60
|
+
|
61
|
+
ActiveRecord::Base.establish_connection(
|
62
|
+
adapter: db.scheme == 'postgres' ? 'postgresql' : db.scheme,
|
63
|
+
encoding: 'utf8',
|
64
|
+
reconnect: true,
|
65
|
+
database: db.path[1..-1],
|
66
|
+
host: db.host,
|
67
|
+
port: db.port,
|
68
|
+
username: db.user,
|
69
|
+
password: db.password,
|
70
|
+
)
|
71
|
+
end
|
72
|
+
|
73
|
+
def config
|
74
|
+
Cutest.config.database
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
ActiveRecord::Base.send :include, Cutest::Database::Helper
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cutest-cj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damian Janowski
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-06-
|
13
|
+
date: 2014-06-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: pry
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- bin/cutest
|
87
87
|
- cutest.gemspec
|
88
88
|
- lib/cutest.rb
|
89
|
+
- lib/database.rb
|
89
90
|
- test/assert.rb
|
90
91
|
- test/assert_equal.rb
|
91
92
|
- test/assert_raise.rb
|