stable 1.7.0 → 1.9.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: 705f529d889248982d60df5c8257a80ddca578714403e68b8a60f7f88478223a
4
- data.tar.gz: e8ace2f93edb08e1981750332c6034408a9d12cc08e2b7a0c1b07b64ca032496
3
+ metadata.gz: 8a2b6fc3bf7590daccd1378415092843366ec6b1513e307fcb25fadbcc61b38c
4
+ data.tar.gz: dbac42dc22435e4004408ff51f087ce48766c856d00879582579fe99633292bb
5
5
  SHA512:
6
- metadata.gz: f51fb0d25f5b0318a8a5759d0849b16d93bd8187bf5ddd97fa2aad4a584e3a18c1f5e24374d164d8f07ad03edc79a4127341bf47099c600544fed0bffb866671
7
- data.tar.gz: da63baa93a76c20c46b51ed5c9fff23671797a46b698d7b277e8db5dafa03c924afe5f32f296051755738613d4c25d8e8dfd35af6b6c951327580eddb10e2296
6
+ metadata.gz: e86bc6d7356812bed7bb283879b14c7ef140b54ba55ea8e3790818af094333859a56a01e3be07f3dbd8a15986610c137449574ed2fddee99401a71c2055559ae
7
+ data.tar.gz: e39ebfeceddf3d8469bc2223caa64dabb7d7068828705b5340d60ee083b5eeff6a70a89c14c0c56814dcc90ffe8d15c62145901f34911ea37e95fed976cba60e
@@ -0,0 +1,15 @@
1
+ # lib/example/calculator.rb
2
+ class Calculator
3
+ def add(a, b)
4
+ a + b
5
+ end
6
+
7
+ def subtract(a, b)
8
+ a - b
9
+ end
10
+
11
+ def divide(a, b)
12
+ raise ZeroDivisionError, "Cannot divide by zero" if b.zero?
13
+ a.to_f / b
14
+ end
15
+ end
data/lib/stable/spec.rb CHANGED
@@ -8,9 +8,9 @@ module Stable
8
8
  # outputs. it's a self-contained, serializable representation of a method's
9
9
  # behavior at a specific point in time.
10
10
  class Spec
11
- attr_reader :class_name, :method_name, :args, :result, :error, :actual_result, :actual_error, :status, :uuid, :signature
11
+ attr_reader :class_name, :method_name, :args, :result, :error, :actual_result, :actual_error, :status, :uuid, :signature, :name
12
12
 
13
- def initialize(class_name:, method_name:, args:, result: nil, error: nil, uuid: SecureRandom.uuid)
13
+ def initialize(class_name:, method_name:, args:, result: nil, error: nil, uuid: SecureRandom.uuid, name: nil)
14
14
  @class_name = class_name
15
15
  @method_name = method_name
16
16
  @args = args
@@ -19,13 +19,13 @@ module Stable
19
19
  @status = :pending
20
20
  @uuid = uuid
21
21
  @signature = Digest::SHA256.hexdigest("#{class_name}##{method_name}:#{args.to_json}")
22
+ @name = name || SecureRandom.hex(8)
22
23
  end
23
24
 
24
25
  def run!
25
- klass = Object.const_get(class_name)
26
- instance = klass.new
27
-
28
26
  begin
27
+ klass = Object.const_get(class_name)
28
+ instance = klass.new
29
29
  @actual_result = instance.public_send(method_name, *args)
30
30
  if error
31
31
  @status = :failed
@@ -49,15 +49,16 @@ module Stable
49
49
  short_uuid = uuid.split('-').last
50
50
  short_sig = signature[0..6]
51
51
  desc = "#{short_uuid}/#{short_sig}"
52
+ name_str = name[..19].ljust(20)
52
53
  call = "#{class_name}##{method_name}(#{args.join(', ')})"
53
54
  status_code = _status_code
54
55
  error_code = _error_code
55
56
 
56
57
  case status
57
58
  when :passed, :passed_with_error
58
- "#{desc} #{status_code}#{error_code} #{call}"
59
+ "#{desc} #{name_str} #{status_code}#{error_code} #{call}"
59
60
  when :failed
60
- lines = ["#{desc} #{status_code}#{error_code} #{call}"]
61
+ lines = ["#{desc} #{name_str} #{status_code}#{error_code} #{call}"]
61
62
  if actual_error
62
63
  if error
63
64
  lines << " Expected error: #{error['class']}"
@@ -77,7 +78,7 @@ module Stable
77
78
  end
78
79
  lines.join("\n")
79
80
  else
80
- "#{desc} #{status_code}#{error_code} #{call}"
81
+ "#{desc} #{name_str} #{status_code}#{error_code} #{call}"
81
82
  end
82
83
  end
83
84
 
@@ -89,7 +90,8 @@ module Stable
89
90
  result: result,
90
91
  error: error,
91
92
  uuid: uuid,
92
- signature: signature
93
+ signature: signature,
94
+ name: name
93
95
  }.compact.to_json
94
96
  end
95
97
 
@@ -101,7 +103,8 @@ module Stable
101
103
  args: data['args'],
102
104
  result: data['result'],
103
105
  error: data['error'],
104
- uuid: data['uuid']
106
+ uuid: data['uuid'],
107
+ name: data['name']
105
108
  )
106
109
  end
107
110
 
data/lib/stable.rb CHANGED
@@ -3,6 +3,10 @@
3
3
  require_relative 'stable/spec'
4
4
  require_relative 'stable/configuration'
5
5
 
6
+ if defined?(Rake)
7
+ load File.expand_path('../tasks/stable.rake', __FILE__)
8
+ end
9
+
6
10
  module Stable
7
11
  class << self
8
12
  def configuration
metadata CHANGED
@@ -1,14 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Lunt
8
8
  bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
- dependencies: []
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rake
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
12
26
  description: an automatic unit test system that captures your usage and records it
13
27
  for future playback
14
28
  email: jefflunt@gmail.com
@@ -16,6 +30,7 @@ executables: []
16
30
  extensions: []
17
31
  extra_rdoc_files: []
18
32
  files:
33
+ - lib/example/calculator.rb
19
34
  - lib/stable.rb
20
35
  - lib/stable/configuration.rb
21
36
  - lib/stable/spec.rb