Class: Ruber::RSpec::ProjectExtension

Inherits:
Qt::Object
  • Object
show all
Includes:
Extension
Defined in:
plugins/rspec/rspec.rb

Instance Attribute Summary

Attributes included from Extension

plugin

Instance Method Summary (collapse)

Methods included from Extension

#query_close, #remove_from_project, #save_settings, #shutdown

API for feature rspec

Constructor Details

- (ProjectExtension) initialize(prj)

A new instance of ProjectExtension



571
572
573
574
575
576
# File 'plugins/rspec/rspec.rb', line 571

def initialize prj
  super
  @project = prj
  @categories = {}
  connect Ruber[:rspec], SIGNAL(:settings_changed), self, SLOT(:clear)
end

Instance Method Details

- (Object) category(file)



609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
# File 'plugins/rspec/rspec.rb', line 609

def category file
  cat = @categories[file]
  return cat if cat
  spec_dir = @project[:rspec, :spec_directory, :abs]
  code_dir = @project[:rspec, :code_directory, :abs]
  if @project.file_in_project? file
    if file.start_with? spec_dir
      if File.fnmatch @project[:rspec, :spec_files], file.sub(spec_dir + '/', '')
        @categories[file] = :spec
      else @categories[file] = :unknown
      end
    elsif file.start_with?(code_dir) and @project.file_in_project?(file)
      @categories[file] = :code
    else @categories[file] = :unknown
    end
  else @categories[file] = :unknown
  end
end

- (Object) clear



628
629
630
# File 'plugins/rspec/rspec.rb', line 628

def clear
  @categories.clear
end

Slot Signature:

clear()

- (Boolean) code_file?(file)

Returns:

  • (Boolean)


601
602
603
# File 'plugins/rspec/rspec.rb', line 601

def code_file? file
  category(file) == :code
end

- (Object) code_for_spec(file)



593
594
595
596
597
598
599
# File 'plugins/rspec/rspec.rb', line 593

def code_for_spec file
  return nil unless @project.file_in_project? file
  return nil unless spec_file? file
  @project.project_files.find do |f|
    specs_for_code(f).include? file
  end
end

- (Boolean) spec_file?(file)

Returns:

  • (Boolean)


605
606
607
# File 'plugins/rspec/rspec.rb', line 605

def spec_file? file
  category(file) == :spec
end

- (Object) specs_for_code(file)



578
579
580
581
582
583
584
585
586
587
588
589
590
591
# File 'plugins/rspec/rspec.rb', line 578

def specs_for_code file
  return [] unless @project.file_in_project? file
  return [] unless code_file? file
  file.sub(@project.project_directory + '/', '')
  res = []
  @project[:rspec, :patterns].each do |pn|
    if File.fnmatch pn[:code], file
      basename = Ruber[:rspec].spec_for_pattern pn, file
      spec = File.join(@project.project_directory, @project[:rspec, :spec_directory], basename)
      res << spec
    end
  end
  res.select{|f| File.exist? f}
end