rspec_tree 0.1.1 → 0.1.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: 69bf1c38057249aa20f8c357e0fe54d8f64928573890e834a5128c88942ee5f7
4
- data.tar.gz: bc57d17307869b055d41b1b1278cd5d9c3fcc8434b582ae4441fbdfc4ef34d15
3
+ metadata.gz: f1d9e799aa7b3e41c8a9e3a874fc6118dee71641bf44c9912ec5a4a91b5af1ec
4
+ data.tar.gz: bdc2b58ef18964025325832d8767206fcd10e73e931e55605313d1fdc51e32f8
5
5
  SHA512:
6
- metadata.gz: 753d815cb5cfd6d846810f2580318f6beb136c63b4bd73f5b84332dd84608a48522d04b8570c262b6fbc53f6013db853d380eceda00cbd02c69efbd6487c703d
7
- data.tar.gz: 2e34458c6ccf09e8f3ddc92e5a4c94cef7692da9bde50d3d20de33c1c353a7e6d6e6317d14ba8eac099558121052a10afa5375358ac3e21472344cc7a530fdf4
6
+ metadata.gz: d411f6635d841e6aaec75577b26a8a8ba7c3236dfbf7c18672af0105fa20a47f52b06956076ec4e6e6ae2f7e705601738f4812ef58eb23093cc0c0e4724ff3b5
7
+ data.tar.gz: 176b03ecda162178c62477b9ad22f26d9c1fedb0cfdee2b9a56813b5ac99c36a7b885c7ce395faaa4d38c2a1f6bd9c6450a4473fa1c90f6e095e5376a27addb3
data/CHANGELOG.md CHANGED
@@ -1,9 +1,15 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.1.0] - 2024-03-07
3
+ ## [0.1.2] - 2024-03-17
4
4
 
5
- - Initial release
5
+ - Fix nested context
6
+ - Support context mode
6
7
 
7
8
  ## [0.1.1] - 2024-03-16
8
9
 
9
10
  - Fix commnad description
