tryouts 2.2.0 → 2.3.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: 64a4341b114113a2302709a5d550682346092cc677c7dbc5933c6d7a3e139fa6
4
- data.tar.gz: 7e1f1e8fed19debc6e2b7766e76510c7904c1b565ae6c841571a0c005fbc755f
3
+ metadata.gz: 964b15141b2d2a8658bb5beee61ef9618ad478b8c29a4c91c5595dfb7ac92323
4
+ data.tar.gz: b33744a232df6dd0020deef5ea682217481ba6fc17d6d1336ccb9dc314080052
5
5
  SHA512:
6
- metadata.gz: 0d6cb90fb7b6e14cbbff68fd5aa5f0d46e93453490a088cdd613cbaf5f10522409a784015fbe5215fcc27c730003a7d3f380df3c303d8f7f6e0293522ae2df45
7
- data.tar.gz: 68f3f1202acf7f7e661435372bf4470462ff254cf2f25dd76902e4a01817d46a40a06e54e8b2a59acfb49c59520682234e19527a6745af0370d45c4cd675e278
6
+ metadata.gz: 4116e1c5918e226ec2232a55cd4dfdc8ff034948ceafa03ca3cdaecee6df4aa2f7d1dc5598eed66074f0c2e22c71492b7fab83c83b8869165897be69cabf4e9c
7
+ data.tar.gz: 826761b6d51762fb214380d05d438ab70b029bab4c7a138b59909ac096bcdc5bc79d7aed6c6f2509d728b6ea59f8ea03201fb42e6e77002fef1cd47a7635ec7d
data/LICENSE.txt CHANGED
@@ -1,4 +1,6 @@
1
- Copyright (c) 2010 Solutious Inc, Delano Mandelbaum
1
+ MIT License
2
+
3
+ Copyright (c) 2011-2024 Delano Mandelbaum
2
4
 
3
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
6
  of this software and associated documentation files (the "Software"), to deal
@@ -7,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
9
  copies of the Software, and to permit persons to whom the Software is
8
10
  furnished to do so, subject to the following conditions:
9
11
 
10
- The above copyright notice and this permission notice shall be included in
11
- all copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
12
14
 
