Class: TestParser::Parser::RSpec

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/test_parser/parser/rspec.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common

#build_test, #parser_type

Constructor Details

#initialize(example) ⇒ RSpec

Returns a new instance of RSpec.



34
35
36
# File 'lib/test_parser/parser/rspec.rb', line 34

def initialize(example)
  @example = example
end

Instance Attribute Details

#exampleObject (readonly)

Returns the value of attribute example.



11
12
13
# File 'lib/test_parser/parser/rspec.rb', line 11

def example
  @example
end

Class Method Details

.find_tests(path, options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/test_parser/parser/rspec.rb', line 17

def self.find_tests(path, options = {})
  glob = options[:glob] || 'spec/**/*_spec.rb'

  ::RSpec.with_world ::RSpec::Core::World.new do |world|

    TestParser.require_all(path, glob)

    groups   = world.example_groups
    examples = groups.collect_concat(&:descendant_filtered_examples)
    examples.map do |example|
      new(example).build_test
    end
  end
end

.typeObject



13
14
15
# File 'lib/test_parser/parser/rspec.rb', line 13

def self.type
  :rspec2
end

Instance Method Details

#file_nameObject



50
51
52
# File 'lib/test_parser/parser/rspec.rb', line 50

def file_name
  example.file_path
end

#identificationObject



38
39
40
# File 'lib/test_parser/parser/rspec.rb', line 38

def identification
  @identification ||= path_to_example.join('/')
end

#line_numberObject



54
55
56
# File 'lib/test_parser/parser/rspec.rb', line 54

def line_number
  example.[:line_number]
end

#snippetObject



46
47
48
# File 'lib/test_parser/parser/rspec.rb', line 46

def snippet
  @snippet ||= snippet_source.snippet
end

#snippet_sourceObject



42
43
44
# File 'lib/test_parser/parser/rspec.rb', line 42

def snippet_source
  @snippet_source ||= SnippetSource::LineNumber.new(file_name, line_number)
end