uspec 1.0.2 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6763c9a1b9995386967bfb824889265c9bee560a86012728055bb107a4dd910
4
- data.tar.gz: 74912e14810a2b03d596addcb14fe3696cd79efd3f8c104c49a4d65055aaca87
3
+ metadata.gz: 8d937f702b24f432fa7a241bd2fdd4f01a6119f6da79f98f1efd3e5f726cba22
4
+ data.tar.gz: 297733864622a5a0032918a9c6d83bac21e90df4b141c5898e7309a248cb1982
5
5
  SHA512:
6
- metadata.gz: ead8cbbee34c75b337685d1c3533c6129d39d870cd9abf94b7365317760f6c42aeab6a7d30749fab352139c947669514c2870d3542bbcd1e2160e020f5574fcc
7
- data.tar.gz: cfa24d4154e3b0a95257cd544fa45451c551e460cb3a7f6ac995c3446a1a09623729d03843c41bace49adfda04ea1a58e42cb1eb62e431a4e149d83afaa85e13
6
+ metadata.gz: e6bb5da0e65a04f60292ee4b74184e02081571eaf942c915eb239a9b98b7bb9f420d7a4da0b2fbacb9f370fb0769b2336deee1686fe250c5793953fe7ba8ed41
7
+ data.tar.gz: 6c1a3721ed8a8d41bc65583812a9abafeacf251dba910867b3567addb412c646237f64c68971a0cbc87e38f0abdaaeb8b652139c9f0b8a412e92dfae9c4e5609
data/.circleci/config.yml CHANGED
@@ -1,16 +1,23 @@
1
1
  version: 2.1
2
2
  orbs:
3
- ruby: circleci/ruby@0.1.2
3
+ ruby: circleci/ruby@2.0.0
4
4
 
5
5
  jobs:
6
6
  build:
7
- executor: ruby/default
7
+ docker:
8
+ - image: cimg/ruby:3.1.2
9
+
10
+ working_directory: ~/repo
11
+
8
12
  steps:
9
13
  - checkout
10
14
  - run:
11
- name: Which bundler?
12
- command: bundle -v
13
- - ruby/bundle-install
15
+ name: install dependencies
16
+ command: |
17
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
18
+
19
+ # run tests!
14
20
  - run:
15
- name: Uspec tests
16
- command: bundle exec uspec
21
+ name: run tests
22
+ command:
23
+ bundle exec uspec
data/.gitignore CHANGED
@@ -15,3 +15,6 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+
19
+ tags
20
+ TAGS
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.0.1
1
+ 3.3.0
data/lib/uspec/dsl.rb CHANGED
@@ -2,6 +2,10 @@ require_relative "result"
2
2
 
3
3
  module Uspec
4
4
  class DSL
5
+ USPEC_CLI_BLOCK = -> { @__uspec_dsl.__uspec_cli }
6
+ USPEC_STAT_BLOCK = -> { @__uspec_dsl.__uspec_cli.stats }
7
+ USPEC_SPEC_BLOCK = ->(description, &block) { @__uspec_dsl.spec description, &block }
8
+
5
9
  def initialize cli
6
10
  @__uspec_cli = cli
7
11
  end
@@ -14,19 +18,35 @@ module Uspec
14
18
  @__uspec_cli.stats
15
19
  end
16
20
 
17
- def spec description
21
+ def __uspec_eval block
22
+ o = Object.new
23
+ o.define_singleton_method :__uspec_stats, USPEC_STAT_BLOCK
24
+ o.define_singleton_method :__uspec_cli, USPEC_CLI_BLOCK
25
+ o.instance_variable_set :@__uspec_cli, @__uspec_cli
26
+ o.instance_variable_set :@__uspec_dsl, self
27
+ o.define_singleton_method :spec, USPEC_SPEC_BLOCK
28
+ o.define_singleton_method :spec_block, &block
29
+ o.spec_block
30
+ end
31
+
32
+ def spec description, &block
33
+ state = 0
18
34
  print ' -- ', description
