ftest 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5738d3080893d015b14e3ce706c0d4dab1f20319
4
- data.tar.gz: c4ae4ac2674e3afcd9b0fabc1e8dd8cc0e0f7aba
3
+ metadata.gz: 7bfcd5052fd652390aed5654ef14e7cc10e4c395
4
+ data.tar.gz: 66de21d81e67dc06e70bbbe5f740c9f190b87092
5
5
  SHA512:
6
- metadata.gz: 516e5a0a8d5910a9347b4e09eb12f25e6226fc76d2a4e8ba31acd56d2d960e37cc4b17e2c9aa627422287d085a71a58a1ae5bf7a35743154c472aa03709c9d11
7
- data.tar.gz: aa759bfee38c2c92ab08da83ae723a1e30c3501a87335e5d56d3a09cf2c61656a2078a538cb7f644991c199aeb54b0060d66686a08796168b7a56816ebe338bc
6
+ metadata.gz: 4daaea4200efd5fd14457617934d1c826cb153a57c03eeea1cdd0a0bfebabb0b717dee76d84f9ab9bb61da69bff911670e25d6908a54a02b7df67d8922fc1c85
7
+ data.tar.gz: e100fb037ddb93e2db9e7ff47c2636e28329536443d1eff2c906b02b2c32f30186ef59fb37ac209e1e8d33a1672d7b6248eda57658ca3e5aefe593527267c259
@@ -23,10 +23,13 @@ module FTest
23
23
  Config.logger
24
24
  end
25
25
 
26
- # Describe can help break up a larger test script into chunks. Blocks are run
27
- # immediately; this is a pure cosmetic enhancement.
28
- def describe msg
29
- yield
26
+ # Describe, context, it, and specify can help break up a larger test script
27
+ # into chunks. Blocks are run # immediately; this is cosmetic enhancement
28
+ # that also enables some degree of compatibility with other frameworks.
29
+ %i(context describe it specify).each do |method_name|
30
+ define_method method_name do |msg, &blk|
31
+ blk.() if blk
32
+ end
30
33
  end
31
34
 
32
35
  def self.included target
@@ -17,7 +17,7 @@ module FTest
17
17
  def call
18
18
  @options = ArgvParser.(@argv)
19
19
  setup_config
20
- Runner.(resolve_files) or exit 1
20
+ Runner.(filter_files) or exit 1
21
21
  end
22
22
 
23
23
  def setup_config
@@ -35,6 +35,12 @@ module FTest
35
35
  logger
36
36
  end
37
37
 
38
+ def filter_files
39
+ resolve_files.reject do |path|
40
+ path.end_with? "init.rb"
41
+ end
42
+ end
43
+
38
44
  def resolve_files
39
45
  options.paths.flat_map do |path|
40
46
  if path.end_with? ".rb"
@@ -153,6 +159,10 @@ If no PATH(s) are specified, ./tests is assumed
153
159
  exit 0
154
160
  end
155
161
 
162
+ opts.on "-m", "--monkeypatch", "Turn on monkeypatching (equivalent to `require \"ftest/script\"'" do
163
+ require "ftest/script"
164
+ end
165
+
156
166
  opts.on "-n", "--num=COUNT", "Max number of sub processes to run concurrently" do |num|
157
167
  @options.child_count = num
158
168
  end
@@ -0,0 +1,62 @@
1
+ module FTest
2
+ class ColoredLogger
3
+ ANSI_COLORS = %i(black red green yellow blue magenta cyan white)
4
+
5
+ DEFAULT_PALETTE = {
6
+ :unknown => -> msg { bg(:blue, :bright, fg(:white, :bright, msg)) },
7
+ :fatal => -> msg { bg(:red, :bright, fg(:white, :bright, msg)) },
8
+ :error => -> msg { fg(:red, :bright, msg) },
9
+ :warn => -> msg { fg(:yellow, :bright, msg) },
10
+ :info => -> msg { fg(:default, :normal, msg) },
11
+ :debug => -> msg { fg(:cyan, :bright, msg) },
12
+ }
13
+
14
+ attr_reader :palette
15
+
16
+ def initialize io, palette = DEFAULT_PALETTE
17
+ @logger = Logger.new io
18
+ @palette = palette
19
+ end
20
+
21
+ %i(level= progname=).each do |method_name|
22
+ define_method method_name do |*args, &block|
23
+ @logger.public_send method_name, *args, &block
24
+ end
25
+ end
26
+
27
+ %i(unknown fatal error warn info debug).each do |log_level|
28
+ define_method log_level do |msg_or_progname = nil, &orig_block|
29
+ colored_msg = format log_level, msg_or_progname
30
+
31
+ if orig_block
32
+ progname = colored_msg
33
+ block = -> do format log_level, orig_block.() end
34
+ else
35
+ block = -> do colored_msg end
36
+ end
37
+
38
+ @logger.public_send log_level, progname, &block
39
+ end
40
+ end
41
+
42
+ def format log_level, msg
43
+ formatter = palette.fetch log_level
44
+ instance_exec msg, &formatter
45
+ end
46
+
47
+ def fg *args
48
+ col :fg, *args
49
+ end
50
+
51
+ def bg *args
52
+ col :bg, *args
53
+ end
54
+
55
+ def col fgbg, color_code, intensity_code, str
56
+ color_num = ANSI_COLORS.index color_code
57
+ intensity_num = { :normal => 0, :bright => 1 }.fetch intensity_code
58
+ fgbg_num = { :fg => 3, :bg => 4 }.fetch fgbg
59
+ "\e[#{fgbg_num}#{color_num};#{intensity_num}m#{str}\e[0m"
60
+ end
61
+ end
62
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ftest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Ladd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-17 00:00:00.000000000 Z
11
+ date: 2015-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logger-logging
@@ -42,6 +42,7 @@ files:
42
42
  - lib/ftest/assert/syntax.rb
43
43
  - lib/ftest/backtrace_filter.rb
44
44
  - lib/ftest/cli.rb
45
+ - lib/ftest/colored_logger.rb
45
46
  - lib/ftest/config.rb
46
47
  - lib/ftest/runner.rb
47
48
  - lib/ftest/script.rb