oktest 1.4.0 → 1.5.0

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
  SHA256:
3
- metadata.gz: 66c4df474c029dfbb1e598274d8959e742fab20f1e158d53ac8c4d6a1bb815ce
4
- data.tar.gz: 4e9b1c680b335a2ae4fcc8b4e698ace15ab5df9f42a143e998c7b2556b5f8f15
3
+ metadata.gz: 71a8ad713c8536b57d4ed59541ea7a734da36187f502566aefee6479b3858e5f
4
+ data.tar.gz: e55ae061182626cab3b75559a0353d13fdbe5042f119a035474e6c28be311798
5
5
  SHA512:
6
- metadata.gz: c35a5ede9c4b9ce53c458bb18f4871782078ff933f6133b369b1058bd122a2f4d0e0f823b0e2f8e6a81fb42560d3c4a6710cead958db4ae1d9c0a53c97131255
7
- data.tar.gz: b739cc6de446f83a92e87119c29c53022376b18495e211c555c03d2f16e82d03f465b343709b93c320f0718c3df585cca5f33d189770d37f84ad77840d5aeca3
6
+ metadata.gz: 579a24fb8c2847bbd53805367d36176cd09fbeacc2b5690212589108517ba19f809fea79a6bfb2b07e87ff83925ef8ea9aa18a0eb420a775683f1876bf60f3e8
7
+ data.tar.gz: 0a3f94d919a328d8d8bfdc19da5e512e2896252df6dba80d2775fc5fedaed245b1465553c56541c110eb79cd2b68dd3cb5aea0685fe89e7b555b02efa7a2fcde
data/README.md CHANGED
@@ -96,6 +96,8 @@ Oktest.rb requires Ruby 2.4 or later.
96
96
  * <a href="#complex-example">Complex Example</a>
97
97
  * <a href="#helper-methods-for-json-matcher">Helper Methods for JSON Matcher</a>
98
98
  * <a href="#tips">Tips</a>
99
+ * <a href="#oktesttopic"><code>Oktest.topic()</code></a>
100
+ * <a href="#topic-target">Topic target</a>
99
101
  * <a href="#ok--in-minitest"><code>ok {}</code> in MiniTest</a>
100
102
  * <a href="#testing-rack-application">Testing Rack Application</a>
101
103
  * <a href="#environment-variale-oktest_rb">Environment Variale <code>$OKTEST_RB</code></a>
@@ -1904,8 +1906,8 @@ Oktest.scope do
1904
1906
  "id": 1000..9999, # range object
1905
1907
  "age": Integer, # class object
1906
1908
  "email": /^\w+@example\.com$/, # regexp
1907
- "gender": Set.new(["M", "F"]), # Set object ("M" or "F")
1908
- "deleted": Set.new([true, false]), # boolean (true or false)
1909
+ "gender": Set["M", "F"], # Set object ("M" or "F")
1910
+ "deleted": Set[true, false], # boolean (true or false)
1909
1911
  "tags": [/^\w+$/].each, # Enumerator object (!= Array obj)
1910
1912
  "twitter?": /^@\w+$/, # key 'xxx?' means optional value
1911
1913
  }
@@ -1980,7 +1982,7 @@ Oktest.scope do
1980
1982
  {
1981
1983
  "team": String,
1982
1984
  "members": [
1983
- {"id": 1000..9999, "name": String, "gender": Set.new(["M", "F"])}
1985
+ {"id": 1000..9999, "name": String, "gender": Set["M", "F"]}
1984
1986
  ].each, # Enumerator object (!= Array obj)
1985
1987
  "leader?": String, # key 'xxx?' means optional value
1986
1988
  }
@@ -2061,7 +2063,7 @@ ok {JSON({"val": 99 })} === {"val": 1..100} # implies Integer value
2061
2063
 
2062
2064
  Oktest.rb provides some helper methods and objects:
2063
2065
 
