brutal 0.1.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 +7 -0
- data/LICENSE.md +21 -0
- data/README.md +136 -0
- data/bin/brutal +38 -0
- data/bin/console +7 -0
- data/bin/setup +7 -0
- data/lib/brutal.rb +8 -0
- data/lib/brutal/framework/base.rb +17 -0
- data/lib/brutal/framework/poro.rb +31 -0
- metadata +137 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6a587ca80409c91605c6f0045e4f3b8b40f517b755e196748f0fc8dba6bff6e9
|
4
|
+
data.tar.gz: 722b740531d4046ef5c3a639e93aa0c9edcfa362f63d43dfe77ae37ab9ee9062
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e3147d44673898eee50b89db97c2f6ad19a48dd64b1c5df8c023ca64fe554a7d0a787f0f3241eb8e613aec2af59b50cda7331814807c80c1d2fed6ab833fac85
|
7
|
+
data.tar.gz: 5e5d91e3d1139fae44f148632d6c94c944e407bf75c684db73ebc7cc15fa804855d90f2e6606280cafdf42d0a630a5a48068a0df45c32311ec2f85096345576c
|
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Cyril Kato
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
# Brutal
|
2
|
+
|
3
|
+
> Brutal test suite scaffold generator
|
4
|
+
|
5
|
+

