fix 0.18.2 → 0.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.md +2 -2
  3. data/README.md +384 -84
  4. data/lib/fix/builder.rb +101 -0
  5. data/lib/fix/doc.rb +59 -0
  6. data/lib/fix/dsl.rb +139 -0
  7. data/lib/fix/error/invalid_specification_name.rb +12 -0
  8. data/lib/fix/error/missing_specification_block.rb +14 -0
  9. data/lib/fix/error/specification_not_found.rb +12 -0
  10. data/lib/fix/matcher.rb +76 -0
  11. data/lib/fix/requirement.rb +119 -0
  12. data/lib/fix/run.rb +88 -0
  13. data/lib/fix/set.rb +67 -0
  14. data/lib/fix.rb +85 -20
  15. data/lib/kernel.rb +49 -0
  16. metadata +41 -153
  17. data/.gitignore +0 -11
  18. data/.rubocop.yml +0 -1
  19. data/.rubocop_todo.yml +0 -25
  20. data/.travis.yml +0 -28
  21. data/.yardopts +0 -1
  22. data/CODE_OF_CONDUCT.md +0 -13
  23. data/Gemfile +0 -5
  24. data/Rakefile +0 -23
  25. data/VERSION.semver +0 -1
  26. data/bin/console +0 -8
  27. data/bin/setup +0 -6
  28. data/checksum/fix-0.0.1.pre.gem.sha512 +0 -1
  29. data/checksum/fix-0.1.0.gem.sha512 +0 -1
  30. data/checksum/fix-0.1.0.pre.gem.sha512 +0 -1
  31. data/checksum/fix-0.10.0.gem.sha512 +0 -1
  32. data/checksum/fix-0.11.0.gem.sha512 +0 -1
  33. data/checksum/fix-0.11.1.gem.sha512 +0 -1
  34. data/checksum/fix-0.12.0.gem.sha512 +0 -1
  35. data/checksum/fix-0.12.1.gem.sha512 +0 -1
  36. data/checksum/fix-0.12.2.gem.sha512 +0 -1
  37. data/checksum/fix-0.12.3.gem.sha512 +0 -1
  38. data/checksum/fix-0.13.0.gem.sha512 +0 -1
  39. data/checksum/fix-0.14.0.gem.sha512 +0 -1
  40. data/checksum/fix-0.14.1.gem.sha512 +0 -1
  41. data/checksum/fix-0.15.0.gem.sha512 +0 -1
  42. data/checksum/fix-0.15.2.gem.sha512 +0 -1
  43. data/checksum/fix-0.16.0.gem.sha512 +0 -1
  44. data/checksum/fix-0.17.0.gem.sha512 +0 -1
  45. data/checksum/fix-0.17.1.gem.sha512 +0 -1
  46. data/checksum/fix-0.17.2.gem.sha512 +0 -1
  47. data/checksum/fix-0.18.0.gem.sha512 +0 -1
  48. data/checksum/fix-0.18.1.gem.sha512 +0 -1
  49. data/checksum/fix-0.2.0.gem.sha512 +0 -1
  50. data/checksum/fix-0.3.0.gem.sha512 +0 -1
  51. data/checksum/fix-0.4.0.gem.sha512 +0 -1
  52. data/checksum/fix-0.5.0.gem.sha512 +0 -1
  53. data/checksum/fix-0.6.0.gem.sha512 +0 -1
  54. data/checksum/fix-0.6.1.gem.sha512 +0 -1
  55. data/checksum/fix-0.7.0.gem.sha512 +0 -1
  56. data/checksum/fix-0.8.0.gem.sha512 +0 -1
  57. data/checksum/fix-0.9.0.gem.sha512 +0 -1
  58. data/checksum/fix-0.9.1.gem.sha512 +0 -1
  59. data/fix.gemspec +0 -29
  60. data/lib/fix/it.rb +0 -41
  61. data/lib/fix/on.rb +0 -139
  62. data/lib/fix/report.rb +0 -120
  63. data/lib/fix/test.rb +0 -89
  64. data/pkg_checksum +0 -12