13
15
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
16
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
17
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- THE SOFTWARE.
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,109 @@
1
+ # Tryouts v2.3.0 (2024-04-04)
2
+
3
+ **Ruby tests that read like documentation.**
4
+
5
+ A simple test framework for Ruby code that uses introspection to allow defining checks in comments.
6
+
7
+ ## Installation
8
+
9
+ One of:
10
+ * In your Gemfile: `gem 'tryouts'`
11
+ * As a gem: `gem install tryouts`
12
+ * From source:
13
+
14
+ ```bash
15
+ $ git clone git://github.com/tryouts/tryouts.git
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ```bash
21
+ # Run all tests accessible from the current directory (e.g. ./try, ./tryouts))
22
+ $ try
23
+
24
+ # Run a single test file
25
+ $ try try/10_utils_try.rb
26
+
27
+ # Command arguments
28
+ $ try -h
29
+ Usage: try [options]
30
+ -V, --version Display the version
31
+ -q, --quiet Run in quiet mode
32
+ -v, --verbose Run in verbose mode
33
+ -f, --fails Show only failing tryouts
34
+ -D, --debug Run in debug mode
35
+ -h, --help Display this help
36
+ ```
37
+
38
+ ### Exit codes
39
+
40
+ When all tests pass, try exits with a 0. An exit code of 1 or more indicates the number of failing tests.
41
+
42
+
43
+ ## Writing tests
44
+
45
+ ```ruby
46
+ ## A very simple test
47
+ 1 + 1
48
+ #=> 2
49
+
50
+ ## The test description can spread
51
+ ## across multiple lines. The same
52
+ ## is true for test definitions.
53
+ a = 'foo'
54
+ b = 'bar'
55
+ a + b
56
+ #=> 'foobar'
57
+
58
+ ## A test will pass when its return
59
+ ## value equals the expectation.
60
+ 'foo'.class
61
+ #=> String
62
+
63
+ ## The expectations are evaluated as well.
64
+ 81
65
+ #=> 9 * 9
66
+
67
+ ## Here's an example of testing errors
68
+ begin
69
+ raise RuntimeError
70
+ rescue RuntimeError
71
+ :success
72
+ end
73
+ #=> :success
74
+ ```
75
+
76
+ For real world examples, see [Onetimesecret](https://github.com/onetimesecret/onetimesecret/) tryouts.
77
+
78
+
79
+ ### Test setup / cleanup
80
+
81
+ Put the setup code at the top of the file, and cleanup code at the bottom. Like this:
82
+
83
+ ```ruby
84
+ # This is called before all tests
85
+ require 'gibbler'
86
+ Gibbler.digest_type = Digest::SHA256
87
+
88
+
89
+ ## This is a single testcase
90
+ :anything.gibbler
91
+ #=> '8574309'
92
+
93
+
94
+ # This will be called after all tests
95
+ Gibbler.digest_type = Digest::SHA1
96
+ ```
97
+
98
+ __
99
+
100
+
101
+ ## Thanks
102
+
103
+ * [cloudhead](https://github.com/cloudhead)
104
+ * [mynyml](https://github.com/mynyml)
105
+ * [Syntenic](https://syntenic.com/) for the hackfest venue.
106
+ * [AlexPeuchert](https://www.rubypulse.com/) for the screencast.
107
+ * Christian Michon for suggesting a better default output format.
108
+
109
+ *This collision was brought to you by Montreal.rb.*
data/exe/try ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require_relative '../lib/tryouts'
5
+
6
+ # Add local lib directories to the load path
7
+ Dir.glob(File.join(Dir.pwd, '{lib,..,lib}')).each { |dir| $LOAD_PATH.unshift(dir) }
8
+
9
+ # Parse command-line arguments
10
+ options = { quiet: false, noisy: false, fails: false }
11
+ OptionParser.new do |opts|
12
+ opts.on('-V', '--version', 'Display the version') { puts "Tryouts: #{Tryouts::VERSION}"; exit }
13
+ opts.on('-q', '--quiet', 'Run in quiet mode') { options[:quiet] = true }
14
+ opts.on('-v', '--verbose', 'Run in verbose mode') { options[:noisy] = true }
15
+ opts.on('-f', '--fails', 'Show only failing tryouts') { options[:fails] = true }
16
+ opts.on('-D', '--debug', 'Run in debug mode') { Tryouts.debug = true }
17
+ opts.on('-h', '--help', 'Display this help') { puts opts; exit }
18
+ end.parse!
19
+
20
+ # Set Tryouts options
21
+ Tryouts.quiet = options[:quiet]
22
+ Tryouts.noisy = options[:noisy]
23
+ Tryouts.fails = options[:fails]
24
+
25
+ # Find tryouts path
26
+ if ARGV.empty?
27
+ paths = Dir.glob(
28
+ ['./{try,tryouts/,.}/*_{try,tryouts}.rb'],
29
+ base: Dir.pwd,
30
+ sort: true # deterministic order
31
+ )
32
+
33
+ else
34
+ paths = ARGV
35
+ end
36
+
37
+ exit Tryouts.run_all(*paths)
data/exe/tryouts ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ load File.expand_path("../try", __FILE__)
@@ -0,0 +1,13 @@
1
+ class Tryouts
2
+ module VERSION
3
+ def self.to_s
4
+ load_config
5
+ [@version[:MAJOR], @version[:MINOR], @version[:PATCH]].join('.')
6
+ end
7
+ alias_method :inspect, :to_s
8
+ def self.load_config
9
+ require 'yaml'
10
+ @version ||= YAML.load_file(File.join(TRYOUTS_LIB_HOME, '..', 'VERSION.yml'))
11
+ end
12
+ end
13
+ end
data/lib/tryouts.rb CHANGED
@@ -4,30 +4,18 @@ unless defined?(TRYOUTS_LIB_HOME)
4
4
  TRYOUTS_LIB_HOME = File.expand_path File.dirname(__FILE__)
5
5
  end
6
6
 
7
- class Tryouts
8
- module VERSION
9
- def self.to_s
10
- load_config
11
- [@version[:MAJOR], @version[:MINOR], @version[:PATCH]].join('.')
12
- end
13
- alias_method :inspect, :to_s
14
- def self.load_config
15
- require 'yaml'
16
- @version ||= YAML.load_file(File.join(TRYOUTS_LIB_HOME, '..', 'VERSION.yml'))
17
- end
18
- end
19
- end
20
-
7
+ require_relative 'tryouts/version'
21
8
 
22
9
  class Tryouts
23
10
  @debug = false
24
11
  @quiet = false
25
12
  @noisy = false
13
+ @fails = false
26
14
  @container = Class.new
27
15
  @cases = []
28
16
  @sysinfo = nil
29
17
  class << self
30
- attr_accessor :debug, :container, :quiet, :noisy
18
+ attr_accessor :debug, :container, :quiet, :noisy, :fails
31
19
  attr_reader :cases
32
20
 
33
21
  def sysinfo
@@ -48,6 +36,12 @@ class Tryouts
48
36
 
49
37
  msg 'Ruby %s @ %-40s' % [RUBY_VERSION, Time.now], $/
50
38
 
39
+ if Tryouts.debug?
40
+ Tryouts.debug "Found #{paths.size} files:"
41
+ paths.each { |path| Tryouts.debug " #{path}" }
42
+ Tryouts.debug
43
+ end
44
+
51
45
  batches.each do |batch|
52
46
 
53
47
  path = batch.path.gsub(/#{Dir.pwd}\/?/, '')
@@ -55,7 +49,7 @@ class Tryouts
55
49
  vmsg '%-60s %s' % [path, '']
56
50
 
57
51
  before_handler = Proc.new do |t|
58
- if Tryouts.noisy
52
+ if Tryouts.noisy && !Tryouts.fails
59
53
  vmsg Console.reverse(' %-58s ' % [t.desc.to_s])
60
54
  vmsg t.test.inspect, t.exps.inspect
61
55
  end
@@ -64,19 +58,19 @@ class Tryouts
64
58
  batch.run(before_handler) do |t|
65
59
  if t.failed?
66
60
  failed_tests += 1
67
- if Tryouts.noisy
61
+ if Tryouts.noisy && Tryouts.fails
68
62
  vmsg Console.color(:red, t.failed.join($/)), $/
69
63
  else
70
64
  msg ' %s (%s:%s)' % [Console.color(:red, "FAIL"), path, t.exps.first]
71
65
  end
72
- elsif t.skipped? || !t.run?
66
+ elsif (t.skipped? || !t.run?) && !Tryouts.fails
73
67
  skipped_tests += 1
74
68
  if Tryouts.noisy
75
69
  vmsg Console.bright(t.skipped.join($/)), $/
76
70
  else
77
71
  msg ' SKIP (%s:%s)' % [path, t.exps.first]
78
72
  end
79
- else
73
+ elsif !Tryouts.fails
80
74
  if Tryouts.noisy
81
75
  vmsg Console.color(:green, t.passed.join($/)), $/
82
76
  else
metadata CHANGED
@@ -1,41 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tryouts
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delano Mandelbaum
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-05 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: sysinfo
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '0.10'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '0.10'
27
- description: 'Tryouts: Don''t waste your time writing tests'
28
- email: delano@solutious.com
11
+ date: 2024-06-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple test framework for Ruby code that uses introspection to allow
14
+ defining checks in comments.
15
+ email: gems@solutious.com
29
16
  executables:
30
17
  - try
18
+ - tryouts
31
19
  extensions: []
32
20
  extra_rdoc_files: []
33
21
  files:
34
22
  - LICENSE.txt
35
- - Rakefile
36
- - bin/try
23
+ - README.md
24
+ - exe/try
25
+ - exe/tryouts
37
26
  - lib/tryouts.rb
38
- homepage: http://github.com/delano/tryouts
27
+ - lib/tryouts/version.rb
28
+ homepage: https://github.com/delano/tryouts
39
29
  licenses:
40
30
  - MIT
41
31
  metadata: {}
@@ -47,7 +37,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
47
37
  requirements:
48
38
  - - ">="
49
39
  - !ruby/object:Gem::Version
50
- version: 2.6.8
40
+ version: 2.7.8
51
41
  required_rubygems_version: !ruby/object:Gem::Requirement
52
42
  requirements:
53
43
  - - ">="
@@ -57,5 +47,5 @@ requirements: []
57
47
  rubygems_version: 3.5.7
58
48
  signing_key:
59
49
  specification_version: 4
60
- summary: Don't waste your time writing tests
50
+ summary: Ruby tests that read like documentation.
61
51
  test_files: []
data/Rakefile DELETED
@@ -1,63 +0,0 @@
1
- require "rubygems"
2
- require "rake"
3
- require "rake/clean"
4
- require 'yaml'
5
-
6
- begin
7
- require 'hanna/rdoctask'
8
- rescue LoadError
9
- require 'rake/rdoctask'
10
- end
11
-
12
- config = YAML.load_file("VERSION.yml")
13
- task :default => ["build"]
14
- CLEAN.include [ 'pkg', 'doc' ]
15
- name = "stella"
16
-
17
- begin
18
- require "jeweler"
19
- Jeweler::Tasks.new do |gem|
20
- gem.version = "#{config[:MAJOR]}.#{config[:MINOR]}.#{config[:PATCH]}"
21
- gem.name = "tryouts"
22
- gem.rubyforge_project = gem.name
23
- gem.summary = "Don't waste your time writing tests"
24
- gem.description = gem.summary
25
- gem.email = "delano@solutious.com"
26
- gem.homepage = "http://github.com/delano/tryouts"
27
- gem.authors = ["Delano Mandelbaum"]
28
- gem.add_dependency("sysinfo", ">= 0.7.3")
29
- end
30
- Jeweler::GemcutterTasks.new
31
- rescue LoadError
32
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
33
- end
34
-
35
-
36
- Rake::RDocTask.new do |rdoc|
37
- version = "#{config[:MAJOR]}.#{config[:MINOR]}.#{config[:PATCH]}}"
38
- rdoc.rdoc_dir = "doc"
39
- rdoc.title = "stella #{version}"
40
- rdoc.rdoc_files.include("README*")
41
- rdoc.rdoc_files.include("LICENSE.txt")
42
- rdoc.rdoc_files.include("bin/*.rb")
43
- rdoc.rdoc_files.include("lib/**/*.rb")
44
- end
45
-
46
-
47
- # Rubyforge Release / Publish Tasks ==================================
48
-
49
- #about 'Publish website to rubyforge'
50
- task 'publish:rdoc' => 'doc/index.html' do
51
- sh "scp -rp doc/* rubyforge.org:/var/www/gforge-projects/#{name}/"
52
- end
53
-
54
- #about 'Public release to rubyforge'
55
- task 'publish:gem' => [:package] do |t|
56
- sh <<-end
57
- rubyforge add_release -o Any -a CHANGES.txt -f -n README.md #{name} #{name} #{@spec.version} pkg/#{name}-#{@spec.version}.gem &&
58
- rubyforge add_file -o Any -a CHANGES.txt -f -n README.md #{name} #{name} #{@spec.version} pkg/#{name}-#{@spec.version}.tgz
59
- end
60
- end
61
-
62
-
63
-
data/bin/try DELETED
@@ -1,47 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- #
4
- # Tryouts - Don't waste your time writing tests
5
- #
6
- # Usage:
7
- #
8
- # $ try
9
- # $ try -q
10
- # $ try -v
11
- # $ try path/2/file.rb
12
- # $ try -q path/2/file.rb path/2/another.rb
13
- #
14
-
15
- # Put our local lib in first place
16
- BASE_PATH = File.expand_path File.join(File.dirname(__FILE__), '..')
17
- lib_dir = File.join(BASE_PATH, 'lib')
18
- $:.unshift lib_dir
19
-
20
- require 'tryouts'
21
-
22
- # Help out the requires in the tryouts
23
- [File.join(Dir.pwd, 'lib'), File.join(Dir.pwd, '..', 'lib')].each do |dir|
24
- $:.unshift dir
25
- end
26
-
27
- unless ARGV.delete('-V').nil?
28
- puts "Tryouts: #{Tryouts::VERSION}"
29
- exit
30
- end
31
-
32
- Tryouts.quiet = !ARGV.delete('-q').nil? # eg try -q [PATH]
33
- Tryouts.noisy = !ARGV.delete('-v').nil? # eg try -v [PATH]
34
-
35
- if ARGV.empty?
36
- paths = Dir.glob(File.join(Dir.pwd, '{try,tryouts}', '*_{try,tryouts}.rb'))
37
- paths += Dir.glob(File.join(Dir.pwd, '*_{try,tryouts}.rb'))
38
- else
39
- paths = ARGV
40
- end
41
-
42
- #Tryouts.quiet
43
- #Tryouts.debug = true
44
- #Tryouts.container = self
45
-
46
- exit Tryouts.run_all(*paths)
47
-