11
+
12
+ ## [0.1.0] - 2024-03-07
13
+
14
+ - Initial release
15
+
data/README.md CHANGED
@@ -1,24 +1,50 @@
1
1
  # RspecTree
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
4
-
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rspec_tree`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ This is tree command for rspec test files.
6
4
 
7
5
  ## Installation
8
6
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
-
11
7
  Install the gem and add to the application's Gemfile by executing:
12
8
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
9
+ $ bundle add rspec_tree
14
10
 
15
11
  If bundler is not being used to manage dependencies, install the gem by executing:
16
12
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
13
+ $ gem install rspec_tree
18
14
 
19
15
  ## Usage
20
16
 
21
- TODO: Write usage instructions here
17
+ ```
18
+ $ rspec_tree all /path/to/your_spec.rb
19
+ desc: Sample
20
+ desc: First describe
21
+ ├─────ctx: First context
22
+ ├───────it: should do something
23
+ ├───────ctx: First nested context
24
+ ├─────────it: should do something
25
+ ├───────it_behaves_like: shared example
26
+ desc: Second describe
27
+ ├─────ctx: Second context
28
+ ├───────it: should do something else
29
+ ```
30
+
31
+ ```
32
+ $ rspec_tree ctx /path/to/your_spec.rb
33
+ desc: Sample
34
+ desc: First describe
35
+ ├─────ctx: First context
36
+ ├───────ctx: First nested context
37
+ desc: Second describe
38
+ ├─────ctx: Second context
39
+ ```
40
+
41
+ ```
42
+ $ rspec_tree help
43
+ Commands:
44
+ rspec_tree all [file] # Print all (describe, context, it, etc.)
45
+ rspec_tree ctx [file] # Print only describe and context
46
+ rspec_tree help [COMMAND] # Describe available commands or one specific command
47
+ ```
22
48
 
23
49
  ## Development
24
50
 
@@ -28,7 +54,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
28
54
 
29
55
  ## Contributing
30
56
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rspec_tree. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/rspec_tree/blob/master/CODE_OF_CONDUCT.md).
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sasamuku/rspec_tree. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/rspec_tree/blob/master/CODE_OF_CONDUCT.md).
32
58
 
33
59
  ## License
34
60
 
data/exe/rspec_tree CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "rspec_tree"
4
5
 
@@ -1,19 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "thor"
2
4
  require "rspec_tree/tree"
3
5
 
4
6
  module RspecTree
7
+ # This class is used to define the CLI
5
8
  class CLI < Thor
6
9
  desc "all [file]", "Print all (describe, context, it, etc.)"
7
10
  def all(file)
8
11
  File.open(file, "r") do |f|
9
- Tree.all(f.read)
12
+ Tree.new(f.read, :all).print
10
13
  end
11
14
  end
12
15
 
13
16
  desc "ctx [file]", "Print only describe and context"
14
17
  def ctx(file)
15
18
  File.open(file, "r") do |f|
16
- Tree.ctx(f.read)
19
+ Tree.new(f.read, :ctx).print
17
20
  end
18
21
  end
19
22
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RspecTree
4
+ # This is a monkey patch to override basic behavior
5
+ class Tree
6
+ Class.class_eval do
7
+ def const_missing(name)
8
+ name.to_s
9
+ end
10
+ end
11
+
12
+ private
13
+
14
+ def require_relative(file); end
15
+
16
+ def require(file); end
17
+
18
+ def include(*args); end
19
+
20
+ def method_missing(method, *args, &block); end
21
+
22
+ def respond_to_missing?(method, *)
23
+ super
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RspecTree
4
+ class Tree
5
+ # This module is used to override the RSpec module
6
+ module RSpec
7
+ class << self
8
+ def describe(*args, &block)
9
+ puts "desc: #{args.first}"
10
+ block.call
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,63 +1,55 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "tree/rspec"
4
+ require_relative "tree/monkey_patch"
5
+
3
6
  module RspecTree
4
- module Tree
5
- Class.class_eval do
6
- def const_missing(name)
7
- name.to_s
8
- end
7
+ # This module is used to parse the RSpec file
8
+ # and print the tree structure of the RSpec file.
9
+ class Tree
10
+ attr_reader :file, :type
11
+ attr_accessor :base_depth
12
+
13
+ def initialize(file, type)
14
+ @file = file
15
+ @type = type
16
+ @base_depth = 0
9
17
  end
10
18
 
11
- module RSpec
12
- class << self
13
- def describe(*args, &block)
14
- puts "desc: #{args.first}"
15
- block.call
16
- end
17
- end
19
+ def print
20
+ eval(file) # rubocop:disable Security/Eval
18
21
  end
19
22
 
20
- class << self
21
- # @param [String] file
22
- def all(file)
23
- eval(file)
24
- end
25
-
26
- # TODO: to be implemented
27
- def ctx(file)
28
- eval(file)
29
- end
30
-
31
- private
23
+ private
32
24
 
33
- def describe(*args, &block)
34
- RSpec.describe(*args, &block)
35
- end
36
-
37
- def context(*args, &block)
38
- puts "├──ctx: #{args.first}"
39
- block.call
40
- end
41
-
42
- def example(*args, &block)
43
- puts "├────ex: #{args.first}"
44
- end
25
+ def describe(*args, &block)
26
+ self.base_depth = caller.size
27
+ RSpec.describe(*args, &block)
28
+ end
45
29
 
46
- def it(*args, &block)
47
- puts "├────it: #{args.first}"
48
- end
30
+ def context(*args, &block)
31
+ tree(args.first, "ctx")
32
+ block.call
33
+ end
49
34
 
50
- def it_behaves_like(*args, &block)
51
- puts "├────it_behaves_like: #{args.first}"
52
- end
35
+ def example(*args, &_block)
36
+ tree(args.first, "ex")
37
+ end
53
38
 
54
- def require_relative(file); end
39
+ def it(*args, &_block)
40
+ tree(args.first, "it") if type == :all
41
+ end
55
42
 
56
- def require(file); end
43
+ def it_behaves_like(*args, &_block)
44
+ tree(args.first, "it_behaves_like") if type == :all
45
+ end
57
46
 
58
- def include(*args); end
47
+ def dash
48
+ "─" * (caller.size - base_depth)
49
+ end
59
50
 
60
- def method_missing(method, *args, &block); end
51
+ def tree(arg, name)
52
+ puts "├#{dash}#{name}: #{arg}"
61
53
  end
62
54
  end
63
55
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RspecTree
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - sasamuku
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-16 00:00:00.000000000 Z
11
+ date: 2024-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -45,6 +45,8 @@ files:
45
45
  - lib/rspec_tree.rb
46
46
  - lib/rspec_tree/cli.rb
47
47
  - lib/rspec_tree/tree.rb
48
+ - lib/rspec_tree/tree/monkey_patch.rb
49
+ - lib/rspec_tree/tree/rspec.rb
48
50
  - lib/rspec_tree/version.rb
49
51
  - rspec_tree.gemspec
50
52
  - sig/rspec_tree.rbs
@@ -70,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
72
  - !ruby/object:Gem::Version
71
73
  version: '0'
72
74
  requirements: []
73
- rubygems_version: 3.3.22
75
+ rubygems_version: 3.5.6
74
76
  signing_key:
75
77
  specification_version: 4
76
78
  summary: tree command for rspec test files.