uspec 0.3.0 → 1.0.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: 641541f23b26b9c14b11950c55f9161aa89142aa41b8627a9f2dcbe54ac11584
4
- data.tar.gz: a02353485421133ac4fa3eb639a7942992152faee3db2f484da4da56917014d6
3
+ metadata.gz: adfc4745c3e11f9afa82923366d86c5515745666b98606ded26418cb520b9bb9
4
+ data.tar.gz: b62be6efc2f67ba658c2701b6984764d7fdb36e0acc79f1e20378efeef1c534c
5
5
  SHA512:
6
- metadata.gz: 1776508a0bc6ca4da5e90167072244305b9994b407d75fce53048bda6cad1a439adee75ecb0ddf534728f6ab6ad268a44588013a57f225df74f38a0e1c85a5c8
7
- data.tar.gz: 1b39cb64033e21f466ee0a8edaea706e20589f92b3cbae80eb41e624c3dca9f24f1c376f277a7c5061f8b5d20608ea49cf1de71b9014409d4d5bc28b6d1ad702
6
+ metadata.gz: b89e9ab10352cbe0d18278c1d5aa823b72d3d9c40dbf49d0c2791b6f92748841d2018e6ac1ddee04016fa40c6353a76c94d8c6c7bfe11c7197a60606e38180b5
7
+ data.tar.gz: 51dc3f357ffff68b6e7ffc3d1a81376ad2755813490a2749e55bbcef6142ae3432f92076b7dcd5599625f55fb77ce6a8f099612972119bf90f24315e30d7f688
@@ -0,0 +1,21 @@
1
+ version: 2.1
2
+ orbs:
3
+ ruby: circleci/ruby@0.1.2
4
+
5
+ jobs:
6
+ build:
7
+ docker:
8
+ - image: circleci/ruby:2.6.3-stretch-node
9
+ executor: ruby/default
10
+ steps:
11
+ - checkout
12
+ - run:
13
+ name: Which bundler?
14
+ command: bundle -v
15
+ - ruby/bundle-install
16
+ test:
17
+ executor: ruby/default
18
+ steps:
19
+ - run:
20
+ name: Uspec tests
21
+ command: bundle exec uspec
data/README.markdown CHANGED
@@ -4,7 +4,7 @@ Uspec
4
4
  Uspec is a shiny little testing framework for your apps!
5
5
 