|
6
|
+
|
7
|
+
[][travis]
|
8
|
+
[][gem]
|
9
|
+
[][inchpages]
|
10
|
+
[][rubydoc]
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'brutal'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle install
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install brutal
|
27
|
+
|
28
|
+
## QuickStart
|
29
|
+
|
30
|
+
Just type `brutal` in a Ruby project's folder and watch the magic happen.
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
The Brutal YAML file handles 4 keys:
|
35
|
+
|
36
|
+
* `header` (optional): Some code to execute before the test suite.
|
37
|
+
* `subject` (required): The front object of the test suite.
|
38
|
+
* `variables` (required): A hash to decline the subject in to various contexts.
|
39
|
+
* `challenges` (required): An array of methods to apply to each result.
|
40
|
+
|
41
|
+
## Example
|
42
|
+
|
43
|
+
Given this `.brutal.yml` config file:
|
44
|
+
|
45
|
+
```yaml
|
46
|
+
header: |
|
47
|
+
# Some string concatenation unit tests
|
48
|
+
|
49
|
+
subject: |
|
50
|
+
"Hello" + "%{hello_target}%{punctuation_mark}"
|
51
|
+
|
52
|
+
variables:
|
53
|
+
:hello_target:
|
54
|
+
-
|
55
|
+
- ", Bob"
|
56
|
+
|
57
|
+
:punctuation_mark:
|
58
|
+
- "!"
|
59
|
+
- ...
|
60
|
+
|
61
|
+
challenges:
|
62
|
+
- .to_s
|
63
|
+
- .length
|
64
|
+
```
|
65
|
+
|
66
|
+
The `brutal` command would generate the following file:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
# Some string concatenation unit tests
|
70
|
+
|
71
|
+
# ------------------------------------------------------------------------------
|
72
|
+
|
73
|
+
result = "Hello" + "!"
|
74
|
+
|
75
|
+
raise unless result.to_s == "Hello!"
|
76
|
+
raise unless result.length == 6
|
77
|
+
|
78
|
+
# ------------------------------------------------------------------------------
|
79
|
+
|
80
|
+
result = "Hello" + "..."
|
81
|
+
|
82
|
+
raise unless result.to_s == "Hello..."
|
83
|
+
raise unless result.length == 8
|
84
|
+
|
85
|
+
# ------------------------------------------------------------------------------
|
86
|
+
|
87
|
+
result = "Hello" + ", Bob!"
|
88
|
+
|
89
|
+
raise unless result.to_s == "Hello, Bob!"
|
90
|
+
raise unless result.length == 11
|
91
|
+
|
92
|
+
# ------------------------------------------------------------------------------
|
93
|
+
|
94
|
+
result = "Hello" + ", Bob..."
|
95
|
+
|
96
|
+
raise unless result.to_s == "Hello, Bob..."
|
97
|
+
raise unless result.length == 13
|
98
|
+
```
|
99
|
+
|
100
|
+
## Integration with Rake
|
101
|
+
|
102
|
+
The generated brutal test suite `test.rb` file can be declared as follows:
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
Rake::TestTask.new do |t|
|
106
|
+
t.pattern = 'test.rb'
|
107
|
+
end
|
108
|
+
```
|
109
|
+
|
110
|
+
## Contact
|
111
|
+
|
112
|
+
* Home page: https://github.com/cyril/brutal.rb
|
113
|
+
* Bugs/issues: https://github.com/cyril/brutal.rb/issues
|
114
|
+
|
115
|
+
## Rubies
|
116
|
+
|
117
|
+
* [MRI](https://www.ruby-lang.org/)
|
118
|
+
* [Rubinius](https://rubinius.com/)
|
119
|
+
* [JRuby](https://www.jruby.org/)
|
120
|
+
|
121
|
+
## Contributing
|
122
|
+
|
123
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/cyril/brutal.rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/cyril/brutal.rb/blob/master/CODE_OF_CONDUCT.md).
|
124
|
+
|
125
|
+
## License
|
126
|
+
|
127
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
128
|
+
|
129
|
+
## Code of Conduct
|
130
|
+
|
131
|
+
Everyone interacting in the GreatGuardian project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/cyril/brutal.rb/blob/master/CODE_OF_CONDUCT.md).
|
132
|
+
|
133
|
+
[gem]: https://rubygems.org/gems/brutal
|
134
|
+
[travis]: https://travis-ci.org/cyril/brutal.rb
|
135
|
+
[inchpages]: https://inch-ci.org/github/cyril/brutal.rb
|
136
|
+
[rubydoc]: https://rubydoc.info/gems/brutal/frames
|
data/bin/brutal
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
FILE_NAME = '.brutal.yml'
|
7
|
+
CONF_PATH = ::File.join(::Dir.pwd, FILE_NAME)
|
8
|
+
|
9
|
+
abort "File #{CONF_PATH} not found!" unless ::File.exist?(CONF_PATH)
|
10
|
+
|
11
|
+
conf = ::YAML.load_file(CONF_PATH)
|
12
|
+
|
13
|
+
header = conf.fetch('header', '')
|
14
|
+
subject = conf.fetch('subject')
|
15
|
+
challenges = conf.fetch('challenges')
|
16
|
+
variables = conf.fetch('variables')
|
17
|
+
|
18
|
+
raise ::TypeError unless header.is_a?(::String)
|
19
|
+
raise ::TypeError unless challenges.is_a?(::Array)
|
20
|
+
raise ::TypeError unless variables.is_a?(::Hash)
|
21
|
+
|
22
|
+
require_relative ::File.join('..', 'lib', 'brutal')
|
23
|
+
|
24
|
+
brutal_scaffold = case ARGV.fetch(0, nil)
|
25
|
+
when nil
|
26
|
+
::Brutal::Framework::Poro
|
27
|
+
else
|
28
|
+
abort "Framework #{ARGV[0].inspect} not (yet) supported!"
|
29
|
+
end
|
30
|
+
|
31
|
+
eval(header)
|
32
|
+
|
33
|
+
brutal_specs = header + brutal_scaffold.new(subject, *challenges, **variables)
|
34
|
+
.to_s
|
35
|
+
|
36
|
+
file = ::File.open('test.rb', 'w')
|
37
|
+
file.write(brutal_specs)
|
38
|
+
file.close
|
data/bin/console
ADDED
data/bin/setup
ADDED
data/lib/brutal.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Brutal
|
2
|
+
module Framework
|
3
|
+
class Base
|
4
|
+
attr_reader :subject, :challenges, :variables
|
5
|
+
|
6
|
+
def initialize(subject, *challenges, **variables)
|
7
|
+
@subject = subject
|
8
|
+
@challenges = challenges
|
9
|
+
@variables = variables
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
raise ::NotImplementedError
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,31 @@
|
|
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
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: brutal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cyril Kato
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-12-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '13.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '13.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop-performance
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.17'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.17'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: yard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.9'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.9'
|
97
|
+
description: Brutal test suite scaffold generator
|
98
|
+
email: contact@cyril.email
|
99
|
+
executables:
|
100
|
+
- brutal
|
101
|
+
- console
|
102
|
+
- setup
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- LICENSE.md
|
107
|
+
- README.md
|
108
|
+
- bin/brutal
|
109
|
+
- bin/console
|
110
|
+
- bin/setup
|
111
|
+
- lib/brutal.rb
|
112
|
+
- lib/brutal/framework/base.rb
|
113
|
+
- lib/brutal/framework/poro.rb
|
114
|
+
homepage: https://github.com/cyril/brutal.rb
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubygems_version: 3.0.6
|
134
|
+
signing_key:
|
135
|
+
specification_version: 4
|
136
|
+
summary: Brutal test suite scaffold generator
|
137
|
+
test_files: []
|