test_that 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: 89d88aaeaf8b5d7f6e95791ab555c97e44fd046bea605907fd355b4aebf5ef29
4
+ data.tar.gz: c6c255452ba3797537a1c4f29f0aa21e90cc81b9a12621b840f5465599448f42
5
+ SHA512:
6
+ metadata.gz: ef360c7fa9f487c73865ba53969aedb048769b489b12358004b40a391b64990f9b24ef30bd23ad210732afa1e61eb1858781e153ebf5103f1add4d64d7f9557c
7
+ data.tar.gz: d9129f434f4970cdd144dd1e342c46f95009db4bb04b2f93b0a971491de41cf0abf2afed722d22320032b390095d4bd20923f7eb32274879ad4a15914b3ccf1c
data/.rubocop.yml ADDED
@@ -0,0 +1,26 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+ NewCops: enable
4
+
5
+ Style/StringLiterals:
6
+ Enabled: true
7
+ EnforcedStyle: double_quotes
8
+
9
+ Style/StringLiteralsInInterpolation:
10
+ Enabled: true
11
+ EnforcedStyle: double_quotes
12
+
13
+ Layout/LineLength:
14
+ Max: 120
15
+
16
+ Style/Documentation:
17
+ Enabled: false
18
+
19
+ Style/TrailingCommaInHashLiteral:
20
+ EnforcedStyleForMultiline: comma
21
+
22
+ Layout/MultilineAssignmentLayout:
23
+ EnforcedStyle: same_line
24
+
25
+ Metrics/MethodLength:
26
+ Max: 15
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-12-23
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at peter@petermccracken.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in test_that.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+
12
+ gem "rubocop", "~> 1.21"
13
+ gem "rubocop-minitest", "~> 0.17"
14
+ gem "rubocop-rake", "~> 0.6"
data/Gemfile.lock ADDED
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ test_that (0.1.0)
5
+ optimist (~> 3.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ minitest (5.15.0)
12
+ optimist (3.0.1)
13
+ parallel (1.21.0)
14
+ parser (3.1.0.0)
15
+ ast (~> 2.4.1)
16
+ rainbow (3.1.1)
17
+ rake (13.0.6)
18
+ regexp_parser (2.2.0)
19
+ rexml (3.2.5)
20
+ rubocop (1.24.1)
21
+ parallel (~> 1.10)
22
+ parser (>= 3.0.0.0)
23
+ rainbow (>= 2.2.2, < 4.0)
24
+ regexp_parser (>= 1.8, < 3.0)
25
+ rexml
26
+ rubocop-ast (>= 1.15.1, < 2.0)
27
+ ruby-progressbar (~> 1.7)
28
+ unicode-display_width (>= 1.4.0, < 3.0)
29
+ rubocop-ast (1.15.1)
30
+ parser (>= 3.0.1.1)
31
+ rubocop-minitest (0.17.0)
32
+ rubocop (>= 0.90, < 2.0)
33
+ rubocop-rake (0.6.0)
34
+ rubocop (~> 1.0)
35
+ ruby-progressbar (1.11.0)
36
+ unicode-display_width (2.1.0)
37
+
38
+ PLATFORMS
39
+ arm64-darwin-21
40
+
41
+ DEPENDENCIES
42
+ minitest (~> 5.0)
43
+ rake (~> 13.0)
44
+ rubocop (~> 1.21)
45
+ rubocop-minitest (~> 0.17)
46
+ rubocop-rake (~> 0.6)
47
+ test_that!
48
+
49
+ BUNDLED WITH
50
+ 2.2.32
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Peter McCracken
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.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # TestThat
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/test_that`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'test_that'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install test_that
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/peterjm/test_that. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/peterjm/test_that/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the TestThat project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/peterjm/test_that/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "test_that"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -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
data/bin/test-that ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../lib/test_that"
5
+ require "optimist"
6
+
7
+ options = Optimist.options do
8
+ banner "Usage: #{$PROGRAM_NAME} [options] [tests]"
9
+ self.ignore_invalid_options = true
10
+
11
+ opt :all, "Run all tests"
12
+ end
13
+ options[:tests] = ARGV
14
+
15
+ runner = TestThat::TestBuilder.build(options)
16
+ success = runner.test
17
+ exit 1 unless success
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TestThat
4
+ class RailsTester
5
+ def enabled?
6
+ File.directory?("test") && File.exist?("config/application.rb")
7
+ end
8
+
9
+ def select_tests(files)
10
+ files
11
+ .select { |f| f.start_with?("test/") }
12
+ .select { |f| f.end_with?("_test.rb") }
13
+ end
14
+
15
+ def test_all_command
16
+ "rails test"
17
+ end
18
+
19
+ def test_files_command(files)
20
+ ["rails", "test", *files].join(" ")
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TestThat
4
+ class RspecTester
5
+ def enabled?
6
+ File.directory?("spec")
7
+ end
8
+
9
+ def select_tests(files)
10
+ files
11
+ .select { |f| f.start_with?("spec/") }
12
+ .select { |f| f.end_with?("_spec.rb") }
13
+ end
14
+
15
+ def test_all_command
16
+ "rspec"
17
+ end
18
+
19
+ def test_files_command(files)
20
+ ["rspec", *files].join(" ")
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TestThat
4
+ class RubyTester
5
+ REQUIRE_ALL_TESTS = '-e "Dir.glob(\"**/*_test.rb\", base: \"test\"){|f| require f}"'
6
+ REQUIRE_EACH_TEST = '-e "ARGV.each{|f| require f}"'
7
+
8
+ def enabled?
9
+ File.directory?("test")
10
+ end
11
+
12
+ def select_tests(files)
13
+ files
14
+ .select { |f| f.start_with?("test/") }
15
+ .select { |f| f.end_with?("_test.rb") }
16
+ end
17
+
18
+ def test_all_command
19
+ ["ruby", "-Itest", REQUIRE_ALL_TESTS].join(" ")
20
+ end
21
+
22
+ def test_files_command(files)
23
+ files_relative_to_test_dir = files.map { |f| f.sub(%r{\Atest/}, "") }
24
+ ["ruby", "-Itest", REQUIRE_EACH_TEST, *files_relative_to_test_dir].join(" ")
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TestThat
4
+ class TestBuilder
5
+ class << self
6
+ def build(options)
7
+ new(options).build
8
+ end
9
+ end
10
+
11
+ attr_reader :options
12
+
13
+ def initialize(options)
14
+ @options = options
15
+ end
16
+
17
+ def build
18
+ if no_tester?
19
+ TestRunner::Error.new
20
+ elsif test_all?
21
+ TestRunner::All.new(tester)
22
+ elsif selected_tests.any?
23
+ TestRunner::Selected.new(tester, selected_tests)
24
+ elsif stream_tests.any?
25
+ TestRunner::VerboseSelected.new(tester, stream_tests)
26
+ else
27
+ TestRunner::Empty.new
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def no_tester?
34
+ tester.nil?
35
+ end
36
+
37
+ def test_all?
38
+ options[:all]
39
+ end
40
+
41
+ def selected_tests
42
+ @selected_tests ||= tester.select_tests(options[:tests])
43
+ end
44
+
45
+ def stream_tests
46
+ @stream_tests ||= begin
47
+ files = content_from_stdin.split.map(&:strip)
48
+ tester.select_tests(files)
49
+ end
50
+ end
51
+
52
+ def tester
53
+ @tester ||= testers.detect(&:enabled?)
54
+ end
55
+
56
+ def testers
57
+ [
58
+ RailsTester.new,
59
+ RubyTester.new,
60
+ RspecTester.new
61
+ ]
62
+ end
63
+
64
+ def content_from_stdin
65
+ content = ""
66
+ loop do
67
+ content += $stdin.read_nonblock(10_000)
68
+ end
69
+ rescue IO::WaitReadable
70
+ ""
71
+ rescue EOFError
72
+ content
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TestThat
4
+ class TestRunner
5
+ class All < TestRunner
6
+ def test
7
+ system(tester.test_all_command)
8
+ end
9
+ end
10
+
11
+ class Selected < TestRunner
12
+ attr_reader :tests_to_run
13
+
14
+ def initialize(tester, tests_to_run)
15
+ super(tester)
16
+ @tests_to_run = tests_to_run
17
+ end
18
+
19
+ def test
20
+ system(tester.test_files_command(tests_to_run))
21
+ end
22
+ end
23
+
24
+ class VerboseSelected < Selected
25
+ def test
26
+ print_tests
27
+ super
28
+ end
29
+
30
+ private
31
+
32
+ def print_tests
33
+ puts "Running tests for:"
34
+ tests_to_run.each { |f| puts " #{f}" }
35
+ end
36
+ end
37
+
38
+ class Empty < TestRunner
39
+ def initialize
40
+ super(nil)
41
+ end
42
+
43
+ def test
44
+ puts "No tests to run"
45
+ true
46
+ end
47
+ end
48
+
49
+ class Error < TestRunner
50
+ def initialize
51
+ super(nil)
52
+ end
53
+
54
+ def test
55
+ warn "Could not run tests; no compatible test environment detected"
56
+ false
57
+ end
58
+ end
59
+
60
+ attr_reader :tester
61
+
62
+ def initialize(tester)
63
+ @tester = tester
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TestThat
4
+ VERSION = "0.1.0"
5
+ end
data/lib/test_that.rb ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TestThat
4
+ require_relative "test_that/version"
5
+ require_relative "test_that/ruby_tester"
6
+ require_relative "test_that/rails_tester"
7
+ require_relative "test_that/rspec_tester"
8
+ require_relative "test_that/test_runner"
9
+ require_relative "test_that/test_builder"
10
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: test_that
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Peter McCracken
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-01-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: optimist
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ description: Runs tests in various test runners either based on command-line arguments
28
+ or from STDIN
29
+ email:
30
+ - peter@petermccracken.com
31
+ executables:
32
+ - test-that
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - ".rubocop.yml"
37
+ - CHANGELOG.md
38
+ - CODE_OF_CONDUCT.md
39
+ - Gemfile
40
+ - Gemfile.lock
41
+ - LICENSE.txt
42
+ - README.md
43
+ - Rakefile
44
+ - bin/console
45
+ - bin/setup
46
+ - bin/test-that
47
+ - lib/test_that.rb
48
+ - lib/test_that/rails_tester.rb
49
+ - lib/test_that/rspec_tester.rb
50
+ - lib/test_that/ruby_tester.rb
51
+ - lib/test_that/test_builder.rb
52
+ - lib/test_that/test_runner.rb
53
+ - lib/test_that/version.rb
54
+ homepage: https://github.com/peterjm/test_that
55
+ licenses:
56
+ - MIT
57
+ metadata:
58
+ homepage_uri: https://github.com/peterjm/test_that
59
+ source_code_uri: https://github.com/peterjm/test_that
60
+ changelog_uri: https://github.com/peterjm/test_that/CHANGELOG.md
61
+ rubygems_mfa_required: 'true'
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 2.6.0
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubygems_version: 3.2.32
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Run tests based on command line or standard-in
81
+ test_files: []