brutal 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: 31ea2d6a9b38faaa03aaed25dfc8b18158a8d243b9aed42e0f4a3a488c8386a3
4
- data.tar.gz: f73e4a2798de7a55deb006898919498a9d6344fcd3ec94728a379bf723370ae2
3
+ metadata.gz: ea124053ebeef681c2e046022936f9d67ca97778733a23bd2d81781e90daa9a8
4
+ data.tar.gz: 677089454fece7f60aedfc4693b53c132f057bbeeaca5e651f88ec52d026ea34
5
5
  SHA512:
6
- metadata.gz: f5a9b52b8608bdf327bb14ad782cde378901285a3d9de0b28d273184480586f868da0b10bf32ac47980bfbc0b637b6bc058de2c42bdb600b4add7bb1865207e0
7
- data.tar.gz: 302e2bf37546bc813caa05eedb38f2ad496123e6ba37b186d449ea2e5782945ef5d652d8cdc05a25c08045a472144ad6efa30f4316c23f5e3ca9ecdbdd8c8818
6
+ metadata.gz: b1d043d4740db1987c188755e9b339da566034a3cc2a43f99ced12fb3de26a93df0f93d669b20700ba662a935d9be662a25bffba8f8ae92aae3e01deade92d9b
7
+ data.tar.gz: 5abc20c46849f69b20de5b89848f8fed831b2d92641f57cfa349be4e0a975c8630c27268d16a022911693d403af8262b4f0d1099dcf468879392e9c2d7fe7ec0
data/README.md CHANGED
@@ -61,28 +61,48 @@ Just type `brutal` in a Ruby project's folder and watch the magic happen.
61
61
 
62
62
  __Brutal__ needs a configuration file to know how to write your tests.
63
63
  Currently, only the YAML format is supported.
64
- This file is composed of 4 top-level sections:
64
+ This file is by default named `.brutal.yml` and is composed of 4 top-level sections:
65
65
 
66
66
  * `header` - Specifies the code to execute before generating the test suite.
67
67
  * `subject` - Specifies the template of the code to be declined across contexts.
68
68
  * `contexts` - Specifies a list of variables to populate the subject's template.
69
69
  * `actuals` - Specifies templates to challenge evaluated subjects & get results.
70
70
 
71
- This file is by default called `.brutal.yml`, but it would be possible to name it differently by passing it as an argument to the brutal command such as:
71
+ When the configuration file is present, the generation of a test suite can be done with the command:
72
72
 
73
73
  ```sh
74
- brutal test_hello_world.yml
74
+ brutal .brutal.yml
75
75
  ```
76
76
 
77
- This would create a `test_hello_world.rb` file containing the test suite.
77
+ or:
78
+
79
+ ```sh
80
+ brutal .
81
+ ```
82
+
83
+ or even:
84
+
85
+ ```sh
86
+ brutal
87
+ ```
88
+
89
+ This would create a `test.rb` file containing the test suite.
90
+
91
+ Configuration files can also be named differently:
92
+
93
+ ```sh
94
+ brutal path/to/test_hello_world.yml
95
+ ```
96
+
97
+ This would create a `path/to/test_hello_world.rb` file containing the test suite.
78
98
 
79
99
  To avoid accidentally overwriting a file, the `--no-force` option can be used:
80
100
 
81
101
  ```sh
82
- brutal test_hello_world.yml --no-force
102
+ brutal path/to/test_hello_world.yml --no-force
83
103
  ```
84
104
 
85
- > A test_hello_world.rb file already exists!
105
+ > A path/to/test_hello_world.rb file already exists!
86
106
 
87
107
  ### Getting started
88
108
 
data/bin/brutal CHANGED
@@ -1,6 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "pathname"
4
5
  require_relative File.join("..", "lib", "brutal")
5
6
 
6
- Brutal.generate! ARGV.fetch(0, Brutal::File::DEFAULT_CONFIG_FILENAME), force: ARGV.none?("--no-force")
7
+ path = ARGV.fetch(0, Brutal::File::DEFAULT_CONFIG_FILENAME)
8
+ pathname = Pathname.new(path)
9
+ pathname += Brutal::File::DEFAULT_CONFIG_FILENAME if pathname.directory?
10
+ force_opt = ARGV.none?("--no-force")
11
+
12
+ Brutal.generate!(pathname, force: force_opt)
@@ -15,7 +15,7 @@ module Brutal
15
15
  def call
16
16
  ::File.read(path)
17
17
  rescue ::Errno::ENOENT => _e
18
- abort("File #{path} not found!")
18
+ abort "File #{path} not found!"
19
19
  end
20
20
 
21
21
  protected
data/lib/brutal/file.rb CHANGED
@@ -10,28 +10,22 @@ module Brutal
10
10
  module File
11
11
  DEFAULT_CONFIG_FILENAME = ".brutal.yml"
12
12
  DEFAULT_GENERATED_FILENAME = "test.rb"
13
+ RUBY_EXTENSION = ".rb"
13
14
 
14
15
  def self.generated_pathname(pathname)
15
- filename = pathname.split(separator).fetch(-1)
16
+ filename = pathname.basename
17
+ return pathname.dirname + DEFAULT_GENERATED_FILENAME if default_config_filename?(filename)
16
18
 
17
- if filename == DEFAULT_CONFIG_FILENAME
18
- directory_parts = pathname.split(separator)[..-2]
19
- path_parts = directory_parts + [DEFAULT_GENERATED_FILENAME]
20
- return path_parts.join(separator)
21
- end
22
-
23
- pathname.gsub(/.[^.]+\z/, ".rb")
19
+ pathname.sub_ext(RUBY_EXTENSION)
24
20
  end
25
21
 
26
22
  def self.override_protection(pathname)
27
- return true unless ::File.exist?(pathname)
28
-
29
- abort "A #{pathname} file already exists!"
23
+ abort "A #{pathname} file already exists!" if pathname.exist?
30
24
  end
31
25
 
32
- def self.separator
33
- ::File::SEPARATOR
26
+ def self.default_config_filename?(filename)
27
+ filename.to_s == DEFAULT_CONFIG_FILENAME
34
28
  end
35
- private_class_method :separator
29
+ private_class_method :default_config_filename?
36
30
  end
37
31
  end
data/lib/brutal/yaml.rb CHANGED
@@ -8,8 +8,8 @@ module Brutal
8
8
  # @since 1.1.0
9
9
  module Yaml
10
10
  FILENAME_EXTENSIONS = %w[
11
- yaml
12
- yml
11
+ .yaml
12
+ .yml
13
13
  ].freeze
14
14
 
15
15
  def self.parse(yaml)
@@ -17,7 +17,7 @@ module Brutal
17
17
  end
18
18
 
19
19
  def self.parse?(pathname)
20
- filename_extension = pathname.split(".")[1..][-1]
20
+ filename_extension = pathname.extname
21
21
  FILENAME_EXTENSIONS.include?(filename_extension)
22
22
  end
23
23
  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: 1.4.0
4
+ version: 1.5.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: 2022-08-22 00:00:00.000000000 Z
11
+ date: 2022-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler