Class: RailChaser::ExampleCollection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ExampleCollection

Returns a new instance of ExampleCollection.



5
6
7
8
# File 'lib/rail_chaser/example_collection.rb', line 5

def initialize(options={})
  @examples = Hash.new { |h, spec| h[spec] = [] }
  @options = options
end

Instance Attribute Details

#examplesObject

Returns the value of attribute examples.



3
4
5
# File 'lib/rail_chaser/example_collection.rb', line 3

def examples
  @examples
end

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/rail_chaser/example_collection.rb', line 3

def options
  @options
end

Instance Method Details

#add_class?(file, classes) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
# File 'lib/rail_chaser/example_collection.rb', line 26

def add_class?(file, classes)
  return false if @options[:skip_spec] && spec?(file)
  return false if @options[:skip_gem] && gem?(file)
  return false if @options[:skip_ruby_core] && ruby_core?(file)
  return false if classes.include?(file)
  return true
end

#add_example(file) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/rail_chaser/example_collection.rb', line 34

def add_example(file)
  @spec = file if spec?(file)

  if @spec
    classes = @examples[@spec]
    classes << file if add_class?(file, classes)
  end
end

#classesObject



51
52
53
# File 'lib/rail_chaser/example_collection.rb', line 51

def classes
  @examples.values.flatten.uniq
end

#each_spec_and_classesObject



43
44
45
46
47
48
49
# File 'lib/rail_chaser/example_collection.rb', line 43

def each_spec_and_classes
  if block_given?
    @examples.each_pair do |spec, classes|
      yield spec, classes
    end
  end
end

#gem?(file) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/rail_chaser/example_collection.rb', line 14

def gem?(file)
  file =~ gem_path_pattern
end

#gem_path_patternObject



10
11
12
# File 'lib/rail_chaser/example_collection.rb', line 10

def gem_path_pattern
  @gem_path_pattern ||= Regexp.compile ENV['GEM_HOME'].gsub(':', '|')
end

#ruby_core?(file) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/rail_chaser/example_collection.rb', line 18

def ruby_core?(file)
  file =~ /#{ENV['MY_RUBY_HOME']}/
end

#spec?(file) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/rail_chaser/example_collection.rb', line 22

def spec?(file)
  file =~ /\/spec\//
end