19
35
 
20
- if block_given? then
36
+ if block then
21
37
  begin
22
- raw_result = yield
38
+ state = 1
39
+ raw_result = __uspec_eval block
40
+ state = 2
23
41
  rescue Exception => raw_result
42
+ state = 3
24
43
  end
25
44
  end
26
45
 
27
46
  result = Result.new description, raw_result, caller
28
47
 
29
- unless block_given? then
48
+ unless block then
49
+ state = 4
30
50
  result.pending!
31
51
  end
32
52
 
@@ -40,6 +60,7 @@ module Uspec
40
60
 
41
61
  print ': ', result.pretty, "\n"
42
62
  rescue => error
63
+ state = 5
43
64
  message = <<-MSG
44
65
  #{error.class} : #{error.message}
45
66
 
@@ -50,6 +71,8 @@ module Uspec
50
71
  puts
51
72
  warn message
52
73
  __uspec_stats.failure << Uspec::Result.new(message, error, caller)
74
+ ensure
75
+ return [state, error, result, raw_result]
53
76
  end
54
77
  end
55
78
  end
data/lib/uspec/result.rb CHANGED
@@ -5,6 +5,8 @@ module Uspec
5
5
  class Result
6
6
  include Terminal
7
7
 
8
+ PREFIX = "#{Terminal.newline}#{Terminal.yellow}>\t#{Terminal.normal}"
9
+
8
10
  def initialize spec, raw, source
9
11
  @spec = spec
10
12
  @raw = raw
@@ -56,11 +58,9 @@ module Uspec
56
58
  def inspector
57
59
  if String === raw && raw.include?(?\n) then
58
60
  # if object is a multiline string, display it unescaped
61
+
59
62
  [
60
- vspace,
61
- hspace, yellow('"""'), newline,
62
- raw, normal, newline,
63
- hspace, yellow('"""')
63
+ raw.split(newline).unshift(newline).join(PREFIX), normal, newline,
64
64
  ].join
65
65
  else
66
66
  handler.inspector!
data/lib/uspec/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Uspec
2
- VERSION = '1.0.2'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -0,0 +1,21 @@
1
+ require_relative "uspec_helper"
2
+
3
+ spec 'when return used in spec, capture it as an error' do
4
+ path = Pathname.new(__FILE__).parent.join('test_specs', 'return_spec')
5
+
6
+ output = capture do
7
+ exec "bin/uspec #{path}"
8
+ end
9
+
10
+ output.include?('Invalid return') || output.include?('Spec did not return a boolean value') || output
11
+ end
12
+
13
+ spec 'when break used in spec, capture it as an error' do
14
+ path = Pathname.new(__FILE__).parent.join('test_specs', 'break_spec')
15
+
16
+ output = capture do
17
+ exec "bin/uspec #{path}"
18
+ end
19
+
20
+ output.include?('Invalid break') || output.include?('Spec did not return a boolean value') || output
21
+ end
data/uspec/result_spec.rb CHANGED
@@ -61,9 +61,9 @@ spec "display a useful error message when a user-defined inspect method fails" d
61
61
  end
62
62
 
63
63
  spec "display strings more like their actual contents" do
