Class: RSpec::Expectations::BlockSnippetExtractor
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/expectations/block_snippet_extractor.rb
Defined Under Namespace
Classes: BlockLocator, BlockTokenExtractor
Instance Attribute Summary collapse
-
#method_name ⇒ Object
readonly
rubocop should properly handle ‘Struct.new {}` as an inner class definition.
-
#proc ⇒ Object
readonly
rubocop should properly handle ‘Struct.new {}` as an inner class definition.
Class Method Summary collapse
Instance Method Summary collapse
-
#body_content_lines ⇒ Object
Ideally we should properly handle indentations of multiline snippet, but it’s not implemented yet since because we use result of this method only when it’s a single line and implementing the logic introduces additional complexity.
-
#initialize(proc, method_name) ⇒ BlockSnippetExtractor
constructor
A new instance of BlockSnippetExtractor.
Constructor Details
#initialize(proc, method_name) ⇒ BlockSnippetExtractor
Returns a new instance of BlockSnippetExtractor.
17 18 19 20 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/expectations/block_snippet_extractor.rb', line 17 def initialize(proc, method_name) @proc = proc @method_name = method_name.to_s.freeze end |
Instance Attribute Details
#method_name ⇒ Object (readonly)
rubocop should properly handle ‘Struct.new {}` as an inner class definition.
7 8 9 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/expectations/block_snippet_extractor.rb', line 7 def method_name @method_name end |
#proc ⇒ Object (readonly)
rubocop should properly handle ‘Struct.new {}` as an inner class definition.
7 8 9 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/expectations/block_snippet_extractor.rb', line 7 def proc @proc end |
Class Method Details
.try_extracting_single_line_body_of(proc, method_name) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/expectations/block_snippet_extractor.rb', line 9 def self.try_extracting_single_line_body_of(proc, method_name) lines = new(proc, method_name).body_content_lines return nil unless lines.count == 1 lines.first rescue Error nil end |
Instance Method Details
#body_content_lines ⇒ Object
Ideally we should properly handle indentations of multiline snippet, but it’s not implemented yet since because we use result of this method only when it’s a single line and implementing the logic introduces additional complexity.
25 26 27 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/expectations/block_snippet_extractor.rb', line 25 def body_content_lines raw_body_lines.map(&:strip).reject(&:empty?) end |