Class: Example

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_examples.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Example

Returns a new instance of Example.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rspec_examples.rb', line 22

def initialize path
  raise ('argument must be path to spec file') unless valid?(path)
  @path = path
  @all = open(path).read
  @results = []
  types = %w(describe context it)
  types.each{|type| self.instance_variable_set("@#{type}s",[])}
  
  @all.each_line do |line|
    types.each do |type|
      examples(type) << line.chomp.strip if line =~ /.*#{type} .* do$/
    end
  end
end

Instance Attribute Details

#allObject (readonly)

Returns the value of attribute all.



20
21
22
# File 'lib/rspec_examples.rb', line 20

def all
  @all
end

#contextsObject (readonly)

Returns the value of attribute contexts.



20
21
22
# File 'lib/rspec_examples.rb', line 20

def contexts
  @contexts
end

#describesObject (readonly)

Returns the value of attribute describes.



20
21
22
# File 'lib/rspec_examples.rb', line 20

def describes
  @describes
end

#itsObject (readonly)

Returns the value of attribute its.



20
21
22
# File 'lib/rspec_examples.rb', line 20

def its
  @its
end

#pathObject (readonly)

Returns the value of attribute path.



20
21
22
# File 'lib/rspec_examples.rb', line 20

def path
  @path
end

#resultsObject (readonly)

Returns the value of attribute results.



20
21
22
# File 'lib/rspec_examples.rb', line 20

def results
  @results
end

Instance Method Details

#matches(word, type) ⇒ Object



41
42
43
44
45
46
# File 'lib/rspec_examples.rb', line 41

def matches word, type
  if examples(type).any?
    @results = examples(type).select{|example| example.include? word}
  end
  @results.any? ? @results : false
end

#nameObject



37
38
39
# File 'lib/rspec_examples.rb', line 37

def name
  @path.match(/^.*gems\/(.*)\/spec\//)[1]
end