@@ -1 +0,0 @@
1
- bdf94bb8790d1d0b5524f6ef0e7ac9a2f682cdd3248c52ef069acabbdc17ea685f050d737fa4fc121e9d7688641e2a8cd831b76537e58a6ebb5d169524f961e1
@@ -1 +0,0 @@
1
- 1acbc3c942908b08c055c50f0191f7e16681bb60388cb154bb3ca86ded0764e40438a0c296b651a8a13c4d62f1006b69c17cc69b8b6b963535be02e5fafd0d54
@@ -1 +0,0 @@
1
- c1529ea230a72517e4d15da268661f0c06c0294f456e2bec9dcb455fd85febda7de4237466414d02a662e3a2b370471d20852138f45fc3fbb5d8fef270d9e356
data/fix.gemspec DELETED
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- Gem::Specification.new do |spec|
4
- spec.name = 'fix'
5
- spec.version = File.read('VERSION.semver').chomp
6
- spec.authors = ['Cyril Kato']
7
- spec.email = ['contact@cyril.email']
8
-
9
- spec.summary = 'Specing framework.'
10
- spec.description = 'Specing framework for Ruby.'
11
- spec.homepage = 'https://github.com/fixrb/fix'
12
- spec.license = 'MIT'
13
-
14
- spec.files =
15
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^test/}) }
16
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
17
- spec.require_paths = ['lib']
18
-
19
- spec.add_dependency 'aw', '~> 0.1.6'
20
- spec.add_dependency 'defi', '~> 1.1.5'
21
- spec.add_dependency 'spectus', '~> 3.0.9'
22
-
23
- spec.add_development_dependency 'bundler', '~> 2.0'
24
- spec.add_development_dependency 'rake', '~> 13.0'
25
- spec.add_development_dependency 'rubocop', '~> 0.75'
26
- spec.add_development_dependency 'rubocop-performance', '~> 1.5'
27
- spec.add_development_dependency 'simplecov', '~> 0.17'
28
- spec.add_development_dependency 'yard', '~> 0.9'
29
- end
data/lib/fix/it.rb DELETED
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spectus/expectation_target'
4
- require 'spectus/matchers'
5
-
6
- module Fix
7
- # Wraps the target of an expectation.
8
- #
9
- # @api private
10
- #
11
- class It < ::Spectus::ExpectationTarget
12
- include ::Spectus::Matchers
13
-
14
- # Create a new expection target
15
- #
16
- # @param subject [BasicObject] The front object.
17
- # @param challenges [Array] The list of challenges.
18
- # @param helpers [Hash] The list of helpers.
19
- def initialize(subject, challenges, helpers)
20
- @subject = subject
21
- @challenges = challenges
22
-
23
- helpers.each do |method_name, method_block|
24
- define_singleton_method(method_name) do
25
- method_block.call
26
- end
27
- end
28
- end
29
-
30
- # Verify the expectation.
31
- #
32
- # @param spec [Proc] A spec to compare against the computed actual value.
33
- #
34
- # @return [::Spectus::Result::Pass, ::Spectus::Result::Fail] Pass or fail.
35
- def verify(&spec)
36
- instance_eval(&spec)
37
- rescue ::Spectus::Result::Fail => e
38
- e
39
- end
40
- end
41
- end
data/lib/fix/on.rb DELETED
@@ -1,139 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'aw'
4
- require 'defi'
5
-
6
- module Fix
7
- # Wraps the target of challenge.
8
- #
9
- # @api private
10
- #
11
- class On
12
- # Initialize the on class.
13
- #
14
- # @param described [#object_id] The front object of the test.
15
- # @param results [Array] The list of collected results.
16
- # @param challenges [Array] The list of challenges to apply.
17
- # @param helpers [Hash] The list of helpers.
18
- # @param configuration [Hash] Settings.
19
- def initialize(described, results, challenges, helpers, configuration)
20
- @described = described
21
- @results = results
22
- @challenges = challenges
23
- @helpers = helpers
24
- @configuration = configuration
25
- end
26
-
27
- # @!attribute [r] described
28
- #
29
- # @return [#object_id] The front object of the test.
30
- attr_reader :described
31
-
32
- # @!attribute [r] results
33
- #
34
- # @return [Array] The list of collected results.
35
- attr_reader :results
36
-
37
- # @!attribute [r] challenges
38
- #
39
- # @return [Array] The list of challenges to apply.
40
- attr_reader :challenges
41
-
42
- # @!attribute [r] helpers
43
- #
44
- # @return [Hash] The list of helpers.
45
- attr_reader :helpers
46
-
47
- # @!attribute [r] configuration
48
- #
49
- # @return [Hash] Settings.
50
- attr_reader :configuration
51
-
52
- # Add it method to the DSL.
53
- #
54
- # @api public
55
- #
56
- # @example It must eql "FOO"
57
- # it { MUST equal 'FOO' }
58
- #
59
- # @param spec [Proc] A spec to compare against the computed actual value.
60
- #
61
- # @return [Array] List of results.
62
- def it(*, &spec)
63
- i = It.new(described, challenges, helpers)
64
-
65
- result = i.verify(&spec)
66
-
67
- if configuration.fetch(:verbose, true)
68
- print result.to_char(configuration.fetch(:color, false))
69
- end
70
-
71
- results << result
72
- end
73
-
74
- # Add on method to the DSL.
75
- #
76
- # @api public
77
- #
78
- # @example On +2, it must equal 44.
79
- # on(:+, 2) do
80
- # it { MUST equal 44 }
81
- # end
82
- #
83
- # @param method_name [Symbol] The identifier of a method.
84
- # @param args [Array] A list of arguments.
85
- # @param block [Proc] A spec to compare against the computed value.
86
- #
87
- # @return [Array] List of results.
88
- def on(method_name, *args, &block)
89
- o = On.new(described,
90
- results,
91
- (challenges + [::Defi.send(method_name, *args)]),
92
- helpers.dup,
93
- configuration)
94
-
95
- o.instance_eval(&block)
96
- end
97
-
98
- # Add let method to the DSL, to define memoized helper methods.
99
- #
100
- # @api public
101
- #
102
- # @example Let's define the answer to the Ultimate Question of Life, the
103
- # Universe, and Everything.
104
- #
105
- # let(:answer) { 42 }
106
- #
107
- # @param method_name [Symbol] The identifier of a method.
108
- # @param block [Proc] A spec to compare against the computed value.
109
- #
110
- # @return [#object_id] List of results.
111
- def let(method_name, &block)
112
- helpers.update(method_name => block)
113
- end
114
-
115
- # Add context method to the DSL, to build an isolated scope.
116
- #
117
- # @api public
118
- #
119
- # @example Context when logged in.
120
- # context 'when logged in' do
121
- # it { MUST equal 200 }
122
- # end
123
- #
124
- # @param block [Proc] A block of specs to test in isolation.
125
- #
126
- # @return [Array] List of results.
127
- def context(*, &block)
128
- o = On.new(described,
129
- [],
130
- challenges,
131
- helpers.dup,
132
- configuration)
133
-
134
- results.concat(::Aw.fork! { o.instance_eval(&block) })
135
- end
136
- end
137
- end
138
-
139
- require_relative 'it'
data/lib/fix/report.rb DELETED
@@ -1,120 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Fix
4
- # The class that is responsible for reporting the result of the test.
5
- #
6
- # @api private
7
- #
8
- class Report
9
- # Initialize the report class.
10
- #
11
- # @param test [Test] The test.
12
- def initialize(test)
13
- @test = test
14
- end
15
-
16
- # @!attribute [r] test
17
- #
18
- # @return [Test] The results of the test.
19
- attr_reader :test
20
-
21
- # The report in plain text.
22
- #
23
- # @return [String] The report in plain text.
24
- def to_s
25
- [maybe_thematic_break, maybe_alerts, total_time, statistics].join
26
- end
27
-
28
- private
29
-
30
- # @private
31
- def maybe_thematic_break
32
- test.results.any? && test.configuration.fetch(:verbose) ? "\n\n" : ''
33
- end
34
-
35
- # @private
36
- def total_time
37
- "Ran #{test.results.length} tests in #{test.total_time} seconds\n"
38
- end
39
-
40
- # @private
41
- def alerts
42
- test.results.reject { |r| r.to_sym.equal?(:success) }
43
- end
44
-
45
- # @private
46
- def maybe_alerts
47
- alerts.any? ? "#{results.join("\n")}\n" : ''
48
- end
49
-
50
- # @private
51
- def results
52
- alerts.map.with_index(1) do |r, i|
53
- maybe_results_color("#{i}. #{r.message}\n" + maybe_backtrace(r), r)
54
- end
55
- end
56
-
57
- # @private
58
- def maybe_results_color(string, result)
59
- return string unless test.configuration.fetch(:color)
60
-
61
- color = send("#{result.to_sym}_color")
62
- "\e[#{color}m#{string}\e[0m"
63
- end
64
-
65
- # @private
66
- def maybe_backtrace(result)
67
- result.respond_to?(:backtrace) ? " #{result.backtrace.first}\n" : ''
68
- end
69
-
70
- # @private
71
- def statistics
72
- if test.configuration.fetch(:color)
73
- statistics_color(statistics_text, test.statistics)
74
- else
75
- statistics_text
76
- end
77
- end
78
-
79
- # @private
80
- def statistics_text
81
- "#{test.statistics.fetch(:pass_percent)}% compliant - " \
82
- "#{test.statistics.fetch(:total_infos)} infos, " \
83
- "#{test.statistics.fetch(:total_failures)} failures, " \
84
- "#{test.statistics.fetch(:total_errors)} errors\n"
85
- end
86
-
87
- # @private
88
- def statistics_color(string, stats)
89
- if stats.fetch(:total_errors).positive?
90
- "\e[#{error_color}m#{string}\e[0m"
91
- elsif stats.fetch(:total_failures).positive?
92
- "\e[#{failure_color}m#{string}\e[0m"
93
- elsif stats.fetch(:total_infos).positive?
94
- "\e[#{info_color}m#{string}\e[0m"
95
- else
96
- "\e[#{success_color}m#{string}\e[0m"
97
- end
98
- end
99
-
100
- # @private
101
- def error_color
102
- 31
103
- end
104
-
105
- # @private
106
- def failure_color
107
- 35
108
- end
109
-
110
- # @private
111
- def info_color
112
- 33
113
- end
114
-
115
- # @private
116
- def success_color
117
- 32
118
- end
119
- end
120
- end
data/lib/fix/test.rb DELETED
@@ -1,89 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Fix
4
- # Wraps the target of the specs document.
5
- #
6
- # @api private
7
- #
8
- class Test
9
- # Initialize the test class.
10
- #
11
- # @param front_object [BasicObject] The front object of the test.
12
- # @param options [Hash] Some options.
13
- # @param specs [Proc] The specs to test against the object.
14
- def initialize(front_object, verbose: true, color: true, **options, &specs)
15
- @configuration = options.merge(
16
- verbose: verbose,
17
- color: color
18
- )
19
-
20
- start_time = ::Time.now
21
-
22
- g = On.new(front_object, [], [], {}, @configuration)
23
- g.instance_eval(&specs)
24
-
25
- @results = g.results
26
- @total_time = ::Time.now - start_time
27
- end
28
-
29
- # @!attribute [r] configuration
30
- #
31
- # @return [Hash] The settings.
32
- attr_reader :configuration
33
-
34
- # @!attribute [r] results
35
- #
36
- # @return [Array] The results.
37
- attr_reader :results
38
-
39
- # @!attribute [r] total_time
40
- #
41
- # @return [Float] The total time.
42
- attr_reader :total_time
43
-
44
- # Some statistics.
45
- #
46
- # @return [Hash] Some statistics.
47
- def statistics
48
- {
49
- pass_percent: pass_percent,
50
- total_infos: results.count { |r| r.to_sym.equal?(:info) },
51
- total_failures: results.count { |r| r.to_sym.equal?(:failure) },
52
- total_errors: results.count { |r| r.to_sym.equal?(:error) }
53
- }
54
- end
55
-
56
- # The report of the test.
57
- #
58
- # @return [Report] The report of the test.
59
- def report
60
- Report.new(self)
61
- end
62
-
63
- # The state of the test.
64
- #
65
- # @return [Boolean] Return true if the test pass.
66
- def pass?
67
- results.all?(&:result?)
68
- end
69
-
70
- # @return [Boolean] Return false if the test fail.
71
- def fail?
72
- !pass?
73
- end
74
-
75
- private
76
-
77
- # @private
78
- #
79
- # @return [Fixnum] Return the percentage of passing specs.
80
- def pass_percent
81
- return 100 if results.empty?
82
-
83
- (results.count(&:result?) / results.length.to_f * 100).round
84
- end
85
- end
86
- end
87
-
88
- require_relative 'on'
89
- require_relative 'report'
data/pkg_checksum DELETED
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require 'digest/sha2'
5
-
6
- gemname = :fix
7
- ARGV[0] = File.read('VERSION.semver').chomp if ARGV[0].nil?
8
- built_gem_path = "pkg/#{gemname}-#{ARGV[0]}.gem"
9
- checksum = Digest::SHA512.new.hexdigest(File.read(built_gem_path))
10
- checksum_path = "checksum/#{gemname}-#{ARGV[0]}.gem.sha512"
11
-
12
- File.open(checksum_path, 'w') { |f| f.write("#{checksum}\n") }