sus 0.3.0 → 0.5.2

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: 1c425b82649b8f50e5976153a010975266ed1484f41507cf81b3c1353223e489
4
- data.tar.gz: a67daffd36d952add4e867f2f8abb8f35a8b77b5c15daf7110bf022078142db0
3
+ metadata.gz: e7af09d0464d3ca51e1934e41acd230f7654faa864a37a6d21937023d282a180
4
+ data.tar.gz: 79205ad8526cd12292909e8509a859beda4854035c46b5ce696c0434b1287da4
5
5
  SHA512:
6
- metadata.gz: 8bcda2c3ad36727e6a4654216e7d82b1311c2194978f463b16798030dfec2bcdadf8daf3df48a00705d4831c1e1d8b24fae62e48c5d452027a13b0f66a9f6a58
7
- data.tar.gz: 31dacb8749146bcfb29a8ccd4a041e515dc03ecebc87b1cd9c02a1a09d5cd75b00f4b80396d1665ccdc10bfff047bc75e69bc0464be84d95ac1cfb9e33d5bcc6
6
+ metadata.gz: 28c12a85e343b51be0203b90aeff2e4c38d7031b2a835fa0cab1dfb9f4401de59dc2b747d5e4f45c7f5247c94a42267d0dfeb123bfdbb0a3b3a5e9eb546c781d
7
+ data.tar.gz: 58a4fe6cd8d9f0ba1c59334783260b60d70abf6ee710944ad1576d8e66e4f81b5c598afbfa6c9e495e544bf906fe02e461de99ecf0d60377552c8c2701a4c08a
data/lib/sus/be.rb CHANGED
@@ -11,7 +11,7 @@ module Sus
11
11
 
12
12
  def call(assertions, subject)
13
13
  assertions.nested(self) do |assertions|
14
- assertions.assert(subject.public_send(*@arguments), self)
14
+ assertions.assert(subject.public_send(*@arguments), subject)
15
15
  end
16
16
  end
17
17
 
data/lib/sus/be_within.rb CHANGED
@@ -12,7 +12,7 @@ module Sus
12
12
 
13
13
  def call(assertions, subject)
14
14
  assertions.nested(self) do |assertions|
15
- assertions.assert(@range.include?(subject), self)
15
+ assertions.assert(@range.include?(subject), subject)
16
16
  end
17
17
  end
18
18
  end
data/lib/sus/describe.rb CHANGED
@@ -7,16 +7,13 @@ module Sus
7
7
 
8
8
  attr_accessor :subject
9
9
 
10
- def self.extended(base)
11
- base.children = Hash.new
12
- end
13
-
14
- def self.build(parent, subject, identity: nil, &block)
10
+ def self.build(parent, subject, unique: true, &block)
15
11
  base = Class.new(parent)
16
- base.extend(Describe)
12
+ base.singleton_class.prepend(Describe)
13
+ base.children = Hash.new
17
14
  base.subject = subject
18
- base.description = subject.inspect
19
- base.identity = identity || Identity.nested(parent.identity, base.description)
15
+ base.description = subject.to_s
16
+ base.identity = Identity.nested(parent.identity, base.description, unique: unique)
20
17
  base.define_method(:subject, ->{subject})
21
18
 
22
19
  if block_given?
@@ -35,8 +32,8 @@ module Sus
35
32
  end
36
33
 
37
34
  module Context
38
- def describe(...)
39
- add Describe.build(self, ...)
35
+ def describe(subject, **options, &block)
36
+ add Describe.build(self, subject, **options, &block)
40
37
  end
41
38
  end
42
39
  end
data/lib/sus/file.rb ADDED
@@ -0,0 +1,34 @@
1
+
2
+ require_relative 'context'
3
+
4
+ # This has to be done at the top level. It allows us to define constants within the given class while still retaining top-level constant resolution.
5
+ Sus::TOPLEVEL_CLASS_EVAL = ->(klass, path){klass.class_eval(::File.read(path), path)}
6
+
7
+ module Sus
8
+ module File
9
+ extend Context
10
+
11
+ attr_accessor :path
12
+
13
+ def self.extended(base)
14
+ base.children = Hash.new
15
+ end
16
+
17
+ def self.build(parent, path)
18
+ base = Class.new(parent)
19
+ base.extend(File)
20
+ base.description = path
21
+ base.identity = Identity.new(path)
22
+
23
+ TOPLEVEL_CLASS_EVAL.call(base, path)
24
+
25
+ return base
26
+ end
27
+ end
28
+
29
+ module Context
30
+ def file(path)
31
+ add File.build(self, path)
32
+ end
33
+ end
34
+ end
data/lib/sus/filter.rb CHANGED
@@ -16,7 +16,13 @@ module Sus
16
16
  end
17
17
 
18
18
  def insert(identity, context)
19
- @contexts[identity.key] = context
19
+ key = identity.key
20
+
21
+ if existing_context = @contexts[key]
22
+ raise KeyError, "Assigning context to existing key: #{key.inspect}!"
23
+ else
24
+ @contexts[key] = context
25
+ end
20
26
  end
21
27
 
22
28
  def [] key
data/lib/sus/identity.rb CHANGED
@@ -7,6 +7,7 @@ module Sus
7
7
  self.new(location.path, name, location.lineno, parent, **options)
