brutal 1.0.0 → 1.1.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: 332c8755656f334781310460780dd233d621ddac83bc7d7dc5f0c555f4d1f955
4
- data.tar.gz: c49ae44f98432fb3839bcf7c76ac3929bfee3eac82113bc4903e6d288863865e
3
+ metadata.gz: 31950aed12f6f2f8a292c6df194cbab35c832f649597df8a96f73a7852688da9
4
+ data.tar.gz: 5300bdf71607debf6de06e4ddf37e8f7c7d4104822b18784cffed24451df8f30
5
5
  SHA512:
6
- metadata.gz: f015f9cbc3f478c66374b72a3c6e7340863b472eac796833700aa11a501c3361b2519939f0e407308a6800df23bb7ba959ec60d70f5b16acb86f3d30ae0440e2
7
- data.tar.gz: 90c7d4fef875977bd991a16405675e424524d2478318d33e694d073a47348986a2bb93bc27f9ff5cdfb5d5d48120d334f55733ad0ff6a3880c401ba901c85391
6
+ metadata.gz: fd76ba0d91ce4a7df5c477906970e1affb5459d2dcffa03709d6078089e95b82a0a80b372d659e6306a870b5c6f73469c6bcf95e7c8367d09f833f53941fa0de
7
+ data.tar.gz: 5cc889579792f8d836de4327eb83007c490e204016da975fdbe60792eea096d41c5906127a5210a5d2899cfc565024eede92d566ad69afe0b4f748fdbd46e8f1
@@ -2,25 +2,23 @@
2
2
 
3
3
  %w[
4
4
  configuration
5
+ file/read
6
+ file/write
5
7
  scaffold
8
+ yaml
6
9
  ].each { |file_name| require_relative(File.join('brutal', file_name)) }
7
10
 
8
11
  # The Brutal namespace
9
12
  module Brutal
10
- def self.settings
11
- Configuration.load!
12
- end
13
-
14
- def self.generate
15
- Scaffold.new(*settings)
16
- end
17
-
18
13
  def self.generate!
19
- file = ::File.open('test.rb', 'w')
20
- file.write(generate)
14
+ yaml = File::Read.new.call
15
+ hash = Yaml.parse(yaml)
16
+ conf = Configuration.new(**hash)
17
+ ruby = Scaffold.new(conf.header,
18
+ conf.subject,
19
+ *conf.actuals,
20
+ **conf.contexts)
21
21
 
22
- true
23
- ensure
24
- file.close
22
+ File::Write.new.call(ruby)
25
23
  end
26
24
  end
@@ -1,45 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'yaml'
4
-
5
3
  module Brutal
6
4
  # Brutal::Configuration
7
5
  #
8
6
  # @since 1.0.0
9
7
  class Configuration
10
- NAME = '.brutal.yml'
11
- PATH = ::File.join(::Dir.pwd, NAME).freeze
12
-
13
- def self.load!
14
- new.to_a
15
- end
16
-
17
- def self.file!
18
- ::YAML.load_file(PATH)
19
- rescue ::Errno::ENOENT => _e
20
- abort("File #{PATH} not found!")
21
- end
22
-
23
- attr_reader(:header, :subject, :contexts, :actuals)
8
+ HEAD = '# Brutal test suite'
24
9
 
25
- # rubocop:disable Metrics/AbcSize
26
- def initialize
27
- settings = self.class.file!
10
+ attr_reader(:actuals, :contexts, :header, :subject)
28
11
 
29
- @header = settings.fetch('header', '# Brutal test suite')
30
- @subject = settings.fetch('subject', '')
31
- @contexts = settings.fetch('contexts', {})
32
- @actuals = settings.fetch('actuals', [])
33
-
34
- raise ::TypeError, @header.inspect unless @header.is_a?(::String)
35
- raise ::TypeError, @subject.inspect unless @subject.is_a?(::String)
36
- raise ::TypeError, @contexts.inspect unless @contexts.is_a?(::Hash)
37
- raise ::TypeError, @actuals.inspect unless @actuals.is_a?(::Array)
38
- end
39
- # rubocop:enable Metrics/AbcSize
12
+ def initialize(actuals: [], contexts: {}, header: HEAD, subject: '')
13
+ raise ::TypeError, actuals.inspect unless actuals.is_a?(::Array)
14
+ raise ::TypeError, contexts.inspect unless contexts.is_a?(::Hash)
15
+ raise ::TypeError, header.inspect unless header.is_a?(::String)
16
+ raise ::TypeError, subject.inspect unless subject.is_a?(::String)
40
17
 
41
- def to_a
42
- [header, subject, *actuals, **contexts]
18
+ @actuals = actuals
19
+ @contexts = contexts
20
+ @header = header
21
+ @subject = subject
43
22
  end
44
23
  end
45
24
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Brutal
4
+ # Brutal::File
5
+ #
6
+ # @since 1.1.0
7
+ module File
8
+ # Brutal::File::Read
9
+ #
10
+ # @since 1.1.0
11
+ class Read
12
+ NAME = '.brutal.yml'
13
+
14
+ attr_reader :name
15
+
16
+ def initialize(name = NAME)
17
+ @name = name
18
+ end
19
+
20
+ def call
21
+ ::File.read(path)
22
+ rescue ::Errno::ENOENT => _e
23
+ abort("File #{path} not found!")
24
+ end
25
+
26
+ protected
27
+
28
+ def path
29
+ ::File.join(::Dir.pwd, name)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Brutal
4
+ # Brutal::File
5
+ #
6
+ # @since 1.1.0
7
+ module File
8
+ # Brutal::File::Write
9
+ #
10
+ # @since 1.1.0
11
+ class Write
12
+ NAME = 'test.rb'
13
+
14
+ attr_reader :name
15
+
16
+ def initialize(name = NAME)
17
+ @name = name
18
+ end
19
+
20
+ def call(scaffold)
21
+ file = ::File.open(path, 'w')
22
+ file.write(scaffold)
23
+
24
+ true
25
+ ensure
26
+ file.close
27
+ end
28
+
29
+ protected
30
+
31
+ def path
32
+ ::File.join(::Dir.pwd, name)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ module Brutal
6
+ # Brutal::Yaml
7
+ #
8
+ # @since 1.1.0
9
+ module Yaml
10
+ def self.parse(yaml)
11
+ ::YAML.safe_load(yaml, symbolize_names: true)
12
+ end
13
+ end
14
+ 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.0.0
4
+ version: 1.1.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: 2020-03-01 00:00:00.000000000 Z
11
+ date: 2020-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -106,7 +106,10 @@ files:
106
106
  - bin/brutal
107
107
  - lib/brutal.rb
108
108
  - lib/brutal/configuration.rb
109
+ - lib/brutal/file/read.rb
110
+ - lib/brutal/file/write.rb
109
111
  - lib/brutal/scaffold.rb
112
+ - lib/brutal/yaml.rb
110
113
  homepage: https://github.com/fixrb/brutal
111
114
  licenses:
112
115
  - MIT
@@ -119,14 +122,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
122
  requirements:
120
123
  - - ">="
121
124
  - !ruby/object:Gem::Version
122
- version: '0'
125
+ version: 2.6.0
123
126
  required_rubygems_version: !ruby/object:Gem::Requirement
124
127
  requirements:
125
128
  - - ">="
126
129
  - !ruby/object:Gem::Version
127
130
  version: '0'
128
131
  requirements: []
129
- rubygems_version: 3.1.2
132
+ rubygems_version: 3.0.1
130
133
  signing_key:
131
134
  specification_version: 4
132
135
  summary: A code-first approach to automate the writing of unit tests.