rspec-debugging 0.0.1 → 0.0.3

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: 896e136df71d2e337174b069c599e26004bc84255a13b226abe2d29aea474f1c
4
- data.tar.gz: 89ce8e417c627add4db5d53896b072fc45b00b25f478f8ee3e383242f837e0f2
3
+ metadata.gz: 36fab720f096a8d0db955d8560666e60cfb13e3346bee84fb228ab1638a6784d
4
+ data.tar.gz: f45cfa7bbc17ba60a3847c05e6feb38c3fb5dcfdeb93227e250bb8afb6cea75f
5
5
  SHA512:
6
- metadata.gz: 46ba38fe0e0e119b61f3648dc6d9b7e3661bc0fe511f710bab8d711d151c071d5ae086c637e5fe7886b3b6a661aed8175286bb7fbf0316dc6f9c86f68610c080
7
- data.tar.gz: 48f3376fc2e14099fc319e18dc64169d020eeff444d14b1452e0f75411eeb99aca47e3cc24680fb5ee5206c409c566d41e91b13b5342ce23e93d3a53476a2f4d
6
+ metadata.gz: 6f69fb8e97573a353809337c5aac04a16d4659f5b0284e126b10db367afb18db1fe493db4cc76a473a03895a3e4eb712986f0fb4b47c1c1ed5d926e4ff9eef21
7
+ data.tar.gz: 726a432e06a848ccc328b9f9ee4857f2eea2754c48520079b2547186490da7c3e18aa6701143f57eb208b92534bfb80ce8e56ffb9a5826b0c1db22c5e8e3a8d6
data/CHANGELOG.md CHANGED
@@ -1,2 +1,10 @@
1
+ ### 0.0.3 (2025-01-21)
2
+ - let_variable_reset
3
+ - test coverage
4
+ - readme
5
+
6
+ ### 0.0.2 (2025-01-14)
7
+ - dit - debugging examples
8
+
1
9
  ### 0.0.1 (2025-01-10)
2
10
  - init
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-debugging (0.0.1)
4
+ rspec-debugging (0.0.3)
5
5
  rspec-expectations (>= 3)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -4,15 +4,77 @@ rspec-debugging
