Class: Example
- Inherits:
-
Object
- Object
- Example
- Defined in:
- lib/rspec_examples.rb
Instance Attribute Summary collapse
-
#all ⇒ Object
readonly
Returns the value of attribute all.
-
#contexts ⇒ Object
readonly
Returns the value of attribute contexts.
-
#describes ⇒ Object
readonly
Returns the value of attribute describes.
-
#its ⇒ Object
readonly
Returns the value of attribute its.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
-
#initialize(path) ⇒ Example
constructor
A new instance of Example.
- #matches(word, type) ⇒ Object
- #name ⇒ Object
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
#all ⇒ Object (readonly)
Returns the value of attribute all.
20 21 22 |
# File 'lib/rspec_examples.rb', line 20 def all @all end |
#contexts ⇒ Object (readonly)
Returns the value of attribute contexts.
20 21 22 |
# File 'lib/rspec_examples.rb', line 20 def contexts @contexts end |
#describes ⇒ Object (readonly)
Returns the value of attribute describes.
20 21 22 |
# File 'lib/rspec_examples.rb', line 20 def describes @describes end |
#its ⇒ Object (readonly)
Returns the value of attribute its.
20 21 22 |
# File 'lib/rspec_examples.rb', line 20 def its @its end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
20 21 22 |
# File 'lib/rspec_examples.rb', line 20 def path @path end |
#results ⇒ Object (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 |
#name ⇒ Object
37 38 39 |
# File 'lib/rspec_examples.rb', line 37 def name @path.match(/^.*gems\/(.*)\/spec\//)[1] end |