64
- expected = "this string:\nshould display \e[42;2mproperly"
65
- result = Uspec::Result.new "Inspect Fail Result", expected, []
64
+ string = "this string:\nshould display \e\[42;2mproperly"
65
+ expected = /this string:\n.*should display \e\[42;2mproperly/
66
+ result = Uspec::Result.new "Inspect Fail Result", string, []
66
67
  actual = result.pretty
67
- actual.include?(expected) || result.inspector
68
+ actual.match?(expected) || result.inspector
68
69
  end
69
-
@@ -0,0 +1,3 @@
1
+ spec "break spec" do
2
+ break 12345
3
+ end
@@ -0,0 +1,6 @@
1
+
2
+ require_relative "../uspec_helper"
3
+
4
+ spec "why is this broken??"
5
+
6
+
@@ -0,0 +1,3 @@
1
+ spec "return spec" do
2
+ return 12345
3
+ end
@@ -0,0 +1,3 @@
1
+ spec 'non-boolean value spec' do
2
+ "abcdef"
3
+ end
@@ -1,3 +1,5 @@
1
+ require 'pry'
2
+
1
3
  require_relative '../lib/uspec'
2
4
  extend Uspec
3
5
 
@@ -17,4 +19,3 @@ def capture
17
19
 
18
20
  output
19
21
  end
20
-
data/uspec/uspec_spec.rb CHANGED
@@ -7,7 +7,7 @@ spec 'catches errors' do
7
7
  end
8
8
  end
9
9
 
10
- output.include? 'Exception'
10
+ output.include?('Exception') || output
11
11
  end
12
12
 
13
13
  spec 'catches even non-StandardError-subclass exceptions' do
@@ -17,7 +17,7 @@ spec 'catches even non-StandardError-subclass exceptions' do
17
17
  end
18
18
  end
19
19
 
20
- output.include? 'Exception'
20
+ output.include?('Exception') || output
21
21
  end
22
22
 
23
23
  spec 'complains when spec block returns non boolean' do
@@ -27,7 +27,7 @@ spec 'complains when spec block returns non boolean' do
27
27
  end
28
28
  end
29
29
 
30
- output.include? 'Failed'
30
+ output.include?('Failed') || output
31
31
  end
32
32
 
33
33
  spec 'marks test as pending when no block supplied' do
@@ -35,7 +35,7 @@ spec 'marks test as pending when no block supplied' do
35
35
  spec 'pending test'
36
36
  end
37
37
 
38
- output.include? 'pending'
38
+ output.include?('pending') || output
39
39
  end
40
40
 
41
41
  spec 'should not define DSL methods on arbitrary objects' do
@@ -57,11 +57,11 @@ spec 'exit code is the number of failures' do
57
57
  end
58
58
  actual = $?.exitstatus
59
59
 
60
- actual == expected || puts("", output) || $?
60
+ actual == expected || output
61
61
  end
62
62
 
63
- spec 'if more than 255 failures, exit status is 255' do
64
- capture do
63
+ spec 'when more than 255 failures, exit status is 255' do
64
+ output = capture do
65
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
@@ -73,5 +73,5 @@ spec 'if more than 255 failures, exit status is 255' do
73
73
  exit __uspec_cli.exit_code
74
74
  end
75
75
 
76
- $?.exitstatus == 255 || $?
76
+ $?.exitstatus == 255 || [$?, output]
77
77
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony M. Cook
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-04 00:00:00.000000000 Z
11
+ date: 2024-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: that_object_is_so_basic
@@ -84,15 +84,20 @@ files:
84
84
  - lib/uspec/version.rb
85
85
  - uspec.gemspec
86
86
  - uspec/cli_spec.rb
87
+ - uspec/jump_spec.rb
87
88
  - uspec/result_spec.rb
89
+ - uspec/test_specs/break_spec
88
90
  - uspec/test_specs/broken_require_spec
91
+ - uspec/test_specs/pending_spec
92
+ - uspec/test_specs/return_spec
93
+ - uspec/test_specs/value_spec
89
94
  - uspec/uspec_helper.rb
90
95
  - uspec/uspec_spec.rb
91
96
  homepage: http://github.com/acook/uspec#readme
92
97
  licenses:
93
98
  - MIT
94
99
  metadata: {}
95
- post_install_message:
100
+ post_install_message:
96
101
  rdoc_options: []
97
102
  require_paths:
98
103
  - lib
@@ -107,8 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
112
  - !ruby/object:Gem::Version
108
113
  version: '0'
109
114
  requirements: []
110
- rubygems_version: 3.2.15
111
- signing_key:
115
+ rubygems_version: 3.5.3
116
+ signing_key:
112
117
  specification_version: 4
113
118
  summary: a shiny little spec framework for your apps!
114
119
  test_files: []