brutal 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +17 -16
- data/bin/brutal +1 -1
- data/lib/brutal.rb +3 -0
- data/lib/brutal/framework/base.rb +5 -0
- data/lib/brutal/framework/por.rb +41 -0
- metadata +3 -3
- data/lib/brutal/framework/poro.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52cb0e853f0cb1644e497b1566b675da404cf9e0570ef449862b03edc8764bac
|
4
|
+
data.tar.gz: 99cd7cb1d648fc3275d811eb41cb5a820bc5c82bce9c9a19b6834677c5626e6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7605a2eb8219c17786724d1129b64a0863e6113c07025d07c5e9a67c16dc6ff42234d553fbfa9e1f940b31142cae729a36749a841496d92f520cd2342e54f44
|
7
|
+
data.tar.gz: f6418c02326b3d52c8436ea640575b154e0c4299940e5907f8842af9d49c68854d5cc2b33b27d212e76c373946833ee7e0f52b22cffbf0665117b82aae2866c7
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
> Brutal test suite scaffold generator
|
4
4
|
|
5
|
-

|
5
|
+

|
6
6
|
|
7
7
|
[][travis]
|
8
8
|
[][gem]
|
@@ -25,7 +25,7 @@ Or install it yourself as:
|
|
25
25
|
|
26
26
|
$ gem install brutal
|
27
27
|
|
28
|
-
##
|
28
|
+
## Quick Start
|
29
29
|
|
30
30
|
Just type `brutal` in a Ruby project's folder and watch the magic happen.
|
31
31
|
|
@@ -43,6 +43,7 @@ The Brutal YAML file handles 4 keys:
|
|
43
43
|
Given this `.brutal.yml` config file:
|
44
44
|
|
45
45
|
```yaml
|
46
|
+
---
|
46
47
|
header: |
|
47
48
|
# Some string concatenation unit tests
|
48
49
|
|
@@ -59,8 +60,8 @@ variables:
|
|
59
60
|
- ...
|
60
61
|
|
61
62
|
challenges:
|
62
|
-
- .to_s
|
63
|
-
- .length
|
63
|
+
- "%{actual}.to_s"
|
64
|
+
- "%{actual}.length"
|
64
65
|
```
|
65
66
|
|
66
67
|
The `brutal` command would generate the following file:
|
@@ -70,31 +71,31 @@ The `brutal` command would generate the following file:
|
|
70
71
|
|
71
72
|
# ------------------------------------------------------------------------------
|
72
73
|
|
73
|
-
|
74
|
+
actual = "Hello" + "!"
|
74
75
|
|
75
|
-
raise unless
|
76
|
-
raise unless
|
76
|
+
raise unless actual.to_s == "Hello!"
|
77
|
+
raise unless actual.length == 6
|
77
78
|
|
78
79
|
# ------------------------------------------------------------------------------
|
79
80
|
|
80
|
-
|
81
|
+
actual = "Hello" + "..."
|
81
82
|
|
82
|
-
raise unless
|
83
|
-
raise unless
|
83
|
+
raise unless actual.to_s == "Hello..."
|
84
|
+
raise unless actual.length == 8
|
84
85
|
|
85
86
|
# ------------------------------------------------------------------------------
|
86
87
|
|
87
|
-
|
88
|
+
actual = "Hello" + ", Bob!"
|
88
89
|
|
89
|
-
raise unless
|
90
|
-
raise unless
|
90
|
+
raise unless actual.to_s == "Hello, Bob!"
|
91
|
+
raise unless actual.length == 11
|
91
92
|
|
92
93
|
# ------------------------------------------------------------------------------
|
93
94
|
|
94
|
-
|
95
|
+
actual = "Hello" + ", Bob..."
|
95
96
|
|
96
|
-
raise unless
|
97
|
-
raise unless
|
97
|
+
raise unless actual.to_s == "Hello, Bob..."
|
98
|
+
raise unless actual.length == 13
|
98
99
|
```
|
99
100
|
|
100
101
|
## Integration with Rake
|
data/bin/brutal
CHANGED
data/lib/brutal.rb
CHANGED
@@ -1,14 +1,19 @@
|
|
1
1
|
module Brutal
|
2
2
|
module Framework
|
3
3
|
class Base
|
4
|
+
# @api private
|
4
5
|
attr_reader :subject, :challenges, :variables
|
5
6
|
|
7
|
+
# Initialize a new framework
|
6
8
|
def initialize(subject, *challenges, **variables)
|
7
9
|
@subject = subject
|
8
10
|
@challenges = challenges
|
9
11
|
@variables = variables
|
10
12
|
end
|
11
13
|
|
14
|
+
# Return a string representation
|
15
|
+
#
|
16
|
+
# @api private
|
12
17
|
def to_s
|
13
18
|
raise ::NotImplementedError
|
14
19
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
module Brutal
|
4
|
+
module Framework
|
5
|
+
# Plain Old Ruby
|
6
|
+
class Por < Base
|
7
|
+
# Return a string representation
|
8
|
+
#
|
9
|
+
# @return [String]
|
10
|
+
#
|
11
|
+
# @api public
|
12
|
+
def to_s
|
13
|
+
names = variables.keys.sort
|
14
|
+
values_arr = names.map { |name| variables.fetch(name) }
|
15
|
+
test_params = Array(values_arr[0]).product(*Array(values_arr[1..-1]))
|
16
|
+
|
17
|
+
test_params.inject('') do |string, values|
|
18
|
+
attributes = names.each_with_index.inject({}) do |h, (name, i)|
|
19
|
+
h.merge(name.to_sym => values.fetch(i))
|
20
|
+
end
|
21
|
+
|
22
|
+
actual_str = subject % attributes
|
23
|
+
|
24
|
+
string += "\n" \
|
25
|
+
"# #{('-' * 78)}\n" \
|
26
|
+
"\n" \
|
27
|
+
"actual = #{actual_str}\n"
|
28
|
+
|
29
|
+
actual = eval(actual_str)
|
30
|
+
|
31
|
+
challenges.each do |challenge|
|
32
|
+
result = challenge % { actual: 'actual' }
|
33
|
+
string += "raise unless #{result} == #{eval(result).inspect}\n"
|
34
|
+
end
|
35
|
+
|
36
|
+
string
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brutal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyril Kato
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -110,7 +110,7 @@ files:
|
|
110
110
|
- bin/setup
|
111
111
|
- lib/brutal.rb
|
112
112
|
- lib/brutal/framework/base.rb
|
113
|
-
- lib/brutal/framework/
|
113
|
+
- lib/brutal/framework/por.rb
|
114
114
|
homepage: https://github.com/cyril/brutal.rb
|
115
115
|
licenses:
|
116
116
|
- MIT
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require_relative 'base'
|
2
|
-
|
3
|
-
module Brutal
|
4
|
-
module Framework
|
5
|
-
class Poro < Base
|
6
|
-
def to_s
|
7
|
-
names = variables.keys.sort
|
8
|
-
values_arr = names.map { |name| variables.fetch(name) }
|
9
|
-
test_params = Array(values_arr[0]).product(*Array(values_arr[1..-1]))
|
10
|
-
|
11
|
-
test_params.inject('') do |scaffold, values|
|
12
|
-
attributes = names.each_with_index.inject({}) do |h, (name, i)|
|
13
|
-
h.merge(name.to_sym => values.fetch(i))
|
14
|
-
end
|
15
|
-
|
16
|
-
populated_subject = subject % attributes
|
17
|
-
result = eval(populated_subject)
|
18
|
-
|
19
|
-
scaffold += "\n# " + ('-' * 78) + "\n\nresult = #{populated_subject}\n"
|
20
|
-
|
21
|
-
challenges.each do |challenge|
|
22
|
-
value = "result#{challenge}"
|
23
|
-
scaffold += "raise unless #{value} == #{eval(value).inspect}\n"
|
24
|
-
end
|
25
|
-
|
26
|
-
scaffold
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|