bddsm 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1ad7823b5ca54cef329506acf05ad1c81b405655de1ee48ccd85e701b79c06e1
4
+ data.tar.gz: 8b23eecef4bab283602e5b1592a2be72c2de07434b94d01d0b53ccb0444372b5
5
+ SHA512:
6
+ metadata.gz: c3652b500acd7842a3168615cee5dd7a7585e29fab5199c6a123e2a835ecd2ce644506781c6683639ec97a4c67d150a7be65c5172feb4c8ee0c7c683289f795d
7
+ data.tar.gz: d26aaf3d620e31be74272a1e6dd6038ea270e2611490612f46d615a234056bd9946aa7dada2c13e073c0c6d086025d78a0bc42bc1424342015342ab3cc81fe77
data/bin/bddsm ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pathname'
4
+ require_relative '../lib/bddsm'
5
+
6
+ suite = BDDSM::Suite.instance
7
+
8
+ suite.add_path File.join(Dir.pwd, ARGV[0])
9
+ suite.run
@@ -0,0 +1,13 @@
1
+ module BDDSM
2
+ class Actual
3
+ attr_reader :value
4
+
5
+ def initialize(value:)
6
+ @value = value
7
+ end
8
+
9
+ def to(matcher)
10
+ matcher.match(self)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ module BDDSM
2
+ class Describe
3
+ def initialize(title, &block)
4
+ @title = title
5
+ @block = block
6
+ end
7
+
8
+ def run
9
+ instance_eval(&@block)
10
+ end
11
+
12
+ def it(&)
13
+ Execution.new(describe: self, &).run
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ module BDDSM
2
+ class EqualMatcher
3
+ def initialize(expected:, location:)
4
+ @expected = expected
5
+ @location = location
6
+ end
7
+
8
+ def match(actual)
9
+ if actual.value == @expected
10
+ suite.register_success
11
+ else
12
+ suite.register_failure("Expected #{actual.value} to eq #{@expected}", location: @location)
13
+ end
14
+ end
15
+
16
+ def suite = Suite.instance
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ module BDDSM
2
+ class Execution
3
+ def initialize(describe:, &block)
4
+ @describe = describe
5
+ @block = block
6
+ end
7
+
8
+ def run
9
+ instance_eval(&@block)
10
+ end
11
+
12
+ def expect(actual)
13
+ Actual.new(value: actual)
14
+ end
15
+
16
+ def eq(expected)
17
+ EqualMatcher.new(expected:, location:)
18
+ end
19
+
20
+ def location = @block.source_location
21
+ end
22
+ end
@@ -0,0 +1,12 @@
1
+ module BDDSM
2
+ class Failure
3
+ attr_reader :error
4
+
5
+ def initialize(error, location:)
6
+ @error = error
7
+ @location = location
8
+ end
9
+
10
+ def location = @location.join('#')
11
+ end
12
+ end
data/lib/bddsm/file.rb ADDED
@@ -0,0 +1,11 @@
1
+ module BDDSM
2
+ class File
3
+ def initialize(path)
4
+ @path = path
5
+ end
6
+
7
+ def run
8
+ require @path
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,30 @@
1
+ module BDDSM
2
+ class ProgressReport
3
+ def initialize(result:, io:)
4
+ @result = result
5
+ @io = io
6
+ end
7
+
8
+ def success
9
+ @io.print '.'
10
+ end
11
+
12
+ def failure
13
+ @io.print 'E'
14
+ end
15
+
16
+ def finalize
17
+ @io.puts
18
+ @io.puts
19
+ @io.puts 'OK!'
20
+ @io.puts "Success: #{@result.successes}"
21
+ @io.puts "Failures: #{@result.failures_count}"
22
+ @io.puts
23
+ @io.puts
24
+ @result.failures.each do |failure|
25
+ @io.puts failure.error
26
+ @io.puts " at #{failure.location}"
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,29 @@
1
+ module BDDSM
2
+ class Result
3
+ attr_reader :successes, :failures
4
+
5
+ def initialize
6
+ @successes = 0
7
+ @failures = []
8
+ @listeners = []
9
+ end
10
+
11
+ def failures_count = @failures.size
12
+
13
+ def register_success
14
+ @successes += 1
15
+
16
+ @listeners.each(&:success)
17
+ end
18
+
19
+ def register_failure(error, location:)
20
+ @failures << Failure.new(error, location:)
21
+
22
+ @listeners.each(&:failure)
23
+ end
24
+
25
+ def subscribe(listener)
26
+ @listeners << listener
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,42 @@
1
+ module BDDSM
2
+ class Suite
3
+ include Singleton
4
+
5
+ def initialize
6
+ @files = []
7
+ @describes = []
8
+
9
+ result.subscribe report
10
+ end
11
+
12
+ def report = @report ||= BDDSM::ProgressReport.new(result:, io: $stdout)
13
+
14
+ def add_path(path)
15
+ @files << BDDSM::File.new(path)
16
+ end
17
+
18
+ def add_describe(describe)
19
+ @describes << describe
20
+ end
21
+
22
+ def load_files = @files.each(&:run)
23
+
24
+ def run_examples = @describes.each(&:run)
25
+
26
+ def run
27
+ load_files
28
+ run_examples
29
+ finalize_report
30
+ end
31
+
32
+ def finalize_report = report.finalize
33
+
34
+ def register_success = result.register_success
35
+
36
+ def register_failure(error, location:)
37
+ result.register_failure(error, location:)
38
+ end
39
+
40
+ def result = @result ||= BDDSM::Result.new
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module BDDSM
2
+ VERSION = '0.1.0'.freeze
3
+ end
data/lib/bddsm.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'singleton'
2
+
3
+ require_relative 'bddsm/actual'
4
+ require_relative 'bddsm/describe'
5
+ require_relative 'bddsm/equal_matcher'
6
+ require_relative 'bddsm/execution'
7
+ require_relative 'bddsm/failure'
8
+ require_relative 'bddsm/file'
9
+ require_relative 'bddsm/progress_report'
10
+ require_relative 'bddsm/result'
11
+ require_relative 'bddsm/suite'
12
+
13
+ module BDDSM
14
+ def self.describe(title, &)
15
+ # TODO: фиксировать файл, из которого подгружен describe,
16
+ # чтобы потом корректно отображать строку ошибки и собирать статистику
17
+ Suite.instance.add_describe Describe.new(title, &)
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bddsm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sergei O. Udalov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-07-01 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ executables:
16
+ - bddsm
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/bddsm
21
+ - lib/bddsm.rb
22
+ - lib/bddsm/actual.rb
23
+ - lib/bddsm/describe.rb
24
+ - lib/bddsm/equal_matcher.rb
25
+ - lib/bddsm/execution.rb
26
+ - lib/bddsm/failure.rb
27
+ - lib/bddsm/file.rb
28
+ - lib/bddsm/progress_report.rb
29
+ - lib/bddsm/result.rb
30
+ - lib/bddsm/suite.rb
31
+ - lib/bddsm/version.rb
32
+ homepage: https://github.com/HeavyTechRuby/bddsm
33
+ licenses: []
34
+ metadata:
35
+ rubygems_mfa_required: 'true'
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '3.2'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubygems_version: 3.5.11
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: Hard Testing Framework. Multi-paradigm spec/feature/xunit-agnostic syntax
55
+ support.
56
+ test_files: []