brutal 0.1.0 → 0.2.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: 6a587ca80409c91605c6f0045e4f3b8b40f517b755e196748f0fc8dba6bff6e9
4
- data.tar.gz: 722b740531d4046ef5c3a639e93aa0c9edcfa362f63d43dfe77ae37ab9ee9062
3
+ metadata.gz: 52cb0e853f0cb1644e497b1566b675da404cf9e0570ef449862b03edc8764bac
4
+ data.tar.gz: 99cd7cb1d648fc3275d811eb41cb5a820bc5c82bce9c9a19b6834677c5626e6a
5
5
  SHA512:
6
- metadata.gz: e3147d44673898eee50b89db97c2f6ad19a48dd64b1c5df8c023ca64fe554a7d0a787f0f3241eb8e613aec2af59b50cda7331814807c80c1d2fed6ab833fac85
7
- data.tar.gz: 5e5d91e3d1139fae44f148632d6c94c944e407bf75c684db73ebc7cc15fa804855d90f2e6606280cafdf42d0a630a5a48068a0df45c32311ec2f85096345576c
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
- ![A lumberjack brutally cutting a tree.](img/Ferdinand_Hodler_-_Woodcutter_-_Google_Art_Project.jpg)
5
+ ![A lumberjack brutally cutting a tree.](https://raw.githubusercontent.com/cyril/brutal.rb/master/img/Ferdinand_Hodler_-_Woodcutter_-_Google_Art_Project.jpg)
6
6
 
7
7
  [![Build Status](https://api.travis-ci.org/cyril/brutal.rb.svg?branch=master)][travis]
8
8
  [![Gem Version](https://badge.fury.io/rb/brutal.svg)][gem]
@@ -25,7 +25,7 @@ Or install it yourself as:
25
25
 
26
26
  $ gem install brutal
27
27
 
28
- ## QuickStart
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
- result = "Hello" + "!"
74
+ actual = "Hello" + "!"
74
75
 
75
- raise unless result.to_s == "Hello!"
76
- raise unless result.length == 6
76
+ raise unless actual.to_s == "Hello!"
77
+ raise unless actual.length == 6
77
78
 
78
79
  # ------------------------------------------------------------------------------
79
80
 
80
- result = "Hello" + "..."
81
+ actual = "Hello" + "..."
81
82
 
82
- raise unless result.to_s == "Hello..."
83
- raise unless result.length == 8
83
+ raise unless actual.to_s == "Hello..."
84
+ raise unless actual.length == 8
84
85
 
85
86
  # ------------------------------------------------------------------------------
86
87
 
87
- result = "Hello" + ", Bob!"
88
+ actual = "Hello" + ", Bob!"
88
89
 
89
- raise unless result.to_s == "Hello, Bob!"
90
- raise unless result.length == 11
90
+ raise unless actual.to_s == "Hello, Bob!"
91
+ raise unless actual.length == 11
91
92
 
92
93
  # ------------------------------------------------------------------------------
93
94
 
94
- result = "Hello" + ", Bob..."
95
+ actual = "Hello" + ", Bob..."
95
96
 
96
- raise unless result.to_s == "Hello, Bob..."
97
- raise unless result.length == 13
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
@@ -23,7 +23,7 @@ require_relative ::File.join('..', 'lib', 'brutal')
23
23
 
24
24
  brutal_scaffold = case ARGV.fetch(0, nil)
25
25
  when nil
26
- ::Brutal::Framework::Poro
26
+ ::Brutal::Framework::Por
27
27
  else
28
28
  abort "Framework #{ARGV[0].inspect} not (yet) supported!"
29
29
  end
data/lib/brutal.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Main namespace
4
+ #
5
+ # @api public
3
6
  module Brutal
4
7
  end
5
8
 
@@ -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.1.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-15 00:00:00.000000000 Z
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/poro.rb
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