4
4
  [![codecov](https://codecov.io/gh/dpep/rspec-debugging/branch/main/graph/badge.svg)](https://codecov.io/gh/dpep/rspec-debugging)
5
5
 
6
6
 
7
- Tools to make debugging RSpec easier.
7
+ Tools to make debugging RSpec tests easier.
8
+
9
+
10
+ Debug broken specs
11
+ ----
12
+ Use `dit`, `dcontext`, or `ddescribe` to run a subset of examples and and start the debugger if anything breaks.
8
13
 
9
14
  ```ruby
10
15
  require "rspec/debugging"
11
16
 
17
+ describe MySpec do
18
+ dit { is_expected.to ... }
19
+ end
20
+ ```
21
+
22
+
23
+ Stop and explore
24
+ ----
25
+ Drop `dit` anywhere to start a debugger.
12
26
 
27
+ ```ruby
28
+ describe MySpec do
29
+ dit
30
+ end
13
31
  ```
14
32
 
15
33
 
34
+ Got let variables?
35
+ ----
36
+ `let` variables are great, but complexity can obscure their value.
37
+
38
+ ```ruby
39
+ describe RSpec::Debugging do
40
+ describe RSpec::Debugging::LetVariables do
41
+ subject { a }
42
+
43
+ let(:a) { "a" }
44
+ let!(:b) { "b" }
45
+
46
+ it { is_expected.to be ??? }
47
+
48
+ context "when we nest" do
49
+ let(:a) { "A" + b }
50
+
51
+ it { is_expected.to be ??? }
52
+
53
+ context "...and nest" do
54
+ let(:a) { super() * 2 }
55
+
56
+ it { is_expected.to be ??? }
57
+ end
58
+ end
59
+ ```
60
+
61
+ ...add a hundred lines of legacy code and then solve for `a`. Or use tooling :)
62
+
63
+ ### let_variables
64
+ * Returns the list of variables defined by RSpec `let`
65
+
66
+
67
+ ### let_variable_initialized?(name)
68
+ * Has the specified let variable been initialized?
69
+
70
+
71
+ ### let_variable_get(name)
72
+ * Returns the value of a let variable, if initialized
73
+
74
+ ### let_variable_values(name)
75
+ * Return all locations where the specified variable has been defined or redefined, and it's value at each location.
76
+
77
+
16
78
  ----
17
79
  ## Contributing
18
80
 
@@ -0,0 +1,59 @@
1
+ require 'debug/session'
2
+
3
+ module RSpec
4
+ module Debugging
5
+ module DebugIt
6
+ ENABLED = ['1', 'true'].include?(ENV['RSPEC_DEBUGGING'])
7
+
8
+ def initialize(example_group_class, description, user_metadata, example_block=nil)
9
+ return super unless user_metadata[:debug] || ENABLED
10
+
11
+ if example_block
12
+ orig_example_block = example_block
13
+
14
+ example_block = Proc.new do
15
+ e = DEBUGGER__::SESSION.capture_exception_frames /(exe|bin|lib)\/rspec/ do
16
+ instance_exec(&orig_example_block)
17
+ end
18
+
19
+ if e
20
+ $stderr.puts <<~MSG
21
+
22
+ Error:
23
+ #{e.message}
24
+
25
+ MSG
26
+
27
+ DEBUGGER__::SESSION.enter_postmortem_session e
28
+ raise e
29
+ end
30
+ end # Proc.new
31
+ elsif user_metadata[:debug] && user_metadata[:skip] == RSpec::Core::Pending::NOT_YET_IMPLEMENTED
32
+ # called with no block
33
+ user_metadata.delete(:skip)
34
+
35
+ location = RSpec::Core::Metadata.relative_path(caller[2].split(":in").first)
36
+
37
+ example_block = Proc.new do
38
+ $stderr.puts <<~MSG
39
+ debugging: #{location}
40
+
41
+ MSG
42
+
43
+ debugger
44
+ end.tap do |block|
45
+ # redefine source_location to return the correct location
46
+ block.define_singleton_method(:source_location) { location.split(":") }
47
+ end
48
+ end
49
+
50
+ super
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ RSpec::Core::Example.prepend RSpec::Debugging::DebugIt
57
+ RSpec::Core::ExampleGroup.define_example_method(:dit, debug: true, focus: true)
58
+ RSpec::Core::ExampleGroup.define_example_group_method(:ddescribe, debug: true, focus: true)
59
+ RSpec::Core::ExampleGroup.define_example_group_method(:dcontext, debug: true, focus: true)
@@ -13,6 +13,10 @@ module RSpec
13
13
  __memoized.instance_variable_get("@memoized")[name]
14
14
  end
15
15
 
16
+ def let_variable_reset(name)
17
+ __memoized.instance_variable_get("@memoized").delete(name)
18
+ end
19
+
16
20
  def let_variable_locations(name)
17
21
  let_variable_methods(self)[name].map do |fn|
18
22
  normalize_path(fn.source_location.join(":"))
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module Debugging
3
- VERSION = Gem.loaded_specs["rspec-debugging"].version.to_s
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -1,5 +1,6 @@
1
1
  require "rspec/expectations"
2
2
 
3
+ require "rspec/debugging/debug_it"
3
4
  require "rspec/debugging/let_variables"
4
5
  require "rspec/debugging/version"
5
6
 
@@ -5,8 +5,8 @@ Gem::Specification.new do |s|
5
5
  s.homepage = "https://github.com/dpep/rspec-debugging"
6
6
  s.license = "MIT"
7
7
  s.name = File.basename(__FILE__, ".gemspec")
8
- s.summary = "RSpec::Debugging"
9
- s.version = "0.0.1"
8
+ s.summary = s.description
9
+ s.version = "0.0.3"
10
10
 
11
11
  s.required_ruby_version = ">= 3.1"
12
12
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-debugging
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Pepper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-11 00:00:00.000000000 Z
11
+ date: 2025-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-expectations
@@ -79,6 +79,7 @@ files:
79
79
  - README.md
80
80
  - lib/rspec-debugging.rb
81
81
  - lib/rspec/debugging.rb
82
+ - lib/rspec/debugging/debug_it.rb
82
83
  - lib/rspec/debugging/let_variables.rb
83
84
  - lib/rspec/debugging/version.rb
84
85
  - rspec-debugging.gemspec
@@ -104,5 +105,5 @@ requirements: []
104
105
  rubygems_version: 3.5.23
105
106
  signing_key:
106
107
  specification_version: 4
107
- summary: RSpec::Debugging
108
+ summary: Tools to improve debugging in RSpec
108
109
  test_files: []