6
6
  [![Gem Version](https://img.shields.io/gem/v/uspec.svg?style=for-the-badge)](https://rubygems.org/gems/uspec/)
7
- [![Build Status](https://img.shields.io/travis/acook/uspec.svg?style=for-the-badge)](https://travis-ci.org/acook/uspec)
7
+ [![Build Status](https://img.shields.io/circleci/build/github/acook/uspec.svg?style=for-the-badge)](https://app.circleci.com/pipelines/github/acook/uspec)
8
8
  [![Code Climate](https://img.shields.io/codeclimate/maintainability/acook/uspec.svg?style=for-the-badge)](https://codeclimate.com/github/acook/uspec)
9
9
 
10
10
  Philosophy / Why Uspec?
data/bin/uspec CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require_relative '../lib/uspec/cli'
4
- Uspec::CLI.invoke ARGV
4
+ Uspec::CLI.new(ARGV).invoke
data/lib/uspec.rb CHANGED
@@ -8,15 +8,10 @@ module Uspec
8
8
  exit 2
9
9
  end
10
10
 
11
+ # this method used to be how we injected the spec method
11
12
  def self.extended object
12
- object.extend Uspec::DSL
13
+ #unless object.respond_to? :spec
14
+ # object.extend Uspec::DSL
15
+ #end
13
16
  end
14
17
  end
15
-
16
- at_exit do
17
- failures = Uspec::Stats.exit_code
18
- status = $!.respond_to?(:status) ? $!.status : 0
19
- errors = $!.respond_to?(:cause) && $!.cause ? 1 : 0
20
- code = [failures, status, errors].max
21
- exit code
22
- end
data/lib/uspec/cli.rb CHANGED
@@ -2,29 +2,34 @@ require 'pathname'
2
2
  require_relative '../uspec'
3
3
 
4
4
  class Uspec::CLI
5
- class << self
6
- def usage
7
- warn "uspec v#{::Uspec::VERSION} - minimalistic ruby testing framework"
8
- warn "usage: #{File.basename $0} [<file_or_path>...]"
9
- end
5
+ def initialize args
6
+ usage unless (args & %w[-h --help -? /? -v --version]).empty?
10
7
 
11
- def run_specs paths
12
- uspec_cli = self.new paths
13
- uspec_cli.run_paths
14
- end
8
+ @paths = args
9
+ @pwd = Pathname.pwd.freeze
10
+ @stats = Uspec::Stats.new
11
+ @dsl = Uspec::DSL.new self
12
+ end
13
+ attr :stats, :dsl
15
14
 
16
- def invoke args
17
- if (args & %w[-h --help -? /? -v --version]).empty? then
18
- run_specs args
19
- else
20
- usage
21
- end
22
- end
15
+ def usage
16
+ warn "uspec v#{::Uspec::VERSION} - minimalistic ruby testing framework"
17
+ warn "usage: #{File.basename $0} [<file_or_path>...]"
18
+ exit 1
23
19
  end
24
20
 
25
- def initialize paths
26
- @paths = paths
27
- @pwd = Pathname.pwd.freeze
21
+ def run_specs
22
+ run_paths
23
+ end
24
+
25
+ def invoke
26
+ run_specs
27
+ puts @stats.summary
28
+ exit exit_code
29
+ end
30
+
31
+ def exit_code
32
+ [@stats.failure.size, 255].min
28
33
  end
29
34
 
30
35
  def paths
@@ -51,7 +56,7 @@ class Uspec::CLI
51
56
  end
52
57
  elsif path.exist? then
53
58
  puts "#{path.basename path.extname}:"
54
- Uspec::DSL.instance_eval(path.read, path.to_s)
59
+ dsl.instance_eval(path.read, path.to_s)
55
60
  else
56
61
  warn "path not found: #{path}"
57
62
  end
@@ -74,7 +79,7 @@ class Uspec::CLI
74
79
  MSG
75
80
  puts
76
81
  warn message
77
- Uspec::Stats.results << Uspec::Result.new(message, error, caller)
82
+ self.class.stats.failure << Uspec::Result.new(message, error, caller)
78
83
  end
79
84
 
80
85
  end
data/lib/uspec/dsl.rb CHANGED
@@ -1,23 +1,42 @@
1
1
  require_relative "result"
2
2
 
3
3
  module Uspec
4
- module DSL
5
- module_function
6
- def spec description
7
- terminal = Uspec::Terminal
4
+ class DSL
5
+ def initialize cli
6
+ @__uspec_cli = cli
7
+ end
8
8
 
9
- print ' -- ', description
9
+ def __uspec_cli
10
+ @__uspec_cli
11
+ end
10
12
 
11
- return print(': ' + terminal.yellow('pending') + terminal.newline) unless block_given?
13
+ def __uspec_stats
14
+ @__uspec_cli.stats
15
+ end
12
16
 
13
- begin
14
- raw_result = yield
15
- rescue Exception => raw_result
17
+ def spec description
18
+ print ' -- ', description
19
+
20
+ if block_given? then
21
+ begin
22
+ raw_result = yield
23
+ rescue Exception => raw_result
24
+ end
16
25
  end
17
26
 
18
27
  result = Result.new description, raw_result, caller
19
28
 
20
- Uspec::Stats.results << result
29
+ unless block_given? then
30
+ result.pending!
31
+ end
32
+
33
+ if result.success?
34
+ __uspec_stats.success << result
35
+ elsif result.pending?
36
+ stats.pending << result
37
+ else
38
+ __uspec_stats.failure << result
39
+ end
21
40
 
22
41
  print ': ', result.pretty, "\n"
23
42
  rescue => error
@@ -30,7 +49,7 @@ module Uspec
30
49
  MSG
31
50
  puts
32
51
  warn message
33
- Uspec::Stats.results << Uspec::Result.new(message, error, caller)
52
+ __uspec_stats.failure << Uspec::Result.new(message, error, caller)
34
53
  end
35
54
  end
36
55
  end
data/lib/uspec/result.rb CHANGED
@@ -18,6 +18,8 @@ module Uspec
18
18
  green raw
19
19
  elsif raw == false then
20
20
  red raw
21
+ elsif pending? then
22
+ yellow 'pending'
21
23
  elsif Exception === raw then
22
24
  [
23
25
  red('Exception'), vspace,
@@ -53,9 +55,9 @@ module Uspec
53
55
  # Attempts to inspect an object
54
56
  def inspector
55
57
  if String === raw && raw.include?(?\n) then
56
- # if object is a multiline string, display it escaped and unescaped
58
+ # if object is a multiline string, display it unescaped
57
59
  [
58
- handler.inspector!, vspace,
60
+ vspace,
59
61
  hspace, yellow('"""'), newline,
60
62
  raw, normal, newline,
61
63
  hspace, yellow('"""')
@@ -86,6 +88,22 @@ module Uspec
86
88
  MSG
87
89
  end
88
90
 
91
+ def success?
92
+ raw == true
93
+ end
94
+
95
+ def failure?
96
+ raw != true && !@pending
97
+ end
98
+
99
+ def pending?
100
+ !!@pending
101
+ end
102
+
103
+ def pending!
104
+ @pending = true
105
+ end
106
+
89
107
  def inspect
90
108
  "#{self.class} for `#{spec}` -> #{pretty}"
91
109
  end
data/lib/uspec/stats.rb CHANGED
@@ -1,30 +1,36 @@
1
1
  module Uspec
2
2
  class Stats
3
- class << self
4
- def results?
5
- !results.empty?
6
- end
7
-
8
- def results
9
- @results ||= clear_results!
10
- end
11
-
12
- def clear_results!
13
- @results = Array.new
14
- end
3
+ def initialize
4
+ clear_results!
5
+ end
6
+ attr :success, :failure, :pending
15
7
 
16
- def exit_code
17
- # checking for truthy isn't good enough, it must be exactly true!
18
- failures = results.count{|result| result.raw != true }
19
- failures > 255 ? 255 : failures
20
- end
8
+ def clear_results!
9
+ @success = Array.new
10
+ @failure = Array.new
11
+ @pending = Array.new
12
+ end
21
13
 
22
- def inspect
23
- <<-INFO
14
+ def inspect
15
+ <<-INFO
24
16
  #{super} Failures: #{exit_code}
25
17
  #{results.map{|r| r.inspect}.join "\n\t" }
26
- INFO
27
- end
18
+ INFO
19
+ end
20
+
21
+ def results
22
+ @success + @failure + @pending
23
+ end
24
+
25
+ def summary
26
+ [
27
+ "test summary: ",
28
+ Uspec::Terminal.green("#{@success.size} successful"),
29
+ ", ",
30
+ Uspec::Terminal.red("#{@failure.size} failed"),
31
+ ", ",
32
+ Uspec::Terminal.yellow("#{@pending.size} pending")
33
+ ].join
28
34
  end
29
35
  end
30
36
  end
data/lib/uspec/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Uspec
2
- VERSION = '0.3.0'
2
+ VERSION = '1.0.0'
3
3
  end
data/uspec/cli_spec.rb CHANGED
@@ -12,7 +12,7 @@ end
12
12
  spec 'runs a path of specs' do
13
13
  output = capture do
14
14
  path = Pathname.new(__FILE__).parent.parent.join('example_specs').to_s
15
- Uspec::CLI.run_specs Array(path)
15
+ Uspec::CLI.new(Array(path)).run_specs
16
16
  end
17
17
 
18
18
  output.include?('I love passing tests') || output
@@ -21,7 +21,7 @@ end
21
21
  spec 'runs an individual spec' do
22
22
  output = capture do
23
23
  path = Pathname.new(__FILE__).parent.parent.join('example_specs', 'example_spec.rb').to_s
24
- Uspec::CLI.run_specs Array(path)
24
+ Uspec::CLI.new(Array(path)).run_specs
25
25
  end
26
26
 
27
27
  output.include?('I love passing tests') || output
data/uspec/uspec_spec.rb CHANGED
@@ -45,7 +45,7 @@ end
45
45
  spec 'exit code is the number of failures' do
46
46
  expected = 50
47
47
  output = capture do
48
- Uspec::Stats.clear_results! # because we're forking, we will have a copy of the current results
48
+ __uspec_stats.clear_results! # because we're forking, we will have a copy of the current results
49
49
 
50
50
  expected.times do |count|
51
51
  spec "fail ##{count + 1}" do
@@ -53,7 +53,7 @@ spec 'exit code is the number of failures' do
53
53
  end
54
54
  end
55
55
 
56
- puts(Uspec::Stats.inspect) unless Uspec::Stats.exit_code == expected
56
+ exit __uspec_cli.exit_code
57
57
  end
58
58
  actual = $?.exitstatus
59
59
 
@@ -62,13 +62,15 @@ end
62
62
 
63
63
  spec 'if more than 255 failures, exit status is 255' do
64
64
  capture do
65
- Uspec::Stats.clear_results! # because we're forking, we will have a copy of the current results
65
+ __uspec_stats.clear_results! # because we're forking, we will have a copy of the current results
66
66
 
67
67
  500.times do
68
68
  spec 'fail' do
69
69
  false
70
70
  end
71
71
  end
72
+
73
+ exit __uspec_cli.exit_code
72
74
  end
73
75
 
74
76
  $?.exitstatus == 255 || $?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony M. Cook
@@ -62,12 +62,12 @@ executables:
62
62
  extensions: []
63
63
  extra_rdoc_files: []
64
64
  files:
65
+ - ".circleci/config.yml"
65
66
  - ".editorconfig"
66
67
  - ".gitignore"
67
68
  - ".rubocop.yml"
68
69
  - ".ruby-gemset"
69
70
  - ".ruby-version"
70
- - ".travis.yml"
71
71
  - Gemfile
72
72
  - LICENSE.txt
73
73
  - README.markdown
data/.travis.yml DELETED
@@ -1,31 +0,0 @@
1
- language: ruby
2
-
3
- rvm:
4
- - 2.6.3
5
- - 2.5.5
6
- - 2.4.6
7
- - 2.3.8
8
- - 2.2.10
9
- - 2.1.10
10
-
11
- - 2.0.0
12
- - 1.9.3
13
- - 1.9.2
14
- - jruby-19mode
15
- - ruby-head
16
-
17
- before_install:
18
- - gem update bundler
19
- before_script:
20
- - bundle exec gem list
21
- script: bundle exec uspec
22
-
23
- matrix:
24
- allow_failures:
25
- - rvm: 2.0.0
26
- - rvm: 1.9.3
27
- - rvm: 1.9.2
28
- - rvm: ruby-head
29
- - rvm: jruby-19mode
30
-
31
- sudo: false