Class: Ruber::RSpec::ProjectWidget

Inherits:
ProjectConfigWidget show all
Defined in:
plugins/rspec/rspec.rb,
plugins/rspec/rspec.rb

Overview

Project widget for the RSpec frontend plugin

Instance Attribute Summary

Attributes inherited from ProjectConfigWidget

project

Instance Method Summary (collapse)

API for feature rspec

Constructor Details

- (ProjectWidget) initialize(prj)

A new instance of ProjectWidget

Parameters:

  • prj (Qt::Widget, nil)

    the parent widget



976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
# File 'plugins/rspec/rspec.rb', line 976

def initialize prj
  super
  @ui = Ui::RSpecProjectWidget.new
  @ui.setupUi self
  view = @ui._rspec__patterns
  mod = Qt::StandardItemModel.new 
  view.model = mod
  mod.horizontal_header_labels = ['Code file', 'Spec file']
  @ui.add_pattern.connect(SIGNAL(:clicked)) do
    row = [Qt::StandardItem.new, Qt::StandardItem.new]
    mod.append_row row
    view.current_index = row[0].index
    view.edit row[0].index
  end
  @ui.remove_pattern.connect(SIGNAL(:clicked)) do
    sel = view.selection_model.selected_indexes
    mod.remove_row sel[0].row
  end
  view.selection_model.connect(SIGNAL('selectionChanged(QItemSelection,QItemSelection)')) do
    @ui.remove_pattern.enabled = view.selection_model.has_selection
  end
end

Instance Method Details

- (Array<String>) pattern (private)

Parses the content of the pattern widget

Returns:



997
998
999
# File 'plugins/rspec/rspec.rb', line 997

def pattern
  @ui._rspec__spec_pattern.text.split(/;\s*/)
end

- (Object) pattern=(value) (private)

Sets the text of the pattern widget the text to put in the widget

Parameters:

  • the (Array<String>)

    pattern to use. They’ll be joined with commas to create



989
990
991
# File 'plugins/rspec/rspec.rb', line 989

def pattern= value
  value.join ', '
end

- (Array<Hash>) patterns (private)

Parses the content of the pattern widget

Returns:

  • (Array<Hash>)

    an array containing the patterns



688
689
690
691
692
693
694
# File 'plugins/rspec/rspec.rb', line 688

def patterns
  mod = @ui._rspec__patterns.model
  mod.each_row.map do |cols|
    code = cols[0].text
    {:code => code, :spec => cols[1].text, :glob => text_glob?(code)}
  end
end

- (Object) patterns=(value) (private)

Sets the text of the pattern widget the text to put in the widget

Parameters:

  • the (Array<String>)

    pattern to use. They’ll be joined with commas to create



674
675
676
677
678
679
680
681
682
# File 'plugins/rspec/rspec.rb', line 674

def patterns= value
  view = @ui._rspec__patterns
  value.each do |h|
    row = [Qt::StandardItem.new(h[:code]), 
           Qt::StandardItem.new(h[:spec])]
    view.model.append_row row
  end
  2.times{|i| view.resize_column_to_contents i}
end

- (Array<String>) spec_options (private)

Parses the text of the “RSpec options” widget

quotes around them keep them, as described in Shellwords.split_with_quotes)

Returns:

  • (Array<String>)

    an array with the options to pass to spec (options with



1017
1018
1019
# File 'plugins/rspec/rspec.rb', line 1017

def spec_options
  Shellwords.split_with_quotes @ui._rspec__options.text
end

- (Object) spec_options=(value) (private)

Changes the text of the “RSpec options” widget

spaces

Parameters:

  • value (Array<String>)

    the options to pass to spec. They’ll be joined with



1007
1008
1009
# File 'plugins/rspec/rspec.rb', line 1007

def spec_options= value
  @ui._rspec__options.text = value.join ' '
end

- (Boolean) text_glob?(text) (private)

Returns:

  • (Boolean)


696
697
698
# File 'plugins/rspec/rspec.rb', line 696

def text_glob? text
  text=~ /[*?{}\[\]]/
end