8
8
  end
9
9
 
10
+ # @parameter unique [Boolean | Symbol] Whether this identity is unique or needs a unique key/line number suffix.
10
11
  def initialize(path, name = nil, line = nil, parent = nil, unique: true)
11
12
  @path = path
12
13
  @name = name
@@ -55,7 +56,8 @@ module Sus
55
56
  unless @key
56
57
  key = Array.new
57
58
 
58
- append_unique_key(key, false)
59
+ # For a specific leaf node, the last part is not unique, i.e. it must be identified explicitly.
60
+ append_unique_key(key, @unique == true ? false : @unique)
59
61
 
60
62
  @key = key.join(':')
61
63
  end
@@ -72,8 +74,14 @@ module Sus
72
74
  key << @path
73
75
  end
74
76
 
75
- if @line
76
- key << @line unless unique
77
+ if unique == true
78
+ # No key is needed because this identity is unique.
79
+ else
80
+ if unique
81
+ key << unique
82
+ elsif @line
83
+ key << @line
84
+ end
77
85
  end
78
86
  end
79
87
  end
@@ -7,15 +7,12 @@ module Sus
7
7
 
8
8
  attr_accessor :shared
9
9
 
10
- def self.extended(base)
11
- base.children = Hash.new
12
- end
13
-
14
- def self.build(parent, shared)
10
+ def self.build(parent, shared, unique: false)
15
11
  base = Class.new(parent)
16
- base.extend(ItBehavesLike)
12
+ base.singleton_class.prepend(ItBehavesLike)
13
+ base.children = Hash.new
17
14
  base.description = shared.name
18
- base.identity = Identity.nested(parent.identity, base.description, unique: false)
15
+ base.identity = Identity.nested(parent.identity, base.description, unique: unique)
19
16
  base.class_exec(&shared.block)
20
17
  return base
21
18
  end
@@ -27,8 +24,8 @@ module Sus
27
24
  end
28
25
 
29
26
  module Context
30
- def it_behaves_like(shared)
31
- add ItBehavesLike.build(self, shared)
27
+ def it_behaves_like(shared, **options)
28
+ add ItBehavesLike.build(self, shared, **options)
32
29
  end
33
30
  end
34
31
  end
data/lib/sus/registry.rb CHANGED
@@ -1,6 +1,7 @@
1
1
 
2
2
  require_relative 'base'
3
3
 
4
+ require_relative 'file'
4
5
  require_relative 'describe'
5
6
  require_relative 'with'
6
7
 
@@ -12,9 +13,6 @@ require_relative 'include_context'
12
13
 
13
14
  require_relative 'let'
14
15
 
15
- # This has to be done at the top level. It allows us to define constants within the given class while still retaining top-level constant resolution.
16
- TOPLEVEL_CLASS_EVAL = ->(klass, path){klass.class_eval(File.read(path), path)}
17
-
18
16
  module Sus
19
17
  class Registry
20
18
  # Create a top level scope with self as the instance:
@@ -25,9 +23,7 @@ module Sus
25
23
  attr :base
26
24
 
27
25
  def load(path)
28
- @base.describe(path, identity: Identity.new(path)) do
29
- TOPLEVEL_CLASS_EVAL.call(self, path)
30
- end
26
+ @base.file(path)
31
27
  end
32
28
 
33
29
  def call(assertions = Assertions.default)
data/lib/sus/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sus
4
- VERSION = "0.3.0"
4
+ VERSION = "0.5.2"
5
5
  end
data/lib/sus/with.rb CHANGED
@@ -8,16 +8,13 @@ module Sus
8
8
  attr_accessor :subject
9
9
  attr_accessor :variables
10
10
 
11
- def self.extended(base)
12
- base.children = Hash.new
13
- end
14
-
15
- def self.build(parent, subject, variables, &block)
11
+ def self.build(parent, subject, variables, unique: true, &block)
16
12
  base = Class.new(parent)
17
- base.extend(With)
13
+ base.singleton_class.prepend(With)
14
+ base.children = Hash.new
18
15
  base.subject = subject
19
16
  base.description = subject
20
- base.identity = Identity.nested(parent.identity, base.description)
17
+ base.identity = Identity.nested(parent.identity, base.description, unique: unique)
21
18
  base.variables = variables
22
19
 
23
20
  variables.each do |key, value|
metadata CHANGED
@@ -1,19 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-08 00:00:00.000000000 Z
11
+ date: 2021-12-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
15
15
  executables:
16
16
  - sus
17
+ - sus-parallel
17
18
  extensions: []
18
19
  extra_rdoc_files: []
19
20
  files:
@@ -27,6 +28,7 @@ files:
27
28
  - lib/sus/context.rb
28
29
  - lib/sus/describe.rb
29
30
  - lib/sus/expect.rb
31
+ - lib/sus/file.rb
30
32
  - lib/sus/filter.rb
31
33
  - lib/sus/have_duration.rb
32
34
  - lib/sus/identity.rb
@@ -68,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
70
  - !ruby/object:Gem::Version
69
71
  version: '0'
70
72
  requirements: []
71
- rubygems_version: 3.3.0.dev
73
+ rubygems_version: 3.2.32
72
74
  signing_key:
73
75
  specification_version: 4
74
76
  summary: A fast and scalable test runner.