2064
- * `Enum(x, y, z)` is almost same as `Set.new([x, y, z])`.
2066
+ * `Enum(x, y, z)` is almost same as `Set[x, y, z]`.
2065
2067
  * `Bool()` is same as `Enum(true, false)`.
2066
2068
  * `Length(3)` matches to length 3, and `Length(1..3)` matches to length 1..3.
2067
2069
 
@@ -2071,7 +2073,7 @@ test/example44_test.rb:
2071
2073
  ```ruby
2072
2074
  actual = {"gender": "M", "deleted": false, "code": "ABCD1234"}
2073
2075
  ok {JSON(actual)} == {
2074
- "gender": Enum("M", "F"), # same as Set.new(["M", "F"])
2076
+ "gender": Enum("M", "F"), # same as Set["M", "F"]
2075
2077
  "deleted": Bool(), # same as Enum(true, false)
2076
2078
  "code": Length(6..10), # code length should be 6..10
2077
2079
  }
@@ -2082,6 +2084,41 @@ test/example44_test.rb:
2082
2084
  ## Tips
2083
2085
 
2084
2086
 
2087
+ ### `Oktest.topic()`
2088
+
2089
+ If you want to reduce nested block depth, `Oktest.topic()` will help you.
2090
+
2091
+ ```ruby
2092
+ ## This...
2093
+ Oktest.topic HelloClass do
2094
+ ...
2095
+ end
2096
+
2097
+ ## ...is equivarent to...
2098
+ Oktest.scope do
2099
+ Oktest.toic HelloClass do
2100
+ ...
2101
+ end
2102
+ end
2103
+ ```
2104
+
2105
+ (Since Oktest >= 1.5)
2106
+
2107
+
2108
+ ### Topic target
2109
+
2110
+ `topic()` passes an target argument to the block.
2111
+
2112
+ ```ruby
2113
+ topic '/api/orders/{id}' do |urlpath|
2114
+ p urlpath #=> "/api/orders/{id}"
2115
+ ...
2116
+ end
2117
+ ```
2118
+
2119
+ (Since Oktest >= 1.5)
2120
+
2121
+
2085
2122
  ### `ok {}` in MiniTest
2086
2123
 
2087
2124
  If you want to use `ok {actual} == expected` style assertion in MiniTest,
data/Rakefile.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  ###
4
- ### $Release: 1.4.0 $
4
+ ### $Release: 1.5.0 $
5
5
  ### $Copyright: copyright(c) 2011-2024 kuwata-lab.com all rights reserved $
6
6
  ### $License: MIT License $
7
7
  ###
data/lib/oktest.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  ###
5
- ### $Release: 1.4.0 $
5
+ ### $Release: 1.5.0 $
6
6
  ### $Copyright: copyright(c) 2011-2024 kuwata-lab.com all rights reserved $
7
7
  ### $License: MIT License $
8
8
  ###
@@ -13,7 +13,7 @@ require 'set'
13
13
  module Oktest
14
14
 
15
15
 
16
- VERSION = '$Release: 1.4.0 $'.split()[1]
16
+ VERSION = '$Release: 1.5.0 $'.split()[1]
17
17
 
18
18
 
19
19
  class OktestError < StandardError
@@ -1125,6 +1125,13 @@ END
1125
1125
  attr_reader :target
1126
1126
  attr_writer :_prefix
1127
1127
 
1128
+ def run_block_in_context_class(&block)
1129
+ #; [!i2kvj] run block in context class.
1130
+ #; [!pr3vj] run block with topic target as an argument.
1131
+ target = @target
1132
+ @context_class.class_exec(target, &block)
1133
+ end
1134
+
1128
1135
  def _prefix
1129
1136
  @_prefix || '*'
1130
1137
  end
@@ -1234,6 +1241,13 @@ END
1234
1241
  @_in_scope = false
1235
1242
  end
1236
1243
 
1244
+ def self.topic(target, &block)
1245
+ #; [!c5j3f] same as `Oktest.scope do topic target do ... end end`.
1246
+ self.scope do
1247
+ topic(target, &block)
1248
+ end
1249
+ end
1250
+
1237
1251
 
1238
1252
  module SpecHelper
1239
1253
 
@@ -2168,9 +2182,6 @@ END
2168
2182
  end
2169
2183
 
2170
2184
 
2171
- REPORTER_CLASS = VerboseReporter
2172
-
2173
-
2174
2185
  REPORTER_CLASSES = {
2175
2186
  'verbose' => VerboseReporter, 'v' => VerboseReporter,
2176
2187
  'simple' => SimpleReporter, 's' => SimpleReporter,
@@ -2179,10 +2190,22 @@ END
2179
2190
  'quiet' => QuietReporter, 'q' => QuietReporter,
2180
2191
  }
2181
2192
 
2193
+ DEFAULT_REPORTING_STYLE = 'verbose'
2194
+
2195
+ def self.DEFAULT_REPORTING_STYLE=(style)
2196
+ #; [!lbufd] raises error if unknown style specified.
2197
+ REPORTER_CLASSES.key?(style) or
2198
+ raise ArgumentError, "#{style}: Unknown reporting style."
2199
+ #; [!dsbmo] changes value of default reporting style.
2200
+ remove_const :DEFAULT_REPORTING_STYLE
2201
+ const_set :DEFAULT_REPORTING_STYLE, style
2202
+ end
2203
+
2182
2204
 
2183
2205
  def self.run(reporter: nil, style: nil)
2184
2206
  #; [!6xn3t] creates reporter object according to 'style:' keyword arg.
2185
- klass = (style ? REPORTER_CLASSES[style] : REPORTER_CLASS) or
2207
+ style ||= DEFAULT_REPORTING_STYLE
2208
+ klass = REPORTER_CLASSES[style] or
2186
2209
  raise ArgumentError, "#{style.inspect}: unknown style."
2187
2210
  reporter ||= klass.new
2188
2211
  #; [!mn451] run test cases.
@@ -2490,12 +2513,12 @@ END
2490
2513
  public
2491
2514
 
2492
2515
  def filter_children!(node)
2493
- _filter_children!(node)
2516
+ _filter_children!(node, 0)
2494
2517
  end
2495
2518
 
2496
2519
  private
2497
2520
 
2498
- def _filter_children!(node) #:nodoc:
2521
+ def _filter_children!(node, _depth) #:nodoc:
2499
2522
  #; [!r6g6a] supports negative filter by topic.
2500
2523
  #; [!doozg] supports negative filter by spec.
2501
2524
  #; [!ntv44] supports negative filter by tag name.
@@ -2516,7 +2539,7 @@ END
2516
2539
  removes << i unless positive
2517
2540
  #; [!mz6id] can filter nested topics.
2518
2541
  elsif item.is_a?(Node)
2519
- removes << i unless _filter_children!(item)
2542
+ removes << i unless _filter_children!(item, _depth+1)
2520
2543
  #; [!1jphf] can filter specs from nested topics.
2521
2544
  elsif item.is_a?(SpecLeaf)
2522
2545
  removes << i if positive
data/oktest.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  ###
4
- ### $Release: 1.4.0 $
4
+ ### $Release: 1.5.0 $
5
5
  ### $License: MIT License $
6
6
  ### $Copyright: copyright(c) 2011-2024 kuwata-lab.com all rights reserved $
7
7
  ###
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.name = "oktest"
14
14
  s.author = "kwatch"
15
15
  s.email = "kwatch@gmail.com"
16
- s.version = "$Release: 1.4.0 $".split()[1]
16
+ s.version = "$Release: 1.5.0 $".split()[1]
17
17
  s.license = "MIT"
18
18
  s.platform = Gem::Platform::RUBY
19
19
  s.homepage = "https://github.com/kwatch/oktest/tree/ruby/ruby"
@@ -41,5 +41,5 @@ END
41
41
  s.files = files
42
42
  s.executables = ['oktest']
43
43
  s.bindir = 'bin'
44
- s.test_file = 'test/run_all.rb'
44
+ s.test_file = 'test/all.rb'
45
45
  end