mini_assert 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6b1a3508296279e350a7e0b7a2d0124a073f5ee5cdef40270569a351c6ae2d95
4
+ data.tar.gz: b393d75a7ab43b18db9922669e5bc85d2629a8cb7cd6e6130e9aed580e68ff40
5
+ SHA512:
6
+ metadata.gz: 4a2c7c2daf17b2315da5c09ff66688bb7412f57fadfd4d448f3e11c748c2ee122f00b8399879f80fbbfdd8b8d38e1a4fbd4594bb7d45feca9a23df4a420d8203
7
+ data.tar.gz: f6bd83fd4d36a8af4441188a27980667299893a8d4558737d509419ea8b950a59f43f79d0359b360b828b71c40d53ed4d7631c24fa369663474c9e5475e4ccd0
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # Development
11
+ tags*
12
+ Session.vim
13
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in assert.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Luis Adrián Chávez Fregoso
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.
@@ -0,0 +1,66 @@
1
+ # MiniAssert
2
+
3
+ Fast, zero-configuration, non-dependencies testing ruby gem.
4
+
5
+ Like Minitest, but worst (in a fun way).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'mini_assert'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install mini_assert
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ require 'mini_assert'
27
+
28
+ class SomeTest < MiniAssert::TestCase
29
+ def test_some
30
+ assert(some_exp = true)
31
+ end
32
+ end
33
+ ```
34
+
35
+ Then run your test suite:
36
+
37
+ $ mini-assert
38
+
39
+ Or:
40
+
41
+ $ bundle exec mini-assert
42
+
43
+ MiniAssert requires `_test.rb` file naming to load your testing files
44
+ - valid name: `some_test.rb`
45
+ - invalid name: `some.rb`
46
+ - invalid name: `test_some.rb`
47
+
48
+ Also, MiniAssert requires `test_` method naming to run your tests
49
+ - valid name: `test_some`
50
+ - invalid name: `some`
51
+ - invalid name: `some_test`
52
+
53
+ ## Development
54
+
55
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
56
+
57
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
58
+
59
+ ## Contributing
60
+
61
+ Bug reports and pull requests are welcome on GitHub at https://github.com/lacf95/mini_assert.
62
+
63
+
64
+ ## License
65
+
66
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'bundler/setup'
6
+ require 'mini_assert'
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+
11
+ # (If you use this, don't forget to add pry to your Gemfile!)
12
+ # require "pry"
13
+ # Pry.start
14
+
15
+ require 'irb'
16
+ IRB.start(__FILE__)
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require_relative '../lib/mini_assert/version'
6
+
7
+ puts "[ bin/install ] Building MiniAssert gem version #{MiniAssert::VERSION}"
8
+ system('gem build mini_assert.gemspec')
9
+
10
+ puts "[ bin/install ] Installing MiniAssert gem version #{MiniAssert::VERSION}"
11
+ system("gem install mini_assert-#{MiniAssert::VERSION}.gem")
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'mini_assert'
6
+
7
+ runnable = MiniAssert::TestRunnable.new
8
+
9
+ at_exit do
10
+ runnable.run!
11
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MiniAssert
4
+ class Error < StandardError; end
5
+ end
6
+
7
+ require 'mini_assert/version'
8
+ require 'mini_assert/assertable'
9
+ require 'mini_assert/test_case'
10
+ require 'mini_assert/crayon'
11
+ require 'mini_assert/test_suite'
12
+ require 'mini_assert/test_runnable'
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MiniAssert
4
+ class AssertionError < MiniAssert::Error; end
5
+
6
+ # Assertion methods
7
+ module Assertable
8
+ def assert(expression, message = 'Expected a truthy value')
9
+ raise AssertionError, message unless expression
10
+ end
11
+
12
+ def assert_equal(expected, value)
13
+ assert(expected == value, "Expected #{expected.inspect} to equal #{value.inspect}")
14
+ end
15
+
16
+ def assert_exception(exception)
17
+ yield
18
+ assert(false, "Expected #{exception} but nothing was raised")
19
+ rescue => e
20
+ assert(e.class == exception, "Expected #{exception} got #{e.class}")
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MiniAssert
4
+ # STD_OUT printing colors
5
+ class Crayon
6
+ class << self
7
+ def colorize(color_code, string)
8
+ "\e[#{color_code}m#{string}\e[0m"
9
+ end
10
+
11
+ def green(string)
12
+ colorize(32, string)
13
+ end
14
+
15
+ def red(string)
16
+ colorize(31, string)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MiniAssert
4
+ # Basic test case object
5
+ class TestCase
6
+ include Assertable
7
+
8
+ attr_reader :total_tests, :passed_tests
9
+
10
+ def initialize
11
+ @total_tests = testable_methods.size
12
+ @passed_tests = 0
13
+ end
14
+
15
+ def each_test!
16
+ testable_methods.each do |testable_method|
17
+ begin
18
+ public_send testable_method
19
+ @passed_tests += 1
20
+ rescue MiniAssert::AssertionError => e
21
+ file_name, method_line = method(testable_method).source_location
22
+ yield("#{file_name}:#{method_line} #{e}") if block_given?
23
+ end
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def testable_methods
30
+ @testable_methods ||= public_methods.select do |method_name|
31
+ method_name.to_s =~ /test_.+/
32
+ end.shuffle
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'find'
4
+
5
+ module MiniAssert
6
+ # Finds, load and run test in given directory
7
+ class TestRunnable
8
+ def initialize(path = '.', file_matcher = /.+_test\.rb$/)
9
+ @path = path
10
+ @file_matcher = file_matcher
11
+ require_test
12
+ end
13
+
14
+ def run!
15
+ MiniAssert::TestSuite.new(testable_classes).run!
16
+ end
17
+
18
+ private
19
+
20
+ def testable_classes
21
+ @testable_classes ||= begin
22
+ classes = []
23
+ ObjectSpace.each_object(Class) do |class_const|
24
+ next unless class_const < MiniAssert::TestCase
25
+
26
+ classes << class_const
27
+ end
28
+ classes
29
+ end
30
+ end
31
+
32
+ def require_test
33
+ test_files.each do |file|
34
+ require file
35
+ end
36
+ end
37
+
38
+ def test_files
39
+ @test_files ||= begin
40
+ found_files = []
41
+ Find.find(@path) do |file|
42
+ found_files << file if file =~ @file_matcher
43
+ end
44
+ found_files
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MiniAssert
4
+ # Test executable object
5
+ class TestSuite
6
+ def initialize(test_classes)
7
+ @test_classes = test_classes
8
+ @results = { total_tests: 0, passed_tests: 0 }
9
+ end
10
+
11
+ def run!
12
+ @test_classes.each do |test_class|
13
+ test_obj = test_class.new
14
+ test_obj.each_test! { |message| show_failure message }
15
+ @results[:total_tests] += test_obj.total_tests
16
+ @results[:passed_tests] += test_obj.passed_tests
17
+ end
18
+ show_results
19
+ end
20
+
21
+ private
22
+
23
+ def show_results
24
+ ratio_string = "#{@results[:passed_tests]}/#{@results[:total_tests]}"
25
+ status = if @results[:passed_tests] == @results[:total_tests]
26
+ MiniAssert::Crayon.green(ratio_string)
27
+ else
28
+ MiniAssert::Crayon.red(ratio_string)
29
+ end
30
+ puts "[#{status}] tests succeded"
31
+ end
32
+
33
+ def show_failure(message)
34
+ status = MiniAssert::Crayon.red('fail')
35
+ puts "[#{status}] #{message}"
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MiniAssert
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/mini_assert/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'mini_assert'
7
+ spec.version = MiniAssert::VERSION
8
+ spec.authors = ['Luis Adrián Chávez Fregoso']
9
+ spec.email = ['biolacf@gmail.com']
10
+
11
+ spec.summary = 'Assertion Gem only for me'
12
+ spec.description = 'Super fast gem for testing stuff'
13
+ spec.homepage = 'https://github.com/lacf95/mini_assert'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = 'exe'
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_development_dependency 'pry', '~> 0.13'
27
+ spec.add_development_dependency 'rake', '~> 13.0'
28
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mini_assert
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Luis Adrián Chávez Fregoso
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-01-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.13'
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
+ description: Super fast gem for testing stuff
42
+ email:
43
+ - biolacf@gmail.com
44
+ executables:
45
+ - mini-assert
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/install
56
+ - bin/setup
57
+ - exe/mini-assert
58
+ - lib/mini_assert.rb
59
+ - lib/mini_assert/assertable.rb
60
+ - lib/mini_assert/crayon.rb
61
+ - lib/mini_assert/test_case.rb
62
+ - lib/mini_assert/test_runnable.rb
63
+ - lib/mini_assert/test_suite.rb
64
+ - lib/mini_assert/version.rb
65
+ - mini_assert.gemspec
66
+ homepage: https://github.com/lacf95/mini_assert
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 2.3.0
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubygems_version: 3.1.2
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Assertion Gem only for me
89
+ test_files: []